Ejemplo n.º 1
0
 public static void DisablePayloadMasking_Property_Get_PNSE_Throws()
 {
     var setting = new WebSocketTransportSettings();
     bool disablePayloadMasking = false;
     Assert.Throws<PlatformNotSupportedException>(() => disablePayloadMasking = setting.DisablePayloadMasking);
     Assert.False(disablePayloadMasking);
 }
    public static void DisablePayloadMasking_Property_Get_PNSE_Throws()
    {
        var  setting = new WebSocketTransportSettings();
        bool disablePayloadMasking = false;

        Assert.Throws <PlatformNotSupportedException>(() => disablePayloadMasking = setting.DisablePayloadMasking);
        Assert.False(disablePayloadMasking);
    }
 public WebSocketTransportDuplexSessionChannel(HttpChannelFactory<IDuplexSessionChannel> channelFactory, EndpointAddress remoteAddresss, Uri via)
     : base(channelFactory, channelFactory, EndpointAddress.AnonymousAddress, channelFactory.MessageVersion.Addressing.AnonymousUri, remoteAddresss, via)
 {
     Fx.Assert(channelFactory.WebSocketSettings != null, "channelFactory.WebSocketTransportSettings should not be null.");
     _webSocketSettings = channelFactory.WebSocketSettings;
     _transferMode = channelFactory.TransferMode;
     _maxBufferSize = channelFactory.MaxBufferSize;
     _transportFactorySettings = channelFactory;
 }
Ejemplo n.º 4
0
    public static TBuilder WithWebSocketTransport <TBuilder>(this TBuilder builder, string address,
                                                             Action <WebSocketTransportSettings> options = null)
        where TBuilder : BaseConnectionBuilder
    {
        var settings = new WebSocketTransportSettings(ConnectionSide.Client);

        options?.Invoke(settings);

        builder.TransportFactory = new WebSocketTransportFactory(address, settings);

        return(builder);
    }
Ejemplo n.º 5
0
    public static TBuilder AddWebSocketServer <TBuilder>(this TBuilder builder, string address,
                                                         Action <WebSocketTransportSettings> options = null)
        where TBuilder : BaseServiceHostBuilder
    {
        var settings = new WebSocketTransportSettings(ConnectionSide.Server);

        options?.Invoke(settings);
        var listener = WebSocketTools.CreateWebSocketListener(address, settings, builder.LoggerFactory);

        builder.Listeners.Add(listener);
        return(builder);
    }
Ejemplo n.º 6
0
        public void ApplyConfiguration(WebSocketTransportSettings settings)
        {
            if (settings == null)
            {
                throw FxTrace.Exception.ArgumentNull("settings");
            }

            settings.TransportUsage = this.TransportUsage;
            settings.CreateNotificationOnConnection = this.CreateNotificationOnConnection;
            settings.KeepAliveInterval     = this.KeepAliveInterval;
            settings.SubProtocol           = string.IsNullOrEmpty(this.SubProtocol) ? null : this.SubProtocol;
            settings.DisablePayloadMasking = this.DisablePayloadMasking;
            settings.MaxPendingConnections = this.MaxPendingConnections;
        }
        public void ApplyConfiguration(WebSocketTransportSettings settings)
        {
            if (settings == null)
            {
                throw FxTrace.Exception.ArgumentNull("settings");
            }

            settings.TransportUsage = this.TransportUsage;
            settings.CreateNotificationOnConnection = this.CreateNotificationOnConnection;
            settings.KeepAliveInterval = this.KeepAliveInterval;
            settings.SubProtocol = string.IsNullOrEmpty(this.SubProtocol) ? null : this.SubProtocol;
            settings.DisablePayloadMasking = this.DisablePayloadMasking;
            settings.MaxPendingConnections = this.MaxPendingConnections;
        }
        public void InitializeFrom(WebSocketTransportSettings settings)
        {
            if (settings == null)
            {
                throw FxTrace.Exception.ArgumentNull("settings");
            }

            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.TransportUsage, settings.TransportUsage);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.CreateNotificationOnConnection, settings.CreateNotificationOnConnection);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.KeepAliveInterval, settings.KeepAliveInterval);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.SubProtocol, settings.SubProtocol);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.DisablePayloadMasking, settings.DisablePayloadMasking);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxPendingConnections, settings.MaxPendingConnections);
        }
