예제 #1
0
        private void OnReadHeaderComplete(TransportAsyncCallbackArgs args)
        {
            if (args.Exception != null)
            {
                CompleteOnException(args);
                return;
            }

            try
            {
                ProtocolHeader receivedHeader = new ProtocolHeader();
                receivedHeader.Decode(new ByteBuffer(args.Buffer, args.Offset, args.Count));
                if (!receivedHeader.Equals(_sentHeader))
                {
                    throw new AmqpException(AmqpErrorCode.NotImplemented, $"The requested protocol version {_sentHeader} is not supported. The supported version is {receivedHeader}");
                }

                SaslTransportProvider provider = _amqpSettings.GetTransportProvider <SaslTransportProvider>();
                var transport = provider.CreateTransport(args.Transport, true);
                _tcs.TrySetResult(transport);
            }
            catch (Exception ex)
            {
                args.Exception = ex;
                CompleteOnException(args);
            }
        }
예제 #2
0
        protected override void OnProtocolHeader(ProtocolHeader header)
        {
            Utils.Trace(TraceLevel.Frame, "RECV  {0}", header);
            this.TransitState("R:HDR", StateTransition.ReceiveHeader);
            Exception exception = null;

            if (this.isInitiator)
            {
                if (!this.initialHeader.Equals(header))
                {
                    exception = new AmqpException(AmqpError.NotImplemented, SRClient.ProtocolVersionNotSupported(this.initialHeader.ToString(), header.ToString()));
                }
            }
            else
            {
                ProtocolHeader supportedHeader = this.amqpSettings.GetSupportedHeader(header);
                this.SendProtocolHeader(supportedHeader);
                if (!supportedHeader.Equals(header))
                {
                    exception = new AmqpException(AmqpError.NotImplemented, SRClient.ProtocolVersionNotSupported(this.initialHeader.ToString(), header.ToString()));
                }
            }

            if (exception != null)
            {
                this.CompleteOpen(false, exception);
            }
        }
예제 #3
0
        void OnReadHeaderComplete(TransportAsyncCallbackArgs args)
        {
            if (args.Exception != null)
            {
                AmqpTrace.Provider.AmqpLogError(this, "ReadHeader", args.Exception.Message);
                this.Complete(args);
                return;
            }

            try
            {
                ProtocolHeader receivedHeader = new ProtocolHeader();
                receivedHeader.Decode(new ByteBuffer(args.Buffer, args.Offset, args.Count));
#if DEBUG
                receivedHeader.Trace(false);
                AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Receive, receivedHeader);
#endif

                if (!receivedHeader.Equals(this.sentHeader))
                {
                    // TODO: need to reconnect with the reply version if supported
                    throw new AmqpException(AmqpErrorCode.NotImplemented, AmqpResources.GetString(AmqpResources.AmqpProtocolVersionNotSupported, this.sentHeader, receivedHeader));
                }

                // upgrade transport
                TransportBase secureTransport = this.settings.TransportProviders[this.providerIndex].CreateTransport(args.Transport, true);
                AmqpTrace.Provider.AmqpUpgradeTransport(this, args.Transport, secureTransport);
                args.Transport = secureTransport;
                IAsyncResult result = args.Transport.BeginOpen(this.timeoutHelper.RemainingTime(), this.OnTransportOpenCompete, args);
                if (result.CompletedSynchronously)
                {
                    this.HandleTransportOpened(result);
                }
            }
            catch (Exception exp)
            {
                if (Fx.IsFatal(exp))
                {
                    throw;
                }

                AmqpTrace.Provider.AmqpLogError(this, "OnProtocolHeader", exp.Message);
                args.Exception = exp;
                this.Complete(args);
            }
        }
예제 #4
0
        private void OnReadHeaderComplete(TransportAsyncCallbackArgs args)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, $"{nameof(OnReadHeaderComplete)}");
            }

            if (args.Exception != null)
            {
                CompleteOnException(args);
                return;
            }

            try
            {
                ProtocolHeader receivedHeader = new ProtocolHeader();
                receivedHeader.Decode(new ByteBuffer(args.Buffer, args.Offset, args.Count));

                if (Logging.IsEnabled)
                {
                    Logging.Info(this, $"{nameof(OnReadHeaderComplete)}: Received Protocol Header: {receivedHeader.ToString()}");
                }

                if (!receivedHeader.Equals(SentProtocolHeader))
                {
                    throw new AmqpException(AmqpErrorCode.NotImplemented, $"The requested protocol version {SentProtocolHeader} is not supported. The supported version is {receivedHeader}");
                }

                SaslTransportProvider provider = AmqpSettings.GetTransportProvider <SaslTransportProvider>();
                var transport = provider.CreateTransport(args.Transport, true);
                if (Logging.IsEnabled)
                {
                    Logging.Info(this, $"{nameof(OnReadHeaderComplete)}: Created SaslTransportHandler ");
                }
                TaskCompletionSource.TrySetResult(transport);
                if (Logging.IsEnabled)
                {
                    Logging.Exit(this, $"{nameof(OnReadHeaderComplete)}");
                }
            }
            catch (Exception ex)
            {
                args.Exception = ex;
                CompleteOnException(args);
            }
        }
