Inheritance: OctoTorrent.Client.Messages.Message
Esempio n. 1
0
 public SendDetails(IPEndPoint destination, Message message)
 {
     Destination = destination;
     Message = message;
     SentAt = DateTime.MinValue;
 }
Esempio n. 2
0
 public void RaiseMessageReceived(Message message, IPEndPoint endpoint)
 {
     DhtEngine.MainLoop.Queue(() => OnMessageReceived(message.Encode(), endpoint));
 }
Esempio n. 3
0
 private void SendMessage(Message message, IPEndPoint endpoint)
 {
     lastSent = DateTime.Now;
     byte[] buffer = message.Encode();
     listener.Send(buffer, endpoint);
 }
Esempio n. 4
0
 internal void EnqueueSend(Message message, Node node)
 {
     EnqueueSend(message, node.EndPoint);
 }
Esempio n. 5
0
        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));
            }
        }
Esempio n. 6
0
 public static bool TryDecodeMessage(BEncodedDictionary dictionary, out Message message)
 {
     string error;
     return TryDecodeMessage(dictionary, out message, out error);
 }
Esempio n. 7
0
        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;
                BEncodedString 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;
        }