Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 1,615 Lines • ▼ Show 20 Lines | const CSipHasher hasher = | ||||
.Write((GetTime() + hashAddr) / (24 * 60 * 60)); | .Write((GetTime() + hashAddr) / (24 * 60 * 60)); | ||||
FastRandomContext insecure_rand; | FastRandomContext insecure_rand; | ||||
std::array<std::pair<uint64_t, CNode *>, 2> best{ | std::array<std::pair<uint64_t, CNode *>, 2> best{ | ||||
{{0, nullptr}, {0, nullptr}}}; | {{0, nullptr}, {0, nullptr}}}; | ||||
assert(nRelayNodes <= best.size()); | assert(nRelayNodes <= best.size()); | ||||
auto sortfunc = [&best, &hasher, nRelayNodes](CNode *pnode) { | auto sortfunc = [&best, &hasher, nRelayNodes](CNode *pnode) { | ||||
if (pnode->nVersion >= CADDR_TIME_VERSION && pnode->IsAddrRelayPeer()) { | if (pnode->IsAddrRelayPeer()) { | ||||
uint64_t hashKey = | uint64_t hashKey = | ||||
CSipHasher(hasher).Write(pnode->GetId()).Finalize(); | CSipHasher(hasher).Write(pnode->GetId()).Finalize(); | ||||
for (unsigned int i = 0; i < nRelayNodes; i++) { | for (unsigned int i = 0; i < nRelayNodes; i++) { | ||||
if (hashKey > best[i].first) { | if (hashKey > best[i].first) { | ||||
std::copy(best.begin() + i, best.begin() + nRelayNodes - 1, | std::copy(best.begin() + i, best.begin() + nRelayNodes - 1, | ||||
best.begin() + i + 1); | best.begin() + i + 1); | ||||
best[i] = std::make_pair(hashKey, pnode); | best[i] = std::make_pair(hashKey, pnode); | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 1,010 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::VERSION) { | ||||
LogPrint(BCLog::NET, | LogPrint(BCLog::NET, | ||||
"ProcessMessages: advertising address %s\n", | "ProcessMessages: advertising address %s\n", | ||||
addr.ToString()); | addr.ToString()); | ||||
pfrom.PushAddress(addr, insecure_rand); | pfrom.PushAddress(addr, insecure_rand); | ||||
} | } | ||||
} | } | ||||
// Get recent addresses | // Get recent addresses | ||||
if (pfrom.fOneShot || pfrom.nVersion >= CADDR_TIME_VERSION || | |||||
connman.GetAddressCount() < 1000) { | |||||
connman.PushMessage( | connman.PushMessage( | ||||
&pfrom, | &pfrom, CNetMsgMaker(nSendVersion).Make(NetMsgType::GETADDR)); | ||||
CNetMsgMaker(nSendVersion).Make(NetMsgType::GETADDR)); | |||||
pfrom.fGetAddr = true; | pfrom.fGetAddr = true; | ||||
} | |||||
connman.MarkAddressGood(pfrom.addr); | connman.MarkAddressGood(pfrom.addr); | ||||
} | } | ||||
std::string remoteAddr; | std::string remoteAddr; | ||||
if (fLogIPs) { | if (fLogIPs) { | ||||
remoteAddr = ", peeraddr=" + pfrom.addr.ToString(); | remoteAddr = ", peeraddr=" + pfrom.addr.ToString(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | if (!pfrom.fSuccessfullyConnected) { | ||||
Misbehaving(pfrom, 10, "missing-verack"); | Misbehaving(pfrom, 10, "missing-verack"); | ||||
return false; | return false; | ||||
} | } | ||||
if (msg_type == NetMsgType::ADDR) { | if (msg_type == NetMsgType::ADDR) { | ||||
std::vector<CAddress> vAddr; | std::vector<CAddress> vAddr; | ||||
vRecv >> vAddr; | vRecv >> vAddr; | ||||
// Don't want addr from older versions unless seeding | |||||
if (pfrom.nVersion < CADDR_TIME_VERSION && | |||||
connman.GetAddressCount() > 1000) { | |||||
return true; | |||||
} | |||||
if (!pfrom.IsAddrRelayPeer()) { | if (!pfrom.IsAddrRelayPeer()) { | ||||
return true; | return true; | ||||
} | } | ||||
if (vAddr.size() > 1000) { | if (vAddr.size() > 1000) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
Misbehaving(pfrom, 20, "oversized-addr"); | Misbehaving(pfrom, 20, "oversized-addr"); | ||||
return error("message addr size() = %u", vAddr.size()); | return error("message addr size() = %u", vAddr.size()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,484 Lines • Show Last 20 Lines |