2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2023-10-24 13:18:03 +00:00
|
|
|
#include "policy.hpp"
|
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/handlers/exit.hpp>
|
2023-10-24 13:18:03 +00:00
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2023-09-15 14:55:32 +00:00
|
|
|
namespace llarp::exit
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
2023-09-15 14:55:32 +00:00
|
|
|
/// owner of all the exit endpoints
|
|
|
|
struct Context
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
2023-09-15 14:55:32 +00:00
|
|
|
Context(Router* r);
|
|
|
|
~Context();
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2023-09-15 14:55:32 +00:00
|
|
|
void
|
|
|
|
Tick(llarp_time_t now);
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2023-09-15 14:55:32 +00:00
|
|
|
void
|
2023-12-06 21:54:51 +00:00
|
|
|
clear_all_endpoints();
|
2018-11-15 21:47:05 +00:00
|
|
|
|
2023-09-15 14:55:32 +00:00
|
|
|
util::StatusObject
|
|
|
|
ExtractStatus() const;
|
2019-02-08 19:43:25 +00:00
|
|
|
|
2023-09-15 14:55:32 +00:00
|
|
|
/// send close to all exit sessions and remove all sessions
|
|
|
|
void
|
2023-12-06 21:54:51 +00:00
|
|
|
stop();
|
2018-12-24 16:09:05 +00:00
|
|
|
|
2023-09-15 14:55:32 +00:00
|
|
|
void
|
2023-12-06 21:54:51 +00:00
|
|
|
add_exit_endpoint(
|
2023-09-15 14:55:32 +00:00
|
|
|
const std::string& name, const NetworkConfig& networkConfig, const DnsConfig& dnsConfig);
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2023-09-15 14:55:32 +00:00
|
|
|
bool
|
2023-12-06 21:54:51 +00:00
|
|
|
obtain_new_exit(const PubKey& remote, const PathID_t& path, bool permitInternet);
|
2018-11-14 12:23:08 +00:00
|
|
|
|
2023-09-15 14:55:32 +00:00
|
|
|
exit::Endpoint*
|
2023-12-06 21:54:51 +00:00
|
|
|
find_endpoint_for_path(const PathID_t& path) const;
|
2018-11-14 12:23:08 +00:00
|
|
|
|
2023-09-15 14:55:32 +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
|
|
|
|
2023-09-15 14:55:32 +00:00
|
|
|
void
|
2023-12-06 21:54:51 +00:00
|
|
|
calculate_exit_traffic(TrafficStats& stats);
|
2018-11-14 18:02:27 +00:00
|
|
|
|
2023-09-15 14:55:32 +00:00
|
|
|
std::shared_ptr<handlers::ExitEndpoint>
|
2023-12-06 21:54:51 +00:00
|
|
|
get_exit_endpoint(std::string name) const;
|
2021-03-26 20:45:19 +00:00
|
|
|
|
2023-09-15 14:55:32 +00:00
|
|
|
private:
|
|
|
|
Router* router;
|
2023-12-06 21:54:51 +00:00
|
|
|
std::unordered_map<std::string, std::shared_ptr<handlers::ExitEndpoint>> _exits;
|
|
|
|
std::list<std::shared_ptr<handlers::ExitEndpoint>> _closed;
|
2023-09-15 14:55:32 +00:00
|
|
|
};
|
|
|
|
} // namespace llarp::exit
|