예제 #1
0
        public Session(ComponentNetwork aNetwork, AChannel aChannel, Action <bool> OnConnnect = null)
        {
            this.network = aNetwork;
            this.channel = aChannel;
            long id = this.Id = IdGenerater.GenerateId();

            channel.ClearAction <AChannel, int>(channel.errorCallback);
            channel.ErrorCallback += (c, e) =>
            {
                if (OnConnnect != null)
                {
                    OnConnnect(false);
                    OnConnnect = null;
                }
                this.network.Remove(id);
            };

            channel.ClearAction <AChannel, int>(channel.errorCallback);
            channel.ConnnectCallback += (c) =>
            {
                if (OnConnnect != null)
                {
                    OnConnnect(true);
                    OnConnnect = null;
                }
            };

            channel.ClearAction <MemoryStream>(channel.readCallback);
            channel.ReadCallback += this.OnRead;

            componentNetMsg = this.network.entity.GetComponent <ComponentNetMsg>();
        }
예제 #2
0
        public void Send(byte flag, IMessage message)
        {
            ComponentNetMsg componentNetMsg = this.network.entity.GetComponent <ComponentNetMsg>();
            int             opcode          = componentNetMsg.GetOpcode(message.GetType());

            Send(flag, opcode, message);
        }
예제 #3
0
        public override void Awake(JToken jd = null)
        {
            ComponentNetMsg componentNetMsg = Entity.Root.GetComponent <ComponentNetMsg>();

            //componentNetMsg.registerMsg(NetOpcode.A2M_HearBeat, A2M_HearBeat_Handle);
            componentNetMsg.registerMsg(NetOpcode.Q2P_New_Node, Q2P_New_Node_Handle);
            //componentNetMsg.registerMsg(NetOpcode.R2P_New_Node, R2P_New_Node_Handle);
        }
예제 #4
0
        private string OnMessage(Dictionary <string, string> map, HttpListenerRequest request, HttpListenerResponse response)
        {
            ComponentNetMsg componentNetMsg = Entity.Root.GetComponent <ComponentNetMsg>();
            HttpMessage     message         = new HttpMessage();

            message.map      = map;
            message.result   = "{\"ret\":\"failed\"}";
            message.request  = request;
            message.response = response;
            componentNetMsg.HandleMsg(null, NetOpcodeBase.HttpMessage, message);
            return(message.result);
        }
예제 #5
0
        public override void Awake(JToken jd = null)
        {
            ComponentNetMsg componentNetMsg = Entity.Root.GetComponent <ComponentNetMsg>();

            //componentNetMsg.registerMsg(NetOpcode.A2M_HearBeat, A2M_HearBeat_Handle);
            componentNetMsg.registerMsg(NetOpcode.Q2P_New_Node, Q2P_New_Node_Handle);
            //componentNetMsg.registerMsg(NetOpcode.R2P_New_Node, R2P_New_Node_Handle);

            // 是否添加自身到Nodes列表
            bool bRun = true;

            if (jd["AddSelfToNodes"] != null)
            {
                bool.TryParse(jd["AddSelfToNodes"].ToString(), out bRun);
            }
            Run(bRun);
        }
예제 #6
0
        public override void Start()
        {
            rule = Entity.Root.GetComponent <Rule>();
            ComponentNetMsg componentNetMsg = Entity.Root.GetComponent <ComponentNetMsg>();

            componentNetMsg.registerMsg(NetOpcode.P2P_NewBlock, P2P_NewBlock_Handle);

            string genesisText = File.ReadAllText("./Data/genesisBlock.dat");
            Block  blk         = JsonHelper.FromJson <Block>(genesisText);

            superAddress = blk.Address;

            long.TryParse(Entity.Root.GetComponent <LevelDBStore>().Get("UndoHeight"), out long UndoHeight);
            if (UndoHeight == 0)
            {
                if (true)
                {
                    blockMgr.AddBlock(blk);
                    ApplyGenesis(blk);
                }
            }

            string consData = Base58.Encode(FileHelper.GetFileData("./Data/Contract/RuleContract_v1.0.lua").ToByteArray());

            consAddress = Wallet.ToAddress(CryptoHelper.Sha256(Encoding.UTF8.GetBytes(consData)));

            using (DbSnapshot snapshot = levelDBStore.GetSnapshot())
            {
                LuaVMScript luaVMScript = new LuaVMScript()
                {
                    script = FileHelper.GetFileData("./Data/Contract/RuleContract_curr.lua").ToByteArray()
                };
                snapshot.Contracts.Add(consAddress, luaVMScript);
                snapshot.Commit();
            }
            ruleInfos = luaVMEnv.GetRules(consAddress, UndoHeight);

            if (bRun)
            {
                Run();
            }
        }
예제 #7
0
        public override void Awake(JToken jd = null)
        {
            if (jd["minerLimit"] != null)
            {
                int.TryParse(jd["minerLimit"]?.ToString(), out minerLimit);
            }
            if (jd["ignorePower"] != null)
            {
                double.TryParse(jd["ignorePower"]?.ToString(), out ignorePower);
            }

            poolPassword = jd["poolPassword"]?.ToString();

            Log.Info($"HttpPool.minerLimit   = {minerLimit}");
            Log.Info($"HttpPool.ignorePower  = {ignorePower}");

            ComponentNetMsg componentNetMsg = Entity.Root.GetComponent <ComponentNetMsg>();

            componentNetMsg.registerMsg(NetOpcodeBase.HttpMessage, OnHttpMessage);
        }
예제 #8
0
        public override void Awake(JToken jd = null)
        {
            ComponentNetMsg componentNetMsg = Entity.Root.GetComponent <ComponentNetMsg>();

            componentNetMsg.registerMsg(NetOpcodeBase.HttpMessage, OnHttpMessage);
        }
예제 #9
0
        public override void Start()
        {
            ComponentNetMsg componentNetMsg = Entity.Root.GetComponent <ComponentNetMsg>();

            componentNetMsg.registerMsg(NetOpcode.P2P_NewBlock, P2P_NewBlock_Handle);
        }
예제 #10
0
        public override void Awake(JToken jd = null)
        {
            ComponentNetMsg componentNetMsg = Entity.Root.GetComponent <ComponentNetMsg>(); // 一级网络

            componentNetMsg.registerMsg(NetOpcode.P2P_NewBlock, P2P_NewBlock_Handle);
        }