mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-18 13:17:55 +02:00
net: handle version push in InitializeNode
This commit is contained in:
parent
7588b85cd2
commit
902768099c
4 changed files with 44 additions and 41 deletions
34
src/main.cpp
34
src/main.cpp
|
|
@ -18,6 +18,7 @@
|
|||
#include "init.h"
|
||||
#include "merkleblock.h"
|
||||
#include "net.h"
|
||||
#include "netbase.h"
|
||||
#include "policy/fees.h"
|
||||
#include "policy/policy.h"
|
||||
#include "pow.h"
|
||||
|
|
@ -354,11 +355,36 @@ void UpdatePreferredDownload(CNode* node, CNodeState* state)
|
|||
nPreferredDownload += state->fPreferredDownload;
|
||||
}
|
||||
|
||||
void InitializeNode(NodeId nodeid, const CNode *pnode) {
|
||||
void PushNodeVersion(CNode *pnode, CConnman& connman, int64_t nTime)
|
||||
{
|
||||
ServiceFlags nLocalNodeServices = pnode->GetLocalServices();
|
||||
uint64_t nonce = pnode->GetLocalNonce();
|
||||
int nNodeStartingHeight = pnode->GetMyStartingHeight();
|
||||
NodeId nodeid = pnode->GetId();
|
||||
CAddress addr = pnode->addr;
|
||||
|
||||
CAddress addrYou = (addr.IsRoutable() && !IsProxy(addr) ? addr : CAddress(CService(), addr.nServices));
|
||||
CAddress addrMe = CAddress(CService(), nLocalNodeServices);
|
||||
|
||||
connman.PushMessageWithVersion(pnode, INIT_PROTO_VERSION, NetMsgType::VERSION, PROTOCOL_VERSION, (uint64_t)nLocalNodeServices, nTime, addrYou, addrMe,
|
||||
nonce, strSubVersion, nNodeStartingHeight, ::fRelayTxes);
|
||||
|
||||
if (fLogIPs)
|
||||
LogPrint("net", "send version message: version %d, blocks=%d, us=%s, them=%s, peer=%d\n", PROTOCOL_VERSION, nNodeStartingHeight, addrMe.ToString(), addrYou.ToString(), nodeid);
|
||||
else
|
||||
LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nNodeStartingHeight, addrMe.ToString(), nodeid);
|
||||
}
|
||||
|
||||
void InitializeNode(CNode *pnode, CConnman& connman) {
|
||||
CAddress addr = pnode->addr;
|
||||
std::string addrName = pnode->addrName;
|
||||
LOCK(cs_main);
|
||||
mapNodeState.emplace_hint(mapNodeState.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(addr, std::move(addrName)));
|
||||
NodeId nodeid = pnode->GetId();
|
||||
{
|
||||
LOCK(cs_main);
|
||||
mapNodeState.emplace_hint(mapNodeState.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(addr, std::move(addrName)));
|
||||
}
|
||||
if(!pnode->fInbound)
|
||||
PushNodeVersion(pnode, connman, GetTime());
|
||||
}
|
||||
|
||||
void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) {
|
||||
|
|
@ -5118,7 +5144,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
|||
|
||||
// Be shy and don't send version until we hear
|
||||
if (pfrom->fInbound)
|
||||
connman.PushVersion(pfrom, GetAdjustedTime());
|
||||
PushNodeVersion(pfrom, connman, GetAdjustedTime());
|
||||
|
||||
pfrom->fClient = !(pfrom->nServices & NODE_NETWORK);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue