@ -203,27 +203,24 @@ bool IsPeerAddrLocalGood(CNode *pnode)
Optional < CAddress > GetLocalAddrForPeer ( CNode * pnode )
{
if ( fListen & & pnode - > fSuccessfullyConnected )
CAddress addrLocal = GetLocalAddress ( & pnode - > addr , pnode - > GetLocalServices ( ) ) ;
if ( gArgs . GetBoolArg ( " -addrmantest " , false ) ) {
// use IPv4 loopback during addrmantest
addrLocal = CAddress ( CService ( LookupNumeric ( " 127.0.0.1 " , GetListenPort ( ) ) ) , pnode - > GetLocalServices ( ) ) ;
}
// If discovery is enabled, sometimes give our peer the address it
// tells us that it sees us as in case it has a better idea of our
// address than we do.
FastRandomContext rng ;
if ( IsPeerAddrLocalGood ( pnode ) & & ( ! addrLocal . IsRoutable ( ) | |
rng . randbits ( ( GetnScore ( addrLocal ) > LOCAL_MANUAL ) ? 3 : 1 ) = = 0 ) )
{
CAddress addrLocal = GetLocalAddress ( & pnode - > addr , pnode - > GetLocalServices ( ) ) ;
if ( gArgs . GetBoolArg ( " -addrmantest " , false ) ) {
// use IPv4 loopback during addrmantest
addrLocal = CAddress ( CService ( LookupNumeric ( " 127.0.0.1 " , GetListenPort ( ) ) ) , pnode - > GetLocalServices ( ) ) ;
}
// If discovery is enabled, sometimes give our peer the address it
// tells us that it sees us as in case it has a better idea of our
// address than we do.
FastRandomContext rng ;
if ( IsPeerAddrLocalGood ( pnode ) & & ( ! addrLocal . IsRoutable ( ) | |
rng . randbits ( ( GetnScore ( addrLocal ) > LOCAL_MANUAL ) ? 3 : 1 ) = = 0 ) )
{
addrLocal . SetIP ( pnode - > GetAddrLocal ( ) ) ;
}
if ( addrLocal . IsRoutable ( ) | | gArgs . GetBoolArg ( " -addrmantest " , false ) )
{
LogPrint ( BCLog : : NET , " Advertising address %s to peer=%d \n " , addrLocal . ToString ( ) , pnode - > GetId ( ) ) ;
return addrLocal ;
}
addrLocal . SetIP ( pnode - > GetAddrLocal ( ) ) ;
}
if ( addrLocal . IsRoutable ( ) | | gArgs . GetBoolArg ( " -addrmantest " , false ) )
{
LogPrint ( BCLog : : NET , " Advertising address %s to peer=%d \n " , addrLocal . ToString ( ) , pnode - > GetId ( ) ) ;
return addrLocal ;
}
// Address is unroutable. Don't advertise.
return nullopt ;