64
64
const static std::string NET_MESSAGE_COMMAND_OTHER = " *other*" ;
65
65
66
66
static const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL ; // SHA256("netgroup")[0:8]
67
+ static const uint64_t RANDOMIZER_ID_LOCALHOSTNONCE = 0xd93e69e2bbfa5735ULL ; // SHA256("localhostnonce")[0:8]
67
68
//
68
69
// Global state variables
69
70
//
@@ -389,7 +390,10 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
389
390
addrman.Attempt (addrConnect, fCountFailure );
390
391
391
392
// Add node
392
- CNode* pnode = new CNode (GetNewNodeId (), nLocalServices, GetBestHeight (), hSocket, addrConnect, CalculateKeyedNetGroup (addrConnect), pszDest ? pszDest : " " , false );
393
+ NodeId id = GetNewNodeId ();
394
+ uint64_t nonce = GetDeterministicRandomizer (RANDOMIZER_ID_LOCALHOSTNONCE).Write (id).Finalize ();
395
+ CNode* pnode = new CNode (id, nLocalServices, GetBestHeight (), hSocket, addrConnect, CalculateKeyedNetGroup (addrConnect), nonce, pszDest ? pszDest : " " , false );
396
+
393
397
GetNodeSignals ().InitializeNode (pnode->GetId (), pnode);
394
398
pnode->AddRef ();
395
399
@@ -1024,7 +1028,10 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
1024
1028
}
1025
1029
}
1026
1030
1027
- CNode* pnode = new CNode (GetNewNodeId (), nLocalServices, GetBestHeight (), hSocket, addr, CalculateKeyedNetGroup (addr), " " , true );
1031
+ NodeId id = GetNewNodeId ();
1032
+ uint64_t nonce = GetDeterministicRandomizer (RANDOMIZER_ID_LOCALHOSTNONCE).Write (id).Finalize ();
1033
+
1034
+ CNode* pnode = new CNode (id, nLocalServices, GetBestHeight (), hSocket, addr, CalculateKeyedNetGroup (addr), nonce, " " , true );
1028
1035
GetNodeSignals ().InitializeNode (pnode->GetId (), pnode);
1029
1036
pnode->AddRef ();
1030
1037
pnode->fWhitelisted = whitelisted;
@@ -2118,7 +2125,11 @@ bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, st
2118
2125
if (pnodeLocalHost == NULL ) {
2119
2126
CNetAddr local;
2120
2127
LookupHost (" 127.0.0.1" , local, false );
2121
- pnodeLocalHost = new CNode (GetNewNodeId (), nLocalServices, GetBestHeight (), INVALID_SOCKET, CAddress (CService (local, 0 ), nLocalServices), 0 );
2128
+
2129
+ NodeId id = GetNewNodeId ();
2130
+ uint64_t nonce = GetDeterministicRandomizer (RANDOMIZER_ID_LOCALHOSTNONCE).Write (id).Finalize ();
2131
+
2132
+ pnodeLocalHost = new CNode (id, nLocalServices, GetBestHeight (), INVALID_SOCKET, CAddress (CService (local, 0 ), nLocalServices), 0 , nonce);
2122
2133
GetNodeSignals ().InitializeNode (pnodeLocalHost->GetId (), pnodeLocalHost);
2123
2134
}
2124
2135
@@ -2509,12 +2520,17 @@ void CNode::Fuzz(int nChance)
2509
2520
unsigned int CConnman::GetReceiveFloodSize () const { return nReceiveFloodSize; }
2510
2521
unsigned int CConnman::GetSendBufferSize () const { return nSendBufferMaxSize; }
2511
2522
2512
- CNode::CNode (NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, const std::string& addrNameIn, bool fInboundIn ) :
2523
+ CNode::CNode (NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const std::string& addrNameIn, bool fInboundIn ) :
2513
2524
ssSend(SER_NETWORK, INIT_PROTO_VERSION),
2514
2525
addr(addrIn),
2526
+ fInbound(fInboundIn ),
2527
+ id(idIn),
2515
2528
nKeyedNetGroup(nKeyedNetGroupIn),
2516
2529
addrKnown(5000 , 0.001 ),
2517
- filterInventoryKnown(50000 , 0.000001 )
2530
+ filterInventoryKnown(50000 , 0.000001 ),
2531
+ nLocalHostNonce(nLocalHostNonceIn),
2532
+ nLocalServices(nLocalServicesIn),
2533
+ nMyStartingHeight(nMyStartingHeightIn)
2518
2534
{
2519
2535
nServices = NODE_NONE;
2520
2536
nServicesExpected = NODE_NONE;
@@ -2533,7 +2549,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
2533
2549
fOneShot = false ;
2534
2550
fClient = false ; // set by version message
2535
2551
fFeeler = false ;
2536
- fInbound = fInboundIn ;
2537
2552
fNetworkNode = false ;
2538
2553
fSuccessfullyConnected = false ;
2539
2554
fDisconnect = false ;
@@ -2562,12 +2577,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
2562
2577
minFeeFilter = 0 ;
2563
2578
lastSentFeeFilter = 0 ;
2564
2579
nextSendTimeFeeFilter = 0 ;
2565
- id = idIn;
2566
2580
nOptimisticBytesWritten = 0 ;
2567
- nLocalServices = nLocalServicesIn;
2568
-
2569
- GetRandBytes ((unsigned char *)&nLocalHostNonce, sizeof (nLocalHostNonce));
2570
- nMyStartingHeight = nMyStartingHeightIn;
2571
2581
2572
2582
BOOST_FOREACH (const std::string &msg, getAllNetMessageTypes ())
2573
2583
mapRecvBytesPerMsgCmd[msg] = 0 ;
0 commit comments