mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-17 15:25:35 +00:00
871c3e3281
* wintun vpn platform for windows * bundle config snippets into nsis installer for exit node, keyfile persisting, reduced hops mode. * use wintun for vpn platform * isolate all windows platform specific code into their own compilation units and libraries * split up internal libraries into more specific components * rename liblokinet.a target to liblokinet-amalgum.a to elimiate ambiguity with liblokinet.so * DNS platform for win32 * rename llarp/ev/ev_libuv.{c,h}pp to llarp/ev/libuv.{c,h}pp as the old name was idiotic * split up net platform into win32 and posix specific compilation units * rename lokinet_init.c to easter_eggs.cpp as that is what they are for and it does not need to be a c compilation target * add cmake option STRIP_SYMBOLS for seperating out debug symbols for windows builds * intercept dns traffic on all interfaces on windows using windivert and feed it into lokinet
144 lines
3.4 KiB
C++
144 lines
3.4 KiB
C++
#pragma once
|
|
|
|
#include <llarp/crypto/types.hpp>
|
|
#include <llarp/net/ip_packet.hpp>
|
|
#include <llarp/path/ihophandler.hpp>
|
|
#include <llarp/routing/transfer_traffic_message.hpp>
|
|
#include <llarp/service/protocol_type.hpp>
|
|
#include <llarp/util/time.hpp>
|
|
|
|
#include <queue>
|
|
|
|
namespace llarp
|
|
{
|
|
namespace handlers
|
|
{
|
|
// forward declare
|
|
struct ExitEndpoint;
|
|
} // namespace handlers
|
|
|
|
namespace exit
|
|
{
|
|
/// persistant exit state for 1 identity on the exit node
|
|
struct Endpoint
|
|
{
|
|
static constexpr size_t MaxUpstreamQueueSize = 256;
|
|
|
|
explicit Endpoint(
|
|
const llarp::PubKey& remoteIdent,
|
|
const llarp::path::HopHandler_ptr& path,
|
|
bool rewriteIP,
|
|
huint128_t ip,
|
|
llarp::handlers::ExitEndpoint* parent);
|
|
|
|
~Endpoint();
|
|
|
|
/// close ourselves
|
|
void
|
|
Close();
|
|
|
|
/// implement istateful
|
|
util::StatusObject
|
|
ExtractStatus() const;
|
|
|
|
/// return true if we are expired right now
|
|
bool
|
|
IsExpired(llarp_time_t now) const;
|
|
|
|
bool
|
|
ExpiresSoon(llarp_time_t now, llarp_time_t dlt = 5s) const;
|
|
|
|
/// return true if this endpoint looks dead right now
|
|
bool
|
|
LooksDead(llarp_time_t now, llarp_time_t timeout = 10s) const;
|
|
|
|
/// tick ourself, reset tx/rx rates
|
|
void
|
|
Tick(llarp_time_t now);
|
|
|
|
/// queue traffic from service node / internet to be transmitted
|
|
bool
|
|
QueueInboundTraffic(std::vector<byte_t> data, service::ProtocolType t);
|
|
|
|
/// flush inbound and outbound traffic queues
|
|
bool
|
|
Flush();
|
|
|
|
/// queue outbound traffic
|
|
/// does ip rewrite here
|
|
bool
|
|
QueueOutboundTraffic(
|
|
PathID_t txid, std::vector<byte_t> data, uint64_t counter, service::ProtocolType t);
|
|
|
|
/// update local path id and cascade information to parent
|
|
/// return true if success
|
|
bool
|
|
UpdateLocalPath(const llarp::PathID_t& nextPath);
|
|
|
|
llarp::path::HopHandler_ptr
|
|
GetCurrentPath() const
|
|
{
|
|
return m_CurrentPath;
|
|
}
|
|
|
|
const llarp::PubKey&
|
|
PubKey() const
|
|
{
|
|
return m_remoteSignKey;
|
|
}
|
|
|
|
uint64_t
|
|
TxRate() const
|
|
{
|
|
return m_TxRate;
|
|
}
|
|
|
|
uint64_t
|
|
RxRate() const
|
|
{
|
|
return m_RxRate;
|
|
}
|
|
|
|
huint128_t
|
|
LocalIP() const
|
|
{
|
|
return m_IP;
|
|
}
|
|
|
|
const llarp_time_t createdAt;
|
|
|
|
private:
|
|
llarp::handlers::ExitEndpoint* m_Parent;
|
|
llarp::PubKey m_remoteSignKey;
|
|
llarp::path::HopHandler_ptr m_CurrentPath;
|
|
llarp::huint128_t m_IP;
|
|
uint64_t m_TxRate, m_RxRate;
|
|
llarp_time_t m_LastActive;
|
|
bool m_RewriteSource;
|
|
using InboundTrafficQueue_t = std::deque<llarp::routing::TransferTrafficMessage>;
|
|
using TieredQueue = std::map<uint8_t, InboundTrafficQueue_t>;
|
|
// maps number of fragments the message will fit in to the queue for it
|
|
TieredQueue m_DownstreamQueues;
|
|
|
|
struct UpstreamBuffer
|
|
{
|
|
UpstreamBuffer(llarp::net::IPPacket p, uint64_t c) : pkt{std::move(p)}, counter(c)
|
|
{}
|
|
|
|
llarp::net::IPPacket pkt;
|
|
uint64_t counter;
|
|
|
|
bool
|
|
operator<(const UpstreamBuffer& other) const
|
|
{
|
|
return counter < other.counter;
|
|
}
|
|
};
|
|
|
|
using UpstreamQueue_t = std::priority_queue<UpstreamBuffer>;
|
|
UpstreamQueue_t m_UpstreamQueue;
|
|
uint64_t m_Counter;
|
|
};
|
|
} // namespace exit
|
|
} // namespace llarp
|