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