Ejemplo n.º 9
0
        public void InitializeFrom(WebSocketTransportSettings settings)
        {
            if (settings == null)
            {
                throw FxTrace.Exception.ArgumentNull("settings");
            }

            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.TransportUsage, settings.TransportUsage);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.CreateNotificationOnConnection, settings.CreateNotificationOnConnection);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.KeepAliveInterval, settings.KeepAliveInterval);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.SubProtocol, settings.SubProtocol);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.DisablePayloadMasking, settings.DisablePayloadMasking);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxPendingConnections, settings.MaxPendingConnections);
        }
Ejemplo n.º 10
0
        static TransportSettings CreateWebSocketsTransportSettings(string hostName)
        {
            var uriBuilder = new UriBuilder(hostName)
            {
                Path   = AmqpClientConstants.WebSocketsPathSuffix,
                Scheme = AmqpClientConstants.UriSchemeWss,
                Port   = -1 // Port will be assigned on transport listener.
            };
            var ts = new WebSocketTransportSettings()
            {
                Uri = uriBuilder.Uri
            };

            return(ts);
        }
Ejemplo n.º 11
0
        public override async Task<WebSocket> CreateWebSocketAsync(Uri address, WebHeaderCollection headers, ICredentials credentials,
            WebSocketTransportSettings settings, TimeoutHelper timeoutHelper)
        {
            ClientWebSocket webSocket = new ClientWebSocket();
            webSocket.Options.Credentials = credentials;
            webSocket.Options.AddSubProtocol(settings.SubProtocol);
            webSocket.Options.KeepAliveInterval = settings.KeepAliveInterval;
            foreach (var headerObj in headers)
            {
                var header = headerObj as string;
                webSocket.Options.SetRequestHeader(header, headers[header]);
            }

            await webSocket.ConnectAsync(address, timeoutHelper.CancellationToken);
            return webSocket;
        }
        public static TransportSettings CreateWebSocketTransportSettings(
            string networkHost,
            string hostName,
            int port)
        {
            var uriBuilder = new UriBuilder(WebSocketConstants.WebSocketSecureScheme, networkHost, port < 0 ? WebSocketConstants.WebSocketSecurePort : port, WebSocketConstants.WebSocketDefaultPath);
            var webSocketTransportSettings = new WebSocketTransportSettings
            {
                Uri = uriBuilder.Uri,
                ReceiveBufferSize = AmqpConstants.TransportBufferSize,
                SendBufferSize    = AmqpConstants.TransportBufferSize
            };

            TransportSettings tpSettings = webSocketTransportSettings;

            return(tpSettings);
        }
        private static TransportSettings CreateWebSocketsTransportSettings(string hostName, IWebProxy webProxy)
        {
            var uriBuilder = new UriBuilder(hostName)
            {
                Path   = AmqpClientConstants.WebSocketsPathSuffix,
                Scheme = AmqpClientConstants.UriSchemeWss,
                Port   = -1 // Port will be assigned on transport listener.
            };
            var ts = new WebSocketTransportSettings
            {
                Uri = uriBuilder.Uri
            };

            // Proxy Uri provided?
            if (webProxy != null)
            {
                ts.Proxy = webProxy;
            }

            return(ts);
        }
Ejemplo n.º 14
0
        public static IListener CreateWebSocketListener(string address, WebSocketTransportSettings settings,
                                                        ILoggerFactory loggerFactory)
        {
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            if (!address.EndsWith("/"))
            {
                address += "/";
            }

            var uri = new Uri(address);

            if (uri.Scheme != Uri.UriSchemeHttp)
            {
                throw new Exception($"{nameof(address)} must be valid http:// address");
            }

            return(new WebSocketListener(uri, settings, loggerFactory));
        }
