internal static UriPrefixTable <HandshakeDelegate> BuildAddressTable(IServiceProvider services)
        {
            var serviceBuilder    = services.GetRequiredService <IServiceBuilder>();
            var dispatcherBuilder = services.GetRequiredService <IDispatcherBuilder>();
            var addressTable      = new UriPrefixTable <HandshakeDelegate>();

            foreach (var serviceType in serviceBuilder.Services)
            {
                var dispatchers = dispatcherBuilder.BuildDispatchers(serviceType);
                foreach (var dispatcher in dispatchers)
                {
                    if (dispatcher.BaseAddress == null)
                    {
                        // TODO: Should we throw? Ignore?
                        continue;
                    }

                    // TODO: Limit to specifically TcpTransportBindingElement if net.tcp etc
                    var be    = dispatcher.Binding.CreateBindingElements();
                    var cotbe = be.Find <ConnectionOrientedTransportBindingElement>();
                    if (cotbe == null)
                    {
                        // TODO: Should we throw? Ignore?
                        continue;
                    }

                    var handshake = BuildHandshakeDelegateForDispatcher(dispatcher);
                    addressTable.RegisterUri(dispatcher.BaseAddress, cotbe.HostNameComparisonMode, handshake);
                }
            }

            return(addressTable);
        }
        internal static UriPrefixTable <HandshakeDelegate> BuildAddressTable(IServiceProvider services)
        {
            ILogger <NetMessageFramingConnectionHandler> logger = services.GetRequiredService <ILogger <NetMessageFramingConnectionHandler> >();
            IServiceBuilder    serviceBuilder    = services.GetRequiredService <IServiceBuilder>();
            IDispatcherBuilder dispatcherBuilder = services.GetRequiredService <IDispatcherBuilder>();
            var addressTable = new UriPrefixTable <HandshakeDelegate>();

            foreach (Type serviceType in serviceBuilder.Services)
            {
                List <IServiceDispatcher> dispatchers = dispatcherBuilder.BuildDispatchers(serviceType);
                foreach (IServiceDispatcher dispatcher in dispatchers)
                {
                    if (dispatcher.BaseAddress == null)
                    {
                        // TODO: Should we throw? Ignore?
                        continue;
                    }

                    // TODO: Limit to specifically TcpTransportBindingElement if net.tcp etc
                    BindingElementCollection be = dispatcher.Binding.CreateBindingElements();
                    ConnectionOrientedTransportBindingElement cotbe = be.Find <ConnectionOrientedTransportBindingElement>();
                    if (cotbe == null)
                    {
                        // TODO: Should we throw? Ignore?
                        continue;
                    }

                    HandshakeDelegate handshake = BuildHandshakeDelegateForDispatcher(dispatcher);
                    logger.LogDebug($"Registering URI {dispatcher.BaseAddress} with NetMessageFramingConnectionHandler");
                    addressTable.RegisterUri(dispatcher.BaseAddress, cotbe.HostNameComparisonMode, handshake);
                }
            }

            return(addressTable);
        }
        private HostedHttpTransportManager CreateTransportManager(BaseUriWithWildcard listenAddress)
        {
            UriPrefixTable <ITransportManagerRegistration> staticTransportManagerTable = null;

            if (object.ReferenceEquals(base.Scheme, Uri.UriSchemeHttp))
            {
                staticTransportManagerTable = HttpChannelListener.StaticTransportManagerTable;
            }
            else
            {
                staticTransportManagerTable = SharedHttpsTransportManager.StaticTransportManagerTable;
            }
            HostedHttpTransportManager item = null;

            lock (staticTransportManagerTable)
            {
                ITransportManagerRegistration registration;
                if (!staticTransportManagerTable.TryLookupUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, out registration))
                {
                    item = new HostedHttpTransportManager(listenAddress);
                    staticTransportManagerTable.RegisterUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, item);
                }
            }
            return(item);
        }
        HostedHttpTransportManager CreateTransportManager(BaseUriWithWildcard listenAddress)
        {
            UriPrefixTable <ITransportManagerRegistration> table = null;

            if (object.ReferenceEquals(this.Scheme, Uri.UriSchemeHttp))
            {
                table = HttpChannelListener.StaticTransportManagerTable;
            }
            else
            {
                table = SharedHttpsTransportManager.StaticTransportManagerTable;
            }

            HostedHttpTransportManager httpManager = null;

            lock (table)
            {
                ITransportManagerRegistration registration;
                if (!table.TryLookupUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, out registration))
                {
                    httpManager = new HostedHttpTransportManager(listenAddress);
                    table.RegisterUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, httpManager);
                }
            }

            return(httpManager);
        }
        public PrefixEndpointAddressMessageFilter(EndpointAddress address, bool includeHostNameInComparison)
        {
            Address = address ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(address));
            _helper = new EndpointAddressMessageFilterHelper(Address);

            _hostNameComparisonMode = includeHostNameInComparison
                ? HostNameComparisonMode.Exact
                : HostNameComparisonMode.StrongWildcard;

            _addressTable = new UriPrefixTable <object>();
            _addressTable.RegisterUri(Address.Uri, _hostNameComparisonMode, new object());
        }
        static ListenerExceptionStatus TcpStart(MessageQueue messageQueue, BaseUriWithWildcard path)
        {
            int encodedSize = System.Text.Encoding.UTF8.GetByteCount(path.BaseAddress.AbsoluteUri);

            if (encodedSize > ListenerConstants.MaxUriSize)
            {
                if (DiagnosticUtility.ShouldTraceInformation)
                {
                    ListenerTraceUtility.TraceEvent(TraceEventType.Information, ListenerTraceCode.RoutingTablePathTooLong, SR.GetString(SR.TraceCodeRoutingTablePathTooLong), new StringTraceRecord("Path", path.ToString()), null, null);
                }

                return(ListenerExceptionStatus.PathTooLong);
            }
            IPEndPoint endPoint = GetEndPoint(path.BaseAddress);

            lock (tcpMessageQueues)
            {
                if (tcpMessageQueues.IsRegistered(path))
                {
                    if (DiagnosticUtility.ShouldTraceInformation)
                    {
                        ListenerTraceUtility.TraceEvent(TraceEventType.Information, ListenerTraceCode.RoutingTableNamespaceConflict, SR.GetString(SR.TraceCodeRoutingTableNamespaceConflict), new StringTraceRecord("Path", path.ToString()), null, null);
                    }

                    return(ListenerExceptionStatus.ConflictingRegistration);
                }

                TransportListener.Listen(endPoint);
                tcpMessageQueues.RegisterUri(path.BaseAddress, path.HostNameComparisonMode, new MessageQueueAndPath(messageQueue, path.BaseAddress));
            }

            if (DiagnosticUtility.ShouldTraceInformation)
            {
                ListenerTraceUtility.TraceEvent(TraceEventType.Information, ListenerTraceCode.RoutingTableRegisterSuccess, SR.GetString(SR.TraceCodeRoutingTableRegisterSuccess), new StringTraceRecord("Path", path.ToString()), null, null);
            }

            return(ListenerExceptionStatus.Success);
        }