1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/llarp/exit/endpoint.hpp

141 lines
3.2 KiB
C++
Raw Normal View History

#ifndef LLARP_EXIT_ENDPOINT_HPP
#define LLARP_EXIT_ENDPOINT_HPP
#include <crypto/types.hpp>
#include <net/ip.hpp>
2019-01-11 02:19:36 +01:00
#include <path/path.hpp>
#include <util/time.hpp>
namespace llarp
{
namespace handlers
{
// forward declare
struct ExitEndpoint;
} // namespace handlers
namespace exit
{
/// persistant exit state for 1 identity on the exit node
struct Endpoint
{
2018-11-29 22:19:20 +01:00
static constexpr size_t MaxUpstreamQueueSize = 256;
Endpoint(const llarp::PubKey& remoteIdent,
2018-11-29 14:12:35 +01:00
const llarp::PathID_t& beginPath, bool rewriteIP, huint32_t ip,
llarp::handlers::ExitEndpoint* parent);
~Endpoint();
2018-11-14 19:02:27 +01:00
/// close ourselves
void
Close();
/// return true if we are expired right now
bool
IsExpired(llarp_time_t now) const;
2018-11-14 19:02:27 +01:00
bool
ExpiresSoon(llarp_time_t now, llarp_time_t dlt = 5000) const;
2018-11-28 13:32:38 +01:00
/// return true if this endpoint looks dead right now
bool
2018-11-28 13:32:38 +01:00
LooksDead(llarp_time_t now, llarp_time_t timeout = 10000) const;
2018-11-14 19:02:27 +01:00
/// tick ourself, reset tx/rx rates
void
Tick(llarp_time_t now);
2018-11-28 17:38:20 +01:00
/// queue traffic from service node / internet to be transmitted
bool
2018-11-28 17:38:20 +01:00
QueueInboundTraffic(llarp_buffer_t buff);
2018-11-29 22:19:20 +01:00
/// flush inbound and outbound traffic queues
2018-11-28 17:38:20 +01:00
bool
2018-11-29 22:19:20 +01:00
Flush();
2018-11-29 22:19:20 +01:00
/// queue outbound traffic
2018-11-14 13:23:08 +01:00
/// does ip rewrite here
bool
2018-11-29 22:19:20 +01:00
QueueOutboundTraffic(llarp_buffer_t pkt, uint64_t counter);
2018-11-14 13:23:08 +01:00
/// update local path id and cascade information to parent
/// return true if success
bool
UpdateLocalPath(const llarp::PathID_t& nextPath);
llarp::path::IHopHandler*
GetCurrentPath() const;
2018-11-14 13:23:08 +01:00
const llarp::PubKey&
PubKey() const
{
return m_remoteSignKey;
}
const llarp::PathID_t&
LocalPath() const
{
return m_CurrentPath;
}
2018-11-14 19:02:27 +01:00
uint64_t
TxRate() const
{
return m_TxRate;
}
uint64_t
RxRate() const
{
return m_RxRate;
}
2018-11-15 22:47:05 +01:00
huint32_t
LocalIP() const
{
return m_IP;
}
2018-12-23 14:29:11 +01:00
const llarp_time_t createdAt;
private:
llarp::handlers::ExitEndpoint* m_Parent;
llarp::PubKey m_remoteSignKey;
llarp::PathID_t m_CurrentPath;
2018-11-14 13:23:08 +01:00
llarp::huint32_t m_IP;
2018-11-14 19:02:27 +01:00
uint64_t m_TxRate, m_RxRate;
2018-11-28 13:32:38 +01:00
llarp_time_t m_LastActive;
2018-11-14 13:23:08 +01: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 22:19:20 +01:00
struct UpstreamBuffer
{
UpstreamBuffer(const llarp::net::IPv4Packet& p, uint64_t c)
: pkt(p), counter(c)
2018-11-29 22:19:20 +01:00
{
}
llarp::net::IPv4Packet pkt;
uint64_t counter;
bool
operator<(const UpstreamBuffer& other) const
2018-11-29 22:19:20 +01:00
{
return counter < other.counter;
}
};
using UpstreamQueue_t = std::priority_queue< UpstreamBuffer >;
2018-11-29 22:19:20 +01:00
UpstreamQueue_t m_UpstreamQueue;
uint64_t m_Counter;
};
} // namespace exit
} // namespace llarp
2018-11-19 23:45:37 +01:00
#endif