2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/crypto/types.hpp>
|
|
|
|
#include <llarp/net/ip_packet.hpp>
|
2023-09-18 21:50:07 +00:00
|
|
|
#include <llarp/path/abstracthophandler.hpp>
|
2021-03-26 13:16:43 +00:00
|
|
|
#include <llarp/service/protocol_type.hpp>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/util/time.hpp>
|
2023-10-24 13:18:03 +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-04-19 15:10:26 +00:00
|
|
|
struct Endpoint
|
2018-11-12 16:43:40 +00:00
|
|
|
{
|
2018-11-29 21:19:20 +00:00
|
|
|
static constexpr size_t MaxUpstreamQueueSize = 256;
|
|
|
|
|
2021-04-07 12:52:17 +00:00
|
|
|
explicit Endpoint(
|
2020-04-07 18:38:56 +00:00
|
|
|
const llarp::PubKey& remoteIdent,
|
2021-04-07 12:52:17 +00:00
|
|
|
const llarp::path::HopHandler_ptr& path,
|
2020-04-07 18:38:56 +00:00
|
|
|
bool rewriteIP,
|
|
|
|
huint128_t ip,
|
|
|
|
llarp::handlers::ExitEndpoint* parent);
|
2018-11-12 16:43:40 +00:00
|
|
|
|
|
|
|
~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
|
|
|
|
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
|
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
|
2018-12-02 18:07:07 +00:00
|
|
|
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
|
2018-11-12 16:43:40 +00:00
|
|
|
bool
|
2022-07-28 16:07:38 +00:00
|
|
|
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-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
|
2023-10-19 11:49:46 +00:00
|
|
|
// bool
|
|
|
|
// QueueOutboundTraffic(
|
|
|
|
// PathID_t txid, std::vector<byte_t> data, uint64_t counter, service::ProtocolType t);
|
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);
|
|
|
|
|
2019-04-23 14:28:59 +00:00
|
|
|
llarp::path::HopHandler_ptr
|
2021-04-07 12:52:17 +00:00
|
|
|
GetCurrentPath() const
|
|
|
|
{
|
2023-10-19 11:49:46 +00:00
|
|
|
return current_path;
|
2021-04-07 12:52:17 +00:00
|
|
|
}
|
2018-11-12 16:43:40 +00:00
|
|
|
|
2018-11-14 12:23:08 +00:00
|
|
|
const llarp::PubKey&
|
|
|
|
PubKey() const
|
|
|
|
{
|
2023-10-19 11:49:46 +00:00
|
|
|
return remote_signkey;
|
2018-11-14 12:23:08 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 22:11:35 +00:00
|
|
|
RouterID
|
|
|
|
router_id() const
|
|
|
|
{
|
|
|
|
return remote_signkey.data();
|
|
|
|
}
|
|
|
|
|
2018-11-14 18:02:27 +00:00
|
|
|
uint64_t
|
|
|
|
TxRate() const
|
|
|
|
{
|
2023-10-19 11:49:46 +00:00
|
|
|
return tx_rate;
|
2018-11-14 18:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
RxRate() const
|
|
|
|
{
|
2023-10-19 11:49:46 +00:00
|
|
|
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
|
|
|
|
{
|
2023-10-19 11:49:46 +00:00
|
|
|
return IP;
|
2018-11-15 21:47:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-23 13:29:11 +00:00
|
|
|
const llarp_time_t createdAt;
|
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
private:
|
2023-10-19 11:49:46 +00:00
|
|
|
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;
|
2018-11-12 16:43:40 +00:00
|
|
|
};
|
|
|
|
} // namespace exit
|
|
|
|
} // namespace llarp
|