Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 1,827 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->IsAddrRelayPeer()) { | if (pnode->RelayAddrsWithConn()) { | ||||
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,101 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::VERSION) { | ||||
pfrom.nRemoteExtraEntropy = nExtraEntropy; | pfrom.nRemoteExtraEntropy = nExtraEntropy; | ||||
// Potentially mark this peer as a preferred download peer. | // Potentially mark this peer as a preferred download peer. | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
UpdatePreferredDownload(pfrom, State(pfrom.GetId())); | UpdatePreferredDownload(pfrom, State(pfrom.GetId())); | ||||
} | } | ||||
if (!pfrom.IsInboundConn() && pfrom.IsAddrRelayPeer()) { | if (!pfrom.IsInboundConn() && !pfrom.IsBlockOnlyConn()) { | ||||
// Advertise our address | |||||
if (fListen && !::ChainstateActive().IsInitialBlockDownload()) { | if (fListen && !::ChainstateActive().IsInitialBlockDownload()) { | ||||
CAddress addr = | CAddress addr = | ||||
GetLocalAddress(&pfrom.addr, pfrom.GetLocalServices()); | GetLocalAddress(&pfrom.addr, pfrom.GetLocalServices()); | ||||
FastRandomContext insecure_rand; | FastRandomContext insecure_rand; | ||||
if (addr.IsRoutable()) { | if (addr.IsRoutable()) { | ||||
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); | ||||
} else if (IsPeerAddrLocalGood(&pfrom)) { | } else if (IsPeerAddrLocalGood(&pfrom)) { | ||||
addr.SetIP(addrMe); | addr.SetIP(addrMe); | ||||
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 | ||||
m_connman.PushMessage(&pfrom, CNetMsgMaker(greatest_common_version) | m_connman.PushMessage(&pfrom, CNetMsgMaker(greatest_common_version) | ||||
.Make(NetMsgType::GETADDR)); | .Make(NetMsgType::GETADDR)); | ||||
majcosta: remove | |||||
pfrom.fGetAddr = true; | pfrom.fGetAddr = true; | ||||
m_connman.MarkAddressGood(pfrom.addr); | m_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 107 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::ADDR || msg_type == NetMsgType::ADDRV2) { | ||||
stream_version |= ADDRV2_FORMAT; | stream_version |= ADDRV2_FORMAT; | ||||
} | } | ||||
OverrideStream<CDataStream> s(&vRecv, vRecv.GetType(), stream_version); | OverrideStream<CDataStream> s(&vRecv, vRecv.GetType(), stream_version); | ||||
std::vector<CAddress> vAddr; | std::vector<CAddress> vAddr; | ||||
s >> vAddr; | s >> vAddr; | ||||
if (!pfrom.IsAddrRelayPeer()) { | if (!pfrom.RelayAddrsWithConn()) { | ||||
return; | return; | ||||
} | } | ||||
if (vAddr.size() > 1000) { | if (vAddr.size() > 1000) { | ||||
Misbehaving( | Misbehaving( | ||||
pfrom, 20, | pfrom, 20, | ||||
strprintf("%s message size = %u", msg_type, vAddr.size())); | strprintf("%s message size = %u", msg_type, vAddr.size())); | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,289 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::GETADDR) { | ||||
// only make outgoing connections ignore the getaddr message mitigates | // only make outgoing connections ignore the getaddr message mitigates | ||||
// the attack. | // the attack. | ||||
if (!pfrom.IsInboundConn()) { | if (!pfrom.IsInboundConn()) { | ||||
LogPrint(BCLog::NET, | LogPrint(BCLog::NET, | ||||
"Ignoring \"getaddr\" from outbound connection. peer=%d\n", | "Ignoring \"getaddr\" from outbound connection. peer=%d\n", | ||||
pfrom.GetId()); | pfrom.GetId()); | ||||
return; | return; | ||||
} | } | ||||
if (!pfrom.IsAddrRelayPeer()) { | if (!pfrom.RelayAddrsWithConn()) { | ||||
LogPrint(BCLog::NET, | LogPrint(BCLog::NET, | ||||
"Ignoring \"getaddr\" from block-relay-only connection. " | "Ignoring \"getaddr\" from block-relay-only connection. " | ||||
"peer=%d\n", | "peer=%d\n", | ||||
pfrom.GetId()); | pfrom.GetId()); | ||||
return; | return; | ||||
} | } | ||||
// Only send one GetAddr response per connection to reduce resource | // Only send one GetAddr response per connection to reduce resource | ||||
▲ Show 20 Lines • Show All 695 Lines • ▼ Show 20 Lines | bool PeerManager::SendMessages(const Config &config, CNode *pto, | ||||
bool fFetch; | bool fFetch; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CNodeState &state = *State(pto->GetId()); | CNodeState &state = *State(pto->GetId()); | ||||
// Address refresh broadcast | // Address refresh broadcast | ||||
if (pto->IsAddrRelayPeer() && | if (pto->RelayAddrsWithConn() && | ||||
!::ChainstateActive().IsInitialBlockDownload() && | !::ChainstateActive().IsInitialBlockDownload() && | ||||
pto->m_next_local_addr_send < current_time) { | pto->m_next_local_addr_send < current_time) { | ||||
AdvertiseLocal(pto); | AdvertiseLocal(pto); | ||||
pto->m_next_local_addr_send = PoissonNextSend( | pto->m_next_local_addr_send = PoissonNextSend( | ||||
current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL); | current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL); | ||||
} | } | ||||
// | // | ||||
// Message: addr | // Message: addr | ||||
// | // | ||||
if (pto->IsAddrRelayPeer() && pto->m_next_addr_send < current_time) { | if (pto->RelayAddrsWithConn() && pto->m_next_addr_send < current_time) { | ||||
pto->m_next_addr_send = | pto->m_next_addr_send = | ||||
PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL); | PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL); | ||||
std::vector<CAddress> vAddr; | std::vector<CAddress> vAddr; | ||||
vAddr.reserve(pto->vAddrToSend.size()); | vAddr.reserve(pto->vAddrToSend.size()); | ||||
assert(pto->m_addr_known); | assert(pto->m_addr_known); | ||||
const char *msg_type; | const char *msg_type; | ||||
int make_flags; | int make_flags; | ||||
▲ Show 20 Lines • Show All 732 Lines • Show Last 20 Lines |
remove