@ -179,7 +179,7 @@ unsigned short GetListenPort()
}
// find 'best' local address for a particular peer
bool GetLocal ( CService & addr , const CNetAddr * paddrP eer )
bool GetLocal ( CService & addr , const CNode & p eer )
{
if ( ! fListen )
return false ;
@ -190,8 +190,18 @@ bool GetLocal(CService& addr, const CNetAddr *paddrPeer)
LOCK ( cs_mapLocalHost ) ;
for ( map < CNetAddr , LocalServiceInfo > : : iterator it = mapLocalHost . begin ( ) ; it ! = mapLocalHost . end ( ) ; it + + )
{
// For privacy reasons, don't advertise our privacy-network address
// to other networks and don't advertise our other-network address
// to privacy networks.
const Network our_net { ( * it ) . first . GetNetwork ( ) } ;
const Network peers_net { peer . ConnectedThroughNetwork ( ) } ;
if ( our_net ! = peers_net & &
( our_net = = NET_ONION | | our_net = = NET_I2P | |
peers_net = = NET_ONION | | peers_net = = NET_I2P ) ) {
continue ;
}
int nScore = ( * it ) . second . nScore ;
int nReachability = ( * it ) . first . GetReachabilityFrom ( paddrPeer ) ;
int nReachability = ( * it ) . first . GetReachabilityFrom ( peer . addr ) ;
if ( nReachability > nBestReachability | | ( nReachability = = nBestReachability & & nScore > nBestScore ) )
{
addr = CService ( ( * it ) . first , ( * it ) . second . nPort ) ;
@ -228,12 +238,11 @@ static std::vector<CAddress> ConvertSeeds(const std::vector<uint8_t> &vSeedsIn)
// Otherwise, return the unroutable 0.0.0.0 but filled in with
// the normal parameters, since the IP may be changed to a useful
// one by discovery.
CAddress GetLocalAddress ( const CNetAddr * paddrP eer )
CService GetLocalAddress ( const CNode & p eer )
{
CAddress ret ( CService ( CNetAddr ( ) , GetListenPort ( ) ) , 0 ) ;
CService addr ;
if ( GetLocal ( addr , paddrPeer ) )
{
if ( GetLocal ( addr , peer ) ) {
ret = CAddress ( addr ) ;
}
ret . nServices = nLocalServices ;
@ -261,7 +270,7 @@ void AdvertizeLocal(CNode *pnode)
{
if ( fListen & & pnode - > fSuccessfullyConnected )
{
CAddress addrLocal = GetLocalAddress ( & pnode - > addr ) ;
CAddress addrLocal { GetLocalAddress ( * pnode ) } ;
// 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.
@ -576,6 +585,10 @@ extern int32_t HUSH_NSPV;
# define HUSH_NSPV_SUPERLITE (HUSH_NSPV > 0)
# endif // !HUSH_NSPV_SUPERLITE
Network CNode : : ConnectedThroughNetwork ( ) const
{
return m_inbound_onion ? NET_ONION : addr . GetNetClass ( ) ;
}
void CNode : : PushVersion ( )
{
@ -583,7 +596,9 @@ void CNode::PushVersion()
int64_t nTime = ( fInbound ? GetTime ( ) : GetTime ( ) ) ;
CAddress addrYou = ( addr . IsRoutable ( ) & & ! IsProxy ( addr ) ? addr : CAddress ( CService ( ) , addr . nServices ) ) ;
CAddress addrMe = GetLocalAddress ( & addr ) ;
CNode * addr = this ;
CService service = GetLocalAddress ( * addr ) ;
CAddress addrMe ( service ) ;
GetRandBytes ( ( unsigned char * ) & nLocalHostNonce , sizeof ( nLocalHostNonce ) ) ;
if ( fLogIPs )
LogPrint ( " net " , " send version message: version %d, blocks=%d, us=%s, them=%s, peer=%d \n " , PROTOCOL_VERSION , nBestHeight , addrMe . ToString ( ) , addrYou . ToString ( ) , id ) ;
@ -1266,6 +1281,7 @@ void CreateNodeFromAcceptedSocket(SOCKET hSocket,
return ;
}
// Don't accept connections from banned peers.
if ( CNode : : IsBanned ( addr ) & & ! allowlisted )
{
LogPrintf ( " connection from %s dropped (banned) \n " , addr . ToString ( ) ) ;
@ -1320,6 +1336,8 @@ void CreateNodeFromAcceptedSocket(SOCKET hSocket,
return ;
}
const bool inbound_onion = std : : find ( m_onion_binds . begin ( ) , m_onion_binds . end ( ) , addr_bind ) ! = m_onion_binds . end ( ) ;
CNode * pnode = new CNode ( hSocket , addr , " " , true , ssl ) ;
pnode - > AddRef ( ) ;
pnode - > fAllowlisted = allowlisted ;