2018-11-12 16:43:40 +00:00
|
|
|
#ifndef LLARP_EXIT_ENDPOINT_HPP
|
|
|
|
#define LLARP_EXIT_ENDPOINT_HPP
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2019-01-13 16:30:07 +00:00
|
|
|
#include <crypto/types.hpp>
|
2019-01-14 21:46:07 +00:00
|
|
|
#include <net/ip.hpp>
|
2019-01-11 01:19:36 +00:00
|
|
|
#include <path/path.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/time.hpp>
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2019-02-11 19:45:42 +00:00
|
|
|
#include <queue>
|
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace handlers
|
|
|
|
{
|
|
|
|
// forward declare
|
|
|
|
struct ExitEndpoint;
|
|
|
|
} // namespace handlers
|
|
|
|
|
|
|
|
namespace exit
|
|
|
|
{
|
|
|
|
/// persistant exit state for 1 identity on the exit node
|
2019-02-08 19:43:25 +00:00
|
|
|
struct Endpoint : public util::IStateful
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
2018-11-29 21:19:20 +00:00
|
|
|
static constexpr size_t MaxUpstreamQueueSize = 256;
|
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
Endpoint(const llarp::PubKey& remoteIdent,
|
2018-11-29 13:12:35 +00:00
|
|
|
const llarp::PathID_t& beginPath, bool rewriteIP, huint32_t ip,
|
2018-11-12 16:43:40 +00:00
|
|
|
llarp::handlers::ExitEndpoint* parent);
|
|
|
|
|
|
|
|
~Endpoint();
|
|
|
|
|
2018-11-14 18:02:27 +00:00
|
|
|
/// close ourselves
|
|
|
|
void
|
|
|
|
Close();
|
|
|
|
|
2019-02-08 19:43:25 +00:00
|
|
|
/// implement istateful
|
2019-02-11 17:14:43 +00:00
|
|
|
util::StatusObject
|
|
|
|
ExtractStatus() const override;
|
2019-02-08 19:43:25 +00:00
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
/// return true if we are expired right now
|
|
|
|
bool
|
|
|
|
IsExpired(llarp_time_t now) const;
|
|
|
|
|
2018-11-14 18:02:27 +00:00
|
|
|
bool
|
|
|
|
ExpiresSoon(llarp_time_t now, llarp_time_t dlt = 5000) const;
|
|
|
|
|
2018-11-28 12:32:38 +00:00
|
|
|
/// return true if this endpoint looks dead right now
|
2018-12-02 18:07:07 +00:00
|
|
|
bool
|
2018-11-28 12:32:38 +00:00
|
|
|
LooksDead(llarp_time_t now, llarp_time_t timeout = 10000) const;
|
|
|
|
|
2018-11-14 18:02:27 +00:00
|
|
|
/// tick ourself, reset tx/rx rates
|
|
|
|
void
|
|
|
|
Tick(llarp_time_t now);
|
|
|
|
|
2018-11-28 16:38:20 +00:00
|
|
|
/// queue traffic from service node / internet to be transmitted
|
2018-11-12 16:43:40 +00:00
|
|
|
bool
|
2019-02-03 00:48:10 +00:00
|
|
|
QueueInboundTraffic(ManagedBuffer buff);
|
2018-11-28 16:38:20 +00:00
|
|
|
|
2018-11-29 21:19:20 +00:00
|
|
|
/// flush inbound and outbound traffic queues
|
2018-11-28 16:38:20 +00:00
|
|
|
bool
|
2018-11-29 21:19:20 +00:00
|
|
|
Flush();
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2018-11-29 21:19:20 +00:00
|
|
|
/// queue outbound traffic
|
2018-11-14 12:23:08 +00:00
|
|
|
/// does ip rewrite here
|
2018-11-12 16:43:40 +00:00
|
|
|
bool
|
2019-02-03 00:48:10 +00:00
|
|
|
QueueOutboundTraffic(ManagedBuffer pkt, uint64_t counter);
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2018-11-14 12:23:08 +00:00
|
|
|
/// update local path id and cascade information to parent
|
|
|
|
/// return true if success
|
|
|
|
bool
|
2018-11-12 16:43:40 +00:00
|
|
|
UpdateLocalPath(const llarp::PathID_t& nextPath);
|
|
|
|
|
|
|
|
llarp::path::IHopHandler*
|
|
|
|
GetCurrentPath() const;
|
|
|
|
|
2018-11-14 12:23:08 +00:00
|
|
|
const llarp::PubKey&
|
|
|
|
PubKey() const
|
|
|
|
{
|
|
|
|
return m_remoteSignKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
const llarp::PathID_t&
|
|
|
|
LocalPath() const
|
|
|
|
{
|
|
|
|
return m_CurrentPath;
|
|
|
|
}
|
|
|
|
|
2018-11-14 18:02:27 +00:00
|
|
|
uint64_t
|
|
|
|
TxRate() const
|
|
|
|
{
|
|
|
|
return m_TxRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
RxRate() const
|
|
|
|
{
|
|
|
|
return m_RxRate;
|
|
|
|
}
|
|
|
|
|
2018-11-15 21:47:05 +00:00
|
|
|
huint32_t
|
|
|
|
LocalIP() const
|
|
|
|
{
|
|
|
|
return m_IP;
|
|
|
|
}
|
|
|
|
|
2018-12-23 13:29:11 +00:00
|
|
|
const llarp_time_t createdAt;
|
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
private:
|
|
|
|
llarp::handlers::ExitEndpoint* m_Parent;
|
|
|
|
llarp::PubKey m_remoteSignKey;
|
|
|
|
llarp::PathID_t m_CurrentPath;
|
2018-11-14 12:23:08 +00:00
|
|
|
llarp::huint32_t m_IP;
|
2018-11-14 18:02:27 +00:00
|
|
|
uint64_t m_TxRate, m_RxRate;
|
2018-11-28 12:32:38 +00:00
|
|
|
llarp_time_t m_LastActive;
|
2018-11-14 12:23:08 +00:00
|
|
|
bool m_RewriteSource;
|
2018-12-02 18:07:07 +00:00
|
|
|
using InboundTrafficQueue_t =
|
|
|
|
std::deque< llarp::routing::TransferTrafficMessage >;
|
|
|
|
using TieredQueue = std::map< uint8_t, InboundTrafficQueue_t >;
|
2018-11-29 15:45:27 +00:00
|
|
|
// maps number of fragments the message will fit in to the queue for it
|
|
|
|
TieredQueue m_DownstreamQueues;
|
2018-11-29 21:19:20 +00:00
|
|
|
|
|
|
|
struct UpstreamBuffer
|
|
|
|
{
|
2018-12-02 18:07:07 +00:00
|
|
|
UpstreamBuffer(const llarp::net::IPv4Packet& p, uint64_t c)
|
|
|
|
: pkt(p), counter(c)
|
2018-11-29 21:19:20 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
llarp::net::IPv4Packet pkt;
|
|
|
|
uint64_t counter;
|
|
|
|
|
2018-12-02 18:07:07 +00:00
|
|
|
bool
|
|
|
|
operator<(const UpstreamBuffer& other) const
|
2018-11-29 21:19:20 +00:00
|
|
|
{
|
|
|
|
return counter < other.counter;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-02 18:07:07 +00:00
|
|
|
using UpstreamQueue_t = std::priority_queue< UpstreamBuffer >;
|
2018-11-29 21:19:20 +00:00
|
|
|
UpstreamQueue_t m_UpstreamQueue;
|
|
|
|
uint64_t m_Counter;
|
2018-11-12 16:43:40 +00:00
|
|
|
};
|
|
|
|
} // namespace exit
|
|
|
|
} // namespace llarp
|
|
|
|
|
2018-11-19 22:45:37 +00:00
|
|
|
#endif
|