void ProcessPendingRemoteFetches() { long chunk_size = Common.LSYNC_MAX_REQUESTED_NODES / 2; while (NodeFetchQueue.Count > 0) { int count = 0; NodeInfoRequest nir = new NodeInfoRequest(); while ((NodeFetchQueue.Count > 0) && (count++ < chunk_size)) { nir.Add(NodeFetchQueue.Dequeue()); } // Create a packet and send. List<NodeSocketData> nsds; // A single random trusted node is okay for fetching data. if (nodeConfig.GetRandomTrustedNode(out nsds, 1)) { NetworkPacket request = new NetworkPacket(nodeConfig.PublicKey, PacketType.TPT_LSYNC_NODE_REQUEST, nir.Serialize(), TNetUtils.GenerateNewToken()); networkPacketSwitch.AddToQueue(nsds[0].PublicKey, request); //DebugPrint("Requesting " + nir.TotalRequestedNodes + " nodes from, " + nsds[0].PublicKey + " ME: " + nodeConfig.PublicKey, DisplayType.ImportantInfo); } } }
void HandleNodeRequest(NetworkPacket packet) { NodeInfoRequest nir = new NodeInfoRequest(); nir.Deserialize(packet.Data); // DebugPrint("NodeRequest from " + packet.PublicKeySource + " Nodes : " + nir.TotalRequestedNodes, DisplayType.Warning); if ((Common.LSYNC_MAX_REQUESTED_NODES >= nir.TotalRequestedNodes) && (nir.TotalRequestedNodes == nir.RequestedNodesAdresses.Count)) { NodeInfoResponse responseData = new NodeInfoResponse(); foreach (Hash nodeAddress in nir.RequestedNodesAdresses) { ListTreeNode ltn; if (LedgerTree.TraverseToNode(nodeAddress, out ltn) == TraverseResult.Success) { responseData.Add(new NodeDataEntity(ltn)); } } NetworkPacket response = new NetworkPacket(nodeConfig.PublicKey, PacketType.TPT_LSYNC_NODE_RESPONSE, responseData.Serialize(), packet.Token); networkPacketSwitch.AddToQueue(packet.PublicKeySource, response); } }