Ejemplo n.º 15
0
        public static WebSocketTransport CreateWebSocketTransport(string address,
                                                                  WebSocketTransportSettings settings, ILoggerFactory loggerFactory)
        {
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            if (address.StartsWith("http://"))
            {
                address = address.Replace("http://", "ws://");
            }

            var uri = new Uri(address);

            if (uri.Scheme != "ws")
            {
                throw new Exception($"{nameof(address)} must be valid http:// or ws:// address");
            }

            return(new WebSocketTransport(uri, settings, loggerFactory));
        }
 // Provides the client WebSocket for step #2. WCF creates the HttpWebRequest in step #1, and passes the HttpWebResponse stream
 // to this method. The 'settings' argument can optionally be used. On Win8 (and above), the WebSocket.CreateClientWebSocket method 
 // requires other arguments (in addition to the Stream) that can be obtained from 'settings'. Since the WebSocket.CreateClientWebSocket 
 // finds this argument to be enough to create a client WebSocket (on Win8, and post Win8 due to backward compatibility requirements), 
 // we estimate that implementors of a custom web socket factory will find it enough too.
 public abstract WebSocket CreateWebSocket(Stream connection, WebSocketTransportSettings settings);
Ejemplo n.º 17
0
            protected override IEnumerator <IteratorTask <object> .TaskStep> GetTasks()
            {
                ConnectivityMode connectivityMode;
                object           obj  = null;
                bool             flag = false;

                try
                {
                    object thisLock = this.relay.ThisLock;
                    object obj1     = thisLock;
                    obj = thisLock;
                    Monitor.Enter(obj1, ref flag);
                    if (this.relay.State != AmqpObjectState.OpenReceived && this.relay.State != AmqpObjectState.Opened)
                    {
                        goto Label0;
                    }
                }
                finally
                {
                    if (flag)
                    {
                        Monitor.Exit(obj);
                    }
                }
                Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(this.timeout);
                string       host        = this.relay.serviceBusUri.Host;
                AmqpSettings amqpSetting = AmqpRelay.ConnectTask.CreateAmqpSettings();

                connectivityMode = (this.relay.connectivitySettings != null ? this.relay.connectivitySettings.Mode : ServiceBusEnvironment.SystemConnectivity.Mode);
                ConnectivityMode connectivityMode1 = connectivityMode;

                if (connectivityMode1 == ConnectivityMode.Tcp)
                {
                    TcpTransportSettings tcpTransportSetting = new TcpTransportSettings()
                    {
                        Host = host,
                        Port = 5671
                    };
                    TlsTransportSettings tlsTransportSetting = new TlsTransportSettings(tcpTransportSetting)
                    {
                        TargetHost = host
                    };
                    AmqpTransportInitiator amqpTransportInitiator = new AmqpTransportInitiator(amqpSetting, tlsTransportSetting);
                    yield return(base.CallTask(amqpTransportInitiator.ConnectTaskAsync(timeoutHelper.RemainingTime()), IteratorTask <TResult> .ExceptionPolicy.Transfer));
                }
                else if (connectivityMode1 == ConnectivityMode.Http || this.relay.httpConnectivitySettings != null)
                {
                    WebSocketTransportSettings webSocketTransportSetting = new WebSocketTransportSettings(this.relay.serviceBusUri);
                    AmqpTransportInitiator     amqpTransportInitiator1   = new AmqpTransportInitiator(amqpSetting, webSocketTransportSetting);
                    yield return(base.CallTask(amqpTransportInitiator1.ConnectTaskAsync(timeoutHelper.RemainingTime()), IteratorTask <TResult> .ExceptionPolicy.Transfer));
                }
                else
                {
                    TcpTransportSettings tcpTransportSetting1 = new TcpTransportSettings()
                    {
                        Host = host,
                        Port = 5671
                    };
                    TlsTransportSettings tlsTransportSetting1 = new TlsTransportSettings(tcpTransportSetting1)
                    {
                        TargetHost = host
                    };
                    AmqpTransportInitiator amqpTransportInitiator2 = new AmqpTransportInitiator(amqpSetting, tlsTransportSetting1);
                    yield return(base.CallTask(amqpTransportInitiator2.ConnectTaskAsync(Microsoft.ServiceBus.Common.TimeoutHelper.Divide(timeoutHelper.RemainingTime(), 2)), IteratorTask <TResult> .ExceptionPolicy.Continue));

                    if (base.LastTask.Exception != null)
                    {
                        if (timeoutHelper.RemainingTime() == TimeSpan.Zero)
                        {
                            throw base.LastTask.Exception;
                        }
                        WebSocketTransportSettings webSocketTransportSetting1 = new WebSocketTransportSettings(this.relay.serviceBusUri);
                        AmqpTransportInitiator     amqpTransportInitiator3    = new AmqpTransportInitiator(amqpSetting, webSocketTransportSetting1);
                        yield return(base.CallTask(amqpTransportInitiator3.ConnectTaskAsync(timeoutHelper.RemainingTime()), IteratorTask <TResult> .ExceptionPolicy.Transfer));
                    }
                }
                TransportBase transportBase = base.LastTaskResult <TransportBase>();

                string[] strArrays = host.Split(new char[] { '.' });
                strArrays[0] = string.Concat(strArrays[0], "-relay");
                AmqpConnectionSettings amqpConnectionSetting = new AmqpConnectionSettings()
                {
                    ContainerId = Guid.NewGuid().ToString(),
                    HostName    = string.Join(".", strArrays)
                };

                this.relay.connection = new AmqpConnection(transportBase, amqpSetting, amqpConnectionSetting);
                yield return(base.CallTask(this.relay.connection.OpenAsync(timeoutHelper.RemainingTime()), IteratorTask <TResult> .ExceptionPolicy.Transfer));

                AmqpSessionSettings amqpSessionSetting = new AmqpSessionSettings();
                AmqpSession         amqpSession        = this.relay.connection.CreateSession(amqpSessionSetting);

                yield return(base.CallTask(amqpSession.OpenAsync(timeoutHelper.RemainingTime()), IteratorTask <TResult> .ExceptionPolicy.Transfer));

                AmqpLinkSettings amqpLinkSetting = new AmqpLinkSettings()
                {
                    Role = new bool?(false),
                    InitialDeliveryCount = new uint?(0),
                    LinkName             = string.Concat("HttpRelayServer_Link_", Guid.NewGuid()),
                    Target          = new Target(this.relay.serviceBusUri),
                    Source          = new Source(this.relay.serviceBusUri),
                    TotalLinkCredit = 1000,
                    AutoSendFlow    = true
                };
                AmqpLinkSettings amqpLinkSetting1 = amqpLinkSetting;

                if (this.relay.tokenRenewer != null)
                {
                    amqpLinkSetting1.AddProperty(AmqpConstants.SimpleWebTokenPropertyName, this.relay.tokenRenewer.CurrentToken.Token);
                }
                if (!this.relay.TransportSecurityRequired)
                {
                    amqpLinkSetting1.AddProperty(ClientConstants.TransportSecurityRequiredName, false);
                }
                if (!this.relay.RelayClientAuthorizationRequired)
                {
                    amqpLinkSetting1.AddProperty(ClientConstants.ClientAuthenticationRequiredName, false);
                }
                if (this.relay.PublishToRegistry)
                {
                    amqpLinkSetting1.AddProperty(ClientConstants.RequiresPublicRegistry, true);
                }
                if (!string.IsNullOrEmpty(this.relay.ClientAgent))
                {
                    amqpLinkSetting1.AddProperty(ClientConstants.ClientAgent, this.relay.ClientAgent);
                }
                if (!string.IsNullOrEmpty(this.relay.DisplayName))
                {
                    amqpLinkSetting1.AddProperty(ClientConstants.DisplayName, this.relay.DisplayName);
                }
                amqpLinkSetting1.AddProperty(ClientConstants.DynamicRelay, this.relay.IsDynamic);
                amqpLinkSetting1.AddProperty(ClientConstants.ListenerTypeName, this.relay.ListenerType.ToString());
                this.relay.link = new DuplexAmqpLink(amqpSession, amqpLinkSetting1);
                yield return(base.CallTask(this.relay.link.OpenAsync(timeoutHelper.RemainingTime()), IteratorTask <TResult> .ExceptionPolicy.Transfer));

                this.relay.link.SafeAddClosed(this.relay.onAmqpObjectClosed);
                this.relay.link.RegisterMessageListener((AmqpMessage msg) => this.relay.messageListener(this.relay.link, msg));
                this.relay.OnOnline();
Label0:
                yield break;
            }
