Simplifications

- a `static` is less verbose and otherwise identical to an empty
  namespace for a single declaration like this.
- operator== on two optionals already does exactly what the `is_equal`
  lambda here is doing.
- formatting
pull/1969/head
Jason Rhinelander 2 years ago
parent 517911b499
commit 45b3365002
No known key found for this signature in database
GPG Key ID: C4992CE7A88D4262

@ -7,10 +7,7 @@
namespace llarp namespace llarp
{ {
namespace static auto logcat = log::Cat("route-poker");
{
auto logcat = log::Cat("route-poker");
}
void void
RoutePoker::AddRoute(net::ipv4addr_t ip) RoutePoker::AddRoute(net::ipv4addr_t ip)
@ -157,16 +154,8 @@ namespace llarp
next_gw = *gw_ptr; next_gw = *gw_ptr;
} }
auto is_equal = [](auto lhs, auto rhs) {
if (lhs == std::nullopt and rhs == std::nullopt)
return true;
if (lhs and rhs)
return *lhs == *rhs;
return false;
};
// update current gateway and apply state chnages as needed // update current gateway and apply state chnages as needed
if (not is_equal(m_CurrentGateway, next_gw)) if (not(m_CurrentGateway == next_gw))
{ {
if (next_gw and m_CurrentGateway) if (next_gw and m_CurrentGateway)
{ {
@ -224,8 +213,8 @@ namespace llarp
route.AddDefaultRouteViaInterface(*vpn); route.AddDefaultRouteViaInterface(*vpn);
log::info(logcat, "route poker up"); log::info(logcat, "route poker up");
} }
if(not m_up) if (not m_up)
SetDNSMode(true); SetDNSMode(true);
m_up = true; m_up = true;
} }
@ -249,8 +238,8 @@ namespace llarp
route.DelBlackhole(); route.DelBlackhole();
log::info(logcat, "route poker down"); log::info(logcat, "route poker down");
} }
if(m_up) if (m_up)
SetDNSMode(false); SetDNSMode(false);
m_up = false; m_up = false;
} }

Loading…
Cancel
Save