Beispiel #1
0
        void HandleRootResponse(NetworkPacket packet)
        {
            // Check that the packet is valid.
            if (networkPacketSwitch.VerifyPendingPacket(packet))
            {
                RootDataResponse rdrm = new RootDataResponse();
                rdrm.Deserialize(packet.Data);

                /// Compare with current tree and matchup.

                if (LedgerTree.RootNode.Hash != rdrm.RootHash) // Need to match up child nodes.
                {
                    DebugPrint("MISMATCH: RootResponse from " + packet.PublicKeySource + " : " + packet.Data.Length + " Bytes", DisplayType.Warning);

                    LedgerState = LedgerSyncStateTypes.ST_DATA_FETCH;

                    for (int i = 0; i < 16; i++)
                    {
                        NodeDataEntity remoteChild = rdrm.Children[i];
                        ListTreeNode currentChild = LedgerTree.RootNode.Children[i];

                        if (PendingNodesToBeFetched.Count > Common.LSYNC_MAX_PENDING_QUEUE_LENGTH) break;

                        if (remoteChild != null)
                        {
                            if (currentChild == null)
                            {
                                // Download all the data below the node.
                                // Needs to be handled properly, as it may have millions of nodes.

                                PendingNodesToBeFetched.Enqueue(remoteChild);
                            }
                            else
                            {
                                if (remoteChild.NodeHash != currentChild.Hash)
                                {
                                    PendingNodesToBeFetched.Enqueue(remoteChild);
                                }
                            }
                        }
                        else
                        {
                            // HANDLE CASE FOR THE REMOTE HAVING NO NODE WHEN WE HAVE
                            // VERIFY WITH OTHERS AND DELETE
                            // ONLY NEEDED IF THE TRUSTED NODES ARE SENDING BAD DATA
                            // SHOULD BE IMPLEMENTED BEFORE FINAL NETWORK COMPLETION
                        }
                    }
                }
                else
                {
                    DebugPrint("ROOT IS SYNCHRONZED WITH: " + packet.PublicKeySource, DisplayType.ImportantInfo);
                }

            }
            else
            {
                DebugPrint("Packet VER FAILED : HandleRootResponse().", DisplayType.Warning);
            }
        }
Beispiel #2
0
        void HandleRootRequest(NetworkPacket packet)
        {
            DebugPrint("ROOT DATA REQUESTED BY " + packet.PublicKeySource.ToString(), DisplayType.ImportantInfo);
            LedgerCloseData ledgerCloseData;
            if (nodeState.PersistentCloseHistory.GetLastRowData(out ledgerCloseData))
            {
                RootDataResponse rdrm = new RootDataResponse(LedgerTree.RootNode, ledgerCloseData);

                NetworkPacket response = new NetworkPacket(nodeConfig.PublicKey, PacketType.TPT_LSYNC_ROOT_RESPONSE,
                    rdrm.Serialize(), packet.Token);

                networkPacketSwitch.AddToQueue(packet.PublicKeySource, response);
            }
        }