mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
refactor: move CAddress-without-nTime logic to net_processing
Historically, the VERSION message contains an "addrMe" and an "addrYou". As these are sent before version negotiation is complete, the protocol version is INIT_PROTO_VERSION (209), and in that protocol, CAddress is serialized without nTime. This is in fact the only situation left where a CAddress is (de)serialized without nTime. As it's such a simple structure (CService for ip/port + uint64_t for nServices), just inline that structure in the few places where it occurs, and remove the logic for dealing with missing nTime from CAddress.
This commit is contained in:
@@ -1087,25 +1087,25 @@ void PeerManagerImpl::PushNodeVersion(CNode& pnode, int64_t nTime)
|
||||
// Note that pnode->GetLocalServices() is a reflection of the local
|
||||
// services we were offering when the CNode object was created for this
|
||||
// peer.
|
||||
ServiceFlags nLocalNodeServices = pnode.GetLocalServices();
|
||||
uint64_t my_services{pnode.GetLocalServices()};
|
||||
uint64_t nonce = pnode.GetLocalNonce();
|
||||
const int nNodeStartingHeight{m_best_height};
|
||||
NodeId nodeid = pnode.GetId();
|
||||
CAddress addr = pnode.addr;
|
||||
|
||||
CAddress addrYou = addr.IsRoutable() && !IsProxy(addr) && addr.IsAddrV1Compatible() ?
|
||||
addr :
|
||||
CAddress(CService(), addr.nServices);
|
||||
CAddress addrMe = CAddress(CService(), nLocalNodeServices);
|
||||
CService addr_you = addr.IsRoutable() && !IsProxy(addr) && addr.IsAddrV1Compatible() ? addr : CService();
|
||||
uint64_t your_services{addr.nServices};
|
||||
|
||||
const bool tx_relay = !m_ignore_incoming_txs && pnode.m_tx_relay != nullptr;
|
||||
m_connman.PushMessage(&pnode, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::VERSION, PROTOCOL_VERSION, (uint64_t)nLocalNodeServices, nTime, addrYou, addrMe,
|
||||
m_connman.PushMessage(&pnode, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::VERSION, PROTOCOL_VERSION, my_services, nTime,
|
||||
your_services, addr_you, // Together the pre-version-31402 serialization of CAddress "addrYou" (without nTime)
|
||||
my_services, CService(), // Together the pre-version-31402 serialization of CAddress "addrMe" (without nTime)
|
||||
nonce, strSubVersion, nNodeStartingHeight, tx_relay));
|
||||
|
||||
if (fLogIPs) {
|
||||
LogPrint(BCLog::NET, "send version message: version %d, blocks=%d, us=%s, them=%s, txrelay=%d, peer=%d\n", PROTOCOL_VERSION, nNodeStartingHeight, addrMe.ToString(), addrYou.ToString(), tx_relay, nodeid);
|
||||
LogPrint(BCLog::NET, "send version message: version %d, blocks=%d, us=%s, them=%s, txrelay=%d, peer=%d\n", PROTOCOL_VERSION, nNodeStartingHeight, CService().ToString(), addr_you.ToString(), tx_relay, nodeid);
|
||||
} else {
|
||||
LogPrint(BCLog::NET, "send version message: version %d, blocks=%d, us=%s, txrelay=%d, peer=%d\n", PROTOCOL_VERSION, nNodeStartingHeight, addrMe.ToString(), tx_relay, nodeid);
|
||||
LogPrint(BCLog::NET, "send version message: version %d, blocks=%d, us=%s, txrelay=%d, peer=%d\n", PROTOCOL_VERSION, nNodeStartingHeight, CService().ToString(), tx_relay, nodeid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2487,21 +2487,20 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||
}
|
||||
|
||||
int64_t nTime;
|
||||
CAddress addrMe;
|
||||
CAddress addrFrom;
|
||||
CService addrMe;
|
||||
uint64_t nNonce = 1;
|
||||
uint64_t nServiceInt;
|
||||
ServiceFlags nServices;
|
||||
int nVersion;
|
||||
std::string cleanSubVer;
|
||||
int starting_height = -1;
|
||||
bool fRelay = true;
|
||||
|
||||
vRecv >> nVersion >> nServiceInt >> nTime >> addrMe;
|
||||
vRecv >> nVersion >> Using<CustomUintFormatter<8>>(nServices) >> nTime;
|
||||
if (nTime < 0) {
|
||||
nTime = 0;
|
||||
}
|
||||
nServices = ServiceFlags(nServiceInt);
|
||||
vRecv.ignore(8); // Ignore the addrMe service bits sent by the peer
|
||||
vRecv >> addrMe;
|
||||
if (!pfrom.IsInboundConn())
|
||||
{
|
||||
m_addrman.SetServices(pfrom.addr, nServices);
|
||||
@@ -2520,8 +2519,14 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||
return;
|
||||
}
|
||||
|
||||
if (!vRecv.empty())
|
||||
vRecv >> addrFrom >> nNonce;
|
||||
if (!vRecv.empty()) {
|
||||
// The version message includes information about the sending node which we don't use:
|
||||
// - 8 bytes (service bits)
|
||||
// - 16 bytes (ipv6 address)
|
||||
// - 2 bytes (port)
|
||||
vRecv.ignore(26);
|
||||
vRecv >> nNonce;
|
||||
}
|
||||
if (!vRecv.empty()) {
|
||||
std::string strSubVer;
|
||||
vRecv >> LIMITED_STRING(strSubVer, MAX_SUBVERSION_LENGTH);
|
||||
|
||||
Reference in New Issue
Block a user