lokinet/llarp/exit/endpoint.hpp

148 lines
3.3 KiB
C++
Raw Normal View History

#ifndef LLARP_EXIT_ENDPOINT_HPP
#define LLARP_EXIT_ENDPOINT_HPP
#include <crypto/types.hpp>
#include <net/ip_packet.hpp>
2019-01-11 01:19:36 +00:00
#include <path/path.hpp>
#include <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
2019-04-19 15:10:26 +00:00
struct Endpoint
{
2018-11-29 21:19:20 +00:00
static constexpr size_t MaxUpstreamQueueSize = 256;
Endpoint(
const llarp::PubKey& remoteIdent,
const llarp::PathID_t& beginPath,
bool rewriteIP,
huint128_t ip,
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
2019-04-19 15:10:26 +00:00
ExtractStatus() const;
2019-02-08 19:43:25 +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
2020-02-24 19:40:45 +00:00
ExpiresSoon(llarp_time_t now, llarp_time_t dlt = 5s) const;
2018-11-14 18:02:27 +00:00
2018-11-28 12:32:38 +00:00
/// return true if this endpoint looks dead right now
bool
2020-02-24 19:40:45 +00:00
LooksDead(llarp_time_t now, llarp_time_t timeout = 10s) const;
2018-11-28 12:32:38 +00:00
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
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-29 21:19:20 +00:00
/// queue outbound traffic
2018-11-14 12:23:08 +00:00
/// does ip rewrite here
bool
2019-02-03 00:48:10 +00:00
QueueOutboundTraffic(ManagedBuffer pkt, uint64_t counter);
2018-11-14 12:23:08 +00:00
/// 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;
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;
}
2019-06-11 16:44:05 +00:00
huint128_t
2018-11-15 21:47:05 +00:00
LocalIP() const
{
return m_IP;
}
2018-12-23 13:29:11 +00:00
const llarp_time_t createdAt;
private:
llarp::handlers::ExitEndpoint* m_Parent;
llarp::PubKey m_remoteSignKey;
llarp::PathID_t m_CurrentPath;
2019-06-11 16:44:05 +00:00
llarp::huint128_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;
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;
2018-11-29 21:19:20 +00:00
struct UpstreamBuffer
{
UpstreamBuffer(const llarp::net::IPPacket& p, uint64_t c) : pkt(p), counter(c)
2018-11-29 21:19:20 +00:00
{
}
2019-06-11 16:44:05 +00:00
llarp::net::IPPacket pkt;
2018-11-29 21:19:20 +00:00
uint64_t counter;
bool
operator<(const UpstreamBuffer& other) const
2018-11-29 21:19:20 +00:00
{
return counter < other.counter;
}
};
using UpstreamQueue_t = std::priority_queue<UpstreamBuffer>;
2018-11-29 21:19:20 +00:00
UpstreamQueue_t m_UpstreamQueue;
uint64_t m_Counter;
};
} // namespace exit
} // namespace llarp
2018-11-19 22:45:37 +00:00
#endif