/// <summary> /// This method waits until the server send the shared secret to the client /// </summary> private void WaitForSharedSecret() { try { Model.QueueDeclarePassive(ClientQueue); } catch { throw new RabbitMQException(RabbitMQException.ExceptionType.NoClientQueue); } var consumer = new EventingBasicConsumer(Model); consumer.Received += (obj, ea) => { var message = BinaryFormatter <ChatMessage> .FromBinary(ea.Body); var handshake = BinaryFormatter <TSharedSecret> .FromBinary(Chat.DecryptData(message)); // If we can't decrypt it, leave and go on if (handshake == null) { return; } OnSharedKeyExchanged?.Invoke(this, Chat.ChatMember, handshake); // Dispose automatically on handshake established if (AutoDispose) { Dispose(); } }; Model.BasicConsume(ClientQueue, true, string.Empty, false, true, null, consumer); }
private void SendHandshakeReply(TSharedSecret sharedSecret) { var message = Chat.EncryptData(BinaryFormatter <TSharedSecret> .ToBinary(sharedSecret)); var toSend = BinaryFormatter <ChatMessage> .ToBinary(message); try { Model.QueueDeclarePassive(ClientQueue); } catch { throw new RabbitMQException(RabbitMQException.ExceptionType.NoClientQueue); } Model.BasicPublish(string.Empty, ClientQueue, true, null, toSend); OnSharedKeyExchanged?.Invoke(this, Chat.ChatMember, sharedSecret); // Dispose automatically on handshake established if (AutoDispose) { Dispose(); } }