@ -392,7 +392,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
addrman . Attempt ( addrConnect , fCountFailure ) ;
addrman . Attempt ( addrConnect , fCountFailure ) ;
// Add node
// Add node
CNode * pnode = new CNode ( GetNewNodeId ( ) , nLocalServices , hSocket , addrConnect , pszDest ? pszDest : " " , false ) ;
CNode * pnode = new CNode ( GetNewNodeId ( ) , nLocalServices , GetBestHeight ( ) , hSocket , addrConnect , pszDest ? pszDest : " " , false ) ;
GetNodeSignals ( ) . InitializeNode ( pnode - > GetId ( ) , pnode ) ;
GetNodeSignals ( ) . InitializeNode ( pnode - > GetId ( ) , pnode ) ;
pnode - > AddRef ( ) ;
pnode - > AddRef ( ) ;
@ -451,17 +451,15 @@ void CNode::CloseSocketDisconnect()
void CNode : : PushVersion ( )
void CNode : : PushVersion ( )
{
{
int nBestHeight = GetNodeSignals ( ) . GetHeight ( ) . get_value_or ( 0 ) ;
int64_t nTime = ( fInbound ? GetAdjustedTime ( ) : GetTime ( ) ) ;
int64_t nTime = ( fInbound ? GetAdjustedTime ( ) : GetTime ( ) ) ;
CAddress addrYou = ( addr . IsRoutable ( ) & & ! IsProxy ( addr ) ? addr : CAddress ( CService ( ) , addr . nServices ) ) ;
CAddress addrYou = ( addr . IsRoutable ( ) & & ! IsProxy ( addr ) ? addr : CAddress ( CService ( ) , addr . nServices ) ) ;
CAddress addrMe = GetLocalAddress ( & addr , nLocalServices ) ;
CAddress addrMe = GetLocalAddress ( & addr , nLocalServices ) ;
if ( fLogIPs )
if ( fLogIPs )
LogPrint ( " net " , " send version message: version %d, blocks=%d, us=%s, them=%s, peer=%d \n " , PROTOCOL_VERSION , nBest Height , addrMe . ToString ( ) , addrYou . ToString ( ) , id ) ;
LogPrint ( " net " , " send version message: version %d, blocks=%d, us=%s, them=%s, peer=%d \n " , PROTOCOL_VERSION , nMyStarting Height , addrMe . ToString ( ) , addrYou . ToString ( ) , id ) ;
else
else
LogPrint ( " net " , " send version message: version %d, blocks=%d, us=%s, peer=%d \n " , PROTOCOL_VERSION , nBest Height , addrMe . ToString ( ) , id ) ;
LogPrint ( " net " , " send version message: version %d, blocks=%d, us=%s, peer=%d \n " , PROTOCOL_VERSION , nMyStarting Height , addrMe . ToString ( ) , id ) ;
PushMessage ( NetMsgType : : VERSION , PROTOCOL_VERSION , ( uint64_t ) nLocalServices , nTime , addrYou , addrMe ,
PushMessage ( NetMsgType : : VERSION , PROTOCOL_VERSION , ( uint64_t ) nLocalServices , nTime , addrYou , addrMe ,
nLocalHostNonce , strSubVersion , nBest Height , : : fRelayTxes ) ;
nLocalHostNonce , strSubVersion , nMyStarting Height , : : fRelayTxes ) ;
}
}
@ -1028,7 +1026,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
}
}
}
}
CNode * pnode = new CNode ( GetNewNodeId ( ) , nLocalServices , hSocket , addr , " " , true ) ;
CNode * pnode = new CNode ( GetNewNodeId ( ) , nLocalServices , GetBestHeight ( ) , hSocket , addr , " " , true ) ;
GetNodeSignals ( ) . InitializeNode ( pnode - > GetId ( ) , pnode ) ;
GetNodeSignals ( ) . InitializeNode ( pnode - > GetId ( ) , pnode ) ;
pnode - > AddRef ( ) ;
pnode - > AddRef ( ) ;
pnode - > fWhitelisted = whitelisted ;
pnode - > fWhitelisted = whitelisted ;
@ -2038,13 +2036,14 @@ CConnman::CConnman()
semOutbound = NULL ;
semOutbound = NULL ;
nMaxConnections = 0 ;
nMaxConnections = 0 ;
nMaxOutbound = 0 ;
nMaxOutbound = 0 ;
nBestHeight = 0 ;
}
}
bool StartNode ( CConnman & connman , boost : : thread_group & threadGroup , CScheduler & scheduler , ServiceFlags nLocalServices , ServiceFlags nRelevantServices , int nMaxConnectionsIn , int nMaxOutboundIn , std : : string & strNodeError )
bool StartNode ( CConnman & connman , boost : : thread_group & threadGroup , CScheduler & scheduler , ServiceFlags nLocalServices , ServiceFlags nRelevantServices , int nMaxConnectionsIn , int nMaxOutboundIn , int nBestHeightIn , std : : string & strNodeError )
{
{
Discover ( threadGroup ) ;
Discover ( threadGroup ) ;
bool ret = connman . Start ( threadGroup , scheduler , nLocalServices , nRelevantServices , nMaxConnectionsIn , nMaxOutboundIn , strNodeError ) ;
bool ret = connman . Start ( threadGroup , scheduler , nLocalServices , nRelevantServices , nMaxConnectionsIn , nMaxOutboundIn , nBestHeightIn , strNodeError ) ;
return ret ;
return ret ;
}
}
@ -2054,7 +2053,7 @@ NodeId CConnman::GetNewNodeId()
return nLastNodeId . fetch_add ( 1 , std : : memory_order_relaxed ) ;
return nLastNodeId . fetch_add ( 1 , std : : memory_order_relaxed ) ;
}
}
bool CConnman : : Start ( boost : : thread_group & threadGroup , CScheduler & scheduler , ServiceFlags nLocalServicesIn , ServiceFlags nRelevantServicesIn , int nMaxConnectionsIn , int nMaxOutboundIn , std : : string & strNodeError )
bool CConnman : : Start ( boost : : thread_group & threadGroup , CScheduler & scheduler , ServiceFlags nLocalServicesIn , ServiceFlags nRelevantServicesIn , int nMaxConnectionsIn , int nMaxOutboundIn , int nBestHeightIn , std : : string & strNodeError )
{
{
nTotalBytesRecv = 0 ;
nTotalBytesRecv = 0 ;
nTotalBytesSent = 0 ;
nTotalBytesSent = 0 ;
@ -2071,6 +2070,8 @@ bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, Se
nSendBufferMaxSize = 1000 * GetArg ( " -maxsendbuffer " , DEFAULT_MAXSENDBUFFER ) ;
nSendBufferMaxSize = 1000 * GetArg ( " -maxsendbuffer " , DEFAULT_MAXSENDBUFFER ) ;
nReceiveFloodSize = 1000 * GetArg ( " -maxreceivebuffer " , DEFAULT_MAXRECEIVEBUFFER ) ;
nReceiveFloodSize = 1000 * GetArg ( " -maxreceivebuffer " , DEFAULT_MAXRECEIVEBUFFER ) ;
SetBestHeight ( nBestHeightIn ) ;
uiInterface . InitMessage ( _ ( " Loading addresses... " ) ) ;
uiInterface . InitMessage ( _ ( " Loading addresses... " ) ) ;
// Load addresses from peers.dat
// Load addresses from peers.dat
int64_t nStart = GetTimeMillis ( ) ;
int64_t nStart = GetTimeMillis ( ) ;
@ -2115,7 +2116,7 @@ bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, Se
if ( pnodeLocalHost = = NULL ) {
if ( pnodeLocalHost = = NULL ) {
CNetAddr local ;
CNetAddr local ;
LookupHost ( " 127.0.0.1 " , local , false ) ;
LookupHost ( " 127.0.0.1 " , local , false ) ;
pnodeLocalHost = new CNode ( GetNewNodeId ( ) , nLocalServices , INVALID_SOCKET , CAddress ( CService ( local , 0 ) , nLocalServices ) ) ;
pnodeLocalHost = new CNode ( GetNewNodeId ( ) , nLocalServices , GetBestHeight ( ) , INVALID_SOCKET , CAddress ( CService ( local , 0 ) , nLocalServices ) ) ;
GetNodeSignals ( ) . InitializeNode ( pnodeLocalHost - > GetId ( ) , pnodeLocalHost ) ;
GetNodeSignals ( ) . InitializeNode ( pnodeLocalHost - > GetId ( ) , pnodeLocalHost ) ;
}
}
@ -2471,6 +2472,16 @@ ServiceFlags CConnman::GetLocalServices() const
return nLocalServices ;
return nLocalServices ;
}
}
void CConnman : : SetBestHeight ( int height )
{
nBestHeight . store ( height , std : : memory_order_release ) ;
}
int CConnman : : GetBestHeight ( ) const
{
return nBestHeight . load ( std : : memory_order_acquire ) ;
}
void CNode : : Fuzz ( int nChance )
void CNode : : Fuzz ( int nChance )
{
{
if ( ! fSuccessfullyConnected ) return ; // Don't fuzz initial handshake
if ( ! fSuccessfullyConnected ) return ; // Don't fuzz initial handshake
@ -2509,7 +2520,7 @@ void CNode::Fuzz(int nChance)
unsigned int CConnman : : GetReceiveFloodSize ( ) const { return nReceiveFloodSize ; }
unsigned int CConnman : : GetReceiveFloodSize ( ) const { return nReceiveFloodSize ; }
unsigned int CConnman : : GetSendBufferSize ( ) const { return nSendBufferMaxSize ; }
unsigned int CConnman : : GetSendBufferSize ( ) const { return nSendBufferMaxSize ; }
CNode : : CNode ( NodeId idIn , ServiceFlags nLocalServicesIn , SOCKET hSocketIn , const CAddress & addrIn , const std : : string & addrNameIn , bool fInboundIn ) :
CNode : : CNode ( NodeId idIn , ServiceFlags nLocalServicesIn , int nMyStartingHeightIn , SOCKET hSocketIn , const CAddress & addrIn , const std : : string & addrNameIn , bool fInboundIn ) :
ssSend ( SER_NETWORK , INIT_PROTO_VERSION ) ,
ssSend ( SER_NETWORK , INIT_PROTO_VERSION ) ,
addr ( addrIn ) ,
addr ( addrIn ) ,
nKeyedNetGroup ( CalculateKeyedNetGroup ( addrIn ) ) ,
nKeyedNetGroup ( CalculateKeyedNetGroup ( addrIn ) ) ,
@ -2567,6 +2578,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const
nLocalServices = nLocalServicesIn ;
nLocalServices = nLocalServicesIn ;
GetRandBytes ( ( unsigned char * ) & nLocalHostNonce , sizeof ( nLocalHostNonce ) ) ;
GetRandBytes ( ( unsigned char * ) & nLocalHostNonce , sizeof ( nLocalHostNonce ) ) ;
nMyStartingHeight = nMyStartingHeightIn ;
BOOST_FOREACH ( const std : : string & msg , getAllNetMessageTypes ( ) )
BOOST_FOREACH ( const std : : string & msg , getAllNetMessageTypes ( ) )
mapRecvBytesPerMsgCmd [ msg ] = 0 ;
mapRecvBytesPerMsgCmd [ msg ] = 0 ;