void Tell_Request_BlockHeight(IModulePipeline remote)
        {
            var dict = new MessagePackObjectDictionary();

            dict["cmd"] = (UInt16)CmdList.Request_BlockHeight;
            remote.Tell(new MessagePackObject(dict));
        }
        void Tell_BoardCast_LosePlevel(IModulePipeline remote)
        {
            var dict = new MessagePackObjectDictionary();

            dict["cmd"] = (UInt16)CmdList.BoardCast_LosePlevel;
            remote.Tell(new MessagePackObject(dict));
        }
        void Tell_Response_Tx(IModulePipeline remote, byte[] tx)
        {
            var dict = new MessagePackObjectDictionary();

            dict["cmd"] = (UInt16)CmdList.Response_Tx;
            dict["tx"]  = tx;
            remote.Tell(new MessagePackObject(dict));
        }
        void Tell_Response_Block(IModulePipeline remote, byte[] header)
        {
            var dict = new MessagePackObjectDictionary();

            dict["cmd"]         = (UInt16)CmdList.Response_Block;
            dict["blockHeader"] = header;
            remote.Tell(new MessagePackObject(dict));
        }
        void Tell_BoradCast_PeerState(IModulePipeline remote)
        {
            var dict = new MessagePackObjectDictionary();

            dict["cmd"]    = (UInt16)CmdList.BoradCast_PeerState;
            dict["plevel"] = this.pLevel;//告诉对方我的优先级
            remote.Tell(new MessagePackObject(dict));
        }
        void Tell_Request_Block(IModulePipeline remote, ulong blockIndex)
        {
            var dict = new MessagePackObjectDictionary();

            dict["cmd"]        = (UInt16)CmdList.Request_Block;
            dict["blockIndex"] = blockIndex;
            remote.Tell(new MessagePackObject(dict));
        }
        void Tell_Response_plevel(IModulePipeline remote)
        {
            var dict = new MessagePackObjectDictionary();

            dict["cmd"]    = (UInt16)CmdList.Response_Plevel;
            dict["plevel"] = this.pLevel;
            remote.Tell(new MessagePackObject(dict));
        }
        void Tell_Response_BlockHeight(IModulePipeline remote)
        {
            var dict = new MessagePackObjectDictionary();

            dict["cmd"]        = (UInt16)CmdList.Response_BlockHeight;
            dict["blockIndex"] = this.blockIndex;
            remote.Tell(new MessagePackObject(dict));
        }
예제 #9
0
        public UInt64 UseSnapshot()
        {
            NetMessage netMessage = Protocol_UseSnapShot.CreateSendMsg(DateTime.UtcNow.ToString());

            actor.Tell(netMessage.ToBytes());
            return(Utc_SID.Get(netMessage.ID).Result);
        }
        void Tell_BoardCast_Tx(IModulePipeline remote, byte[] message, byte[] signData)
        {
            var dict = new MessagePackObjectDictionary();

            dict["cmd"]      = (UInt16)CmdList.BoardCast_Tx;
            dict["message"]  = message;
            dict["signData"] = signData;
            remote.Tell(new MessagePackObject(dict));
        }
        void Tell_Response_Iamhere(IModulePipeline remote, string provedpubep)
        {
            var dict = new MessagePackObjectDictionary();

            dict["cmd"]         = (UInt16)CmdList.Response_Iamhere;
            dict["provedpubep"] = provedpubep;
            dict["isProved"]    = this.isProved;
            remote.Tell(new MessagePackObject(dict));
        }
예제 #12
0
 public override void OnTell(IModulePipeline from, byte[] data)
 {
     if (from != null && from.system.Remote != null)//从远程投递而来
     {
         Console.WriteLine("Hello get from:" + from.system.Remote + " // " + from.path);
         from.Tell(global::System.Text.Encoding.UTF8.GetBytes("hihihihi"));
     }
     Console.WriteLine("Hello get info=" + global::System.Text.Encoding.UTF8.GetString(data));
 }
        void Tell_SendRaw(IModulePipeline remote, byte[] message, byte[] signData)
        {
            logger.Info($"------Tell_SendRaw  To:{remote.ToString()}-------");
            var dict = new MessagePackObjectDictionary();

            dict["cmd"]      = (UInt16)CmdList.Post_SendRaw;
            dict["message"]  = message;
            dict["signData"] = signData;
            remote.Tell(new MessagePackObject(dict));
        }
        void Tell_Request_ProvePeer(IModulePipeline remote, byte[] addinfo, byte[] signdata)
        {
            var dict = new MessagePackObjectDictionary();

            dict["cmd"]      = (UInt16)CmdList.Request_ProvePeer;
            dict["pubkey"]   = this.pubkey;
            dict["addinfo"]  = addinfo;
            dict["signdata"] = signdata;
            remote.Tell(new MessagePackObject(dict));
        }