예제 #5
0
        void OnReadHeaderComplete(TransportAsyncCallbackArgs args)
        {
            if (args.Exception != null)
            {
                this.Complete(args);
                return;
            }

            try
            {
                ProtocolHeader receivedHeader = ProtocolHeader.Decode(ByteBuffer.Wrap(args.Buffer, args.Offset, args.Count));
                Utils.Trace(TraceLevel.Info, "{0}: Received header {1}", this, receivedHeader);
                Utils.Trace(TraceLevel.Frame, "RECV  {0}", receivedHeader);

                if (!receivedHeader.Equals(this.sentHeader))
                {
                    // TODO: need to reconnect with the reply version if supported
                    throw new AmqpException(AmqpError.NotImplemented, SRClient.ProtocolVersionNotSupported(this.sentHeader, receivedHeader));
                }

                // upgrade transport
                TransportBase secureTransport = this.settings.TransportProviders[this.providerIndex].CreateTransport(args.Transport, true);
                Utils.Trace(TraceLevel.Info, "{0}: Upgrade transport {1} -> {2}.", this, args.Transport, secureTransport);
                args.Transport = secureTransport;
                IAsyncResult result = args.Transport.BeginOpen(this.timeoutHelper.RemainingTime(), this.OnTransportOpenCompete, args);
                if (result.CompletedSynchronously)
                {
                    this.HandleTransportOpened(result);
                }
            }
            catch (Exception exp)
            {
                if (Fx.IsFatal(exp))
                {
                    throw;
                }

                Utils.Trace(TraceLevel.Info, "{0}: exception: {1}", this, exp.Message);
                args.Exception = exp;
                this.Complete(args);
            }
        }
예제 #6
0
        protected override void OnProtocolHeader(ProtocolHeader header)
        {
            base.TransitState("R:HDR", StateTransition.ReceiveHeader);
            Exception amqpException = null;

            if (!this.isInitiator)
            {
                ProtocolHeader supportedHeader = this.amqpSettings.GetSupportedHeader(header);
                this.SendProtocolHeader(supportedHeader);
                if (!supportedHeader.Equals(header))
                {
                    amqpException = new AmqpException(AmqpError.NotImplemented, SRAmqp.AmqpProtocolVersionNotSupported(this.initialHeader.ToString(), header.ToString()));
                }
            }
            else if (!this.initialHeader.Equals(header))
            {
                amqpException = new AmqpException(AmqpError.NotImplemented, SRAmqp.AmqpProtocolVersionNotSupported(this.initialHeader.ToString(), header.ToString()));
            }
            if (amqpException != null)
            {
                base.CompleteOpen(false, amqpException);
            }
        }
예제 #7
0
        protected override void OnProtocolHeader(ProtocolHeader header)
        {
#if DEBUG
            header.Trace(false);
            AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Receive, header);
#endif
            this.heartBeat.OnReceive();
            if (this.UsageMeter != null)
            {
                this.UsageMeter.OnRead(this, 0, header.EncodeSize);
            }

            this.TransitState("R:HDR", StateTransition.ReceiveHeader);
            Exception exception = null;

            if (this.isInitiator)
            {
                if (!this.initialHeader.Equals(header))
                {
                    exception = new AmqpException(AmqpErrorCode.NotImplemented, AmqpResources.GetString(AmqpResources.AmqpProtocolVersionNotSupported, this.initialHeader.ToString(), header.ToString()));
                }
            }
            else
            {
                ProtocolHeader supportedHeader = this.amqpSettings.GetSupportedHeader(header);
                this.SendProtocolHeader(supportedHeader);
                if (!supportedHeader.Equals(header))
                {
                    exception = new AmqpException(AmqpErrorCode.NotImplemented, AmqpResources.GetString(AmqpResources.AmqpProtocolVersionNotSupported, this.initialHeader.ToString(), header.ToString()));
                }
            }

            if (exception != null)
            {
                this.CompleteOpen(false, exception);
            }
        }
예제 #8
0
 private void OnReadHeaderComplete(TransportAsyncCallbackArgs args)
 {
     if (args.Exception != null)
     {
         MessagingClientEtwProvider.TraceClient <AmqpTransportInitiator, Exception>((AmqpTransportInitiator source, Exception ex) => MessagingClientEtwProvider.Provider.EventWriteAmqpLogError(source, "ReadHeader", ex.Message), this, args.Exception);
         this.Complete(args);
         return;
     }
     try
     {
         ProtocolHeader protocolHeader = new ProtocolHeader();
         protocolHeader.Decode(new ByteBuffer(args.Buffer, args.Offset, args.Count));
         if (!protocolHeader.Equals(this.sentHeader))
         {
             throw new AmqpException(AmqpError.NotImplemented, SRAmqp.AmqpProtocolVersionNotSupported(this.sentHeader, protocolHeader));
         }
         TransportBase transportBase = this.settings.TransportProviders[this.providerIndex].CreateTransport(args.Transport, true);
         MessagingClientEtwProvider.TraceClient <AmqpTransportInitiator, TransportBase, TransportBase>((AmqpTransportInitiator source, TransportBase from, TransportBase to) => MessagingClientEtwProvider.Provider.EventWriteAmqpUpgradeTransport(source, from, to), this, args.Transport, transportBase);
         args.Transport = transportBase;
         IAsyncResult asyncResult = args.Transport.BeginOpen(this.timeoutHelper.RemainingTime(), new AsyncCallback(this.OnTransportOpenCompete), args);
         if (asyncResult.CompletedSynchronously)
         {
             this.HandleTransportOpened(asyncResult);
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         MessagingClientEtwProvider.TraceClient <AmqpTransportInitiator, Exception>((AmqpTransportInitiator source, Exception ex) => MessagingClientEtwProvider.Provider.EventWriteAmqpLogError(source, "OnProtocolHeader", ex.Message), this, exception);
         args.Exception = exception;
         this.Complete(args);
     }
 }