feedback from jason

* use emplace in PeerSectionConfig::Acceptable use insert everywhere else
* use const l-value references
* fix typos and spelling mistakes
pull/1539/head
Jeff Becker 3 years ago
parent 5d465264a8
commit 3425069b41
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -1000,10 +1000,10 @@ namespace llarp
throw std::invalid_argument{"[paths]:unique-range-size must be between 4 and 32"};
m_UniqueHopsNetmaskSize = arg;
},
Comment{"In path hop selection use this as the default netmkask for testing if we should "
"include a relay in our hop list",
"i.e. 32 for uniuqe ip addresses for every hop, 24 for all hops are in a different "
"/24, 16 for all hops are in a different /16, etc..."});
Comment{"Netmask for router path selection; each router must be from a distinct IP subnet "
"of the given size.",
"E.g. 16 ensures that all routers are using distinct /16 IP addresses."});
#ifdef WITH_GEOIP
conf.defineOption<std::string>(
"paths",
@ -1014,32 +1014,27 @@ namespace llarp
m_ExcludeCountries.emplace(lowercase_ascii_string(std::move(arg)));
},
Comment{"exclude a country given its 2 letter country code from being used in path builds",
"i.e. exlcude-country=DE",
"can be listed multiple times to exlcude multiple countries"});
"e.g. exclude-country=DE",
"can be listed multiple times to exclude multiple countries"});
#endif
}
bool
PeerSelectionConfig::Acceptable(std::set<RouterContact> rcs) const
PeerSelectionConfig::Acceptable(const std::set<RouterContact>& rcs) const
{
if (m_UniqueHopsNetmaskSize)
{
auto makeRange =
[netmask = netmask_ipv6_bits(96 + *m_UniqueHopsNetmaskSize)](IpAddress addr) -> IPRange {
return IPRange{net::ExpandV4(addr.toIP()) & netmask, netmask};
};
const auto netmask = netmask_ipv6_bits(96 + *m_UniqueHopsNetmaskSize);
std::set<IPRange> seenRanges;
for (const auto& hop : rcs)
{
for (const auto& addr : hop.addrs)
{
const auto range = makeRange(addr.toIpAddress());
if (seenRanges.count(range))
const auto network_addr = net::In6ToHUInt(addr.ip) & netmask;
if (auto [it, inserted] = seenRanges.emplace(network_addr, netmask); not inserted)
{
return false;
}
seenRanges.emplace(range);
}
}
}

@ -87,7 +87,7 @@ namespace llarp
/// return true if this set of router contacts is acceptable against this config
bool
Acceptable(std::set<RouterContact> hops) const;
Acceptable(const std::set<RouterContact>& hops) const;
};
struct NetworkConfig

@ -14,6 +14,12 @@ namespace llarp
huint128_t addr = {0};
huint128_t netmask_bits = {0};
constexpr IPRange()
{}
constexpr IPRange(huint128_t address, huint128_t netmask)
: addr{std::move(address)}, netmask_bits{std::move(netmask)}
{}
static constexpr IPRange
FromIPv4(byte_t a, byte_t b, byte_t c, byte_t d, byte_t mask)
{

@ -206,7 +206,7 @@ namespace llarp
}
std::optional<RouterContact>
Builder::SelectFirstHop(std::set<RouterID> exclude) const
Builder::SelectFirstHop(const std::set<RouterID>& exclude) const
{
std::optional<RouterContact> found = std::nullopt;
m_router->ForEachPeer(
@ -295,7 +295,7 @@ namespace llarp
}
std::optional<std::vector<RouterContact>>
Builder::GetHopsAlignedToForBuild(RouterID endpoint, std::set<RouterID> exclude)
Builder::GetHopsAlignedToForBuild(RouterID endpoint, const std::set<RouterID>& exclude)
{
const auto pathConfig = m_router->GetConfig()->paths;
@ -329,9 +329,8 @@ namespace llarp
return false;
std::set<RouterContact> hopsSet;
hopsSet.emplace(endpointRC);
for (const auto& hop : hops)
hopsSet.emplace(hop);
hopsSet.insert(endpointRC);
hopsSet.insert(hops.begin(), hops.end());
if (r->routerProfiling().IsBadForPath(rc.pubkey))
return false;
@ -341,7 +340,7 @@ namespace llarp
return false;
}
hopsSet.emplace(rc);
hopsSet.insert(rc);
if (not pathConfig.Acceptable(hopsSet))
return false;

@ -94,14 +94,14 @@ namespace llarp
BuildOneAlignedTo(const RouterID endpoint) override;
std::optional<std::vector<RouterContact>>
GetHopsAlignedToForBuild(RouterID endpoint, std::set<RouterID> exclude = {});
GetHopsAlignedToForBuild(RouterID endpoint, const std::set<RouterID>& exclude = {});
void
Build(std::vector<RouterContact> hops, PathRole roles = ePathRoleAny) override;
/// pick a first hop
std::optional<RouterContact>
SelectFirstHop(std::set<RouterID> exclude = {}) const;
SelectFirstHop(const std::set<RouterID>& exclude = {}) const;
virtual std::optional<std::vector<RouterContact>>
GetHopsForBuild() override;

Loading…
Cancel
Save