|
|
@ -46,7 +46,7 @@ bool fClient = false; |
|
|
|
static bool fUseUPnP = false; |
|
|
|
static bool fUseUPnP = false; |
|
|
|
uint64 nLocalServices = (fClient ? 0 : NODE_NETWORK); |
|
|
|
uint64 nLocalServices = (fClient ? 0 : NODE_NETWORK); |
|
|
|
static CCriticalSection cs_mapLocalHost; |
|
|
|
static CCriticalSection cs_mapLocalHost; |
|
|
|
static map<CNetAddr, int> mapLocalHost; |
|
|
|
static map<CService, int> mapLocalHost; |
|
|
|
static bool vfReachable[NET_MAX] = {}; |
|
|
|
static bool vfReachable[NET_MAX] = {}; |
|
|
|
static bool vfLimited[NET_MAX] = {}; |
|
|
|
static bool vfLimited[NET_MAX] = {}; |
|
|
|
static CNode* pnodeLocalHost = NULL; |
|
|
|
static CNode* pnodeLocalHost = NULL; |
|
|
@ -96,7 +96,7 @@ void CNode::PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// find 'best' local address for a particular peer
|
|
|
|
// find 'best' local address for a particular peer
|
|
|
|
bool GetLocal(CNetAddr& addr, const CNetAddr *paddrPeer) |
|
|
|
bool GetLocal(CService& addr, const CNetAddr *paddrPeer) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (fUseProxy || mapArgs.count("-connect") || fNoListen) |
|
|
|
if (fUseProxy || mapArgs.count("-connect") || fNoListen) |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -105,7 +105,7 @@ bool GetLocal(CNetAddr& addr, const CNetAddr *paddrPeer) |
|
|
|
int nBestReachability = -1; |
|
|
|
int nBestReachability = -1; |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_mapLocalHost); |
|
|
|
LOCK(cs_mapLocalHost); |
|
|
|
for (map<CNetAddr, int>::iterator it = mapLocalHost.begin(); it != mapLocalHost.end(); it++) |
|
|
|
for (map<CService, int>::iterator it = mapLocalHost.begin(); it != mapLocalHost.end(); it++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int nCount = (*it).second; |
|
|
|
int nCount = (*it).second; |
|
|
|
int nReachability = (*it).first.GetReachabilityFrom(paddrPeer); |
|
|
|
int nReachability = (*it).first.GetReachabilityFrom(paddrPeer); |
|
|
@ -124,11 +124,10 @@ bool GetLocal(CNetAddr& addr, const CNetAddr *paddrPeer) |
|
|
|
CAddress GetLocalAddress(const CNetAddr *paddrPeer) |
|
|
|
CAddress GetLocalAddress(const CNetAddr *paddrPeer) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CAddress ret(CService("0.0.0.0",0),0); |
|
|
|
CAddress ret(CService("0.0.0.0",0),0); |
|
|
|
CNetAddr addr; |
|
|
|
CService addr; |
|
|
|
if (GetLocal(addr, paddrPeer)) |
|
|
|
if (GetLocal(addr, paddrPeer)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ret.SetIP(addr); |
|
|
|
ret = CAddress(addr); |
|
|
|
ret.SetPort(GetListenPort()); |
|
|
|
|
|
|
|
ret.nServices = nLocalServices; |
|
|
|
ret.nServices = nLocalServices; |
|
|
|
ret.nTime = GetAdjustedTime(); |
|
|
|
ret.nTime = GetAdjustedTime(); |
|
|
|
} |
|
|
|
} |
|
|
@ -196,7 +195,7 @@ void static AdvertizeLocal() |
|
|
|
if (pnode->fSuccessfullyConnected) |
|
|
|
if (pnode->fSuccessfullyConnected) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CAddress addrLocal = GetLocalAddress(&pnode->addr); |
|
|
|
CAddress addrLocal = GetLocalAddress(&pnode->addr); |
|
|
|
if (addrLocal.IsRoutable() && (CNetAddr)addrLocal != (CNetAddr)pnode->addrLocal) |
|
|
|
if (addrLocal.IsRoutable() && (CService)addrLocal != (CService)pnode->addrLocal) |
|
|
|
{ |
|
|
|
{ |
|
|
|
pnode->PushAddress(addrLocal); |
|
|
|
pnode->PushAddress(addrLocal); |
|
|
|
pnode->addrLocal = addrLocal; |
|
|
|
pnode->addrLocal = addrLocal; |
|
|
@ -206,7 +205,7 @@ void static AdvertizeLocal() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// learn a new local address
|
|
|
|
// learn a new local address
|
|
|
|
bool AddLocal(const CNetAddr& addr, int nScore) |
|
|
|
bool AddLocal(const CService& addr, int nScore) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!addr.IsRoutable()) |
|
|
|
if (!addr.IsRoutable()) |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -226,6 +225,13 @@ bool AddLocal(const CNetAddr& addr, int nScore) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool AddLocal(const CNetAddr& addr, int nScore, int port) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (port == -1) |
|
|
|
|
|
|
|
port = GetListenPort(); |
|
|
|
|
|
|
|
return AddLocal(CService(addr, port), nScore); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Make a particular network entirely off-limits (no automatic connects to it) */ |
|
|
|
/** Make a particular network entirely off-limits (no automatic connects to it) */ |
|
|
|
void SetLimited(enum Network net, bool fLimited) |
|
|
|
void SetLimited(enum Network net, bool fLimited) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -240,7 +246,7 @@ bool IsLimited(const CNetAddr& addr) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** vote for a local address */ |
|
|
|
/** vote for a local address */ |
|
|
|
bool SeenLocal(const CNetAddr& addr) |
|
|
|
bool SeenLocal(const CService& addr) |
|
|
|
{ |
|
|
|
{ |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_mapLocalHost); |
|
|
|
LOCK(cs_mapLocalHost); |
|
|
@ -255,7 +261,7 @@ bool SeenLocal(const CNetAddr& addr) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** check whether a given address is potentially local */ |
|
|
|
/** check whether a given address is potentially local */ |
|
|
|
bool IsLocal(const CNetAddr& addr) |
|
|
|
bool IsLocal(const CService& addr) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_mapLocalHost); |
|
|
|
LOCK(cs_mapLocalHost); |
|
|
|
return mapLocalHost.count(addr) > 0; |
|
|
|
return mapLocalHost.count(addr) > 0; |
|
|
|