예제 #15
0
 public override void OnTell(IModulePipeline from, byte[] data)
 {
     if (from != null && from.system.Remote != null)//从远程投递而来
     {
         UInt64 peerid = from.system.PeerID;
         //Console.WriteLine("peerid:"+from.system.PeerID);
         NetMessage netMessage = server.Process(peerid, data);
         from.Tell(netMessage.ToBytes());
     }
 }
        void Tell_ReqJoinPeer(IModulePipeline remote)
        {
            var dict = new MessagePackObjectDictionary();

            dict["cmd"]   = (UInt16)CmdList.Request_JoinPeer;
            dict["id"]    = this.guid.data;
            dict["pubep"] = this.config.PublicEndPoint.ToString();
            //Console.WriteLine("Tell_ReqJoinPeer----->:"+ dict["pubep"]);
            dict["chaininfo"] = chainHash.data;
            remote.Tell(new MessagePackObject(dict));
        }
예제 #17
0
 public static void Tell(this IModulePipeline pipeline, MessagePackObject?obj)
 {
     if (pipeline.IsLocal)
     {
         pipeline.TellLocalObj(obj);
     }
     else
     {
         pipeline.Tell(Pack(obj).ToArray());
     }
 }
예제 #18
0
 public static void Tell(this IModulePipeline pipeline, Newtonsoft.Json.Linq.JToken json)
 {
     if (pipeline.IsLocal)
     {
         pipeline.TellLocalObj(json);
     }
     else
     {
         pipeline.Tell(Pack(json).ToArray());
     }
 }
        void Tell_Request_PeerList(IModulePipeline remote)
        {
            if (!this.beEnableQueryPeers)
            {
                return;
            }
            var dict = new MessagePackObjectDictionary();

            dict["cmd"] = (UInt16)CmdList.Request_PeerList;
            remote.Tell(new MessagePackObject(dict));
        }
        void Tell_ResponseAcceptJoin(IModulePipeline remote)
        {
            var link = this.linkNodes[remote.system.PeerID];

            link.CheckInfo = Guid.NewGuid().ToByteArray();
            var dict = new MessagePackObjectDictionary();

            dict["cmd"]       = (UInt16)CmdList.Response_AcceptJoin;
            dict["checkinfo"] = link.CheckInfo;
            dict["plevel"]    = this.pLevel;//告诉对方我的优先级
            //选个挑战信息
            remote.Tell(new MessagePackObject(dict));
        }
        void Tell_Post_TouchProvedPeer(IModulePipeline remote, string pubep, string nodeid)
        {
            if (this.beObserver)
            {
                return;
            }
            var dict = new MessagePackObjectDictionary();

            dict["cmd"]    = (UInt16)CmdList.Post_TouchProvedPeer;
            dict["pubep"]  = pubep;
            dict["nodeid"] = nodeid;
            remote.Tell(new MessagePackObject(dict));
        }
            //默认多线程接收
            public override void OnTell(IModulePipeline from, byte[] data)
            {
                if (recvcount == 0)
                {
                    begin = DateTime.Now;
                }
                recvcount++;
                recvbytes += data.Length;
                if (recvcount == 100000)
                {//接收完毕
                    var    end  = DateTime.Now;
                    var    time = (end - begin).TotalSeconds;
                    double mbs  = recvbytes / (1024.0 * 1024.0 * time);

                    Console.WriteLine("发Msg次数:{0}  msg大小:{1}kb  时间{2}s  速率:{3}m/s   ", recvcount, data.Length / 1024, time, mbs);
                    {
                        recvcount = 0;
                        recvbytes = 0;
                    }
                    from.Tell(new byte[2]);
                }
            }
        void Tell_Response_PeerList(IModulePipeline remote)
        {
            var dict = new MessagePackObjectDictionary();

            dict["cmd"] = (UInt16)CmdList.Response_PeerList;
            var list = new List <MessagePackObject>();

            foreach (var n in this.linkNodes.Values)
            {
                if (n.hadJoin && n.publicEndPoint != null)
                {
                    var item = new MessagePackObjectDictionary();
                    item["pubep"]  = n.publicEndPoint.ToString();
                    item["pubkey"] = n.PublicKey;
                    item["id"]     = n.ID.data;
                    //var ipep = n.publicEndPoint.ToString();
                    list.Add(new MessagePackObject(item));
                }
            }
            dict["nodes"] = list.ToArray();

            remote.Tell(new MessagePackObject(dict));
        }
예제 #24
0
 public override void OnStart()
 {
     this.refhello2 = this.GetPipeline("this/hello2");
     refhello2.Tell(new Newtonsoft.Json.Linq.JValue("hi there"));
 }
