public SendDetails(IPEndPoint destination, Message message) { Destination = destination; Message = message; SentAt = DateTime.MinValue; }
public void RaiseMessageReceived(Message message, IPEndPoint endpoint) { DhtEngine.MainLoop.Queue(() => OnMessageReceived(message.Encode(), endpoint)); }
private void SendMessage(Message message, IPEndPoint endpoint) { lastSent = DateTime.Now; byte[] buffer = message.Encode(); listener.Send(buffer, endpoint); }
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)); } }
public static bool TryDecodeMessage(BEncodedDictionary dictionary, out Message message) { string error; return TryDecodeMessage(dictionary, out message, out error); }
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; }