2018-11-12 17:43:40 +01:00
|
|
|
#ifndef LLARP_EXIT_SESSION_HPP
|
|
|
|
#define LLARP_EXIT_SESSION_HPP
|
|
|
|
#include <llarp/pathbuilder.hpp>
|
2018-11-14 20:34:17 +01:00
|
|
|
#include <llarp/ip.hpp>
|
2018-11-28 17:38:20 +01:00
|
|
|
#include <llarp/messages/transfer_traffic.hpp>
|
2018-11-29 14:12:35 +01:00
|
|
|
#include <llarp/messages/exit.hpp>
|
2018-11-28 17:38:20 +01:00
|
|
|
#include <deque>
|
2018-11-12 17:43:40 +01:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace exit
|
|
|
|
{
|
2018-11-29 14:12:35 +01:00
|
|
|
|
2018-11-12 17:43:40 +01:00
|
|
|
/// a persisiting exit session with an exit router
|
|
|
|
struct BaseSession : public llarp::path::Builder
|
|
|
|
{
|
2018-11-29 14:12:35 +01:00
|
|
|
static constexpr size_t MaxUpstreamQueueLength = 256;
|
|
|
|
|
2018-11-14 20:34:17 +01:00
|
|
|
BaseSession(const llarp::RouterID& exitRouter,
|
|
|
|
std::function< bool(llarp_buffer_t) > writepkt,
|
|
|
|
llarp_router* r, size_t numpaths, size_t hoplen);
|
2018-11-12 17:43:40 +01:00
|
|
|
|
2018-11-29 14:12:35 +01:00
|
|
|
virtual ~BaseSession();
|
2018-11-12 17:43:40 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
SelectHop(llarp_nodedb* db, const RouterContact& prev, RouterContact& cur,
|
2018-11-14 19:02:27 +01:00
|
|
|
size_t hop, llarp::path::PathRole roles) override;
|
2018-11-12 17:43:40 +01:00
|
|
|
|
2018-11-16 15:03:13 +01:00
|
|
|
bool
|
|
|
|
ShouldBuildMore(llarp_time_t now) const override;
|
|
|
|
|
2018-11-14 20:34:17 +01:00
|
|
|
void
|
|
|
|
HandlePathBuilt(llarp::path::Path* p) override;
|
|
|
|
|
|
|
|
bool
|
2018-11-28 17:38:20 +01:00
|
|
|
QueueUpstreamTraffic(llarp::net::IPv4Packet pkt, const size_t packSize);
|
|
|
|
|
|
|
|
bool
|
|
|
|
FlushUpstreamTraffic();
|
|
|
|
|
2018-11-29 14:12:35 +01:00
|
|
|
bool
|
|
|
|
IsReady() const;
|
|
|
|
|
2018-11-14 20:34:17 +01:00
|
|
|
|
2018-11-12 17:43:40 +01:00
|
|
|
protected:
|
|
|
|
llarp::RouterID m_ExitRouter;
|
2018-11-14 20:34:17 +01:00
|
|
|
std::function< bool(llarp_buffer_t) > m_WritePacket;
|
2018-11-29 14:12:35 +01:00
|
|
|
|
|
|
|
virtual void
|
|
|
|
PopulateRequest(llarp::routing::ObtainExitMessage & msg) const = 0;
|
2018-11-12 17:43:40 +01:00
|
|
|
|
2018-11-14 20:34:17 +01:00
|
|
|
bool
|
|
|
|
HandleTrafficDrop(llarp::path::Path* p, const llarp::PathID_t& path,
|
|
|
|
uint64_t s);
|
2018-11-12 17:43:40 +01:00
|
|
|
|
2018-11-14 20:34:17 +01:00
|
|
|
bool
|
|
|
|
HandleGotExit(llarp::path::Path* p, llarp_time_t b);
|
|
|
|
|
|
|
|
bool
|
|
|
|
HandleTraffic(llarp::path::Path* p, llarp_buffer_t buf);
|
|
|
|
|
2018-11-28 17:38:20 +01:00
|
|
|
private:
|
|
|
|
using UpstreamTrafficQueue_t = std::deque<llarp::routing::TransferTrafficMessage>;
|
2018-11-29 16:45:27 +01:00
|
|
|
using TieredQueue_t = std::map<uint8_t, UpstreamTrafficQueue_t>;
|
|
|
|
TieredQueue_t m_Upstream;
|
2018-11-14 20:34:17 +01:00
|
|
|
llarp::SecretKey m_ExitIdentity;
|
2018-11-12 17:43:40 +01:00
|
|
|
};
|
|
|
|
|
2018-11-29 14:12:35 +01:00
|
|
|
struct ExitSession final : public BaseSession
|
|
|
|
{
|
|
|
|
ExitSession(const llarp::RouterID& snodeRouter,
|
|
|
|
std::function< bool(llarp_buffer_t) > writepkt,
|
|
|
|
llarp_router* r, size_t numpaths, size_t hoplen) : BaseSession(snodeRouter, writepkt, r,numpaths, hoplen) {};
|
|
|
|
|
|
|
|
~ExitSession() {};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void
|
|
|
|
PopulateRequest(llarp::routing::ObtainExitMessage & msg) const override
|
|
|
|
{
|
|
|
|
// TODO: set expiration time
|
|
|
|
msg.X = 0;
|
|
|
|
msg.E = 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SNodeSession final : public BaseSession
|
|
|
|
{
|
|
|
|
SNodeSession(const llarp::RouterID& snodeRouter,
|
|
|
|
std::function< bool(llarp_buffer_t) > writepkt,
|
|
|
|
llarp_router* r, size_t numpaths, size_t hoplen) : BaseSession(snodeRouter, writepkt, r,numpaths, hoplen) {};
|
|
|
|
|
|
|
|
~SNodeSession() {};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void
|
|
|
|
PopulateRequest(llarp::routing::ObtainExitMessage & msg) const override
|
|
|
|
{
|
|
|
|
// TODO: set expiration time
|
|
|
|
msg.X = 0;
|
|
|
|
msg.E = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-12 17:43:40 +01:00
|
|
|
} // namespace exit
|
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|