コード例 #1
0
        public NetworkResult AddToQueue(NetworkPacketQueueEntry npqe)
        {
            outgoingPacketQueue.Enqueue(npqe);
            Interlocked.Increment(ref nodeState.NodeInfo.NodeDetails.NetworkPacketsOut);

            if (npqe.Packet.Token.Hex.Length == Common.NETWORK_TOKEN_LENGTH)
            {
                if (messageTypePairs.Pairs.ContainsKey(npqe.Packet.Type))
                {
                    PendingNetworkRequest pnr = new PendingNetworkRequest(nodeState.SystemTime, npqe.PublicKeyDestination,
                        messageTypePairs.Pairs[npqe.Packet.Type]);

                    nodeState.PendingNetworkRequests.AddOrUpdate(npqe.Packet.Token, pnr, (k, v) => pnr);
                }
                else
                {
                    if (!messageTypePairs.Responses.Contains(npqe.Packet.Type))
                    {
                        DisplayUtils.Display("Non-Pair packet with valid Token.", DisplayType.CodeAssertionFailed);
                    }
                }
            }
            else
            {
                if (npqe.Packet.Token.Hex.Length != 0)
                    DisplayUtils.Display("Bad token Length.", DisplayType.CodeAssertionFailed);
            }

            return NetworkResult.Queued;
        }
コード例 #2
0
 /// <summary>
 /// Adds the current packet to the outgoing queue for processing.
 /// If the processing fails, the packets are dropped. 
 /// TODO: Try to open a new connection and try again in future.
 /// </summary>
 /// <param name="npqe"></param>
 /// <returns></returns>
 public bool EnqueuePacket(NetworkPacketQueueEntry npqe)
 {
     if (IncomingConnections.ContainsKey(npqe.PublicKeyDestination))
     {
         outgoingQueue.Enqueue(npqe);
         return true;
     }
     else return false;
 }