lokinet/llarp/exit/context.hpp

57 lines
1.3 KiB
C++
Raw Normal View History

#pragma once
#include "policy.hpp"
#include <llarp/handlers/exit.hpp>
2018-12-12 01:12:59 +00:00
#include <string>
#include <unordered_map>
namespace llarp
{
namespace exit
{
/// owner of all the exit endpoints
2019-04-19 15:10:26 +00:00
struct Context
{
Context(AbstractRouter* r);
~Context();
void
Tick(llarp_time_t now);
2018-11-15 21:47:05 +00:00
void
ClearAllEndpoints();
2019-02-11 17:14:43 +00:00
util::StatusObject
2019-04-19 15:10:26 +00:00
ExtractStatus() const;
2019-02-08 19:43:25 +00:00
/// send close to all exit sessions and remove all sessions
void
Stop();
void
2020-04-27 15:24:05 +00:00
AddExitEndpoint(
const std::string& name, const NetworkConfig& networkConfig, const DnsConfig& dnsConfig);
2018-11-14 12:23:08 +00:00
bool
ObtainNewExit(const PubKey& remote, const PathID_t& path, bool permitInternet);
2018-11-14 12:23:08 +00:00
exit::Endpoint*
FindEndpointForPath(const PathID_t& path) const;
2018-11-14 12:23:08 +00:00
2018-11-14 18:02:27 +00:00
/// calculate (pk, tx, rx) for all exit traffic
using TrafficStats = std::unordered_map<PubKey, std::pair<uint64_t, uint64_t>>;
2018-11-14 18:02:27 +00:00
void
CalculateExitTraffic(TrafficStats& stats);
2018-11-14 18:02:27 +00:00
std::shared_ptr<handlers::ExitEndpoint>
GetExitEndpoint(std::string name) const;
private:
AbstractRouter* m_Router;
std::unordered_map<std::string, std::shared_ptr<handlers::ExitEndpoint>> m_Exits;
std::list<std::shared_ptr<handlers::ExitEndpoint>> m_Closed;
};
} // namespace exit
} // namespace llarp