Exemplo n.º 1
0
        // For testing
        internal KestrelServerImpl(
            IEnumerable <IConnectionListenerFactory> transportFactories,
            IEnumerable <IMultiplexedConnectionListenerFactory> multiplexedFactories,
            ServiceContext serviceContext)
        {
            if (transportFactories == null)
            {
                throw new ArgumentNullException(nameof(transportFactories));
            }

            _transportFactory            = transportFactories?.LastOrDefault();
            _multiplexedTransportFactory = multiplexedFactories?.LastOrDefault();

            if (_transportFactory == null && _multiplexedTransportFactory == null)
            {
                throw new InvalidOperationException(CoreStrings.TransportNotFound);
            }

            ServiceContext = serviceContext;

            Features         = new FeatureCollection();
            _serverAddresses = new ServerAddressesFeature();
            Features.Set <IServerAddressesFeature>(_serverAddresses);

            _transportManager = new TransportManager(_transportFactory, _multiplexedTransportFactory, ServiceContext);

            HttpCharacters.Initialize();
        }
Exemplo n.º 2
0
        public async Task StartAsync(ILogger <Local> logger,
                                     IConnectionListenerFactory listenerFactory,
                                     string localListenAddress,
                                     int localListenPort,
                                     string remoteAddress,
                                     int remotePort)
        {
            this.logger        = logger;
            this.remoteAddress = remoteAddress;
            this.remotePort    = remotePort;

            try
            {
                var bind = await listenerFactory.BindAsync(new IPEndPoint(IPAddress.Parse(localListenAddress), localListenPort));

                logger.LogInformation($"客户端正在监听{localListenPort}端口");

                while (true)
                {
                    ConnectionContext browser = await bind.AcceptAsync();

                    TcpHandlerAsync(browser);
                }
            }
            catch (Exception ex)
            {
                logger.LogCritical(ex.Message);
            }
        }
Exemplo n.º 3
0
 public GatewayConnectionListener(
     IServiceProvider serviceProvider,
     IOptions <ConnectionOptions> connectionOptions,
     IConnectionListenerFactory listenerFactory,
     MessageFactory messageFactory,
     OverloadDetector overloadDetector,
     Gateway gateway,
     INetworkingTrace trace,
     ILocalSiloDetails localSiloDetails,
     IOptions <MultiClusterOptions> multiClusterOptions,
     IOptions <EndpointOptions> endpointOptions,
     MessageCenter messageCenter,
     ISiloStatusOracle siloStatusOracle)
     : base(serviceProvider, listenerFactory, connectionOptions, trace)
 {
     this.messageFactory      = messageFactory;
     this.overloadDetector    = overloadDetector;
     this.gateway             = gateway;
     this.trace               = trace;
     this.localSiloDetails    = localSiloDetails;
     this.multiClusterOptions = multiClusterOptions;
     this.messageCenter       = messageCenter;
     this.siloStatusOracle    = siloStatusOracle;
     this.endpointOptions     = endpointOptions.Value;
 }
Exemplo n.º 4
0
 protected ConnectionListener(
     IServiceProvider serviceProvider,
     IConnectionListenerFactory listenerFactory,
     IOptions <ConnectionOptions> connectionOptions,
     INetworkingTrace trace)
 {
     this.ServiceProvider   = serviceProvider;
     this.listenerFactory   = listenerFactory;
     this.ConnectionOptions = connectionOptions.Value;
     this.trace             = trace;
 }
 protected ConnectionListener(
     IConnectionListenerFactory listenerFactory,
     IOptions <ConnectionOptions> connectionOptions,
     ConnectionManager connectionManager,
     ConnectionCommon connectionShared)
 {
     this.listenerFactory   = listenerFactory;
     this.connectionManager = connectionManager;
     this.ConnectionOptions = connectionOptions.Value;
     this.connectionShared  = connectionShared;
 }
Exemplo n.º 6
0
        public KestrelServer(IConnectionListenerFactory transportFactory, IOptions <KestrelServerOptions> options, ILoggerFactory loggerFactory)
        {
            _transportFactory = transportFactory;
            ServerOptions     = options.Value;
            var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel");

            ServiceContext = new ServiceContext()
            {
                Logger = logger
            };
        }
Exemplo n.º 7
0
        public Local(IConnectionListenerFactory connectionListenerFactory,
                     IConfiguration configuration,
                     ILogger <Local> logger)
        {
            this.connectionListenerFactory = connectionListenerFactory;
            this.logger   = logger;
            remoteAddress = configuration["RemoteConnectAddress"];
            if (string.IsNullOrEmpty(remoteAddress))
            {
                throw new Exception(nameof(remoteAddress) + " is null");
            }
            if (!int.TryParse(configuration["RemoteConnectPort"], out int remotePort))
            {
                remotePort = 2020;
            }

            this.remotePort = remotePort;
        }
