Ejemplo n.º 1
0
 public AsyncIO(
     int bufferSize,
     TransportBase transport,
     Action<ByteBuffer> receiveBufferHandler,
     Action<Exception> faultHandler)
 {
     Fx.Assert(transport != null, "transport required");
     Fx.Assert(receiveBufferHandler != null, "receiveBufferHandler required");
     this.transport = transport;
     this.faultHandler = faultHandler;
     this.reader = new AsyncReader(this, bufferSize, receiveBufferHandler);
     this.writer = new AsyncWriter(this, bufferSize);
 }
Ejemplo n.º 2
0
        public AmqpConnection(TransportBase transport, ProtocolHeader protocolHeader, bool isInitiator, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings) :
            base(transport, connectionSettings)
        {
            if (amqpSettings == null)
            {
                throw new ArgumentNullException("amqpSettings");
            }

            this.initialHeader = protocolHeader;
            this.isInitiator = isInitiator;
            this.amqpSettings = amqpSettings;
            this.frameDecoder = new FrameDecoder((int)this.Settings.MaxFrameSize);
            this.sessionsByLocalHandle = new HandleTable<AmqpSession>(this.Settings.ChannelMax.Value);
            this.sessionsByRemoteHandle = new HandleTable<AmqpSession>(this.Settings.ChannelMax.Value);
            this.SessionFactory = this;
        }
Ejemplo n.º 3
0
        public TlsTransport(TransportBase innerTransport, TlsTransportSettings tlsSettings)
            : base()
        {
            Fx.Assert((tlsSettings.IsInitiator && tlsSettings.TargetHost != null) || (!tlsSettings.IsInitiator && tlsSettings.Certificate != null),
                tlsSettings.IsInitiator ? "Must have a target host for the client." : "Must have a certificate for the server.");
            this.innerTransport = innerTransport;
            this.isInitiator = tlsSettings.IsInitiator;
            this.targetHost = tlsSettings.TargetHost;
            this.serverCert = tlsSettings.Certificate;
            this.sslStream = tlsSettings.CertificateValidationCallback == null ?
                new SslStream(new TransportStream(this.innerTransport), false) :
                new SslStream(new TransportStream(this.innerTransport), false, tlsSettings.CertificateValidationCallback);

            this.onReadComplete = this.OnReadComplete;
            this.onOpenComplete = this.OnOpenComplete;
            this.onWriteComplete = this.OnWriteComplete;
        }
Ejemplo n.º 4
0
        public AmqpConnectionBase(TransportBase transport, AmqpConnectionSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            this.settings = settings;

            Fx.Assert(transport != null, "transport must not be null.");
            this.principal = transport.Principal;
            this.asyncIO = new AsyncIO(
                AmqpConstants.AsyncBufferSize,
                transport,
                new Action<ByteBuffer>(this.OnReceiveBuffer),
                this.OnAsyncIoFaulted);
            this.bufferHandler = new SerializedWorker<ByteBuffer>(this.OnReceiveFrameBuffer, null, false);
        }
        private void Complete(IAsyncResult connectAsyncResult, bool completeSynchronously)
        {
            EventTraceActivity eventTraceActivity       = new EventTraceActivity();
            TransportBase      clientWebSocketTransport = null;

            try
            {
                try
                {
                    ServiceBusClientWebSocket clientWebSocket = AsyncResult <WebSocketConnectAsyncResult> .End(connectAsyncResult).ClientWebSocket;

                    clientWebSocketTransport = new ClientWebSocketTransport(clientWebSocket, this.uri, this.webSocketTransportSettings, eventTraceActivity);
                    clientWebSocketTransport.Open();
                    MessagingClientEtwProvider.Provider.WebSocketTransportEstablished(eventTraceActivity, this.uri.AbsoluteUri);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    this.callbackArgs.Exception = exception;
                    if (clientWebSocketTransport != null)
                    {
                        clientWebSocketTransport.SafeClose(exception);
                    }
                    clientWebSocketTransport = null;
                }
            }
            finally
            {
                this.callbackArgs.Transport = clientWebSocketTransport;
                this.callbackArgs.CompletedSynchronously = completeSynchronously;
                if (!completeSynchronously)
                {
                    this.callbackArgs.CompletedCallback(this.callbackArgs);
                }
            }
        }
Ejemplo n.º 6
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);
     }
 }
