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