internal static MessageQueue Lookup(Uri uri, IPAddress address, int port)
        {
            if (TD.RoutingTableLookupStartIsEnabled())
            {
                TD.RoutingTableLookupStart();
            }

            Uri wildCardUri = uri;
            UriPrefixTable <MessageQueueAndPath> table = namedPipeMessageQueues;

            if (address != null)
            {
                // Including port number to support TCP proxy (see MB56472). We only use it for wildcard matching below.
                // NOTE: we don't need to call TcpChannelListener.FixIpv6Hostname to fix the host name because it's ignored anyway.
                UriBuilder uriBuilder = new UriBuilder(uri.Scheme, uri.Host, port, uri.PathAndQuery);
                wildCardUri = uriBuilder.Uri;
                table       = tcpMessageQueues;
            }

            MessageQueueAndPath found = null;
            bool success = table.TryLookupUri(wildCardUri, HostNameComparisonMode.StrongWildcard, out found);

            if (success && address != null)
            {
                success = ValidateAddress(address, ref found);
            }
            if (!success)
            {
                success = table.TryLookupUri(uri, HostNameComparisonMode.Exact, out found);
                if (success && address != null)
                {
                    success = ValidateAddress(address, ref found);
                }
            }
            if (!success)
            {
                success = table.TryLookupUri(wildCardUri, HostNameComparisonMode.WeakWildcard, out found);
                if (success && address != null)
                {
                    success = ValidateAddress(address, ref found);
                }
            }

            if (DiagnosticUtility.ShouldTraceInformation)
            {
                ListenerTraceUtility.TraceEvent(TraceEventType.Information, ListenerTraceCode.RoutingTableLookup, SR.GetString(SR.TraceCodeRoutingTableLookup), new StringTraceRecord("Uri", uri.ToString()), null, null);
            }

            Debug.Print("RoutingTable.Lookup(" + uri + ") matched: " + (found == null ? "<NoMatch!>" : found.Uri.ToString()));
            if (TD.RoutingTableLookupStopIsEnabled())
            {
                TD.RoutingTableLookupStop();
            }
            return(found == null ? null : found.MessageQueue);
        }
        internal static HandshakeDelegate GetServiceHandshakeDelegate(UriPrefixTable <HandshakeDelegate> addressTable, Uri via)
        {
            if (addressTable.TryLookupUri(via, HostNameComparisonMode.StrongWildcard, out HandshakeDelegate handshake))
            {
                return(handshake);
            }

            if (addressTable.TryLookupUri(via, HostNameComparisonMode.Exact, out handshake))
            {
                return(handshake);
            }

            addressTable.TryLookupUri(via, HostNameComparisonMode.WeakWildcard, out handshake);
            return(handshake);
        }
        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 override bool Match(Message message)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message));
            }

            // To
            Uri to = message.Headers.To;

            if (to == null || !_addressTable.TryLookupUri(to, _hostNameComparisonMode, out object o))
            {
                return(false);
            }

            return(_helper.Match(message));
        }
        public override bool Match(Message message)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }

            // To
#pragma warning suppress 56506 // [....], Message.Headers can never be null
            Uri to = message.Headers.To;

            object o;
            if (to == null || !addressTable.TryLookupUri(to, this.hostNameComparisonMode, out o))
            {
                return(false);
            }

            return(helper.Match(message));
        }