Example #1
0
        void OnAcceptInnerTransport(TransportListener innerListener, TransportAsyncCallbackArgs innerArgs)
        {
            Fx.Assert(innerArgs.Exception == null, "Should not be called with an exception.");
            Fx.Assert(innerArgs.Transport != null, "Should be called with a transport.");
            AmqpTrace.Provider.AmqpLogOperationInformational(this, TraceOperation.Accept, innerArgs.Transport);

            try
            {
                // upgrade transport
                innerArgs.Transport = new TlsTransport(innerArgs.Transport, this.transportSettings);
                IAsyncResult result = innerArgs.Transport.BeginOpen(
                    innerArgs.Transport.DefaultOpenTimeout, 
                    this.onTransportOpened,
                    innerArgs);
                if (result.CompletedSynchronously)
                {
                    this.HandleTransportOpened(result);
                    return;
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }

                innerArgs.Transport.SafeClose(exception);
            }
        }
        void OnAcceptInnerTransport(TransportListener innerListener, TransportAsyncCallbackArgs innerArgs)
        {
            Fx.Assert(innerArgs.Exception == null, "Should not be called with an exception.");
            Fx.Assert(innerArgs.Transport != null, "Should be called with a transport.");
            AmqpTrace.Provider.AmqpLogOperationInformational(this, TraceOperation.Accept, innerArgs.Transport);

            try
            {
                // upgrade transport
                innerArgs.Transport = new TlsTransport(innerArgs.Transport, this.transportSettings);
                IAsyncResult result = innerArgs.Transport.BeginOpen(
                    innerArgs.Transport.DefaultOpenTimeout,
                    this.onTransportOpened,
                    innerArgs);
                if (result.CompletedSynchronously)
                {
                    this.HandleTransportOpened(result);
                    return;
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }

                innerArgs.Transport.SafeClose(exception);
            }
        }
Example #3
0
 protected override void OnListen()
 {
     TransportSettings innerSettings = this.transportSettings.InnerTransportSettings;
     this.innerListener = innerSettings.CreateListener();
     this.innerListener.Closed += new EventHandler(OnInnerListenerClosed);
     this.innerListener.Listen(this.OnAcceptInnerTransport);
 }
 void OnInnerListenerClosed(object sender, EventArgs e)
 {
     if (!this.IsClosing())
     {
         TransportListener innerListener = (TransportListener)sender;
         this.SafeClose(innerListener.TerminalException);
     }
 }
        protected override void OnListen()
        {
            TransportSettings innerSettings = this.transportSettings.InnerTransportSettings;

            this.innerListener         = innerSettings.CreateListener();
            this.innerListener.Closed += new EventHandler(OnInnerListenerClosed);
            this.innerListener.Listen(this.OnAcceptInnerTransport);
        }
Example #6
0
 void OnListenerClosed(object sender, EventArgs e)
 {
     if (!this.IsClosing())
     {
         // If we weren't shutting down then this class needs to Close itself (with the TerminalException) since
         // it is no longer doing all the listening it is supposed to do.
         TransportListener innerListener = (TransportListener)sender;
         AmqpTrace.Provider.AmqpLogError(this, "OnListenerClosed", innerListener.ToString());
         this.SafeClose(innerListener.TerminalException);
     }
 }
 TransportHandler(AmqpTransportListener parent, TransportListener innerListener, TransportAsyncCallbackArgs args)
 {
     this.parent          = parent;
     this.args            = args;
     this.args.UserToken  = this;
     this.args.UserToken2 = innerListener;
     this.buffer          = new byte[AmqpConstants.ProtocolHeaderSize];
     this.bufferReader    = new AsyncIO.AsyncBufferReader(args.Transport);
     this.bufferWriter    = new AsyncIO.AsyncBufferWriter(args.Transport);
     this.timeoutHelper   = new TimeoutHelper(AmqpConstants.DefaultTimeout);
 }
Example #8
0
 void OnAcceptTransport(TransportListener innerListener, TransportAsyncCallbackArgs args)
 {
     AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Execute, "OnAcceptTransport");
     TransportHandler.SpawnHandler(this, args);
 }
Example #9
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]);

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

                    TlsTransportSettings tlsSettings = new TlsTransportSettings(tcpSettings) { Certificate = certificate, IsInitiator = false };
                    listeners[i] = tlsSettings.CreateListener();
                }
                else
                {
                    listeners[i] = tcpSettings.CreateListener();
                }
            }

            this.transportListener = new AmqpTransportListener(listeners, settings);
            this.settings = settings;
        }
Example #10
0
        void OnAcceptTransport(TransportListener listener, TransportAsyncCallbackArgs args)
        {
            AmqpConnectionSettings connectionSettings = new AmqpConnectionSettings()
            {
                ContainerId = this.containerId,
                MaxFrameSize = this.maxFrameSize
            };

            AmqpConnection connection = null;
            try
            {
                connection = this.CreateConnection(
                    args.Transport,
                    (ProtocolHeader)args.UserToken,
                    false,
                    this.settings,
                    connectionSettings);

                connection.BeginOpen(connection.DefaultOpenTimeout, this.OnConnectionOpenComplete, connection);
            }
            catch (Exception ex)
            {
                if (connection != null)
                {
                    connection.SafeClose(ex);
                }
            }
        }
            public static void SpawnHandler(AmqpTransportListener parent, TransportListener innerListener, TransportAsyncCallbackArgs args)
            {
                TransportHandler handler = new TransportHandler(parent, innerListener, args);

                ActionItem.Schedule(s => Start(s), handler);
            }