コード例 #1
0
ファイル: HttpRpc.cs プロジェクト: yuop2002cn/IOBft
        public async ETTask <Session> OnTransferAsync2(Transfer transfer, Session session2)
        {
            Consensus consensus = Entity.Root.GetComponent <Consensus>();

            Q2P_Transfer q2p_Transfer = new Q2P_Transfer();

            q2p_Transfer.transfer = JsonHelper.ToJson(transfer);

            var networkInner = Entity.Root.GetComponent <ComponentNetworkInner>();
            var nodeList     = Entity.Root.GetComponent <NodeManager>().GetNodeList();

            // 遍历node提交交易,直到找个一个可以出块的节点
            int start = RandomHelper.Random();

            for (int i = start; i < start + nodeList.Count; i++)
            {
                var     node    = nodeList[i % nodeList.Count];
                Session session = session2 ?? await networkInner.Get(NetworkHelper.ToIPEndPoint(node.ipEndPoint));

                if (session != null && session.IsConnect())
                {
                    var r2p_Transfer = (R2P_Transfer)await session.Query(q2p_Transfer, 5);

                    if (r2p_Transfer != null && r2p_Transfer.rel != "-1")
                    {
                        return(session);
                    }
                }
            }
            await Task.Delay(10);

            return(null);
        }
コード例 #2
0
ファイル: SmartxRpc.cs プロジェクト: yangbaitu/smartx-dotnet
        public async void OnTransferAsync(BlockSub transfer)
        {
            Consensus consensus = Entity.Root.GetComponent <Consensus>();

            Q2P_Transfer q2p_Transfer = new Q2P_Transfer();

            q2p_Transfer.transfer = JsonHelper.ToJson(transfer);

            var networkInner = Entity.Root.GetComponent <ComponentNetworkInner>();
            var nodeList     = Entity.Root.GetComponent <NodeManager>().GetNodeRandomList();

            // 遍历node提交交易,直到找个一个可以出块的节点
            for (int i = 0; i < nodeList.Count; i++)
            {
                var     node    = nodeList[i];
                Session session = await networkInner.Get(NetworkHelper.ToIPEndPoint(node.ipEndPoint));

                if (session != null && session.IsConnect())
                {
                    var r2p_Transfer = (R2P_Transfer)await session.Query(q2p_Transfer, 5);

                    if (r2p_Transfer != null && r2p_Transfer.rel != "-1")
                    {
                        break;
                    }
                }
            }
        }
コード例 #3
0
ファイル: Rule.cs プロジェクト: mangodager/smartx-dotnet
        public static void Q2P_Transfer_Handle(Session session, int opcode, object msg)
        {
            Q2P_Transfer q2p_Transfer = msg as Q2P_Transfer;
            BlockSub     transfer     = JsonHelper.FromJson <BlockSub>(q2p_Transfer.transfer);

            R2P_Transfer r2p_Transfer = new R2P_Transfer()
            {
                rel = "-10000"
            };

            if (transfer.CheckSign())
            {
                r2p_Transfer.rel = Entity.Root.GetComponent <Rule>().AddTransfer(transfer).ToString();
            }
            session.Reply(q2p_Transfer, r2p_Transfer);
        }