コード例 #1
0
 public virtual async Task BindAsync(ReplicaAddressBindContext context)
 {
     foreach (var endpoint in _endpoints)
     {
         await endpoint.BindAsync(context).ConfigureAwait(false);
     }
 }
コード例 #2
0
        internal override async Task BindAsync(ReplicaAddressBindContext context)
        {
            var exceptions = new List <Exception>();

            try
            {
                var v4Options = Clone(IPAddress.Loopback);
                await ReplicaAddressBinder.BindEndpointAsync(v4Options, context).ConfigureAwait(false);
            }
            catch (Exception ex) when(!(ex is IOException))
            {
                context.Logger.LogWarning(0, ReplicaCoreStrings.NetworkInterfaceBindingFailed, GetDisplayName(), "IPv4 loopback", ex.Message);
                exceptions.Add(ex);
            }

            try
            {
                var v6Options = Clone(IPAddress.IPv6Loopback);
                await ReplicaAddressBinder.BindEndpointAsync(v6Options, context).ConfigureAwait(false);
            }
            catch (Exception ex) when(!(ex is IOException))
            {
                context.Logger.LogWarning(0, ReplicaCoreStrings.NetworkInterfaceBindingFailed, GetDisplayName(), "IPv6 loopback", ex.Message);
                exceptions.Add(ex);
            }

            if (exceptions.Count == 2)
            {
                throw new IOException(ReplicaCoreStrings.FormatAddressBindingFailed(GetDisplayName()), new AggregateException(exceptions));
            }

            // If StartLocalhost doesn't throw, there is at least one listener.
            // The port cannot change for "localhost".
            context.Addresses.Add(GetDisplayName());
        }
コード例 #3
0
        public static async Task BindAsync(IServerAddressesFeature addresses,
                                           ReplicaKestrelServerOptions serverOptions,
                                           ILogger logger,
                                           Func <ReplicaListenOptions, Task> createBinding)
        {
            var listenOptions = serverOptions.ListenOptions;
            var strategy      = CreateStrategy(
                listenOptions.ToArray(),
                addresses.Addresses.ToArray(),
                addresses.PreferHostingUrls);

            var context = new ReplicaAddressBindContext
            {
                Addresses     = addresses.Addresses,
                ListenOptions = listenOptions,
                ServerOptions = serverOptions,
                Logger        = logger,
                CreateBinding = createBinding
            };

            // reset options. The actual used options and addresses will be populated
            // by the address binding feature
            listenOptions.Clear();
            addresses.Addresses.Clear();

            await strategy.BindAsync(context).ConfigureAwait(false);
        }
コード例 #4
0
            public async Task BindAsync(ReplicaAddressBindContext context)
            {
                var httpDefault = ParseAddress(ReplicaConstants.DefaultServerAddress, out var https);

                context.ServerOptions.ApplyEndpointDefaults(httpDefault);
                await httpDefault.BindAsync(context).ConfigureAwait(false);

                // Conditional https default, only if a cert is available
                var httpsDefault = ParseAddress(ReplicaConstants.DefaultServerHttpsAddress, out https);

                context.ServerOptions.ApplyEndpointDefaults(httpsDefault);

                if (httpsDefault.ConnectionAdapters.Any(f => f.IsHttps) ||
                    httpsDefault.TryUseHttps())
                {
                    await httpsDefault.BindAsync(context).ConfigureAwait(false);

                    context.Logger.LogDebug(ReplicaCoreStrings.BindingToDefaultAddresses,
                                            ReplicaConstants.DefaultServerAddress, ReplicaConstants.DefaultServerHttpsAddress);
                }
                else
                {
                    // No default cert is available, do not bind to the https endpoint.
                    context.Logger.LogDebug(ReplicaCoreStrings.BindingToDefaultAddress, ReplicaConstants.DefaultServerAddress);
                }
            }
コード例 #5
0
            public override Task BindAsync(ReplicaAddressBindContext context)
            {
                var joined = string.Join(", ", _originalAddresses);

                context.Logger.LogWarning(ReplicaCoreStrings.OverridingWithKestrelOptions, joined, "UseKestrel()");

                return(base.BindAsync(context));
            }
コード例 #6
0
            public override Task BindAsync(ReplicaAddressBindContext context)
            {
                var joined = string.Join(", ", _addresses);

                context.Logger.LogInformation(ReplicaCoreStrings.OverridingWithPreferHostingUrls, nameof(IServerAddressesFeature.PreferHostingUrls), joined);

                return(base.BindAsync(context));
            }
コード例 #7
0
        internal static async Task BindEndpointAsync(ReplicaListenOptions endpoint, ReplicaAddressBindContext context)
        {
            try
            {
                await context.CreateBinding(endpoint).ConfigureAwait(false);
            }
            catch (AddressInUseException ex)
            {
                throw new IOException(ReplicaCoreStrings.FormatEndpointAlreadyInUse(endpoint), ex);
            }

            context.ListenOptions.Add(endpoint);
        }
コード例 #8
0
            public virtual async Task BindAsync(ReplicaAddressBindContext context)
            {
                foreach (var address in _addresses)
                {
                    var options = ParseAddress(address, out var https);
                    context.ServerOptions.ApplyEndpointDefaults(options);

                    if (https && !options.ConnectionAdapters.Any(f => f.IsHttps))
                    {
                        options.UseHttps();
                    }

                    await options.BindAsync(context).ConfigureAwait(false);
                }
            }
コード例 #9
0
        internal override async Task BindAsync(ReplicaAddressBindContext context)
        {
            // when address is 'http://hostname:port', 'http://*:port', or 'http://+:port'
            try
            {
                await base.BindAsync(context).ConfigureAwait(false);
            }
            catch (Exception ex) when(!(ex is IOException))
            {
                context.Logger.LogDebug(ReplicaCoreStrings.FormatFallbackToIPv4Any(IPEndPoint.Port));

                // for machines that do not support IPv6
                IPEndPoint = new IPEndPoint(IPAddress.Any, IPEndPoint.Port);
                await base.BindAsync(context).ConfigureAwait(false);
            }
        }