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);
        }
        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);
        }
 private HandshakeDelegate BuildHandshake(IFramingConnectionHandshakeBuilder handshakeBuilder)
 {
     handshakeBuilder.UseMiddleware <FramingModeHandshakeMiddleware>();
     handshakeBuilder.Map(connection => connection.FramingMode == FramingMode.Duplex,
                          configuration =>
     {
         configuration.UseMiddleware <DuplexFramingMiddleware>();
         configuration.Use(next => async(connection) =>
         {
             UriPrefixTable <HandshakeDelegate> addressTable = configuration.HandshakeServices.GetRequiredService <UriPrefixTable <HandshakeDelegate> >();
             HandshakeDelegate serviceHandshake = GetServiceHandshakeDelegate(addressTable, connection.Via);
             await serviceHandshake(connection);
             await next(connection);
         });
         configuration.UseMiddleware <ServerFramingDuplexSessionMiddleware>();
         configuration.UseMiddleware <ServerSessionConnectionReaderMiddleware>();
     });
     handshakeBuilder.Map(connection => connection.FramingMode == FramingMode.Singleton,
                          configuration =>
     {
         configuration.UseMiddleware <SingletonFramingMiddleware>();
         configuration.Use(next => async(connection) =>
         {
             UriPrefixTable <HandshakeDelegate> addressTable = configuration.HandshakeServices.GetRequiredService <UriPrefixTable <HandshakeDelegate> >();
             HandshakeDelegate serviceHandshake = GetServiceHandshakeDelegate(addressTable, connection.Via);
             await serviceHandshake(connection);
             await next(connection);
         });
         configuration.UseMiddleware <ServerFramingSingletonMiddleware>();
         configuration.UseMiddleware <ServerSingletonConnectionReaderMiddleware>();
     });
     return(handshakeBuilder.Build());
 }
        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);
        }
        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);
        }
 internal HttpAnonymousUriPrefixMatcher(HttpAnonymousUriPrefixMatcher objectToClone) : this()
 {
     if (objectToClone.anonymousUriPrefixes != null)
     {
         this.anonymousUriPrefixes = new UriPrefixTable<Uri>(objectToClone.anonymousUriPrefixes);
     }
 }
        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);
        }
        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());
        }
 public PrefixEndpointAddressMessageFilter(EndpointAddress address, bool includeHostNameInComparison)
 {
     if (address == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("address");
     }
     this.address = address;
     this.helper  = new EndpointAddressMessageFilterHelper(this.address);
     this.hostNameComparisonMode = includeHostNameInComparison ? HostNameComparisonMode.Exact : HostNameComparisonMode.StrongWildcard;
     this.addressTable           = new UriPrefixTable <object>();
     this.addressTable.RegisterUri(this.address.Uri, this.hostNameComparisonMode, new object());
 }
 public AmqpTransportManager(Uri listenUri, AmqpSettings amqpSettings, TimeSpan openTimeout)
 {
     this.ListenUri    = new Uri(listenUri.GetLeftPart(UriPartial.Authority));
     this.addressTable = new UriPrefixTable <AmqpChannelListenerBase>(false);
     this.OpenTimeout  = openTimeout;
     this.amqpSettings = amqpSettings.Clone();
     this.amqpSettings.RuntimeProvider = this;
     this.amqpConnectionSettings       = new AmqpConnectionSettings()
     {
         ContainerId = Guid.NewGuid().ToString("N")
     };
     this.id = string.Concat(base.GetType().Name, this.GetHashCode());
     MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteAmqpLogOperation(this, TraceOperation.Create, this.ListenUri));
 }