Ejemplo n.º 7
0
            private void OnProtocolHeader(ByteBuffer buffer)
            {
                AmqpVersion    amqpVersion;
                ProtocolHeader protocolHeader = new ProtocolHeader();

                protocolHeader.Decode(buffer);
                MessagingClientEtwProvider.TraceClient <AmqpTransportListener.TransportHandler, ProtocolHeader>((AmqpTransportListener.TransportHandler source, ProtocolHeader detail) => MessagingClientEtwProvider.Provider.EventWriteAmqpLogOperation(source, TraceOperation.Receive, detail), this, protocolHeader);
                TransportProvider transportProvider = null;

                if (!this.parent.settings.TryGetTransportProvider(protocolHeader, out transportProvider))
                {
                    this.WriteReplyHeader(new ProtocolHeader(transportProvider.ProtocolId, transportProvider.DefaultVersion), true);
                    return;
                }
                if (!transportProvider.TryGetVersion(protocolHeader.Version, out amqpVersion))
                {
                    this.WriteReplyHeader(new ProtocolHeader(transportProvider.ProtocolId, amqpVersion), true);
                    return;
                }
                TransportBase transportBase = transportProvider.CreateTransport(this.args.Transport, false);

                if (!object.ReferenceEquals(transportBase, this.args.Transport))
                {
                    MessagingClientEtwProvider.TraceClient <AmqpTransportListener.TransportHandler, TransportBase, TransportBase>((AmqpTransportListener.TransportHandler source, TransportBase from, TransportBase to) => MessagingClientEtwProvider.Provider.EventWriteAmqpUpgradeTransport(source, from, to), this, this.args.Transport, transportBase);
                    this.args.Transport = transportBase;
                    this.WriteReplyHeader(protocolHeader, false);
                    return;
                }
                if ((!this.parent.settings.RequireSecureTransport || transportBase.IsSecure) && (this.parent.settings.AllowAnonymousConnection || transportBase.IsAuthenticated))
                {
                    this.args.UserToken = protocolHeader;
                    this.parent.OnHandleTransportComplete(this.args);
                    return;
                }
                MessagingClientEtwProvider.TraceClient <AmqpTransportListener, TransportBase>((AmqpTransportListener source, TransportBase transport) => MessagingClientEtwProvider.Provider.EventWriteAmqpInsecureTransport(source, transport, transport.IsSecure, transport.IsAuthenticated), this.parent, transportBase);
                this.WriteReplyHeader(this.parent.settings.GetDefaultHeader(), true);
            }
Ejemplo n.º 8
0
 protected void OnTransport(TransportBase transport)
 {
     this.connection = new AmqpFrameConnection(this.parent, transport, (int)AmqpConstants.DefaultMaxFrameSize);
     IAsyncResult result = this.connection.BeginOpen(this.timeoutHelper.RemainingTime(), this.PrepareAsyncCompletion(onConnectionOpen), this);
     this.SyncContinue(result);
 }
Ejemplo n.º 9
0
 public TlsTransport(TransportBase innerTransport, TlsTransportSettings tlsSettings) : base("tls")
 {
     this.innerTransport = innerTransport;
     this.tlsSettings    = tlsSettings;
     this.sslStream      = (tlsSettings.CertificateValidationCallback == null ? new SslStream(new TransportStream(this.innerTransport), false) : new SslStream(new TransportStream(this.innerTransport), false, tlsSettings.CertificateValidationCallback));
 }
Ejemplo n.º 10
0
 public WriteAsyncResult(TransportBase transport)
 {
     this.transport = transport;
     this.args = new TransportAsyncCallbackArgs();
     this.args.CompletedCallback = OnWriteComplete;
     this.args.UserToken = this;
 }
Ejemplo n.º 11
0
 protected override TransportBase OnCreateTransport(TransportBase innerTransport, bool isInitiator)
 {
     return new TlsTransport(innerTransport, this.tlsSettings);
 }
Ejemplo n.º 12
0
 protected abstract TransportBase OnCreateTransport(TransportBase innerTransport, bool isInitiator);
		protected override TransportBase OnCreateTransport(TransportBase innerTransport, bool isInitiator)
		{
			return innerTransport;
		}
Ejemplo n.º 14
0
 protected abstract TransportBase OnCreateTransport(TransportBase innerTransport, bool isInitiator);
 protected override TransportBase OnCreateTransport(TransportBase innerTransport, bool isInitiator)
 {
     return(new TlsTransport(innerTransport, this.tlsSettings));
 }
Ejemplo n.º 16
0
 protected override TransportBase OnCreateTransport(TransportBase innerTransport, bool isInitiator)
 {
     return new SaslTransport(innerTransport, this, isInitiator);
 }
