public void ParseDidICatchUp(DidICatchUpRequest request, Peer from) { var catcherUp = new CatcherUpRequest() { EndOfLongestChain = _blockChainService.Info.EndOfLongestChain, Invs = new List <InvitationRequest>() }; foreach (var trans in _minerService.MemPool) { var inv = new InvitationRequest() { DataId = trans.Body.TransactionId, IsBlock = false }; catcherUp.Invs.Add(inv); } if (request.LastKnownEnd != _blockChainService.Info.EndOfLongestChain) { var newBs = _blockChainService.GetNewerBlockInfos(request.LastOnline, request.LastKnownEnd); foreach (var blockInfo in newBs) { var inv = new InvitationRequest() { DataId = blockInfo.Id, IsBlock = true }; catcherUp.Invs.Add(inv); } } Console.WriteLine("Response to didI {0} {1}", catcherUp.EndOfLongestChain, catcherUp.Invs.Count); _server.SendResponse(catcherUp, from); }
public void ParseCatcherUpRequest(CatcherUpRequest request, Peer from) { supposedLongestBlockId = request.EndOfLongestChain; _logger.Log($"Ketchupper {request.EndOfLongestChain} - Count:{request.Invs.Count}"); foreach (var inv in request.Invs) { if (inv.IsBlock) { if (!IsBlockBuffered(inv.DataId)) { var req = new InvitationResponseRequest() { IsBlock = true, WantedDataId = inv.DataId }; _server.SendResponse(req, from); } } else { if (!bufferedTransactions.Exists(r => r.Body.TransactionId == inv.DataId)) { var req = new InvitationResponseRequest() { IsBlock = false, WantedDataId = inv.DataId }; _server.SendResponse(req, from); } } } if (request.EndOfLongestChain == _blockChainService.Info.EndOfLongestChain && request.Invs.Count == 0) { CaughtUp = true; _logger.Log("Ketchup cas its ended and no invs."); } }