lokinet/llarp/exit/endpoint.hpp

126 lines
2.7 KiB
C++
Raw Normal View History

#pragma once
#include <llarp/crypto/types.hpp>
#include <llarp/net/ip_packet.hpp>
#include <llarp/path/abstracthophandler.hpp>
2021-03-26 13:16:43 +00:00
#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
2019-04-19 15:10:26 +00:00
struct Endpoint
{
2018-11-29 21:19:20 +00:00
static constexpr size_t MaxUpstreamQueueSize = 256;
2021-04-07 12:52:17 +00:00
explicit Endpoint(
const llarp::PubKey& remoteIdent,
2021-04-07 12:52:17 +00:00
const llarp::path::HopHandler_ptr& path,
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
QueueInboundTraffic(std::vector<byte_t> data, service::ProtocolType t);
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
// QueueOutboundTraffic(
// PathID_t txid, std::vector<byte_t> data, uint64_t counter, service::ProtocolType t);
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
2021-04-07 12:52:17 +00:00
GetCurrentPath() const
{
return current_path;
2021-04-07 12:52:17 +00:00
}
2018-11-14 12:23:08 +00:00
const llarp::PubKey&
PubKey() const
{
return remote_signkey;
2018-11-14 12:23:08 +00:00
}
RouterID
router_id() const
{
return remote_signkey.data();
}
2018-11-14 18:02:27 +00:00
uint64_t
TxRate() const
{
return tx_rate;
2018-11-14 18:02:27 +00:00
}
uint64_t
RxRate() const
{
return rx_rate;
2018-11-14 18:02:27 +00:00
}
2019-06-11 16:44:05 +00:00
huint128_t
2018-11-15 21:47:05 +00:00
LocalIP() const
{
return IP;
2018-11-15 21:47:05 +00:00
}
2018-12-23 13:29:11 +00:00
const llarp_time_t createdAt;
private:
llarp::handlers::ExitEndpoint* parent;
llarp::PubKey remote_signkey;
llarp::path::HopHandler_ptr current_path;
llarp::huint128_t IP;
uint64_t tx_rate, rx_rate;
llarp_time_t last_active;
bool rewrite_source;
};
} // namespace exit
} // namespace llarp