1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/llarp/handlers/exit.hpp

188 lines
4.5 KiB
C++
Raw Normal View History

#ifndef LLARP_HANDLERS_EXIT_HPP
#define LLARP_HANDLERS_EXIT_HPP
2018-12-12 02:06:46 +01:00
#include <exit/endpoint.hpp>
2018-12-12 02:12:59 +01:00
#include <handlers/tun.hpp>
#include <dns/server.hpp>
#include <unordered_map>
namespace llarp
{
struct AbstractRouter;
namespace handlers
{
2019-04-19 17:10:26 +02:00
struct ExitEndpoint : public dns::IQueryHandler
{
ExitEndpoint(const std::string& name, AbstractRouter* r);
~ExitEndpoint();
void
Tick(llarp_time_t now);
bool
SetOption(const std::string& k, const std::string& v);
std::string
Name() const;
2018-11-14 20:53:03 +01:00
bool
2019-05-07 19:46:38 +02:00
VisitEndpointsFor(const PubKey& pk,
std::function< bool(exit::Endpoint* const) > visit);
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
2019-06-11 21:42:11 +02:00
bool
SupportsV6() const;
bool
ShouldHookDNSMessage(const dns::Message& msg) const override;
bool
HandleHookedDNSMessage(dns::Message&& msg,
std::function< void(dns::Message) >) override;
2018-11-14 13:23:08 +01:00
bool
AllocateNewExit(const PubKey pk, const PathID_t& path,
2018-11-14 13:23:08 +01:00
bool permitInternet);
exit::Endpoint*
FindEndpointByPath(const PathID_t& path);
2018-11-14 13:23:08 +01:00
exit::Endpoint*
FindEndpointByIP(huint32_t ip);
2018-11-14 13:23:08 +01:00
bool
UpdateEndpointPath(const PubKey& remote, const PathID_t& next);
2018-11-14 13:23:08 +01:00
/// handle ip packet from outside
void
OnInetPacket(const llarp_buffer_t& buf);
AbstractRouter*
GetRouter();
2018-11-28 13:32:38 +01:00
llarp_time_t
Now() const;
2018-11-14 19:02:27 +01:00
template < typename Stats >
void
CalculateTrafficStats(Stats& stats)
{
auto itr = m_ActiveExits.begin();
while(itr != m_ActiveExits.end())
{
2018-11-15 22:47:05 +01:00
stats[itr->first].first += itr->second->TxRate();
stats[itr->first].second += itr->second->RxRate();
2018-11-14 19:02:27 +01:00
++itr;
}
}
/// DO NOT CALL ME
2018-11-14 13:23:08 +01:00
void
DelEndpointInfo(const PathID_t& path);
2018-11-14 13:23:08 +01:00
/// DO NOT CALL ME
2018-11-14 19:02:27 +01:00
void
RemoveExit(const exit::Endpoint* ep);
2018-11-14 19:02:27 +01:00
bool
QueueOutboundTraffic(const llarp_buffer_t& buf);
/// sets up networking and starts traffic
bool
Start();
bool
Stop();
bool
ShouldRemove() const;
2018-11-15 17:19:24 +01:00
bool
HasLocalMappedAddrFor(const PubKey& pk) const;
2018-11-15 17:19:24 +01:00
2019-06-11 18:44:05 +02:00
huint128_t
GetIfAddr() const;
void
2018-11-28 17:38:20 +01:00
Flush();
private:
2019-06-11 18:44:05 +02:00
huint128_t
GetIPForIdent(const PubKey pk);
2019-06-11 18:44:05 +02:00
huint128_t
AllocateNewAddress();
/// obtain ip for service node session, creates a new session if one does
/// not existing already
2019-06-11 18:44:05 +02:00
huint128_t
ObtainServiceNodeIP(const RouterID& router);
bool
2019-06-11 18:44:05 +02:00
QueueSNodePacket(const llarp_buffer_t& buf, huint128_t from);
void
2019-06-11 18:44:05 +02:00
MarkIPActive(huint128_t ip);
void
KickIdentOffExit(const PubKey& pk);
AbstractRouter* m_Router;
2019-05-22 18:20:50 +02:00
std::shared_ptr< dns::Proxy > m_Resolver;
2018-11-15 22:47:05 +01:00
bool m_ShouldInitTun;
std::string m_Name;
2018-11-14 13:23:08 +01:00
bool m_PermitExit;
std::unordered_map< PathID_t, PubKey, PathID_t::Hash > m_Paths;
2018-12-23 14:29:11 +01:00
std::unordered_map< PubKey, exit::Endpoint*, PubKey::Hash > m_ChosenExits;
2018-12-23 14:29:11 +01:00
std::unordered_multimap< PubKey, std::unique_ptr< exit::Endpoint >,
PubKey::Hash >
m_ActiveExits;
2019-06-11 18:44:05 +02:00
using KeyMap_t = std::unordered_map< PubKey, huint128_t, PubKey::Hash >;
2018-11-15 17:05:31 +01:00
KeyMap_t m_KeyToIP;
using SNodes_t = std::set< PubKey >;
/// set of pubkeys we treat as snodes
SNodes_t m_SNodeKeys;
using SNodeSessions_t =
2019-04-23 18:13:22 +02:00
std::unordered_map< RouterID, std::shared_ptr< exit::SNodeSession >,
RouterID::Hash >;
/// snode sessions we are talking to directly
SNodeSessions_t m_SNodeSessions;
2019-06-11 18:44:05 +02:00
std::unordered_map< huint128_t, PubKey, huint128_t::Hash > m_IPToKey;
2019-06-11 18:44:05 +02:00
huint128_t m_IfAddr;
huint128_t m_HigestAddr;
huint128_t m_NextAddr;
IPRange m_OurRange;
2019-06-11 18:44:05 +02:00
std::unordered_map< huint128_t, llarp_time_t, huint128_t::Hash >
m_IPActivity;
llarp_tun_io m_Tun;
Addr m_LocalResolverAddr;
std::vector< Addr > m_UpstreamResolvers;
2019-06-11 18:44:05 +02:00
using Pkt_t = net::IPPacket;
using PacketQueue_t =
util::CoDelQueue< Pkt_t, Pkt_t::GetTime, Pkt_t::PutTime,
Pkt_t::CompareOrder, Pkt_t::GetNow, util::NullMutex,
util::NullLock, 5, 100, 1024 >;
/// internet to llarp packet queue
PacketQueue_t m_InetToNetwork;
2019-06-11 21:42:11 +02:00
bool m_UseV6;
};
} // namespace handlers
} // namespace llarp
2018-11-15 02:33:00 +01:00
#endif