2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/path/pathbuilder.hpp>
|
2023-10-17 15:42:27 +00:00
|
|
|
#include <llarp/service/convotag.hpp>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/util/status.hpp>
|
2019-04-21 16:44:27 +00:00
|
|
|
|
|
|
|
#include <unordered_map>
|
2019-09-20 16:56:19 +00:00
|
|
|
#include <unordered_set>
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
namespace llarp::service
|
2019-04-21 16:44:27 +00:00
|
|
|
{
|
2023-10-11 21:17:00 +00:00
|
|
|
struct AsyncKeyExchange;
|
|
|
|
struct Endpoint;
|
|
|
|
|
|
|
|
/// context needed to initiate an outbound hidden service session
|
2023-10-17 15:42:27 +00:00
|
|
|
struct OutboundContext : public llarp::path::Builder,
|
2023-10-11 21:17:00 +00:00
|
|
|
public std::enable_shared_from_this<OutboundContext>
|
2019-04-21 16:44:27 +00:00
|
|
|
{
|
2023-10-17 15:42:27 +00:00
|
|
|
private:
|
|
|
|
Endpoint& ep;
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-17 15:42:27 +00:00
|
|
|
IntroSet current_intro;
|
|
|
|
Introduction next_intro;
|
|
|
|
|
|
|
|
const dht::Key_t location;
|
|
|
|
const Address addr;
|
|
|
|
|
|
|
|
ServiceInfo remote_identity;
|
|
|
|
Introduction remote_intro;
|
|
|
|
|
|
|
|
ConvoTag current_tag;
|
|
|
|
|
|
|
|
uint64_t update_introset_tx = 0;
|
|
|
|
uint16_t lookup_fails = 0;
|
|
|
|
uint16_t build_fails = 0;
|
|
|
|
|
|
|
|
bool got_inbound_traffic = false;
|
|
|
|
bool generated_intro = false;
|
|
|
|
bool sent_intro = false;
|
|
|
|
bool marked_bad = false;
|
|
|
|
|
|
|
|
const std::chrono::milliseconds created_at;
|
|
|
|
std::chrono::milliseconds last_send = 0ms;
|
|
|
|
std::chrono::milliseconds send_timeout = path::BUILD_TIMEOUT;
|
|
|
|
std::chrono::milliseconds connect_timeout = send_timeout * 2;
|
|
|
|
std::chrono::milliseconds last_shift = 0ms;
|
|
|
|
std::chrono::milliseconds last_inbound_traffic = 0ms;
|
|
|
|
std::chrono::milliseconds last_introset_update = 0ms;
|
|
|
|
std::chrono::milliseconds last_keep_alive = 0ms;
|
|
|
|
|
|
|
|
public:
|
|
|
|
OutboundContext(const IntroSet& introSet, Endpoint* parent);
|
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
~OutboundContext() override;
|
|
|
|
|
|
|
|
void
|
2023-10-17 15:42:27 +00:00
|
|
|
encrypt_and_send(std::string buf);
|
|
|
|
|
|
|
|
void
|
|
|
|
Tick(std::chrono::milliseconds now) override;
|
2023-10-11 21:17:00 +00:00
|
|
|
|
|
|
|
util::StatusObject
|
|
|
|
ExtractStatus() const;
|
2020-05-21 14:18:23 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
void
|
|
|
|
BlacklistSNode(const RouterID) override{};
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
path::PathSet_ptr
|
|
|
|
GetSelf() override
|
|
|
|
{
|
|
|
|
return shared_from_this();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::weak_ptr<path::PathSet>
|
|
|
|
GetWeak() override
|
|
|
|
{
|
|
|
|
return weak_from_this();
|
|
|
|
}
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
Address
|
|
|
|
Addr() const;
|
2020-05-21 14:18:23 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
bool
|
|
|
|
Stop() override;
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
void
|
|
|
|
HandlePathDied(path::Path_ptr p) override;
|
2021-06-04 12:34:41 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
/// set to true if we are updating the remote introset right now
|
|
|
|
bool updatingIntroSet;
|
2021-06-03 12:21:15 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
/// update the current selected intro to be a new best introduction
|
|
|
|
/// return true if we have changed intros
|
|
|
|
bool
|
2023-10-17 15:42:27 +00:00
|
|
|
ShiftIntroduction(bool rebuild = true);
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
/// shift the intro off the current router it is using
|
|
|
|
void
|
2023-10-17 15:42:27 +00:00
|
|
|
ShiftIntroRouter(const RouterID remote);
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
/// return true if we are ready to send
|
|
|
|
bool
|
|
|
|
ReadyToSend() const;
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
/// for exits
|
|
|
|
void
|
2023-10-17 15:42:27 +00:00
|
|
|
send_packet_to_remote(std::string buf) override;
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
bool
|
2023-10-17 15:42:27 +00:00
|
|
|
ShouldBuildMore(std::chrono::milliseconds now) const override;
|
2019-09-20 16:56:19 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
/// pump internal state
|
|
|
|
/// return true to mark as dead
|
|
|
|
bool
|
2023-10-17 15:42:27 +00:00
|
|
|
Pump(std::chrono::milliseconds now);
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
/// return true if it's safe to remove ourselves
|
|
|
|
bool
|
2023-10-17 15:42:27 +00:00
|
|
|
IsDone(std::chrono::milliseconds now) const;
|
2021-03-27 18:54:09 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
bool
|
2023-10-17 15:42:27 +00:00
|
|
|
CheckPathIsDead(path::Path_ptr p, std::chrono::milliseconds dlt);
|
2020-05-21 14:18:23 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
void
|
2023-10-17 15:42:27 +00:00
|
|
|
AsyncGenIntro(const llarp_buffer_t& payload, ProtocolType t);
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
/// issues a lookup to find the current intro set of the remote service
|
|
|
|
void
|
2023-10-17 15:42:27 +00:00
|
|
|
UpdateIntroSet();
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
void
|
|
|
|
HandlePathBuilt(path::Path_ptr path) override;
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
void
|
|
|
|
HandlePathBuildTimeout(path::Path_ptr path) override;
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
void
|
|
|
|
HandlePathBuildFailedAt(path::Path_ptr path, RouterID hop) override;
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
std::optional<std::vector<RouterContact>>
|
|
|
|
GetHopsForBuild() override;
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
std::string
|
|
|
|
Name() const override;
|
2019-09-20 16:56:19 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
void
|
|
|
|
KeepAlive();
|
2020-11-04 16:08:29 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
bool
|
2023-10-17 15:42:27 +00:00
|
|
|
ShouldKeepAlive(std::chrono::milliseconds now) const;
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2023-10-11 21:17:00 +00:00
|
|
|
const IntroSet&
|
|
|
|
GetCurrentIntroSet() const
|
|
|
|
{
|
2023-10-17 15:42:27 +00:00
|
|
|
return current_intro;
|
2023-10-11 21:17:00 +00:00
|
|
|
}
|
|
|
|
|
2023-10-17 15:42:27 +00:00
|
|
|
std::chrono::milliseconds
|
2023-10-11 21:17:00 +00:00
|
|
|
RTT() const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
OnIntroSetUpdate(
|
|
|
|
const Address& addr,
|
|
|
|
std::optional<IntroSet> i,
|
|
|
|
const RouterID& endpoint,
|
2023-10-17 15:42:27 +00:00
|
|
|
std::chrono::milliseconds,
|
2023-10-11 21:17:00 +00:00
|
|
|
uint64_t relayOrder);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// swap remoteIntro with next intro
|
|
|
|
void
|
2023-10-17 15:42:27 +00:00
|
|
|
swap_intros();
|
2023-10-11 21:17:00 +00:00
|
|
|
};
|
|
|
|
} // namespace llarp::service
|