Beispiel #1
0
        public void ParseRequest(string request, Peer source)
        {
            var header = JsonConvert.DeserializeObject <RequestHeader>(request);

            //Logger.Log(String.Format("V:{0},T:{1},D:{2}",header.Version,header.Type,request),show:true);
            source.Port = header.Sender.Port;
            Logger.Log($"Got {header.Type} {source.Port}");
            //Logger.Log($"Ketc {_catchUpService.CaughtUp}");
            if (source.Address.StartsWith("192"))
            {
                source.Address = header.Sender.Address;
            }

            var mapper = Services.GetService <IMappingService>();

            if (header.Type == 0)
            {
                var req = JsonConvert.DeserializeObject <GetAddressesRequest>(request);
                mapper.ParseGetAddressesRequest(req, source);
            }
            else if (header.Type == 1)
            {
                var req = JsonConvert.DeserializeObject <AddressesRequest>(request);
                mapper.ParseAddressesRequest(req, source);
            }
            else if (header.Type == 2)
            {
                var req = JsonConvert.DeserializeObject <InvitationRequest>(request);
                if (_catchUpService.CaughtUp)
                {
                    _blockChainService.ParseInvitationRequest(req, source);
                }
            }
            else if (header.Type == 3)
            {
                var req = JsonConvert.DeserializeObject <InvitationResponseRequest>(request);
                if (_catchUpService.CaughtUp)
                {
                    _blockChainService.ParseInvitationResponseRequest(req, source);
                }
            }
            else if (header.Type == 4)
            {
                var req = JsonConvert.DeserializeObject <TransactionRequest>(request);
                if (_catchUpService.CaughtUp)
                {
                    //Logger.Log("New data to pars");
                    _blockChainService.ParseDataRequest(req);
                }
                else
                {
                    //Logger.Log("New data to kechup");
                    _catchUpService.ParseCatchUpData(req);
                }
            }
            else if (header.Type == 5)
            {
                var req = JsonConvert.DeserializeObject <BlockRequest>(request);
                if (_catchUpService.CaughtUp)
                {
                    _blockChainService.ParseDataRequest(req);
                }
                else
                {
                    _catchUpService.ParseCatchUpData(req);
                }
            }
            else if (header.Type == 6)
            {
                if (_catchUpService.CaughtUp)
                {
                    var req = JsonConvert.DeserializeObject <DidICatchUpRequest>(request);
                    _catchUpService.ParseDidICatchUp(req, source);
                }
            }
            else if (header.Type == 7)
            {
                if (!_catchUpService.CaughtUp)
                {
                    var req = JsonConvert.DeserializeObject <CatcherUpRequest>(request);
                    _catchUpService.ParseCatcherUpRequest(req, source);
                }
            }
        }