Ejemplo n.º 18
0
        /// <summary>
        /// Opens a connection to the specified address.
        /// </summary>
        /// <param name="addressUri">The address Uri. User info is ignored.</param>
        /// <param name="saslHandler">The SASL handler which determines the SASL mechanism. Null means no SASL handshake.</param>
        /// <param name="timeout">The operation timeout.</param>
        /// <returns>An AMQP connection.</returns>
        public async Task <AmqpConnection> OpenConnectionAsync(Uri addressUri, SaslHandler saslHandler, TimeSpan timeout)
        {
            TransportSettings transportSettings;

            if (addressUri.Scheme.Equals(AmqpConstants.SchemeAmqp, StringComparison.OrdinalIgnoreCase))
            {
                transportSettings = new TcpTransportSettings()
                {
                    Host = addressUri.Host,
                    Port = addressUri.Port > -1 ? addressUri.Port : AmqpConstants.DefaultPort
                };
            }
            else if (addressUri.Scheme.Equals(AmqpConstants.SchemeAmqps, StringComparison.OrdinalIgnoreCase))
            {
                TcpTransportSettings tcpSettings = new TcpTransportSettings()
                {
                    Host = addressUri.Host,
                    Port = addressUri.Port > -1 ? addressUri.Port : AmqpConstants.DefaultSecurePort
                };

                var tls = new TlsTransportSettings(tcpSettings)
                {
                    TargetHost = addressUri.Host
                };
                TlsTransportProvider tlsProvider = this.settings.GetTransportProvider <TlsTransportProvider>();
                if (tlsProvider != null)
                {
                    tls.CertificateValidationCallback = tlsProvider.Settings.CertificateValidationCallback;
                    tls.CheckCertificateRevocation    = tlsProvider.Settings.CheckCertificateRevocation;
                    tls.Certificate = tlsProvider.Settings.Certificate;
                    tls.Protocols   = tlsProvider.Settings.Protocols;
                }

                transportSettings = tls;
            }
            else if (addressUri.Scheme.Equals(WebSocketTransportSettings.WebSockets, StringComparison.OrdinalIgnoreCase) ||
                     addressUri.Scheme.Equals(WebSocketTransportSettings.SecureWebSockets, StringComparison.OrdinalIgnoreCase))
            {
                transportSettings = new WebSocketTransportSettings()
                {
                    Uri = addressUri
                };
            }
            else
            {
                throw new NotSupportedException(addressUri.Scheme);
            }

            AmqpSettings settings = this.settings.Clone();

            settings.TransportProviders.Clear();

            if (saslHandler != null)
            {
                // Provider for "AMQP3100"
                SaslTransportProvider saslProvider = new SaslTransportProvider(AmqpVersion.V100);
                saslProvider.AddHandler(saslHandler);
                settings.TransportProviders.Add(saslProvider);
            }

            // Provider for "AMQP0100"
            AmqpTransportProvider amqpProvider = new AmqpTransportProvider(AmqpVersion.V100);

            settings.TransportProviders.Add(amqpProvider);

            AmqpTransportInitiator initiator = new AmqpTransportInitiator(settings, transportSettings);
            TransportBase          transport = await Task.Factory.FromAsync(
                (c, s) => initiator.BeginConnect(timeout, c, s),
                (r) => initiator.EndConnect(r),
                null).ConfigureAwait(false);

            try
            {
                AmqpConnectionSettings connectionSettings = new AmqpConnectionSettings()
                {
                    ContainerId = Guid.NewGuid().ToString(),
                    HostName    = addressUri.Host
                };

                AmqpConnection connection = new AmqpConnection(transport, settings, connectionSettings);
                await connection.OpenAsync(timeout).ConfigureAwait(false);

                return(connection);
            }
            catch
            {
                transport.Abort();
                throw;
            }
        }
    public static void DisablePayloadMasking_Property_Set_PNSE_Throws()
    {
        var setting = new WebSocketTransportSettings();

        Assert.Throws <PlatformNotSupportedException>(() => setting.DisablePayloadMasking = true);
    }
