@ -340,6 +340,22 @@ bool CConnman::CheckIncomingNonce(uint64_t nonce)
return true ;
return true ;
}
}
/** Get the bind address for a socket as CAddress */
static CAddress GetBindAddress ( SOCKET sock )
{
CAddress addr_bind ;
struct sockaddr_storage sockaddr_bind ;
socklen_t sockaddr_bind_len = sizeof ( sockaddr_bind ) ;
if ( sock ! = INVALID_SOCKET ) {
if ( ! getsockname ( sock , ( struct sockaddr * ) & sockaddr_bind , & sockaddr_bind_len ) ) {
addr_bind . SetSockAddr ( ( const struct sockaddr * ) & sockaddr_bind ) ;
} else {
LogPrint ( BCLog : : NET , " Warning: getsockname failed \n " ) ;
}
}
return addr_bind ;
}
CNode * CConnman : : ConnectNode ( CAddress addrConnect , const char * pszDest , bool fCountFailure )
CNode * CConnman : : ConnectNode ( CAddress addrConnect , const char * pszDest , bool fCountFailure )
{
{
if ( pszDest = = NULL ) {
if ( pszDest = = NULL ) {
@ -393,7 +409,8 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
// Add node
// Add node
NodeId id = GetNewNodeId ( ) ;
NodeId id = GetNewNodeId ( ) ;
uint64_t nonce = GetDeterministicRandomizer ( RANDOMIZER_ID_LOCALHOSTNONCE ) . Write ( id ) . Finalize ( ) ;
uint64_t nonce = GetDeterministicRandomizer ( RANDOMIZER_ID_LOCALHOSTNONCE ) . Write ( id ) . Finalize ( ) ;
CNode * pnode = new CNode ( id , nLocalServices , GetBestHeight ( ) , hSocket , addrConnect , CalculateKeyedNetGroup ( addrConnect ) , nonce , pszDest ? pszDest : " " , false ) ;
CAddress addr_bind = GetBindAddress ( hSocket ) ;
CNode * pnode = new CNode ( id , nLocalServices , GetBestHeight ( ) , hSocket , addrConnect , CalculateKeyedNetGroup ( addrConnect ) , nonce , addr_bind , pszDest ? pszDest : " " , false ) ;
pnode - > nServicesExpected = ServiceFlags ( addrConnect . nServices & nRelevantServices ) ;
pnode - > nServicesExpected = ServiceFlags ( addrConnect . nServices & nRelevantServices ) ;
pnode - > AddRef ( ) ;
pnode - > AddRef ( ) ;
@ -635,6 +652,7 @@ void CNode::copyStats(CNodeStats &stats)
stats . nodeid = this - > GetId ( ) ;
stats . nodeid = this - > GetId ( ) ;
X ( nServices ) ;
X ( nServices ) ;
X ( addr ) ;
X ( addr ) ;
X ( addrBind ) ;
{
{
LOCK ( cs_filter ) ;
LOCK ( cs_filter ) ;
X ( fRelayTxes ) ;
X ( fRelayTxes ) ;
@ -1036,9 +1054,11 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
int nInbound = 0 ;
int nInbound = 0 ;
int nMaxInbound = nMaxConnections - ( nMaxOutbound + nMaxFeeler ) ;
int nMaxInbound = nMaxConnections - ( nMaxOutbound + nMaxFeeler ) ;
if ( hSocket ! = INVALID_SOCKET )
if ( hSocket ! = INVALID_SOCKET ) {
if ( ! addr . SetSockAddr ( ( const struct sockaddr * ) & sockaddr ) )
if ( ! addr . SetSockAddr ( ( const struct sockaddr * ) & sockaddr ) ) {
LogPrintf ( " Warning: Unknown socket family \n " ) ;
LogPrintf ( " Warning: Unknown socket family \n " ) ;
}
}
bool whitelisted = hListenSocket . whitelisted | | IsWhitelistedRange ( addr ) ;
bool whitelisted = hListenSocket . whitelisted | | IsWhitelistedRange ( addr ) ;
{
{
@ -1092,8 +1112,9 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
NodeId id = GetNewNodeId ( ) ;
NodeId id = GetNewNodeId ( ) ;
uint64_t nonce = GetDeterministicRandomizer ( RANDOMIZER_ID_LOCALHOSTNONCE ) . Write ( id ) . Finalize ( ) ;
uint64_t nonce = GetDeterministicRandomizer ( RANDOMIZER_ID_LOCALHOSTNONCE ) . Write ( id ) . Finalize ( ) ;
CAddress addr_bind = GetBindAddress ( hSocket ) ;
CNode * pnode = new CNode ( id , nLocalServices , GetBestHeight ( ) , hSocket , addr , CalculateKeyedNetGroup ( addr ) , nonce , " " , true ) ;
CNode * pnode = new CNode ( id , nLocalServices , GetBestHeight ( ) , hSocket , addr , CalculateKeyedNetGroup ( addr ) , nonce , addr_bind , " " , true ) ;
pnode - > AddRef ( ) ;
pnode - > AddRef ( ) ;
pnode - > fWhitelisted = whitelisted ;
pnode - > fWhitelisted = whitelisted ;
GetNodeSignals ( ) . InitializeNode ( pnode , * this ) ;
GetNodeSignals ( ) . InitializeNode ( pnode , * this ) ;
@ -2639,9 +2660,10 @@ int CConnman::GetBestHeight() const
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 , int nMyStartingHeightIn , SOCKET hSocketIn , const CAddress & addrIn , uint64_t nKeyedNetGroupIn , uint64_t nLocalHostNonceIn , const std: : string & addrNameIn , bool fInboundIn ) :
CNode : : CNode ( NodeId idIn , ServiceFlags nLocalServicesIn , int nMyStartingHeightIn , SOCKET hSocketIn , const CAddress & addrIn , uint64_t nKeyedNetGroupIn , uint64_t nLocalHostNonceIn , const CAddress & addrBindIn , const std: : string & addrNameIn , bool fInboundIn ) :
nTimeConnected ( GetSystemTimeInSeconds ( ) ) ,
nTimeConnected ( GetSystemTimeInSeconds ( ) ) ,
addr ( addrIn ) ,
addr ( addrIn ) ,
addrBind ( addrBindIn ) ,
fInbound ( fInboundIn ) ,
fInbound ( fInboundIn ) ,
nKeyedNetGroup ( nKeyedNetGroupIn ) ,
nKeyedNetGroup ( nKeyedNetGroupIn ) ,
addrKnown ( 5000 , 0.001 ) ,
addrKnown ( 5000 , 0.001 ) ,