Exemplo n.º 1
0
 public void RaiseMessageReceived(Message message, IPEndPoint endpoint)
 {
     DhtEngine.MainLoop.Queue(delegate
     {
         OnMessageReceived(message.Encode(), endpoint);
     });
 }
Exemplo n.º 2
0
 private void Compare(Message m, string expected)
 {
     byte[] b = m.Encode();
     Assert.AreEqual(Encoding.UTF8.GetString(b), expected);
 }
Exemplo n.º 3
0
 public SendDetails(IPEndPoint destination, Message message)
 {
     Destination = destination;
     Message = message;
     SentAt = DateTime.MinValue;
 }
Exemplo n.º 4
0
 private void SendMessage(Message message, IPEndPoint endpoint)
 {
     lastSent = DateTime.Now;
     byte[] buffer = message.Encode();
     listener.Send(buffer, endpoint);
 }
Exemplo n.º 5
0
 internal void EnqueueSend(Message message, Node node)
 {
     EnqueueSend(message, node.EndPoint);
 }
Exemplo n.º 6
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));
            }
        }
Exemplo n.º 7
0
 private void SendMessage(Message message, IPEndPoint endpoint)
 {
     lastSent = Environment.TickCount;
     byte[] buffer = message.Encode();
     listener.Send(buffer, endpoint);
 }
Exemplo n.º 8
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;
        }
Exemplo n.º 9
0
 public static bool TryDecodeMessage(BEncodedDictionary dictionary, out Message message)
 {
     string error;
     return TryDecodeMessage(dictionary, out message, out error);
 }