Ejemplo n.º 20
0
        internal static WebSocketTransportSettings GetRuntimeWebSocketSettings(WebSocketTransportSettings settings)
        {
            WebSocketTransportSettings runtimeSettings = settings.Clone();
            if (runtimeSettings.MaxPendingConnections == WebSocketDefaults.DefaultMaxPendingConnections)
            {
                runtimeSettings.MaxPendingConnections = WebSocketDefaults.MaxPendingConnectionsCpuCount;
            }

            return runtimeSettings;
        }
Ejemplo n.º 21
0
        public async Task <AmqpConnection> OpenConnectionAsync(Uri addressUri, SaslHandler saslHandler, TimeSpan timeout)
        {
            TransportSettings transportSettings;

            if (addressUri.Scheme.Equals(AmqpConstants.SchemeAmqp, StringComparison.OrdinalIgnoreCase))
            {
                transportSettings = new TcpTransportSettings()
                {
                    Host = addressUri.Host,
                    Port = addressUri.Port > -1 ? addressUri.Port : AmqpConstants.DefaultPort
                };
            }
            else if (addressUri.Scheme.Equals(AmqpConstants.SchemeAmqps, StringComparison.OrdinalIgnoreCase))
            {
                TcpTransportSettings tcpSettings = new TcpTransportSettings()
                {
                    Host = addressUri.Host,
                    Port = addressUri.Port > -1 ? addressUri.Port : AmqpConstants.DefaultSecurePort
                };

                transportSettings = new TlsTransportSettings(tcpSettings)
                {
                    TargetHost = addressUri.Host
                };
            }
#if NET45
            else if (addressUri.Scheme.Equals(WebSocketTransport.WebSockets, StringComparison.OrdinalIgnoreCase) ||
                     addressUri.Scheme.Equals(WebSocketTransport.SecureWebSockets, StringComparison.OrdinalIgnoreCase))
            {
                transportSettings = new WebSocketTransportSettings()
                {
                    Uri = addressUri
                };
            }
#endif
            else
            {
                throw new NotSupportedException(addressUri.Scheme);
            }

            AmqpSettings settings = new AmqpSettings();

            if (saslHandler != null)
            {
                // Provider for "AMQP3100"
                SaslTransportProvider saslProvider = new SaslTransportProvider();
                saslProvider.Versions.Add(new AmqpVersion(1, 0, 0));
                saslProvider.AddHandler(saslHandler);
                settings.TransportProviders.Add(saslProvider);
            }

            // Provider for "AMQP0100"
            AmqpTransportProvider amqpProvider = new AmqpTransportProvider();
            amqpProvider.Versions.Add(new AmqpVersion(new Version(1, 0, 0, 0)));
            settings.TransportProviders.Add(amqpProvider);

            AmqpTransportInitiator initiator = new AmqpTransportInitiator(settings, transportSettings);
            TransportBase          transport = await Task.Factory.FromAsync(
                (c, s) => initiator.BeginConnect(timeout, c, s),
                (r) => initiator.EndConnect(r),
                null);

            try
            {
                AmqpConnectionSettings connectionSettings = new AmqpConnectionSettings()
                {
                    ContainerId = Guid.NewGuid().ToString(),
                    HostName    = addressUri.Host
                };

                AmqpConnection connection = new AmqpConnection(transport, settings, connectionSettings);
                await connection.OpenAsync(timeout);

                return(connection);
            }
            catch
            {
                transport.Abort();
                throw;
            }
        }
