Пример #1
0
        internal void EnqueueSend(DhtMessage message, Node node, IPEndPoint endpoint, TaskCompletionSource <SendQueryEventArgs> tcs = null)
        {
            if (message.TransactionId == null)
            {
                if (message is ResponseMessage)
                {
                    throw new ArgumentException("Message must have a transaction id");
                }
                do
                {
                    message.TransactionId = TransactionId.NextId();
                } while (DhtMessageFactory.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)
            {
                DhtMessageFactory.RegisterSend((QueryMessage)message);
            }

            SendQueue.Enqueue(new SendDetails(node, endpoint, message, tcs));
        }