Пример #1
0
        void P2P_NewBlock_Handle(Session session, int opcode, object msg)
        {
            P2P_NewBlock p2p_Block = msg as P2P_NewBlock;
            Block        blk       = JsonHelper.FromJson <Block>(p2p_Block.block);

            if (!NodeManager.CheckNetworkID(p2p_Block.networkID))
            {
                Log.Warning($"NewBlk:{blk.Address} H:{blk.height} ipEndPoint:{p2p_Block.ipEndPoint} RemoteAddress:{session.RemoteAddress}");
                return;
            }

            //Log.Debug($"NewBlock IP:{session.RemoteAddress.ToString()} {blk.Address} hash:{blk.hash} ");
            Log.Debug($"NewBlk:{blk.Address} H:{blk.height} Pre:{blk.prehash} T:{blk.linkstran.Count}");

            newBlockHeight = blk.height;
            // 有高度差的直接忽略
            long.TryParse(levelDBStore.Get("UndoHeight"), out long transferHeight);
            if (transferHeight - 1 < blk.height)
            {
                AddBlock(blk);
            }

            //// 如果收到的是桶外的数据 , 向K桶内进行一次广播
            //if (nodeManager.IsNeedBroadcast2Kad(p2p_Block.ipEndPoint))
            //{
            //    p2p_Block.ipEndPoint = Entity.Root.GetComponent<ComponentNetworkInner>().ipEndPoint.ToString();
            //    nodeManager.Broadcast2Kad(p2p_Block);
            //}
        }
Пример #2
0
        void P2P_NewBlock_Handle(Session session, int opcode, object msg)
        {
            P2P_NewBlock p2p_Block = msg as P2P_NewBlock;

            if (!NodeManager.CheckNetworkID(p2p_Block.networkID))
            {
                return;
            }

            //var newBlock = new P2P_NewBlock() { block = p2p_Block.block, networkID = BlockMgr.networkID,ipEndPoint = p2p_Block.ipEndPoint };
            var newBlock = new P2P_NewBlock()
            {
                block = p2p_Block.block, networkID = NodeManager.networkIDBase, ipEndPoint = Entity.Root.GetComponent <ComponentNetworkInner>().ipEndPoint.ToString()
            };

            relayNetworkInner.BroadcastToAll(newBlock);
        }