Ejemplo n.º 22
0
 public WebSocketTransportFactory(string address, WebSocketTransportSettings settings)
 {
     _address  = address;
     _settings = settings;
 }
Ejemplo n.º 23
0
 internal static WebSocketTransportSettings GetRuntimeWebSocketSettings(WebSocketTransportSettings settings)
 {
     WebSocketTransportSettings runtimeSettings = settings.Clone();
     return runtimeSettings;
 }
Ejemplo n.º 24
0
        public TestAmqpBroker(IList <string> endpoints, string userInfo, string sslValue, string[] queues)
        {
            this.containerId  = "TestAmqpBroker-P" + Process.GetCurrentProcess().Id;
            this.maxFrameSize = 64 * 1024;
            this.txnManager   = new TxnManager();
            this.connections  = new Dictionary <SequenceNumber, AmqpConnection>();
            this.queues       = new Dictionary <string, TestQueue>();
            if (queues != null)
            {
                foreach (string q in queues)
                {
                    this.queues.Add(q, new TestQueue(this));
                }
            }
            else
            {
                this.implicitQueue = true;
            }

            // create and initialize AmqpSettings
            AmqpSettings     settings    = new AmqpSettings();
            X509Certificate2 certificate = sslValue == null ? null : GetCertificate(sslValue);

            settings.RuntimeProvider = this;

            SaslHandler saslHandler;

            if (userInfo != null)
            {
                string[] creds     = userInfo.Split(':');
                string   usernanme = Uri.UnescapeDataString(creds[0]);
                string   password  = creds.Length == 1 ? string.Empty : Uri.UnescapeDataString(creds[1]);
                saslHandler = new SaslPlainHandler(new TestPlainAuthenticator(userInfo, password));
            }
            else
            {
                saslHandler = new SaslAnonymousHandler();
            }

            SaslTransportProvider saslProvider = new SaslTransportProvider();

            saslProvider.AddHandler(saslHandler);
            saslProvider.Versions.Add(new AmqpVersion(1, 0, 0));
            settings.TransportProviders.Add(saslProvider);

            AmqpTransportProvider amqpProvider = new AmqpTransportProvider();

            amqpProvider.Versions.Add(new AmqpVersion(1, 0, 0));
            settings.TransportProviders.Add(amqpProvider);

            // create and initialize transport listeners
            TransportListener[] listeners = new TransportListener[endpoints.Count];
            for (int i = 0; i < endpoints.Count; i++)
            {
                Uri addressUri = new Uri(endpoints[i]);

                if (addressUri.Scheme.Equals(AmqpConstants.SchemeAmqps, StringComparison.OrdinalIgnoreCase))
                {
                    if (certificate == null)
                    {
                        throw new InvalidOperationException("/cert option was not set when amqps address is specified.");
                    }

                    TcpTransportSettings tcpSettings = new TcpTransportSettings()
                    {
                        Host = addressUri.Host, Port = addressUri.Port
                    };
                    TlsTransportSettings tlsSettings = new TlsTransportSettings(tcpSettings)
                    {
                        Certificate = certificate, IsInitiator = false
                    };
                    listeners[i] = tlsSettings.CreateListener();
                }
                else if (addressUri.Scheme.Equals(AmqpConstants.SchemeAmqp, StringComparison.OrdinalIgnoreCase))
                {
                    TcpTransportSettings tcpSettings = new TcpTransportSettings()
                    {
                        Host = addressUri.Host, Port = addressUri.Port
                    };
                    listeners[i] = tcpSettings.CreateListener();
                }
#if !NETSTANDARD
                else if (addressUri.Scheme.Equals("ws", StringComparison.OrdinalIgnoreCase))
                {
                    WebSocketTransportSettings wsSettings = new WebSocketTransportSettings()
                    {
                        Uri = addressUri
                    };
                    listeners[i] = wsSettings.CreateListener();
                }
#endif
                else
                {
                    throw new NotSupportedException(addressUri.Scheme);
                }
            }

            this.transportListener = new AmqpTransportListener(listeners, settings);
            this.settings          = settings;
        }
