public static void Q2P_Block_Handle(Session session, int opcode, object msg) { Q2P_Block q2p_Block = msg as Q2P_Block; Block blk = Entity.Root.GetComponent <BlockMgr>().GetBlock(q2p_Block.hash); R2P_Block r2p_Block = new R2P_Block() { block = blk != null?JsonHelper.ToJson(blk) : "" }; session.Reply(q2p_Block, r2p_Block); }
public async Task <Block> QueryBlock(string hash, string ipEndPoint = null) { Q2P_Block q2p_Block = new Q2P_Block(); q2p_Block.ActorId = nodeManager.GetMyNodeId(); q2p_Block.hash = hash; Session session = null; if (ipEndPoint != null && ipEndPoint != "") { session = await networkInner.Get(NetworkHelper.ToIPEndPoint(ipEndPoint)); } if (session != null && !session.IsConnect()) { session = null; } Block blk = null; //if (session == null) { NodeManager.NodeData node = nodeManager.GetRandomNode(); if (node != null) { session = await networkInner.Get(NetworkHelper.ToIPEndPoint(node.ipEndPoint)); } } if (session != null) { R2P_Block r2p_Block = (R2P_Block)await session.Query(q2p_Block); if (r2p_Block != null && r2p_Block.block != "") { blk = JsonHelper.FromJson <Block>(r2p_Block.block); } } return(blk); }