Ejemplo n.º 17
0
 public AsyncBufferWriter(TransportBase transport)
 {
     this.transport = transport;
     this.onWriteComplete = this.OnWriteComplete;
 }
Ejemplo n.º 18
0
            int state;  //0: idle, 1: busy, 2: closed

            public AsyncWriter(AsyncIO parent, int bufferSize)
            {
                this.parent = parent;
                this.transport = parent.transport;
                this.writeAsyncEventArgs = new TransportAsyncCallbackArgs();
                this.writeAsyncEventArgs.CompletedCallback = this.WriteCompleteCallback;
                this.writeBuffer = ByteBuffer.Wrap(new byte[bufferSize]);
                this.syncRoot = new object();
            }
Ejemplo n.º 19
0
 public FrameBufferReader(TransportBase transport)
 {
     this.transport = transport;
     this.onSizeComplete = this.OnReadSizeComplete;
     this.onFrameComplete = this.OnReadFrameComplete;
     this.sizeBuffer = new byte[FixedWidth.UInt];
 }
Ejemplo n.º 20
0
 public AsyncBufferReader(TransportBase transport)
 {
     this.transport = transport;
     this.onReadComplete = this.OnReadComplete;
 }
Ejemplo n.º 21
0
        public AmqpConnection CreateConnection(TransportBase transport, ProtocolHeader protocolHeader, bool isInitiator, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings)
        {
            if (this.amqpSettings.RequireSecureTransport && !transport.IsSecure)
            {
                throw new AmqpException(AmqpError.NotAllowed, SR.AmqpTransportNotSecure);
            }

            AmqpConnection connection = new AmqpConnection(transport, protocolHeader, isInitiator, amqpSettings, connectionSettings);
            Utils.Trace(TraceLevel.Info, "{0}: Created {1}", this, connection);
            return connection;
        }
Ejemplo n.º 22
0
 public AmqpFrameConnection(AmqpStream parent, TransportBase transport, int maxFrameSize) :
     base(transport, new AmqpConnectionSettings() { MaxFrameSize = (uint)maxFrameSize })
 {
     this.parent = parent;
     this.decoder = new FrameDecoder(maxFrameSize);
 }
Ejemplo n.º 23
0
 public TransportBase CreateTransport(TransportBase innerTransport, bool isInitiator)
 {
     return(this.OnCreateTransport(innerTransport, isInitiator));
 }
Ejemplo n.º 24
0
 public AmqpConnection(TransportBase transport, ProtocolHeader protocolHeader, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings) :
     this(transport, protocolHeader, true, amqpSettings, connectionSettings)
 {
 }
Ejemplo n.º 25
0
 AmqpConnection IConnectionFactory.CreateConnection(TransportBase transport, ProtocolHeader protocolHeader, bool isInitiator, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 26
0
 public TransportStream(TransportBase transport)
 {
     this.transport = transport;
 }
Ejemplo n.º 27
0
 public AmqpConnection(TransportBase transport, AmqpSettings amqpSettings, AmqpConnectionSettings connectionSettings) :
     this(transport, amqpSettings.GetDefaultHeader(), true, amqpSettings, connectionSettings)
 {
 }
Ejemplo n.º 28
0
 public TransportBase CreateTransport(TransportBase innerTransport, bool isInitiator)
 {
     return this.OnCreateTransport(innerTransport, isInitiator);
 }
Ejemplo n.º 29
0
 public ReadAsyncResult(TransportBase transport)
 {
     this.transport = transport;
     this.readBuffer = new byte[AmqpConstants.AsyncBufferSize];
     this.readArgs = new TransportAsyncCallbackArgs();
     this.readArgs.SetBuffer(this.readBuffer, 0, this.readBuffer.Length);
     this.readArgs.CompletedCallback = OnReadComplete;
     this.readArgs.UserToken = this;
 }
Ejemplo n.º 30
0
 public TransportStream(TransportBase transport)
 {
     this.transport = transport;
     this.readResult = new ReadAsyncResult(this.transport);
     this.writeResult = new WriteAsyncResult(this.transport);
 }
Ejemplo n.º 31
0
 public TransportStream(TransportBase transport)
 {
     this.transport   = transport;
     this.readResult  = new ReadAsyncResult(this.transport);
     this.writeResult = new WriteAsyncResult(this.transport);
 }
Ejemplo n.º 32
0
 public SaslTransport(TransportBase transport, SaslTransportProvider provider, bool isInitiator)
 {
     this.innerTransport = transport;
     this.provider = provider;
     this.isInitiator = isInitiator;
 }