thaw router when connectivity changes

pull/1532/head
Jeff Becker 3 years ago
parent 676ca7f511
commit 07b599430e
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -115,23 +115,38 @@ namespace llarp
if (not m_Router)
throw std::runtime_error("Attempting to use RoutePoker before calling Init");
// check for network
const auto maybe = GetDefaultGateway();
if (not maybe.has_value())
{
LogError("Network is down");
// mark network lost
m_HasNetwork = false;
return;
}
const huint32_t gateway = *maybe;
if (m_CurrentGateway != gateway or m_Enabling)
const bool gatewayChanged = m_CurrentGateway.h != 0 and m_CurrentGateway != gateway;
if (m_CurrentGateway != gateway)
{
LogInfo("found default gateway: ", gateway);
m_CurrentGateway = gateway;
if (not m_Enabling) // if route was already set up
if (m_Enabled) // if route was already set up
{
DisableAllRoutes();
EnableAllRoutes();
Up();
}
if (m_Enabling)
{
EnableAllRoutes();
}
}
// revive network connectitivity on gateway change or network wakeup
if (gatewayChanged or not m_HasNetwork)
{
LogInfo("our network changed, thawing router state");
m_Router->Thaw();
m_HasNetwork = true;
}
}

@ -69,5 +69,7 @@ namespace llarp
bool m_Enabling = false;
AbstractRouter* m_Router = nullptr;
bool m_HasNetwork = true;
};
} // namespace llarp

@ -124,7 +124,6 @@ namespace llarp
void
Router::Thaw()
{
LogInfo("We arise from a long sleep, probably need to reset the network state");
// get pubkeys we are connected to
std::unordered_set<RouterID> peerPubkeys;
linkManager().ForEachPeer([&peerPubkeys](auto peer) {
@ -143,7 +142,7 @@ namespace llarp
ep->Thaw();
return true;
});
LogInfo("We are ready to go bruh");
LogInfo("We are ready to go bruh... probably");
}
void
@ -827,13 +826,18 @@ namespace llarp
_linkManager.CheckPersistingSessions(now);
if (HasClientExit())
if (not isSvcNode)
{
m_RoutePoker.Enable();
if (HasClientExit())
{
m_RoutePoker.Enable();
}
else
{
m_RoutePoker.Disable();
}
m_RoutePoker.Update();
}
else
m_RoutePoker.Disable();
size_t connected = NumberOfConnectedRouters();
if (not isSvcNode)

Loading…
Cancel
Save