Example #11
0
 public SocketConnectionTransportManagerRegistration(Uri listenUri, SocketConnectionChannelListener channelListener) : base(listenUri, channelListener.HostNameComparisonMode)
 {
     this.connectionBufferSize         = channelListener.ConnectionBufferSize;
     this.channelInitializationTimeout = channelListener.ChannelInitializationTimeout;
     this.teredoEnabled         = channelListener.TeredoEnabled;
     this.listenBacklog         = channelListener.ListenBacklog;
     this.maxOutputDelay        = channelListener.MaxOutputDelay;
     this.maxPendingConnections = channelListener.MaxPendingConnections;
     this.maxPendingAccepts     = channelListener.MaxPendingAccepts;
     this.idleTimeout           = channelListener.IdleTimeout;
     this.maxPooledConnections  = channelListener.MaxPooledConnections;
     this.transferMode          = channelListener.TransferMode;
     this.connectionElement     = channelListener.ConnectionElement;
     this.transportManagerTable = channelListener.TransportManagerTable;
 }
        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);
        }
 public void Register(Uri anonymousUriPrefix)
 {
     if (anonymousUriPrefix == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("anonymousUriPrefix");
     }
     if (!anonymousUriPrefix.IsAbsoluteUri)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("anonymousUriPrefix", System.ServiceModel.SR.GetString("UriMustBeAbsolute"));
     }
     if (this.anonymousUriPrefixes == null)
     {
         this.anonymousUriPrefixes = new UriPrefixTable<Uri>(true);
     }
     if (!this.anonymousUriPrefixes.IsRegistered(new BaseUriWithWildcard(anonymousUriPrefix, HostNameComparisonMode.Exact)))
     {
         this.anonymousUriPrefixes.RegisterUri(anonymousUriPrefix, HostNameComparisonMode.Exact, anonymousUriPrefix);
     }
 }
 internal override void Register(TransportChannelListener channelListener)
 {
     UriPrefixTable<HttpChannelListener> table;
     string method = ((HttpChannelListener) channelListener).Method;
     if (!this.addressTables.TryGetValue(method, out table))
     {
         lock (base.ThisLock)
         {
             if (!this.addressTables.TryGetValue(method, out table))
             {
                 Dictionary<string, UriPrefixTable<HttpChannelListener>> dictionary = new Dictionary<string, UriPrefixTable<HttpChannelListener>>(this.addressTables);
                 table = new UriPrefixTable<HttpChannelListener>();
                 dictionary[method] = table;
                 this.addressTables = dictionary;
             }
         }
     }
     table.RegisterUri(channelListener.Uri, channelListener.InheritBaseAddressSettings ? this.hostNameComparisonMode : channelListener.HostNameComparisonModeInternal, (HttpChannelListener) channelListener);
 }
        internal static void DumpTables(TransportType transportType)
        {
            UriPrefixTable <MessageQueueAndPath> table = transportType == TransportType.Tcp ? tcpMessageQueues : namedPipeMessageQueues;

            lock (table)
            {
                Debug.Print("RoutingTable dumping " + table.Count + " Route(s) for TransportType: " + transportType);
                int count = 0;
                foreach (KeyValuePair <BaseUriWithWildcard, MessageQueueAndPath> item in table.GetAll())
                {
                    bool activated = item.Value.MessageQueue.GetType().Equals(typeof(ActivatedMessageQueue));
                    Debug.Print("Registration #" + (++count).ToString(CultureInfo.CurrentUICulture));
                    Debug.Print("\tActivated:" + activated);
                    Debug.Print("\tCanDispatch:" + item.Value.MessageQueue.CanDispatch);
                    Debug.Print("\tBaseAddress:" + item.Key.BaseAddress);
                    Debug.Print("\tHostNameComparisonMode:" + item.Key.HostNameComparisonMode);
                    List <WorkerProcess> workers = item.Value.MessageQueue.SnapshotWorkers();
                    if (workers.Count == 0)
                    {
                        Debug.Print("\tNo WorkerProcess Active.");
                    }
                    else
                    {
                        Debug.Print("\t" + workers.Count + " WorkerProcess(es) Registered:");
                        foreach (WorkerProcess wp in workers)
                        {
                            Debug.Print("\t\tPid:" + wp.ProcessId);
                            if (activated)
                            {
                                Debug.Print("\t\tActive:" + wp.IsRegistered);
                                Debug.Print("\t\tQueueId:" + wp.QueueId);
                            }
                        }
                    }
                }
            }
        }
        internal override void Register(TransportChannelListener channelListener)
        {
            string method = ((HttpChannelListener)channelListener).Method;

            UriPrefixTable<HttpChannelListener> addressTable;
            if (!addressTables.TryGetValue(method, out addressTable))
            {
                lock (ThisLock)
                {
                    if (!addressTables.TryGetValue(method, out addressTable))
                    {
                        Dictionary<string, UriPrefixTable<HttpChannelListener>> newAddressTables =
                            new Dictionary<string, UriPrefixTable<HttpChannelListener>>(addressTables);

                        addressTable = new UriPrefixTable<HttpChannelListener>();
                        newAddressTables[method] = addressTable;

                        addressTables = newAddressTables;
                    }
                }
            }

            addressTable.RegisterUri(channelListener.Uri,
                channelListener.InheritBaseAddressSettings ? hostNameComparisonMode : channelListener.HostNameComparisonModeInternal,
                (HttpChannelListener)channelListener);
        }
 static WebStreamOnewayClientConnectionElement()
 {
     WebStreamOnewayClientConnectionElement.transportManagerTable = new UriPrefixTable <ITransportManagerRegistration>(true);
 }
 protected override void ClearLookupTables()
 {
     toHostTable   = new UriPrefixTable <EndpointAddressMessageFilterTable <TFilterData> .CandidateSet>();
     toNoHostTable = new UriPrefixTable <EndpointAddressMessageFilterTable <TFilterData> .CandidateSet>();
 }
 protected override void InitializeLookupTables()
 {
     toHostTable   = new UriPrefixTable <CandidateSet>();
     toNoHostTable = new UriPrefixTable <CandidateSet>();
 }
 static AmqpTransportManager()
 {
     AmqpTransportManager.TransportManagerTable = new UriPrefixTable <ITransportManagerRegistration>(true);
     AmqpTransportManager.sessionOpenCallback   = new AsyncCallback(AmqpTransportManager.SessionOpenCallback);
 }
 static DemuxSocketElement()
 {
     DemuxSocketElement.transportManagerTable = new UriPrefixTable <ITransportManagerRegistration>(true);
 }