Inheritance: Universal.Torrent.Client.Messages.Message
        public static bool TryDecodeMessage(BEncodedDictionary dictionary, out Message message, out string error)
        {
            message = null;
            error = null;

            if (dictionary[MessageTypeKey].Equals(QueryMessage.QueryType))
            {
                message = QueryDecoders[(BEncodedString) dictionary[QueryNameKey]](dictionary);
            }
            else if (dictionary[MessageTypeKey].Equals(ErrorMessage.ErrorType))
            {
                message = new ErrorMessage(dictionary);
            }
            else
            {
                QueryMessage query;
                var key = (BEncodedString) dictionary[TransactionIdKey];
                if (Messages.TryGetValue(key, out query))
                {
                    Messages.Remove(key);
                    try
                    {
                        message = query.ResponseCreator(dictionary, query);
                    }
                    catch
                    {
                        error = "Response dictionary was invalid";
                    }
                }
                else
                {
                    error = "Response had bad transaction ID";
                }
            }

            return error == null && message != null;
        }
 public static bool TryDecodeMessage(BEncodedDictionary dictionary, out Message message)
 {
     string error;
     return TryDecodeMessage(dictionary, out message, out error);
 }
 public SendDetails(IPEndPoint destination, Message message)
 {
     Destination = destination;
     Message = message;
     SentAt = DateTime.MinValue;
 }
 internal void EnqueueSend(Message message, Node node)
 {
     EnqueueSend(message, node.EndPoint);
 }
        internal void EnqueueSend(Message message, IPEndPoint endpoint)
        {
            lock (_locker)
            {
                if (message.TransactionId == null)
                {
                    if (message is ResponseMessage)
                        throw new ArgumentException("Message must have a transaction id");
                    do
                    {
                        message.TransactionId = TransactionId.NextId();
                    } while (MessageFactory.IsRegistered(message.TransactionId));
                }

                // We need to be able to cancel a query message if we time out waiting for a response
                if (message is QueryMessage)
                    MessageFactory.RegisterSend((QueryMessage) message);

                _sendQueue.Enqueue(new SendDetails(endpoint, message));
            }
        }
 private void SendMessage(Message message, IPEndPoint endpoint)
 {
     _lastSent = DateTime.Now;
     var buffer = message.Encode();
     _listener.Send(buffer, endpoint);
 }