Наследование: OctoTorrent.Client.Messages.Message
Пример #1
0
 public SendDetails(IPEndPoint destination, Message message)
 {
     Destination = destination;
     Message = message;
     SentAt = DateTime.MinValue;
 }
Пример #2
0
 public void RaiseMessageReceived(Message message, IPEndPoint endpoint)
 {
     DhtEngine.MainLoop.Queue(() => OnMessageReceived(message.Encode(), endpoint));
 }
Пример #3
0
 private void SendMessage(Message message, IPEndPoint endpoint)
 {
     lastSent = DateTime.Now;
     byte[] buffer = message.Encode();
     listener.Send(buffer, endpoint);
 }
Пример #4
0
 internal void EnqueueSend(Message message, Node node)
 {
     EnqueueSend(message, node.EndPoint);
 }
Пример #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));
            }
        }
Пример #6
0
 public static bool TryDecodeMessage(BEncodedDictionary dictionary, out Message message)
 {
     string error;
     return TryDecodeMessage(dictionary, out message, out error);
 }
Пример #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;
        }