private Task __SendConnectionStartOk(string username, string password)
        {
            var tcs = new TaskCompletionSource <bool>();

            // Only supports PLAIN authentication for now

            var auth   = Encoding.UTF8.GetBytes("\0" + username + "\0" + password);
            var writer = AmqpConnectionFrameWriter.ConnectionStartOk(Protocol.ClientProperties, "PLAIN", auth, "en_US");

            SendCommand(0, 10, 30,
                        writer,
                        reply: (channel, classMethodId, error) =>
            {
                if (classMethodId == AmqpClassMethodConnectionLevelConstants.ConnectionTune)
                {
                    _frameReader.Read_ConnectionTune((channelMax, frameMax, heartbeat) =>
                    {
                        this._channelMax = channelMax;
                        this._heartbeat  = heartbeat;
                        this._frameMax   = frameMax;

                        tcs.SetResult(true);
                    });
                }
                else
                {
                    AmqpIOBase.SetException(tcs, error, classMethodId);
                }
                return(Task.CompletedTask);
            }, expectsReply: true);

            return(tcs.Task);
        }
Example #2
0
        private Task <string> __SendConnectionOpen(string vhost)
        {
            if (LogAdapter.ProtocolLevelLogEnabled)
            {
                LogAdapter.LogDebug("ConnectionIO", "__SendConnectionOpen > vhost " + vhost);
            }

            var tcs    = new TaskCompletionSource <string>();
            var writer = AmqpConnectionFrameWriter.ConnectionOpen(vhost, string.Empty, false);

            SendCommand(0, 10, 40, writer,
                        reply: (channel, classMethodId, error) =>
            {
                if (classMethodId == AmqpClassMethodConnectionLevelConstants.ConnectionOpenOk)
                {
                    _frameReader.Read_ConnectionOpenOk((knowHosts) =>
                    {
                        if (LogAdapter.ProtocolLevelLogEnabled)
                        {
                            LogAdapter.LogDebug("ConnectionIO", "__SendConnectionOpen completed for vhost " + vhost);
                        }

                        tcs.SetResult(knowHosts);
                    });
                }
                else
                {
                    AmqpIOBase.SetException(tcs, error, classMethodId);
                }
                return(Task.CompletedTask);
            }, expectsReply: true);

            return(tcs.Task);
        }
        private Task __SendGreeting()
        {
            var tcs = new TaskCompletionSource <bool>();

            SendCommand(0, 0, 0,
                        AmqpConnectionFrameWriter.Greeting(),
                        reply: (channel, classMethodId, _) =>
            {
                if (classMethodId == AmqpClassMethodConnectionLevelConstants.ConnectionStart)
                {
                    _frameReader.Read_ConnectionStart((versionMajor, versionMinor, serverProperties, mechanisms, locales) =>
                    {
                        this._serverProperties = serverProperties;
                        this._mechanisms       = mechanisms;

                        tcs.SetResult(true);
                    });
                }
                else
                {
                    // Unexpected
                    tcs.SetException(new Exception("Unexpected result. Got " + classMethodId));
                }
                return(Task.CompletedTask);
            }, expectsReply: true);

            return(tcs.Task);
        }
        private Task __SendConnectionTuneOk(ushort channelMax, uint frameMax, ushort heartbeat)
        {
            var tcs = new TaskCompletionSource <bool>();

            var writer = AmqpConnectionFrameWriter.ConnectionTuneOk(channelMax, frameMax, heartbeat);

            SendCommand(0, 10, 31, writer, reply: null, expectsReply: false, tcs: tcs);

            return(tcs.Task);
        }
Example #5
0
        private Task __SendConnectionStartOk(string username, string password, string connectionName)
        {
            if (LogAdapter.ProtocolLevelLogEnabled)
            {
                LogAdapter.LogDebug(LogSource, "__SendConnectionStartOk >");
            }

            var tcs = new TaskCompletionSource <bool>();

            // Only supports PLAIN authentication for now

            var clientProperties = Protocol.ClientProperties;

            if (!string.IsNullOrEmpty(connectionName))
            {
                clientProperties = new Dictionary <string, object>(clientProperties);
                clientProperties["connection_name"] = connectionName;
            }

            var auth   = Encoding.UTF8.GetBytes("\0" + username + "\0" + password);
            var writer = AmqpConnectionFrameWriter.ConnectionStartOk(clientProperties, "PLAIN", auth, "en_US");

            SendCommand(0, Amqp.Connection.ClassId, 30,
                        writer,
                        reply: (channel, classMethodId, error) =>
            {
                if (classMethodId == AmqpClassMethodConnectionLevelConstants.ConnectionTune)
                {
                    _frameReader.Read_ConnectionTune((channelMax, frameMax, heartbeat) =>
                    {
                        this._channelMax = channelMax;
                        this._frameMax   = frameMax;
                        this.Heartbeat   = heartbeat;

                        if (LogAdapter.ProtocolLevelLogEnabled)
                        {
                            LogAdapter.LogDebug(LogSource, "__SendConnectionStartOk completed.");
                        }

                        if (LogAdapter.IsDebugEnabled)
                        {
                            LogAdapter.LogDebug(LogSource, "Tune results: Channel max: " + channel + " Frame max size: " + frameMax + " heartbeat: " + heartbeat);
                        }

                        tcs.SetResult(true);
                    });
                }
                else
                {
                    AmqpIOBase.SetException(tcs, error, classMethodId);
                }
            }, expectsReply: true, immediately: true);

            return(tcs.Task);
        }
Example #6
0
        private Task __SendConnectionTuneOk(ushort channelMax, uint frameMax, ushort heartbeat)
        {
            var tcs = new TaskCompletionSource <bool>();

            var writer = AmqpConnectionFrameWriter.ConnectionTuneOk(channelMax, frameMax, heartbeat);

            SendCommand(0, 10, 31, writer, reply: null, expectsReply: false, tcs: tcs);

            if (LogAdapter.ProtocolLevelLogEnabled)
            {
                LogAdapter.LogDebug("ConnectionIO", "__SendConnectionTuneOk >");
            }

            return(tcs.Task);
        }
Example #7
0
        private Task __SendGreeting()
        {
            if (LogAdapter.ProtocolLevelLogEnabled)
            {
                LogAdapter.LogDebug(LogSource, "__SendGreeting >");
            }

            var tcs = new TaskCompletionSource <bool>();

            SendCommand(0, 0, 0,
                        AmqpConnectionFrameWriter.Greeting(),
                        reply: (channel, classMethodId, _) =>
            {
                if (classMethodId == AmqpClassMethodConnectionLevelConstants.ConnectionStart)
                {
                    _frameReader.Read_ConnectionStart((versionMajor, versionMinor, serverProperties, mechanisms, locales) =>
                    {
                        this.ServerProperties = serverProperties;
                        this.AuthMechanisms   = mechanisms;

                        if (LogAdapter.ProtocolLevelLogEnabled)
                        {
                            LogAdapter.LogDebug(LogSource, "__SendGreeting completed");
                        }

                        tcs.SetResult(true);
                    });
                }
                else
                {
                    // Unexpected
                    tcs.SetException(new Exception("Unexpected result. Got " + classMethodId));
                }
            }, expectsReply: true, immediately: true);

            return(tcs.Task);
        }