Ejemplo n.º 25
0
 public static void DisablePayloadMasking_Property_Set_PNSE_Throws()
 {
     var setting = new WebSocketTransportSettings();
     Assert.Throws<PlatformNotSupportedException>(() => setting.DisablePayloadMasking = true);
 }
Ejemplo n.º 26
0
        public void Start()
        {
            // create and initialize AmqpSettings
            AmqpSettings     settings    = new AmqpSettings();
            X509Certificate2 certificate = this.sslValue == null ? null : GetCertificate(this.sslValue);

            settings.RuntimeProvider = this;

            SaslHandler saslHandler;

            if (this.userInfo != null)
            {
                string[] creds     = this.userInfo.Split(':');
                string   usernanme = Uri.UnescapeDataString(creds[0]);
                string   password  = creds.Length == 1 ? string.Empty : Uri.UnescapeDataString(creds[1]);
                saslHandler = new SaslPlainHandler(new TestPlainAuthenticator(this.userInfo, password));
            }
            else
            {
                saslHandler = new SaslAnonymousHandler();
            }

            SaslTransportProvider saslProvider = new SaslTransportProvider(AmqpVersion.V100);

            saslProvider.AddHandler(saslHandler);
            settings.TransportProviders.Add(saslProvider);

            AmqpTransportProvider amqpProvider = new AmqpTransportProvider(AmqpVersion.V100);

            settings.TransportProviders.Add(amqpProvider);

            // create and initialize transport listeners
            TransportListener[] listeners = new TransportListener[this.endpoints.Count];
            for (int i = 0; i < this.endpoints.Count; i++)
            {
                Uri addressUri = new Uri(this.endpoints[i]);

                if (addressUri.Scheme.Equals(AmqpConstants.SchemeAmqps, StringComparison.OrdinalIgnoreCase))
                {
                    if (certificate == null)
                    {
                        throw new InvalidOperationException("/cert option was not set when amqps address is specified.");
                    }

                    TcpTransportSettings tcpSettings = new TcpTransportSettings()
                    {
                        Host = addressUri.Host, Port = addressUri.Port
                    };
                    TlsTransportSettings tlsSettings = new TlsTransportSettings(tcpSettings)
                    {
                        Certificate = certificate, IsInitiator = false
                    };
                    listeners[i] = tlsSettings.CreateListener();
                }
                else if (addressUri.Scheme.Equals(AmqpConstants.SchemeAmqp, StringComparison.OrdinalIgnoreCase))
                {
                    TcpTransportSettings tcpSettings = new TcpTransportSettings()
                    {
                        Host = addressUri.Host, Port = addressUri.Port
                    };
                    listeners[i] = tcpSettings.CreateListener();
                }
                else if (addressUri.Scheme.Equals("ws", StringComparison.OrdinalIgnoreCase))
                {
                    WebSocketTransportSettings wsSettings = new WebSocketTransportSettings()
                    {
                        Uri = addressUri
                    };
                    listeners[i] = wsSettings.CreateListener();
                }
                else
                {
                    throw new NotSupportedException(addressUri.Scheme);
                }
            }

            this.settings          = settings;
            this.transportListener = new AmqpTransportListener(listeners, settings);
            this.transportListener.Listen(this.OnAcceptTransport);
        }
Ejemplo n.º 27
0
 public abstract Task<WebSocket> CreateWebSocketAsync(Uri address, WebHeaderCollection headers, ICredentials credentials, WebSocketTransportSettings settings, TimeoutHelper timeoutHelper);