X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Fnet.cpp;h=5dcf9fc6e7e46c2d6091516de722974833f926c1;hp=7255cab3f70c77010399fb998047db72841d9c15;hb=09ccabeb1ace011357b4767aac6566d1cfc99eb6;hpb=73e57db0e728423c3541f5ad7b260e8fd9e6e7d1 diff --git a/src/net.cpp b/src/net.cpp index 7255cab..5dcf9fc 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -218,6 +218,44 @@ void SetReachable(enum Network net, bool fFlag) vfReachable[NET_IPV4] = true; } +int GetnScore(const CService& addr) +{ + LOCK(cs_mapLocalHost); + if (mapLocalHost.count(addr) == LOCAL_NONE) + return 0; + return mapLocalHost[addr].nScore; +} + + +// Is our peer's addrLocal potentially useful as an external IP source? +bool IsPeerAddrLocalGood(CNode *pnode) +{ + return fDiscover && pnode->addr.IsRoutable() && pnode->addrLocal.IsRoutable() && + !IsLimited(pnode->addrLocal.GetNetwork()); +} + +// pushes our own address to a peer +void AdvertiseLocal(CNode *pnode) +{ + if (!fNoListen && pnode->fSuccessfullyConnected) + { + CAddress addrLocal = GetLocalAddress(&pnode->addr); + // 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. + if (IsPeerAddrLocalGood(pnode) && (!addrLocal.IsRoutable() || + GetRand((GetnScore(addrLocal) > LOCAL_MANUAL) ? 8:2) == 0)) + { + addrLocal.SetIP(pnode->addrLocal); + } + if (addrLocal.IsRoutable()) + { + printf("AdvertiseLocal: advertising address %s\n", addrLocal.ToString().c_str()); + pnode->PushAddress(addrLocal); + } + } +} + // learn a new local address bool AddLocal(const CService& addr, int nScore) { @@ -1874,3 +1912,6 @@ uint64_t CNode::GetTotalBytesSent() LOCK(cs_totalBytesSent); return nTotalBytesSent; } +int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds) { + return nNow + (int64_t)(log1p(GetRand(1ULL << 48) * -0.0000000000000035527136788 /* -1/2^48 */) * average_interval_seconds * -1000000.0 + 0.5); +}