예제 #1
0
        void SendProtocolHeader(ProtocolHeader header)
        {
#if DEBUG
            header.Trace(true);
            AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Send, header);
#endif
            this.TransitState("S:HDR", StateTransition.SendHeader);
            this.SendDatablock(header);
        }
예제 #2
0
            void OnProtocolHeader(ByteBuffer buffer)
            {
                ProtocolHeader header = new ProtocolHeader();

                header.Decode(buffer);
                AmqpTrace.Provider.AmqpLogOperationInformational(this, TraceOperation.Receive, header);

                // Protocol id negotiation
                TransportProvider provider = null;

                if (!this.parent.settings.TryGetTransportProvider(header, out provider))
                {
                    Fx.Assert(provider != null, "At least on provider should be configured.");
                    this.WriteReplyHeader(new ProtocolHeader(provider.ProtocolId, provider.DefaultVersion), true);
                    return;
                }

                // Protocol version negotiation
                AmqpVersion version;

                if (!provider.TryGetVersion(header.Version, out version))
                {
                    this.WriteReplyHeader(new ProtocolHeader(provider.ProtocolId, version), true);
                    return;
                }

                TransportBase newTransport = provider.CreateTransport(this.args.Transport, false);

                if (object.ReferenceEquals(newTransport, this.args.Transport))
                {
                    if ((this.parent.settings.RequireSecureTransport && !newTransport.IsSecure) ||
                        (!this.parent.settings.AllowAnonymousConnection && !newTransport.IsAuthenticated))
                    {
                        AmqpTrace.Provider.AmqpInsecureTransport(this.parent, newTransport, newTransport.IsSecure, newTransport.IsAuthenticated);
                        this.WriteReplyHeader(this.parent.settings.GetDefaultHeader(), true);
                    }
                    else
                    {
                        this.args.UserToken = header;
                        this.parent.OnHandleTransportComplete(this.args);
                    }
                }
                else
                {
#if DEBUG
                    header.Trace(false);
#endif
                    AmqpTrace.Provider.AmqpUpgradeTransport(this, args.Transport, newTransport);
                    this.args.Transport = newTransport;
                    this.WriteReplyHeader(header, false);
                }
            }
예제 #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
            void WriteReplyHeader(ProtocolHeader header, bool fail)
            {
                AmqpTrace.Provider.AmqpLogOperationInformational(this, TraceOperation.Send, header);
#if DEBUG
                header.Trace(true);
#endif

                ByteBuffer byteBuffer = new ByteBuffer(this.buffer);
                header.Encode(byteBuffer);
                this.args.SetBuffer(this.buffer, 0, this.buffer.Length);
                this.args.CompletedCallback = fail ? null : TransportHandler.writeCompleteCallback;
                this.bufferWriter.WriteBuffer(this.args);

                if (fail)
                {
                    this.args.Exception = new NotSupportedException(header.ToString());
                    this.parent.OnHandleTransportComplete(this.args);
                }
            }
예제 #5
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);
            }
        }