| 377 | } |
| 378 | |
| 379 | std::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 | } |