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>
|
|
|
|
#include "sendcontext.hpp"
|
|
|
|
#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
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
|
|
|
struct AsyncKeyExchange;
|
|
|
|
struct Endpoint;
|
|
|
|
|
|
|
|
/// context needed to initiate an outbound hidden service session
|
2020-04-07 18:38:56 +00:00
|
|
|
struct OutboundContext : public path::Builder,
|
|
|
|
public SendContext,
|
|
|
|
public std::enable_shared_from_this<OutboundContext>
|
2019-04-21 16:44:27 +00:00
|
|
|
{
|
|
|
|
OutboundContext(const IntroSet& introSet, Endpoint* parent);
|
2020-05-21 14:18:23 +00:00
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
~OutboundContext() override;
|
2019-04-21 16:44:27 +00:00
|
|
|
|
|
|
|
util::StatusObject
|
|
|
|
ExtractStatus() const;
|
|
|
|
|
2020-05-21 14:18:23 +00:00
|
|
|
void
|
|
|
|
BlacklistSNode(const RouterID) override{};
|
|
|
|
|
2019-04-21 16:44:27 +00:00
|
|
|
bool
|
|
|
|
ShouldBundleRC() const override;
|
|
|
|
|
2019-04-23 16:13:22 +00:00
|
|
|
path::PathSet_ptr
|
|
|
|
GetSelf() override
|
|
|
|
{
|
|
|
|
return shared_from_this();
|
|
|
|
}
|
|
|
|
|
2019-04-21 16:44:27 +00:00
|
|
|
bool
|
|
|
|
Stop() override;
|
|
|
|
|
|
|
|
bool
|
2019-04-23 14:28:59 +00:00
|
|
|
HandleDataDrop(path::Path_ptr p, const PathID_t& dst, uint64_t s);
|
2019-04-21 16:44:27 +00:00
|
|
|
|
|
|
|
void
|
2019-04-23 14:28:59 +00:00
|
|
|
HandlePathDied(path::Path_ptr p) override;
|
2019-04-21 16:44:27 +00:00
|
|
|
|
|
|
|
/// set to true if we are updating the remote introset right now
|
|
|
|
bool updatingIntroSet;
|
|
|
|
|
|
|
|
/// update the current selected intro to be a new best introduction
|
|
|
|
/// return true if we have changed intros
|
|
|
|
bool
|
|
|
|
ShiftIntroduction(bool rebuild = true) override;
|
|
|
|
|
2019-09-20 16:56:19 +00:00
|
|
|
/// shift the intro off the current router it is using
|
|
|
|
void
|
|
|
|
ShiftIntroRouter(const RouterID remote);
|
|
|
|
|
2019-04-21 16:44:27 +00:00
|
|
|
/// mark the current remote intro as bad
|
|
|
|
bool
|
|
|
|
MarkCurrentIntroBad(llarp_time_t now) override;
|
|
|
|
|
2019-09-20 16:56:19 +00:00
|
|
|
bool
|
|
|
|
MarkIntroBad(const Introduction& marked, llarp_time_t now);
|
|
|
|
|
2019-04-21 16:44:27 +00:00
|
|
|
/// return true if we are ready to send
|
|
|
|
bool
|
|
|
|
ReadyToSend() const;
|
|
|
|
|
2021-03-27 18:54:09 +00:00
|
|
|
void
|
|
|
|
SetReadyHook(std::function<void(OutboundContext*)> readyHook, llarp_time_t timeout);
|
|
|
|
|
2020-05-21 14:18:23 +00:00
|
|
|
/// for exits
|
|
|
|
void
|
2021-03-16 11:56:27 +00:00
|
|
|
SendPacketToRemote(const llarp_buffer_t&, ProtocolType t) override;
|
2020-05-21 14:18:23 +00:00
|
|
|
|
2019-04-21 16:44:27 +00:00
|
|
|
bool
|
|
|
|
ShouldBuildMore(llarp_time_t now) const override;
|
|
|
|
|
2019-04-23 16:13:22 +00:00
|
|
|
/// pump internal state
|
2019-04-21 16:44:27 +00:00
|
|
|
/// return true to mark as dead
|
|
|
|
bool
|
2019-04-23 16:13:22 +00:00
|
|
|
Pump(llarp_time_t now);
|
2019-04-21 16:44:27 +00:00
|
|
|
|
|
|
|
/// return true if it's safe to remove ourselves
|
|
|
|
bool
|
|
|
|
IsDone(llarp_time_t now) const;
|
|
|
|
|
|
|
|
bool
|
2019-04-23 14:28:59 +00:00
|
|
|
CheckPathIsDead(path::Path_ptr p, llarp_time_t dlt);
|
2019-04-21 16:44:27 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
AsyncGenIntro(const llarp_buffer_t& payload, ProtocolType t) override;
|
|
|
|
|
|
|
|
/// issues a lookup to find the current intro set of the remote service
|
|
|
|
void
|
2020-02-14 20:14:43 +00:00
|
|
|
UpdateIntroSet() override;
|
2019-04-21 16:44:27 +00:00
|
|
|
|
|
|
|
void
|
2019-04-23 14:28:59 +00:00
|
|
|
HandlePathBuilt(path::Path_ptr path) override;
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2019-09-20 16:56:19 +00:00
|
|
|
void
|
|
|
|
HandlePathBuildTimeout(path::Path_ptr path) override;
|
|
|
|
|
2020-11-04 16:08:29 +00:00
|
|
|
void
|
|
|
|
HandlePathBuildFailed(path::Path_ptr path) override;
|
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
std::optional<std::vector<RouterContact>>
|
|
|
|
GetHopsForBuild() override;
|
2019-04-21 16:44:27 +00:00
|
|
|
|
|
|
|
bool
|
2019-04-23 14:28:59 +00:00
|
|
|
HandleHiddenServiceFrame(path::Path_ptr p, const ProtocolFrame& frame);
|
2019-04-21 16:44:27 +00:00
|
|
|
|
|
|
|
std::string
|
|
|
|
Name() const override;
|
|
|
|
|
2021-03-27 18:54:09 +00:00
|
|
|
void
|
|
|
|
KeepAlive();
|
|
|
|
|
2020-08-31 20:07:17 +00:00
|
|
|
const IntroSet&
|
|
|
|
GetCurrentIntroSet() const
|
|
|
|
{
|
|
|
|
return currentIntroSet;
|
|
|
|
}
|
|
|
|
|
2019-04-21 16:44:27 +00:00
|
|
|
private:
|
|
|
|
/// swap remoteIntro with next intro
|
|
|
|
void
|
|
|
|
SwapIntros();
|
|
|
|
|
|
|
|
void
|
|
|
|
OnGeneratedIntroFrame(AsyncKeyExchange* k, PathID_t p);
|
|
|
|
|
|
|
|
bool
|
2021-03-27 18:54:09 +00:00
|
|
|
OnIntroSetUpdate(
|
|
|
|
const Address& addr, std::optional<IntroSet> i, const RouterID& endpoint, llarp_time_t);
|
2019-04-21 16:44:27 +00:00
|
|
|
|
2020-01-27 21:30:41 +00:00
|
|
|
const dht::Key_t location;
|
2019-04-21 16:44:27 +00:00
|
|
|
uint64_t m_UpdateIntrosetTX = 0;
|
|
|
|
IntroSet currentIntroSet;
|
|
|
|
Introduction m_NextIntro;
|
2021-03-09 18:39:40 +00:00
|
|
|
std::unordered_map<Introduction, llarp_time_t> m_BadIntros;
|
2020-02-24 19:40:45 +00:00
|
|
|
llarp_time_t lastShift = 0s;
|
2019-04-21 16:44:27 +00:00
|
|
|
uint16_t m_LookupFails = 0;
|
2020-04-07 18:38:56 +00:00
|
|
|
uint16_t m_BuildFails = 0;
|
2020-05-21 14:18:23 +00:00
|
|
|
llarp_time_t m_LastInboundTraffic = 0s;
|
|
|
|
bool m_GotInboundTraffic = false;
|
2021-03-27 18:54:09 +00:00
|
|
|
bool sentIntro = false;
|
|
|
|
std::function<void(OutboundContext*)> m_ReadyHook;
|
2019-04-21 16:44:27 +00:00
|
|
|
};
|
|
|
|
} // namespace service
|
|
|
|
|
|
|
|
} // namespace llarp
|