Exemplo n.º 8
0
 public SiloConnectionListener(
     IServiceProvider serviceProvider,
     IOptions <ConnectionOptions> connectionOptions,
     IConnectionListenerFactory listenerFactory,
     MessageCenter messageCenter,
     MessageFactory messageFactory,
     INetworkingTrace trace,
     IOptions <EndpointOptions> endpointOptions,
     ILocalSiloDetails localSiloDetails,
     ConnectionManager connectionManager)
     : base(serviceProvider, listenerFactory, connectionOptions, connectionManager, trace)
 {
     this.messageCenter     = messageCenter;
     this.messageFactory    = messageFactory;
     this.trace             = trace;
     this.localSiloDetails  = localSiloDetails;
     this.connectionManager = connectionManager;
     this.endpointOptions   = endpointOptions.Value;
 }
Exemplo n.º 9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            IConnectionListenerFactory listenerFactory = app.ApplicationServices.GetRequiredService <IConnectionListenerFactory>();

            Task.Run(async() =>
            {
                try
                {
                    var listener = await listenerFactory.BindAsync(new IPEndPoint(IPAddress.Any, 2019));

                    while (true)
                    {
                        ConnectionContext browser = await listener.AcceptAsync();
                        //处理浏览器
                        ProcessBrowserAsync(browser);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            });
        }
Exemplo n.º 10
0
 // For testing
 internal KestrelServerImpl(IConnectionListenerFactory transportFactory, ServiceContext serviceContext)
     : this(new[] { transportFactory }, null, serviceContext)
 {
 }
Exemplo n.º 11
0
 public LocalHostBinding(int port, ConnectionDelegate application, IConnectionListenerFactory connectionListenerFactory)
 {
     Port         = port;
     _application = application;
     ConnectionListenerFactory = connectionListenerFactory;
 }
Exemplo n.º 12
0
 public RSocketHost(IConnectionListenerFactory connectionListenerFactory, ILogger <RSocketHost> logger)
 {
     _connectionListenerFactory = connectionListenerFactory;
     _logger = logger;
 }
Exemplo n.º 13
0
        public static ServerBuilder Listen(this ServerBuilder builder, EndPoint endPoint, IConnectionListenerFactory connectionListenerFactory, Action <IConnectionBuilder> configure)
        {
            var connectionBuilder = new ConnectionBuilder(builder.ApplicationServices);

            configure(connectionBuilder);
            builder.Bindings.Add(new EndPointBinding(endPoint, connectionBuilder.Build(), connectionListenerFactory));
            return(builder);
        }
Exemplo n.º 14
0
        public async ValueTask <IConnectionListener> BindAsync(EndPoint endpoint, CancellationToken cancellationToken = default)
        {
            IPEndPoint iPEndPoint = null;

            switch (endpoint)
            {
            // Kestrel doesn't natively support UriEndpoints as yet
            case UriEndPoint uriEndPoint:
                IPAddress address = null;
                if (uriEndPoint.Uri.Host == "localhost")
                {
                    address = IPAddress.Loopback;
                }
                else
                {
                    IPAddress.Parse(uriEndPoint.Uri.Host);
                }
                iPEndPoint = new IPEndPoint(address, uriEndPoint.Uri.Port);
                break;

            case IPEndPoint ip:
                iPEndPoint = ip;
                break;

            default:
                throw new NotSupportedException($"{endpoint} not supported");
            }

            var services = new ServiceCollection();

            services.AddSingleton(_loggerFactory);
            services.AddLogging();
            var serverOptions = Options.Create(new KestrelServerOptions()
            {
                ApplicationServices = services.BuildServiceProvider()
            });;
            var socketOptions          = Options.Create(new SocketTransportOptions());
            var socketTransportFactory = new SocketTransportFactory(socketOptions, _loggerFactory);
            IConnectionListenerFactory transportFactories = socketTransportFactory;


            var           server        = new KestrelServer(serverOptions, transportFactories, _loggerFactory);
            ListenOptions listenOptions = null;

            // Bind an HTTP/2 endpoint
            server.Options.Listen(iPEndPoint, options =>
            {
                options.UseHttps();
                options.Protocols = HttpProtocols.Http2;
                // Storing the options so we can get the resolved EndPoint later
                listenOptions = options;
            });

            var listener = new Http2ConnectionListener(server);

            await listener.BindAsync(cancellationToken).ConfigureAwait(false);

            listener.EndPoint = listenOptions.IPEndPoint;

            return(listener);
        }
Exemplo n.º 15
0
 public KestrelServer(IOptions <KestrelServerOptions> options, IConnectionListenerFactory transportFactory, ILoggerFactory loggerFactory)
 {
     _innerKestrelServer = new KestrelServerImpl(
         options,
         new[] { transportFactory ?? throw new ArgumentNullException(nameof(transportFactory)) },
Exemplo n.º 16
0
 public Worker(ILogger <Worker> logger, IConnectionListenerFactory factory)
 {
     _factory = factory;
     _logger  = logger;
 }
Exemplo n.º 17
0
 public EndPointBinding(EndPoint endPoint, ConnectionDelegate application, IConnectionListenerFactory connectionListenerFactory)
 {
     EndPoint     = endPoint;
     _application = application;
     ConnectionListenerFactory = connectionListenerFactory;
 }
Exemplo n.º 18
0
 public TcpEchoServer(ILogger <TcpEchoServer> logger, IConnectionListenerFactory factory)
 {
     _logger  = logger;
     _factory = factory;
 }