/// <summary> /// Creates a new connection with a custom open frame and a callback to handle remote open frame. /// </summary> /// <param name="address">The address of remote endpoint to connect to.</param> /// <param name="open">If specified, it is sent to open the connection, otherwise an open frame created from the AMQP settings property is sent.</param> /// <param name="onOpened">If specified, it is invoked when an open frame is received from the remote peer.</param> /// <returns></returns> public async Task <Connection> CreateAsync(Address address, Open open, OnOpened onOpened) { IAsyncTransport transport; #if !WINDOWS_PHONE if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address); transport = wsTransport; } else #endif if (string.Equals(address.Scheme, Address.Amqp, StringComparison.OrdinalIgnoreCase) || string.Equals(address.Scheme, Address.Amqps, StringComparison.OrdinalIgnoreCase)) { TcpTransport tcpTransport = new TcpTransport(); await tcpTransport.ConnectAsync(address, this); transport = tcpTransport; } else { throw new NotSupportedException(address.Scheme); } if (address.User != null) { SaslPlainProfile profile = new SaslPlainProfile(address.User, address.Password); transport = await profile.OpenAsync(address.Host, null, transport); } else if (this.saslSettings != null && this.saslSettings.Profile != null) { transport = await this.saslSettings.Profile.OpenAsync(address.Host, null, transport); } AsyncPump pump = new AsyncPump(null, transport); Connection connection = new Connection(null, this.AMQP, address, transport, open, onOpened); pump.Start(connection); return(connection); }
internal async Task ConnectAsync(Address address, SaslProfile saslProfile, Open open, Connection connection) { if (saslProfile == null) { if (address.User != null) { saslProfile = new SaslPlainProfile(address.User, address.Password); } else if (this.saslSettings != null && this.saslSettings.Profile != null) { saslProfile = this.saslSettings.Profile; } } IAsyncTransport transport = await this.CreateTransportAsync(address, saslProfile, connection.Handler).ConfigureAwait(false); connection.Init(this.BufferManager, this.AMQP, transport, open); AsyncPump pump = new AsyncPump(this.BufferManager, transport); pump.Start(connection); }
async Task <Connection> CreateAsync(Address address, Open open, OnOpened onOpened, IHandler handler) { SaslProfile saslProfile = null; if (address.User != null) { saslProfile = new SaslPlainProfile(address.User, address.Password); } else if (this.saslSettings != null && this.saslSettings.Profile != null) { saslProfile = this.saslSettings.Profile; } IAsyncTransport transport = await this.CreateTransportAsync(address, saslProfile, handler).ConfigureAwait(false); Connection connection = new Connection(this.BufferManager, this.AMQP, address, transport, open, onOpened, handler); AsyncPump pump = new AsyncPump(this.BufferManager, transport); pump.Start(connection); return(connection); }
/// <summary> /// Creates a new connection with a custom open frame and a callback to handle remote open frame. /// </summary> /// <param name="address">The address of remote endpoint to connect to.</param> /// <param name="open">If specified, it is sent to open the connection, otherwise an open frame created from the AMQP settings property is sent.</param> /// <param name="onOpened">If specified, it is invoked when an open frame is received from the remote peer.</param> /// <returns></returns> public async Task <Connection> CreateAsync(Address address, Open open, OnOpened onOpened) { IAsyncTransport transport; if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address); transport = wsTransport; } else { TcpTransport tcpTransport = new TcpTransport(); await tcpTransport.ConnectAsync(address, this); transport = tcpTransport; } if (address.User != null) { SaslPlainProfile profile = new SaslPlainProfile(address.User, address.Password); transport = await profile.OpenAsync(address.Host, null, transport); } else if (this.saslSettings != null && this.saslSettings.Profile != null) { transport = await this.saslSettings.Profile.OpenAsync(address.Host, null, transport); } AsyncPump pump = new AsyncPump(null, transport); Connection connection = new Connection(null, this.AMQP, address, transport, open, onOpened); pump.Start(connection); return(connection); }
internal static async Task<IAsyncTransport> OpenAsync(this SaslProfile saslProfile, string hostname, IAsyncTransport transport) { ProtocolHeader header = saslProfile.Start(hostname, transport); AsyncPump pump = new AsyncPump(transport); await pump.PumpAsync( h => { saslProfile.OnHeader(header, h); return true; }, b => { SaslCode code; return saslProfile.OnFrame(transport, b, out code); }); return (IAsyncTransport)saslProfile.UpgradeTransportInternal(transport); }
internal static async Task<IAsyncTransport> OpenAsync(this SaslProfile saslProfile, string hostname, IBufferManager bufferManager, IAsyncTransport transport) { // if transport is closed, pump reader should throw exception TransportWriter writer = new TransportWriter(transport, e => { }); ProtocolHeader myHeader = saslProfile.Start(hostname, writer); AsyncPump pump = new AsyncPump(bufferManager, transport); SaslCode code = SaslCode.Auth; await pump.PumpAsync( header => { saslProfile.OnHeader(myHeader, header); return true; }, buffer => { return saslProfile.OnFrame(writer, buffer, out code); }); await writer.FlushAsync(); if (code != SaslCode.Ok) { throw new AmqpException(ErrorCode.UnauthorizedAccess, Fx.Format(SRAmqp.SaslNegoFailed, code)); } return (IAsyncTransport)saslProfile.UpgradeTransportInternal(transport); }
/// <summary> /// Creates a new connection with a custom open frame and a callback to handle remote open frame. /// </summary> /// <param name="address">The address of remote endpoint to connect to.</param> /// <param name="open">If specified, it is sent to open the connection, otherwise an open frame created from the AMQP settings property is sent.</param> /// <param name="onOpened">If specified, it is invoked when an open frame is received from the remote peer.</param> /// <returns>A task for the connection creation operation. On success, the result is an AMQP <see cref="Connection"/></returns> public async Task<Connection> CreateAsync(Address address, Open open, OnOpened onOpened) { IAsyncTransport transport; TransportProvider provider; if (this.transportFactories != null && this.transportFactories.TryGetValue(address.Scheme, out provider)) { transport = await provider.CreateAsync(address); } else if (TcpTransport.MatchScheme(address.Scheme)) { TcpTransport tcpTransport = new TcpTransport(this.BufferManager); await tcpTransport.ConnectAsync(address, this); transport = tcpTransport; } #if NETFX else if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address, null); transport = wsTransport; } #endif else { throw new NotSupportedException(address.Scheme); } if (address.User != null) { SaslPlainProfile profile = new SaslPlainProfile(address.User, address.Password); transport = await profile.OpenAsync(address.Host, this.BufferManager, transport); } else if (this.saslSettings != null && this.saslSettings.Profile != null) { transport = await this.saslSettings.Profile.OpenAsync(address.Host, this.BufferManager, transport); } AsyncPump pump = new AsyncPump(this.BufferManager, transport); Connection connection = new Connection(this.BufferManager, this.AMQP, address, transport, open, onOpened); pump.Start(connection); return connection; }
/// <summary> /// Creates a new connection with a custom open frame and a callback to handle remote open frame. /// </summary> /// <param name="address">The address of remote endpoint to connect to.</param> /// <param name="open">If specified, it is sent to open the connection, otherwise an open frame created from the AMQP settings property is sent.</param> /// <param name="onOpened">If specified, it is invoked when an open frame is received from the remote peer.</param> /// <returns></returns> public async Task<Connection> CreateAsync(Address address, Open open, OnOpened onOpened) { IAsyncTransport transport; if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address); transport = wsTransport; } else { TcpTransport tcpTransport = new TcpTransport(); await tcpTransport.ConnectAsync(address, this); transport = tcpTransport; } if (address.User != null) { SaslPlainProfile profile = new SaslPlainProfile(address.User, address.Password); transport = await profile.OpenAsync(address.Host, transport); } else if (this.saslSettings != null && this.saslSettings.Profile != null) { transport = await this.saslSettings.Profile.OpenAsync(address.Host, transport); } AsyncPump pump = new AsyncPump(transport); Connection connection = new Connection(this.AMQP, address, transport, open, onOpened); pump.Start(connection); return connection; }
/// <summary> /// Creates a new connection with a custom open frame and a callback to handle remote open frame. /// </summary> /// <param name="address">The address of remote endpoint to connect to.</param> /// <param name="open">If specified, it is sent to open the connection, otherwise an open frame created from the AMQP settings property is sent.</param> /// <param name="onOpened">If specified, it is invoked when an open frame is received from the remote peer.</param> /// <returns></returns> public async Task<Connection> CreateAsync(Address address, Open open, OnOpened onOpened) { IAsyncTransport transport; if (string.Equals(address.Scheme, Address.Amqp, StringComparison.OrdinalIgnoreCase) || string.Equals(address.Scheme, Address.Amqps, StringComparison.OrdinalIgnoreCase)) { TcpTransport tcpTransport = new TcpTransport(this.BufferManager); await tcpTransport.ConnectAsync(address, this); transport = tcpTransport; } #if NETFX else if (WebSocketTransport.MatchScheme(address.Scheme)) { WebSocketTransport wsTransport = new WebSocketTransport(); await wsTransport.ConnectAsync(address); transport = wsTransport; } #endif else { throw new NotSupportedException(address.Scheme); } if (address.User != null) { SaslPlainProfile profile = new SaslPlainProfile(address.User, address.Password); transport = await profile.OpenAsync(address.Host, this.BufferManager, transport); } else if (this.saslSettings != null && this.saslSettings.Profile != null) { transport = await this.saslSettings.Profile.OpenAsync(address.Host, this.BufferManager, transport); } AsyncPump pump = new AsyncPump(this.BufferManager, transport); Connection connection = new Connection(this.BufferManager, this.AMQP, address, transport, open, onOpened); pump.Start(connection); return connection; }
internal static async Task<IAsyncTransport> OpenAsync(this SaslProfile saslProfile, string hostname, IBufferManager bufferManager, IAsyncTransport transport) { // if transport is closed, pump reader should throw exception TransportWriter writer = new TransportWriter(transport, e => { }); ProtocolHeader myHeader = saslProfile.Start(hostname, writer); AsyncPump pump = new AsyncPump(bufferManager, transport); await pump.PumpAsync( header => { saslProfile.OnHeader(myHeader, header); return true; }, buffer => { SaslCode code; return saslProfile.OnFrame(writer, buffer, out code); }); await writer.FlushAsync(); return (IAsyncTransport)saslProfile.UpgradeTransportInternal(transport); }