コード例 #1
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));
            }
        }
コード例 #2
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));
        }