public ProtocolHeader ExtractProtocolHeader(ByteBuffer buffer) { if (buffer.Length < AmqpConstants.ProtocolHeaderSize) { return null; } ProtocolHeader header = new ProtocolHeader(); header.Decode(buffer); return header; }
public override bool Equals(object obj) { ProtocolHeader otherHeader = obj as ProtocolHeader; if (otherHeader == null) { return(false); } return(otherHeader.protocolId == this.protocolId && otherHeader.version.Equals(this.version)); }
public AmqpConnection(TransportBase transport, ProtocolHeader protocolHeader, bool isInitiator, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings) : base((isInitiator ? "out" : "in") + "-connection", transport, connectionSettings, isInitiator) { if (amqpSettings == null) { throw new ArgumentNullException("amqpSettings"); } this.initialHeader = protocolHeader; this.isInitiator = isInitiator; this.amqpSettings = amqpSettings; this.sessionsByLocalHandle = new HandleTable<AmqpSession>(this.Settings.ChannelMax ?? AmqpConstants.DefaultMaxConcurrentChannels - 1); this.sessionsByRemoteHandle = new HandleTable<AmqpSession>(this.Settings.ChannelMax ?? AmqpConstants.DefaultMaxConcurrentChannels - 1); this.SessionFactory = this; this.heartBeat = HeartBeat.None; }
public AmqpConnection CreateConnection(TransportBase transport, ProtocolHeader protocolHeader, bool isInitiator, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings) { return new AmqpConnection(transport, protocolHeader, false, amqpSettings, connectionSettings); }
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); }
public AmqpConnection(TransportBase transport, ProtocolHeader protocolHeader, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings) : this(transport, protocolHeader, true, amqpSettings, connectionSettings) { }
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); } }
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); } }
void WriteSecurityHeader(TransportAsyncCallbackArgs args) { // secure transport: header negotiation TransportProvider provider = this.settings.TransportProviders[this.providerIndex]; this.sentHeader = new ProtocolHeader(provider.ProtocolId, provider.DefaultVersion); #if DEBUG this.sentHeader.Trace(true); AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Send, this.sentHeader); #endif ByteBuffer buffer = new ByteBuffer(new byte[AmqpConstants.ProtocolHeaderSize]); this.sentHeader.Encode(buffer); args.SetBuffer(buffer.Buffer, buffer.Offset, buffer.Length); args.CompletedCallback = this.OnWriteHeaderComplete; this.writer.WriteBuffer(args); }
void OnReceiveFrameBuffer(ByteBuffer buffer) { if (this.State <= AmqpObjectState.OpenClosePipe) { Fx.Assert(buffer.Length == AmqpConstants.ProtocolHeaderSize, "protocol header size is wrong"); try { ProtocolHeader header = new ProtocolHeader(); header.Decode(buffer); this.OnProtocolHeader(header); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } AmqpTrace.Provider.AmqpLogError(this, "OnProtocolHeader", exception.Message); this.TerminalException = exception; this.Abort(); } } else { try { this.OnFrameBuffer(buffer); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } AmqpTrace.Provider.AmqpLogError(this, "OnFrame", exception.Message); this.SafeClose(exception); } } }
protected abstract void OnProtocolHeader(ProtocolHeader header);