예제 #25
0
        public override void OnTell(IModulePipeline from, MessagePackObject?obj)
        {
            var dict = obj.Value.AsDictionary();
            var cmd  = (CmdList)dict["cmd"].AsUInt16();

            //rpc消息无所谓本地还是远程
            if (cmd == CmdList.RPC)
            {
                MessagePackObjectDictionary msgBack = new MessagePackObjectDictionary();
                msgBack["cmd"] = (UInt16)cmd;
                msgBack["id"]  = dict["id"];
                string method = dict["method"].AsString();
                msgBack["method"] = method;
                var        _params = dict.ContainsKey("params") ? dict["params"].AsList() : null;
                RPC_Result result  = null;
                switch (method)
                {
                case "listpeer":
                    result = RPC_ListPeer(_params);
                    break;

                case "sendrawtransaction":
                    result = RPC_SendRawTransaction(_params);
                    break;

                case "gettransactioncount":
                    result = RPC_GetTXCount(_params);
                    break;

                case "gettransaction":
                    result = RPC_GetTX(_params);
                    break;

                default:
                    result = new RPC_Result(null, -100, "not found that RPC command.");
                    break;
                }
                if (result.error_code != 0)
                {
                    msgBack["error"]     = result.error_msg;
                    msgBack["errorcode"] = result.error_code;
                }
                if (result.result != null)
                {
                    msgBack["result"] = result.result.Value;
                }

                from.Tell(new MessagePackObject(msgBack));
                //rpc消息处理完
            }
            else if (from == null || from.IsLocal)//本地发来的消息
            {
                logger.Info("local msg:" + obj.Value.ToString());

                switch (cmd)
                {
                case CmdList.Local_Cmd:
                {
                    var _params = dict["params"].AsList();
                    if (_params.Count > 0)
                    {
                        var _cmd = _params[0].AsString();
                        if (_cmd == "peer.update")
                        {
                            foreach (var n in this.linkNodes.Values)
                            {
                                if (n.hadJoin)
                                {
                                    this.Tell_Request_PeerList(n.remoteNode);
                                }
                            }
                        }
                        if (_cmd == "peer.list")
                        {
                            foreach (var n in this.linkNodes.Values)
                            {
                                if (n.hadJoin)

                                {
                                    var publickey = n.PublicKey == null ? null : Helper.Bytes2HexString(n.PublicKey);
                                    logger.Info("peer=" + n.remoteNode.system.PeerID + " pubep=" + n.publicEndPoint + " beAccepted:" + n.beAccepted + " publickey=" + publickey);
                                }
                            }
                        }
                        if (_cmd == "proved.list")
                        {
                            foreach (var n in this.provedNodes.Values)
                            {
                                var publickey = n.PublicKey == null ? null : Helper.Bytes2HexString(n.PublicKey);
                                logger.Info("proved=" + n.remoteNode.system.Remote.ToString() + "  public=" + publickey + "  pubep=" + n.publicEndPoint + "  isProved=" + n.isProved + "  provedPubep=" + n.provedPubep);
                            }
                        }
                        if (_cmd == "peer.plevel")
                        {
                            foreach (var item in this.linkNodes.Values)
                            {
                                this.Tell_Request_plevel(item.remoteNode);
                            }
                        }
                        if (_cmd == "block.index")
                        {
                            logger.Info("blockIndex=" + this.blockIndex + "   txpool.Count=" + this.txpool.Txs.Count());
                        }
                    }
                }
                break;

                case CmdList.Post_SendRaw:
                    OnRecv_Post_SendRaw(from, dict);
                    break;

                case CmdList.Fake_Remote:
                    this.onRecv_FakeRemote(dict);
                    break;

                default:
                    logger.Error("unknow msg:" + dict.ToString());
                    break;
                }
                return;
            }
            else //远程发来的消息
            {
                if (this.linkNodes.TryGetValue(from.system.PeerID, out LinkObj link) == false)
                {
                    linkNodes[from.system.PeerID] = new LinkObj()
                    {
                        ID             = null,
                        remoteNode     = from,
                        publicEndPoint = null,
                        beAccepted     = true
                    };
                    RegNetEvent(from.system);
                }
                this.OnReceiveMsgFromRemote(from, cmd, dict);
            }
        }
예제 #26
0
 public override void OnStart()
 {
     this.refhello2 = this.GetPipeline("this/hello2");
     refhello2.Tell(new MsgPack.MessagePackObject("hi there"));
 }
예제 #27
0
 public override void OnTell(IModulePipeline from, MsgPack.MessagePackObject?obj)
 {
     Console.WriteLine("got:" + obj.ToString());
     refhello2.Tell(new MsgPack.MessagePackObject("hi there"));
 }
예제 #28
0
            public override void OnTell(IModulePipeline from, byte[] data)
            {
                Console.WriteLine("Hello2:" + global::System.Text.Encoding.UTF8.GetString(data));

                from.Tell(global::System.Text.Encoding.UTF8.GetBytes("hello back."));
            }
예제 #29
0
 public override void OnTell(IModulePipeline from, Newtonsoft.Json.Linq.JToken json)
 {
     Console.WriteLine("got:" + json.ToString());
     refhello2.Tell(new Newtonsoft.Json.Linq.JValue("hi there"));
 }