lokinet/llarp/router/route_poker.hpp
Thomas Winget df36ed953d
Route Poker changes (#1416)
If not using an exit, messing with the routing table is not good.
As such, the ability to keep track of routes we *might* want is good,
but the ability to set/unset those routes is necessary, to correspond
to enabling/disabling exit functionality.
2020-10-20 05:15:39 -04:00

65 lines
1.1 KiB
C++

#pragma once
#include <unordered_map>
#include <string>
#include <net/net_int.hpp>
namespace llarp
{
struct AbstractRouter;
struct RoutePoker
{
void
AddRoute(huint32_t ip);
void
DelRoute(huint32_t ip);
void
Init(AbstractRouter* router, bool enable = false);
~RoutePoker();
void
Update();
// sets stored routes and causes AddRoute to actually
// set routes rather than just storing them
void
Enable();
// unsets stored routes, and causes AddRoute to simply
// remember the desired routes rather than setting them.
void
Disable();
private:
void
DeleteAllRoutes();
void
DisableAllRoutes();
void
EnableAllRoutes();
void
EnableRoute(huint32_t ip, huint32_t gateway);
void
DisableRoute(huint32_t ip, huint32_t gateway);
std::optional<huint32_t>
GetDefaultGateway() const;
std::unordered_map<huint32_t, huint32_t> m_PokedRoutes;
huint32_t m_CurrentGateway;
bool m_Enabled = false;
bool m_Enabling = false;
AbstractRouter* m_Router = nullptr;
};
} // namespace llarp