Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | static int GetnScore(const CService &addr) { | ||||
} | } | ||||
return mapLocalHost[addr].nScore; | return mapLocalHost[addr].nScore; | ||||
} | } | ||||
// Is our peer's addrLocal potentially useful as an external IP source? | // Is our peer's addrLocal potentially useful as an external IP source? | ||||
bool IsPeerAddrLocalGood(CNode *pnode) { | bool IsPeerAddrLocalGood(CNode *pnode) { | ||||
CService addrLocal = pnode->GetAddrLocal(); | CService addrLocal = pnode->GetAddrLocal(); | ||||
return fDiscover && pnode->addr.IsRoutable() && addrLocal.IsRoutable() && | return fDiscover && pnode->addr.IsRoutable() && addrLocal.IsRoutable() && | ||||
!IsLimited(addrLocal.GetNetwork()); | IsReachable(addrLocal.GetNetwork()); | ||||
} | } | ||||
// Pushes our own address to a peer. | // Pushes our own address to a peer. | ||||
void AdvertiseLocal(CNode *pnode) { | void AdvertiseLocal(CNode *pnode) { | ||||
if (fListen && pnode->fSuccessfullyConnected) { | if (fListen && pnode->fSuccessfullyConnected) { | ||||
CAddress addrLocal = | CAddress addrLocal = | ||||
GetLocalAddress(&pnode->addr, pnode->GetLocalServices()); | GetLocalAddress(&pnode->addr, pnode->GetLocalServices()); | ||||
if (gArgs.GetBoolArg("-addrmantest", false)) { | if (gArgs.GetBoolArg("-addrmantest", false)) { | ||||
Show All 25 Lines | bool AddLocal(const CService &addr, int nScore) { | ||||
if (!addr.IsRoutable()) { | if (!addr.IsRoutable()) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!fDiscover && nScore < LOCAL_MANUAL) { | if (!fDiscover && nScore < LOCAL_MANUAL) { | ||||
return false; | return false; | ||||
} | } | ||||
if (IsLimited(addr)) { | if (!IsReachable(addr)) { | ||||
return false; | return false; | ||||
} | } | ||||
LogPrintf("AddLocal(%s,%i)\n", addr.ToString(), nScore); | LogPrintf("AddLocal(%s,%i)\n", addr.ToString(), nScore); | ||||
{ | { | ||||
LOCK(cs_mapLocalHost); | LOCK(cs_mapLocalHost); | ||||
bool fAlready = mapLocalHost.count(addr) > 0; | bool fAlready = mapLocalHost.count(addr) > 0; | ||||
Show All 12 Lines | |||||
} | } | ||||
void RemoveLocal(const CService &addr) { | void RemoveLocal(const CService &addr) { | ||||
LOCK(cs_mapLocalHost); | LOCK(cs_mapLocalHost); | ||||
LogPrintf("RemoveLocal(%s)\n", addr.ToString()); | LogPrintf("RemoveLocal(%s)\n", addr.ToString()); | ||||
mapLocalHost.erase(addr); | mapLocalHost.erase(addr); | ||||
} | } | ||||
/** | void SetReachable(enum Network net, bool reachable) { | ||||
* Make a particular network entirely off-limits (no automatic connects to it). | |||||
*/ | |||||
void SetLimited(enum Network net, bool fLimited) { | |||||
if (net == NET_UNROUTABLE || net == NET_INTERNAL) { | if (net == NET_UNROUTABLE || net == NET_INTERNAL) { | ||||
return; | return; | ||||
} | } | ||||
LOCK(cs_mapLocalHost); | LOCK(cs_mapLocalHost); | ||||
vfLimited[net] = fLimited; | vfLimited[net] = !reachable; | ||||
} | } | ||||
bool IsLimited(enum Network net) { | bool IsReachable(enum Network net) { | ||||
LOCK(cs_mapLocalHost); | LOCK(cs_mapLocalHost); | ||||
return vfLimited[net]; | return !vfLimited[net]; | ||||
} | } | ||||
bool IsLimited(const CNetAddr &addr) { | bool IsReachable(const CNetAddr &addr) { | ||||
return IsLimited(addr.GetNetwork()); | return IsReachable(addr.GetNetwork()); | ||||
} | } | ||||
/** vote for a local address */ | /** vote for a local address */ | ||||
bool SeenLocal(const CService &addr) { | bool SeenLocal(const CService &addr) { | ||||
LOCK(cs_mapLocalHost); | LOCK(cs_mapLocalHost); | ||||
if (mapLocalHost.count(addr) == 0) { | if (mapLocalHost.count(addr) == 0) { | ||||
return false; | return false; | ||||
} | } | ||||
mapLocalHost[addr].nScore++; | mapLocalHost[addr].nScore++; | ||||
return true; | return true; | ||||
} | } | ||||
/** check whether a given address is potentially local */ | /** check whether a given address is potentially local */ | ||||
bool IsLocal(const CService &addr) { | bool IsLocal(const CService &addr) { | ||||
LOCK(cs_mapLocalHost); | LOCK(cs_mapLocalHost); | ||||
return mapLocalHost.count(addr) > 0; | return mapLocalHost.count(addr) > 0; | ||||
} | } | ||||
/** check whether a given network is one we can probably connect to */ | |||||
bool IsReachable(enum Network net) { | |||||
return !IsLimited(net); | |||||
} | |||||
/** check whether a given address is in a network we can probably connect to */ | |||||
bool IsReachable(const CNetAddr &addr) { | |||||
return IsReachable(addr.GetNetwork()); | |||||
} | |||||
CNode *CConnman::FindNode(const CNetAddr &ip) { | CNode *CConnman::FindNode(const CNetAddr &ip) { | ||||
LOCK(cs_vNodes); | LOCK(cs_vNodes); | ||||
for (CNode *pnode : vNodes) { | for (CNode *pnode : vNodes) { | ||||
if (static_cast<CNetAddr>(pnode->addr) == ip) { | if (static_cast<CNetAddr>(pnode->addr) == ip) { | ||||
return pnode; | return pnode; | ||||
} | } | ||||
} | } | ||||
return nullptr; | return nullptr; | ||||
▲ Show 20 Lines • Show All 1,462 Lines • ▼ Show 20 Lines | while (!interruptNet) { | ||||
// loop run again (which sleeps, adds seed nodes, recalculates | // loop run again (which sleeps, adds seed nodes, recalculates | ||||
// already-connected network ranges, ...) before trying new addrman | // already-connected network ranges, ...) before trying new addrman | ||||
// addresses. | // addresses. | ||||
nTries++; | nTries++; | ||||
if (nTries > 100) { | if (nTries > 100) { | ||||
break; | break; | ||||
} | } | ||||
if (IsLimited(addr)) { | if (!IsReachable(addr)) { | ||||
continue; | continue; | ||||
} | } | ||||
// only consider very recently tried nodes after 30 failed attempts | // only consider very recently tried nodes after 30 failed attempts | ||||
if (nANow - addr.nLastTry < 600 && nTries < 30) { | if (nANow - addr.nLastTry < 600 && nTries < 30) { | ||||
continue; | continue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 389 Lines • ▼ Show 20 Lines | CConnman::CConnman(const Config &configIn, uint64_t nSeed0In, uint64_t nSeed1In) | ||||
Init(connOptions); | Init(connOptions); | ||||
} | } | ||||
NodeId CConnman::GetNewNodeId() { | NodeId CConnman::GetNewNodeId() { | ||||
return nLastNodeId.fetch_add(1, std::memory_order_relaxed); | return nLastNodeId.fetch_add(1, std::memory_order_relaxed); | ||||
} | } | ||||
bool CConnman::Bind(const CService &addr, unsigned int flags) { | bool CConnman::Bind(const CService &addr, unsigned int flags) { | ||||
if (!(flags & BF_EXPLICIT) && IsLimited(addr)) { | if (!(flags & BF_EXPLICIT) && !IsReachable(addr)) { | ||||
return false; | return false; | ||||
} | } | ||||
std::string strError; | std::string strError; | ||||
if (!BindListenPort(addr, strError, (flags & BF_WHITELIST) != 0)) { | if (!BindListenPort(addr, strError, (flags & BF_WHITELIST) != 0)) { | ||||
if ((flags & BF_REPORT_ERROR) && clientInterface) { | if ((flags & BF_REPORT_ERROR) && clientInterface) { | ||||
clientInterface->ThreadSafeMessageBox( | clientInterface->ThreadSafeMessageBox( | ||||
strError, "", CClientUIInterface::MSG_ERROR); | strError, "", CClientUIInterface::MSG_ERROR); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 678 Lines • Show Last 20 Lines |