Skip to content

Commit

Permalink
minimal changes to net.h and net_processing.cpp
Browse files Browse the repository at this point in the history
minimally change net_processing by adding "addrv2" as a strCommand
minimally change net.h with addition of m_wants_addrv2

(cherry picked from commit 353a3fd)
  • Loading branch information
zancas committed Oct 18, 2021
1 parent 878e63c commit d2d5557
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "policy/policy.h"
#include "pow.h"
#include "reverse_iterator.h"
#include "streams.h"
#include "txmempool.h"
#include "ui_interface.h"
#include "undo.h"
Expand Down Expand Up @@ -6345,6 +6346,9 @@ bool static ProcessMessage(const CChainParams& chainparams, CNode* pfrom, string

// Change version
pfrom->PushMessage("verack");
//
// Signal ADDRv2 support (BIP155).
pfrom->PushMessage("sendaddrv2");
pfrom->ssSend.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION));

if (!pfrom->fInbound)
Expand Down Expand Up @@ -6443,10 +6447,19 @@ bool static ProcessMessage(const CChainParams& chainparams, CNode* pfrom, string
}


else if (strCommand == "addr")
else if (strCommand == "addr" || strCommand == "addrv2")
{
int stream_version = vRecv.GetVersion();
if (strCommand == "addrv2") {
// Add ADDRV2_FORMAT to the version so that the CNetAddr and CAddress
// unserialize methods know that an address in v2 format is coming.
stream_version |= ADDRV2_FORMAT;
}

OverrideStream<CDataStream> s(&vRecv, vRecv.GetType(), stream_version);
vector<CAddress> vAddr;
vRecv >> vAddr;

s >> vAddr;

// Don't want addr from older versions unless seeding
if (pfrom->nVersion < CADDR_TIME_VERSION && addrman.size() > 1000)
Expand Down Expand Up @@ -6506,6 +6519,12 @@ bool static ProcessMessage(const CChainParams& chainparams, CNode* pfrom, string
pfrom->fDisconnect = true;
}

if (strCommand == "sendaddrv2") {
pfrom->m_wants_addrv2 = true;
return true;
}



else if (strCommand == "inv")
{
Expand Down Expand Up @@ -7406,6 +7425,16 @@ bool SendMessages(const Consensus::Params& params, CNode* pto)
pto->nNextAddrSend = PoissonNextSend(nNow, AVG_ADDRESS_BROADCAST_INTERVAL);
vector<CAddress> vAddr;
vAddr.reserve(pto->vAddrToSend.size());

const char* msg_type;
int make_flags;
if (pto->m_wants_addrv2) {
msg_type = "addrv2";
make_flags = ADDRV2_FORMAT;
} else {
msg_type = "addr";
make_flags = 0;
}
for (const CAddress& addr : pto->vAddrToSend)
{
if (!pto->addrKnown.contains(addr.GetKey()))
Expand All @@ -7415,7 +7444,7 @@ bool SendMessages(const Consensus::Params& params, CNode* pto)
// receiver rejects addr messages larger than 1000
if (vAddr.size() >= 1000)
{
pto->PushMessage("addr", vAddr);
pto->PushMessage(msg_type, vAddr);
vAddr.clear();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ class CNode
bool fWhitelisted; // This peer can bypass DoS banning.
bool fOneShot;
bool fClient;
/**
* Whether the peer has signaled support for receiving ADDRv2 (BIP155)
* messages, implying a preference to receive ADDRv2 instead of ADDR ones.
*/
std::atomic_bool m_wants_addrv2{false};
bool fInbound;
bool fNetworkNode;
std::atomic_bool fSuccessfullyConnected;
Expand Down

0 comments on commit d2d5557

Please sign in to comment.