Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseListener"/> class.
        /// </summary>
        /// <param name="logger">A reference to the logger in use.</param>
        /// <param name="options">The options for this listener.</param>
        /// <param name="socketConnectionFactory">A reference to the socekt connection factory in use.</param>
        /// <param name="dosDefender">A reference to a DoS defender service implementation.</param>
        /// <param name="keepConnectionOpen">Optional. A value indicating whether to maintain the connection open after processing a message in the connection.</param>
        /// <param name="tcpListener">Optional. An intance to use as the TCP listener, useful for unit testing.</param>
        protected BaseListener(ILogger logger, BaseListenerOptions options, ISocketConnectionFactory socketConnectionFactory, IDoSDefender dosDefender, bool keepConnectionOpen = true, ITcpListener tcpListener = null)
        {
            logger.ThrowIfNull(nameof(logger));
            options.ThrowIfNull(nameof(options));
            socketConnectionFactory.ThrowIfNull(nameof(socketConnectionFactory));

            DataAnnotationsValidator.ValidateObjectRecursive(options);

            this.dosDefender             = dosDefender;
            this.keepConnectionOpen      = keepConnectionOpen;
            this.socketConnectionFactory = socketConnectionFactory;

            this.tcpListener = tcpListener ?? new FibulaTcpListener(IPAddress.Any, options?.Port ?? 0);

            this.Logger = logger.ForContext(this.GetType());
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseTcpListener"/> class.
        /// </summary>
        /// <param name="logger">A reference to the logger in use.</param>
        /// <param name="options">The options for this listener.</param>
        /// <param name="socketConnectionFactory">A reference to the socekt connection factory in use.</param>
        /// <param name="dosDefender">A reference to a DoS defender service implementation.</param>
        /// <param name="keepConnectionOpen">Optional. A value indicating whether to maintain the connection open after processing a message in the connection.</param>
        protected BaseTcpListener(ILogger logger, BaseTcpListenerOptions options, ISocketConnectionFactory socketConnectionFactory, IDoSDefender dosDefender, bool keepConnectionOpen = true)
        {
            logger.ThrowIfNull(nameof(logger));
            options.ThrowIfNull(nameof(options));
            socketConnectionFactory.ThrowIfNull(nameof(socketConnectionFactory));

            DataAnnotationsValidator.ValidateObjectRecursive(options);

            this.dosDefender             = dosDefender;
            this.keepConnectionOpen      = keepConnectionOpen;
            this.socketConnectionFactory = socketConnectionFactory;

            this.internalListener = new TcpListener(IPAddress.Any, options?.Port ?? 0);

            this.Logger = logger;
        }