net_processing: modernize PushNodeVersion()
Rename some variables in `PeerManagerImpl::PushNodeVersion()` and use one log call instead of 2 almost identical. Also, assign variables after they are declared to make it easy to assign them different values, conditionally. This is a non-functional change.
This commit is contained in:
1 file changed
+34
-18
+34
-18
@@ -1528,27 +1528,43 @@ void PeerManagerImpl::FindNextBlocks(std::vector<const CBlockIndex*>& vBlocks, c
|
|||||||
|
|
||||||
void PeerManagerImpl::PushNodeVersion(CNode& pnode, const Peer& peer)
|
void PeerManagerImpl::PushNodeVersion(CNode& pnode, const Peer& peer)
|
||||||
{
|
{
|
||||||
uint64_t my_services{peer.m_our_services};
|
uint64_t my_services;
|
||||||
const int64_t nTime{count_seconds(GetTime<std::chrono::seconds>())};
|
int64_t my_time;
|
||||||
uint64_t nonce = pnode.GetLocalNonce();
|
uint64_t your_services;
|
||||||
const int nNodeStartingHeight{m_best_height};
|
CService your_addr;
|
||||||
NodeId nodeid = pnode.GetId();
|
std::string my_user_agent;
|
||||||
CAddress addr = pnode.addr;
|
int my_height;
|
||||||
|
bool my_tx_relay;
|
||||||
|
|
||||||
CService addr_you = addr.IsRoutable() && !IsProxy(addr) && addr.IsAddrV1Compatible() ? addr : CService();
|
const CAddress& addr{pnode.addr};
|
||||||
uint64_t your_services{addr.nServices};
|
my_services = peer.m_our_services;
|
||||||
|
my_time = count_seconds(GetTime<std::chrono::seconds>());
|
||||||
|
your_services = addr.nServices;
|
||||||
|
your_addr = addr.IsRoutable() && !IsProxy(addr) && addr.IsAddrV1Compatible() ? CService{addr} : CService{};
|
||||||
|
my_user_agent = strSubVersion;
|
||||||
|
my_height = m_best_height;
|
||||||
|
my_tx_relay = !RejectIncomingTxs(pnode);
|
||||||
|
|
||||||
const bool tx_relay{!RejectIncomingTxs(pnode)};
|
MakeAndPushMessage(
|
||||||
MakeAndPushMessage(pnode, NetMsgType::VERSION, PROTOCOL_VERSION, my_services, nTime,
|
pnode,
|
||||||
your_services, CNetAddr::V1(addr_you), // Together the pre-version-31402 serialization of CAddress "addrYou" (without nTime)
|
NetMsgType::VERSION,
|
||||||
my_services, CNetAddr::V1(CService{}), // Together the pre-version-31402 serialization of CAddress "addrMe" (without nTime)
|
PROTOCOL_VERSION,
|
||||||
nonce, strSubVersion, nNodeStartingHeight, tx_relay);
|
my_services,
|
||||||
|
my_time,
|
||||||
|
// your_services + CNetAddr::V1(your_addr) is the pre-version-31402 serialization of your_addr (without nTime)
|
||||||
|
your_services, CNetAddr::V1(your_addr),
|
||||||
|
// same, for a dummy address
|
||||||
|
my_services, CNetAddr::V1(CService{}),
|
||||||
|
pnode.GetLocalNonce(),
|
||||||
|
my_user_agent,
|
||||||
|
my_height,
|
||||||
|
my_tx_relay);
|
||||||
|
|
||||||
if (fLogIPs) {
|
LogDebug(
|
||||||
LogDebug(BCLog::NET, "send version message: version %d, blocks=%d, them=%s, txrelay=%d, peer=%d\n", PROTOCOL_VERSION, nNodeStartingHeight, addr_you.ToStringAddrPort(), tx_relay, nodeid);
|
BCLog::NET, "send version message: version=%d, blocks=%d%s, txrelay=%d, peer=%d\n",
|
||||||
} else {
|
PROTOCOL_VERSION, my_height,
|
||||||
LogDebug(BCLog::NET, "send version message: version %d, blocks=%d, txrelay=%d, peer=%d\n", PROTOCOL_VERSION, nNodeStartingHeight, tx_relay, nodeid);
|
fLogIPs ? strprintf(", them=%s", your_addr.ToStringAddrPort()) : "",
|
||||||
}
|
my_tx_relay, pnode.GetId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerManagerImpl::UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
|
void PeerManagerImpl::UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
|
||||||
|
|||||||
Reference in new issue
Block a user