MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / AssignIPGroupSlot

Function AssignIPGroupSlot

src/ipgroups.cpp:379–403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

377}
378
379std::unique_ptr<IPGroupSlot> AssignIPGroupSlot(const CNetAddr& ip) {
380 LOCK(*cs_groups);
381
382 CIPGroupData group = FindGroupForIP(ip);
383
384 // IP belongs to a group already.
385 if (!group.name.empty())
386 return std::unique_ptr<IPGroupSlot>(new IPGroupSlot(group.name));
387
388 // If IP does not belong to a group, create a new group
389 // for only this IP. This group is used to de-prioritize multiple
390 // connections from same IP.
391 //
392 // The goal is to force an attacker to spread out in order to get lots of priority.
393
394 // IPGROUP_CONN_MODIFIER will be decremented again when slot is constructed.
395 int pri = DEFAULT_IPGROUP_PRI + IPGROUP_CONN_MODIFIER;
396
397 CIPGroup newGroup;
398 newGroup.header = CIPGroupData(ip.ToStringIP(), pri, true, true);
399 newGroup.subnets.push_back(CSubNet(ip.ToStringIP() + "/32"));
400 groups.push_back(newGroup);
401
402 return std::unique_ptr<IPGroupSlot>(new IPGroupSlot(newGroup.header.name));
403}

Callers 2

CNodeMethod · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 6

FindGroupForIPFunction · 0.85
CIPGroupDataClass · 0.85
CSubNetClass · 0.85
ToStringIPMethod · 0.80
emptyMethod · 0.45
push_backMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68