Skip to content

Commit

Permalink
Refactoring net_processing, removed duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
knst committed Jun 3, 2022
1 parent b9a7040 commit 3dad53f
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4689,6 +4689,20 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
}
pto->vInventoryBlockToSend.clear();

auto queueAndMaybePushInv = [this, pto, &vInv, &msgMaker](const CInv& invIn) {
if (pto->m_tx_relay != nullptr) {
AssertLockHeld(pto->m_tx_relay->cs_tx_inventory);
pto->m_tx_relay->filterInventoryKnown.insert(invIn.hash);
}
LogPrint(BCLog::NET, "SendMessages -- queued inv: %s index=%d peer=%d\n", invIn.ToString(), vInv.size(), pto->GetId());
vInv.push_back(invIn);
if (vInv.size() == MAX_INV_SZ) {
LogPrint(BCLog::NET, "SendMessages -- pushing invs: count=%d peer=%d\n", vInv.size(), pto->GetId());
connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
vInv.clear();
}
};

if (pto->m_tx_relay != nullptr) {
LOCK(pto->m_tx_relay->cs_tx_inventory);
// Check whether periodic sends should happen
Expand All @@ -4712,18 +4726,6 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
if (!pto->m_tx_relay->fRelayTxes) pto->m_tx_relay->setInventoryTxToSend.clear();
}

auto queueAndMaybePushInv = [this, pto, &vInv, &msgMaker](const CInv& invIn) {
AssertLockHeld(pto->m_tx_relay->cs_tx_inventory);
pto->m_tx_relay->filterInventoryKnown.insert(invIn.hash);
LogPrint(BCLog::NET, "SendMessages -- queued inv: %s index=%d peer=%d\n", invIn.ToString(), vInv.size(), pto->GetId());
vInv.push_back(invIn);
if (vInv.size() == MAX_INV_SZ) {
LogPrint(BCLog::NET, "SendMessages -- pushing invs: count=%d peer=%d\n", vInv.size(), pto->GetId());
connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
vInv.clear();
}
};

// Respond to BIP35 mempool requests
if (fSendTrickle && pto->m_tx_relay->fSendMempool) {
auto vtxinfo = m_mempool.infoAll();
Expand Down Expand Up @@ -4818,19 +4820,10 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
queueAndMaybePushInv(inv);
}
pto->vInventoryOtherToSend.clear();
} else if (true || false) {
auto queueAndMaybePushInv_non_tx = [this, pto, &vInv, &msgMaker](const CInv& invIn) {
LogPrint(BCLog::NET, "SendMessages -- queued inv: %s index=%d peer=%d\n", invIn.ToString(), vInv.size(), pto->GetId());
vInv.push_back(invIn);
if (vInv.size() == MAX_INV_SZ) {
LogPrint(BCLog::NET, "SendMessages -- pushing invs: count=%d peer=%d\n", vInv.size(), pto->GetId());
connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
vInv.clear();
}
};
} else { // m_tx_relay is nullptr but we still need to send items from `vInventoryOtherToSend`
// Send non-tx/non-block inventory items
for (const auto& inv : pto->vInventoryOtherToSend) {
queueAndMaybePushInv_non_tx(inv);
queueAndMaybePushInv(inv);
}
pto->vInventoryOtherToSend.clear();
}
Expand Down

0 comments on commit 3dad53f

Please sign in to comment.