2018-07-09 17:32:11 +00:00
|
|
|
#ifndef LLARP_SERVICE_ENDPOINT_HPP
|
|
|
|
#define LLARP_SERVICE_ENDPOINT_HPP
|
2018-12-12 02:15:08 +00:00
|
|
|
|
2018-12-12 02:52:51 +00:00
|
|
|
#include <codel.hpp>
|
|
|
|
#include <ev.h>
|
2018-12-12 01:06:46 +00:00
|
|
|
#include <exit/session.hpp>
|
2018-12-12 02:52:51 +00:00
|
|
|
#include <net.hpp>
|
|
|
|
#include <path.hpp>
|
|
|
|
#include <pathbuilder.hpp>
|
2018-12-12 02:15:08 +00:00
|
|
|
#include <service/Identity.hpp>
|
|
|
|
#include <service/handler.hpp>
|
|
|
|
#include <service/protocol.hpp>
|
2018-07-09 17:32:11 +00:00
|
|
|
|
2018-09-18 17:48:26 +00:00
|
|
|
// minimum time between interoset shifts
|
|
|
|
#ifndef MIN_SHIFT_INTERVAL
|
|
|
|
#define MIN_SHIFT_INTERVAL (5 * 1000)
|
|
|
|
#endif
|
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
2019-01-02 01:03:53 +00:00
|
|
|
// forward declare
|
2018-09-14 13:43:42 +00:00
|
|
|
struct AsyncKeyExchange;
|
|
|
|
|
2018-08-30 18:48:43 +00:00
|
|
|
struct Endpoint : public path::Builder,
|
2018-08-09 19:02:17 +00:00
|
|
|
public ILookupHolder,
|
|
|
|
public IDataHandler
|
2018-07-09 17:32:11 +00:00
|
|
|
{
|
2018-07-18 03:10:21 +00:00
|
|
|
/// minimum interval for publishing introsets
|
|
|
|
static const llarp_time_t INTROSET_PUBLISH_INTERVAL =
|
|
|
|
DEFAULT_PATH_LIFETIME / 4;
|
|
|
|
|
|
|
|
static const llarp_time_t INTROSET_PUBLISH_RETRY_INTERVAL = 5000;
|
|
|
|
|
2018-09-28 12:22:50 +00:00
|
|
|
static const size_t MAX_OUTBOUND_CONTEXT_COUNT = 4;
|
|
|
|
|
2018-12-10 16:26:46 +00:00
|
|
|
Endpoint(const std::string& nickname, llarp::Router* r);
|
2018-07-09 17:32:11 +00:00
|
|
|
~Endpoint();
|
|
|
|
|
2018-08-08 19:37:33 +00:00
|
|
|
void
|
|
|
|
SetHandler(IDataHandler* h);
|
|
|
|
|
2018-08-16 14:34:15 +00:00
|
|
|
virtual bool
|
2018-07-09 17:32:11 +00:00
|
|
|
SetOption(const std::string& k, const std::string& v);
|
|
|
|
|
2018-08-16 14:34:15 +00:00
|
|
|
virtual void
|
2018-07-18 22:50:05 +00:00
|
|
|
Tick(llarp_time_t now);
|
2018-07-11 16:11:19 +00:00
|
|
|
|
2018-08-09 19:02:17 +00:00
|
|
|
/// router's logic
|
2018-12-10 14:14:55 +00:00
|
|
|
llarp::Logic*
|
2018-08-09 19:02:17 +00:00
|
|
|
RouterLogic();
|
|
|
|
|
|
|
|
/// endpoint's logic
|
2018-12-10 14:14:55 +00:00
|
|
|
llarp::Logic*
|
2018-08-09 19:02:17 +00:00
|
|
|
EndpointLogic();
|
2018-07-19 04:58:39 +00:00
|
|
|
|
2018-08-17 19:49:58 +00:00
|
|
|
/// endpoint's net loop for sending data to user
|
|
|
|
llarp_ev_loop*
|
|
|
|
EndpointNetLoop();
|
|
|
|
|
2018-12-11 00:53:11 +00:00
|
|
|
llarp::Crypto*
|
2018-07-19 04:58:39 +00:00
|
|
|
Crypto();
|
|
|
|
|
|
|
|
llarp_threadpool*
|
|
|
|
Worker();
|
|
|
|
|
2018-12-10 16:26:46 +00:00
|
|
|
llarp::Router*
|
2018-07-22 23:14:29 +00:00
|
|
|
Router()
|
|
|
|
{
|
|
|
|
return m_Router;
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:34:15 +00:00
|
|
|
virtual bool
|
2018-07-09 17:32:11 +00:00
|
|
|
Start();
|
|
|
|
|
2018-11-12 16:43:40 +00:00
|
|
|
virtual std::string
|
2018-07-16 03:32:13 +00:00
|
|
|
Name() const;
|
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
bool
|
2018-12-24 21:10:35 +00:00
|
|
|
ShouldPublishDescriptors(llarp_time_t now) const override;
|
2018-07-18 03:10:21 +00:00
|
|
|
|
2018-09-14 13:43:42 +00:00
|
|
|
void
|
|
|
|
EnsureReplyPath(const ServiceInfo& addr);
|
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
bool
|
2018-12-24 21:10:35 +00:00
|
|
|
PublishIntroSet(llarp::Router* r) override;
|
2018-07-18 03:10:21 +00:00
|
|
|
|
2018-09-18 14:48:06 +00:00
|
|
|
bool
|
2018-12-10 16:26:46 +00:00
|
|
|
PublishIntroSetVia(llarp::Router* r, path::Path* p);
|
2018-09-18 14:48:06 +00:00
|
|
|
|
2018-07-11 16:11:19 +00:00
|
|
|
bool
|
2018-12-24 21:10:35 +00:00
|
|
|
HandleGotIntroMessage(const llarp::dht::GotIntroMessage* msg) override;
|
2018-07-11 16:11:19 +00:00
|
|
|
|
2018-08-10 21:34:11 +00:00
|
|
|
bool
|
2018-12-24 21:10:35 +00:00
|
|
|
HandleGotRouterMessage(const llarp::dht::GotRouterMessage* msg) override;
|
2018-08-10 21:34:11 +00:00
|
|
|
|
2018-07-12 18:21:44 +00:00
|
|
|
bool
|
2018-09-18 21:32:17 +00:00
|
|
|
HandleHiddenServiceFrame(path::Path* p,
|
|
|
|
const llarp::service::ProtocolFrame* msg);
|
2018-07-12 18:21:44 +00:00
|
|
|
|
|
|
|
/// return true if we have an established path to a hidden service
|
|
|
|
bool
|
|
|
|
HasPathToService(const Address& remote) const;
|
|
|
|
|
2018-10-23 18:06:55 +00:00
|
|
|
virtual huint32_t
|
2019-01-02 01:03:53 +00:00
|
|
|
ObtainIPForAddr(const AlignedBuffer< 32 >& addr, bool serviceNode) = 0;
|
2018-10-23 18:06:55 +00:00
|
|
|
|
2018-10-23 18:18:00 +00:00
|
|
|
virtual bool
|
2019-01-02 01:04:04 +00:00
|
|
|
HasAddress(const AlignedBuffer< 32 >& addr) const = 0;
|
2018-11-07 15:30:22 +00:00
|
|
|
|
2018-08-10 03:51:38 +00:00
|
|
|
/// return true if we have a pending job to build to a hidden service but
|
|
|
|
/// it's not done yet
|
|
|
|
bool
|
|
|
|
HasPendingPathToService(const Address& remote) const;
|
|
|
|
|
2018-07-12 18:21:44 +00:00
|
|
|
/// return false if we don't have a path to the service
|
|
|
|
/// return true if we did and we removed it
|
|
|
|
bool
|
|
|
|
ForgetPathToService(const Address& remote);
|
|
|
|
|
2018-09-18 17:48:26 +00:00
|
|
|
bool
|
2018-12-24 21:10:35 +00:00
|
|
|
HandleDataMessage(const PathID_t&, ProtocolMessage* msg) override;
|
2018-08-09 19:02:17 +00:00
|
|
|
|
2018-12-02 18:07:07 +00:00
|
|
|
virtual bool
|
|
|
|
HandleWriteIPPacket(llarp_buffer_t pkt,
|
|
|
|
std::function< huint32_t(void) > getFromIP) = 0;
|
2018-11-29 13:12:35 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
ProcessDataMessage(ProtocolMessage* msg);
|
2018-09-18 17:48:26 +00:00
|
|
|
|
2018-08-10 21:34:11 +00:00
|
|
|
/// ensure that we know a router, looks up if it doesn't
|
|
|
|
void
|
|
|
|
EnsureRouterIsKnown(const RouterID& router);
|
|
|
|
|
2018-12-24 16:09:05 +00:00
|
|
|
/// lookup a router via closest path
|
|
|
|
bool
|
|
|
|
LookupRouterAnon(RouterID router);
|
|
|
|
|
|
|
|
/// stop this endpoint
|
|
|
|
bool
|
|
|
|
Stop() override;
|
|
|
|
|
2018-08-13 23:22:31 +00:00
|
|
|
const Identity&
|
2018-11-21 14:30:14 +00:00
|
|
|
GetIdentity() const
|
2018-07-22 23:14:29 +00:00
|
|
|
{
|
2018-08-13 23:22:31 +00:00
|
|
|
return m_Identity;
|
2018-07-22 23:14:29 +00:00
|
|
|
}
|
2018-07-19 04:58:39 +00:00
|
|
|
|
2018-08-04 02:59:32 +00:00
|
|
|
void
|
2018-12-24 21:10:35 +00:00
|
|
|
PutLookup(IServiceLookup* lookup, uint64_t txid) override;
|
2018-08-04 02:59:32 +00:00
|
|
|
|
2018-08-02 00:48:43 +00:00
|
|
|
void
|
2018-12-24 21:10:35 +00:00
|
|
|
HandlePathBuilt(path::Path* path) override;
|
2018-08-02 00:48:43 +00:00
|
|
|
|
2018-08-22 15:52:10 +00:00
|
|
|
bool
|
2019-01-02 01:03:53 +00:00
|
|
|
SendToServiceOrQueue(const RouterID& addr, llarp_buffer_t payload,
|
2018-12-02 18:07:07 +00:00
|
|
|
ProtocolType t);
|
2018-11-29 13:12:35 +00:00
|
|
|
|
|
|
|
bool
|
2019-01-02 01:03:53 +00:00
|
|
|
SendToSNodeOrQueue(const RouterID& addr, llarp_buffer_t payload);
|
2018-08-22 15:52:10 +00:00
|
|
|
|
2018-12-12 18:37:03 +00:00
|
|
|
void
|
|
|
|
FlushSNodeTraffic();
|
|
|
|
|
2018-08-22 15:52:10 +00:00
|
|
|
struct PendingBuffer
|
|
|
|
{
|
|
|
|
std::vector< byte_t > payload;
|
|
|
|
ProtocolType protocol;
|
|
|
|
|
|
|
|
PendingBuffer(llarp_buffer_t buf, ProtocolType t)
|
|
|
|
: payload(buf.sz), protocol(t)
|
|
|
|
{
|
|
|
|
memcpy(payload.data(), buf.base, buf.sz);
|
|
|
|
}
|
|
|
|
|
|
|
|
llarp_buffer_t
|
|
|
|
Buffer()
|
|
|
|
{
|
2019-01-02 01:04:04 +00:00
|
|
|
return llarp::Buffer(payload);
|
2018-08-22 15:52:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-11 15:28:36 +00:00
|
|
|
bool
|
|
|
|
HandleDataDrop(path::Path* p, const PathID_t& dst, uint64_t s);
|
|
|
|
|
2018-09-13 12:27:28 +00:00
|
|
|
bool
|
|
|
|
CheckPathIsDead(path::Path* p, llarp_time_t latency);
|
|
|
|
|
2018-11-22 23:59:03 +00:00
|
|
|
using PendingBufferQueue = std::queue< PendingBuffer >;
|
2018-08-22 15:52:10 +00:00
|
|
|
|
2018-09-14 13:43:42 +00:00
|
|
|
struct SendContext
|
|
|
|
{
|
|
|
|
SendContext(const ServiceInfo& ident, const Introduction& intro,
|
|
|
|
PathSet* send, Endpoint* ep);
|
|
|
|
|
|
|
|
void
|
2018-09-18 17:48:26 +00:00
|
|
|
AsyncEncryptAndSendTo(llarp_buffer_t payload, ProtocolType t);
|
2018-09-14 13:43:42 +00:00
|
|
|
|
|
|
|
/// send a fully encrypted hidden service frame
|
|
|
|
/// via a path on our pathset with path id p
|
|
|
|
void
|
2018-09-18 17:48:26 +00:00
|
|
|
Send(ProtocolFrame& f);
|
2018-09-14 13:43:42 +00:00
|
|
|
|
|
|
|
llarp::SharedSecret sharedKey;
|
|
|
|
ServiceInfo remoteIdent;
|
|
|
|
Introduction remoteIntro;
|
2018-10-01 15:45:55 +00:00
|
|
|
ConvoTag currentConvoTag;
|
2018-09-14 13:43:42 +00:00
|
|
|
PathSet* m_PathSet;
|
|
|
|
IDataHandler* m_DataHandler;
|
|
|
|
Endpoint* m_Endpoint;
|
2018-09-24 15:34:56 +00:00
|
|
|
uint64_t sequenceNo = 0;
|
|
|
|
llarp_time_t lastGoodSend = 0;
|
|
|
|
llarp_time_t createdAt;
|
2018-09-27 17:29:26 +00:00
|
|
|
llarp_time_t sendTimeout = 40 * 1000;
|
|
|
|
llarp_time_t connectTimeout = 60 * 1000;
|
2018-09-24 19:50:52 +00:00
|
|
|
bool markedBad = false;
|
2018-09-14 13:43:42 +00:00
|
|
|
|
2018-09-27 16:15:40 +00:00
|
|
|
virtual bool
|
|
|
|
ShiftIntroduction()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2018-09-14 13:43:42 +00:00
|
|
|
virtual void
|
2018-11-07 15:30:22 +00:00
|
|
|
UpdateIntroSet(bool randomizePath = false) = 0;
|
2018-10-23 18:06:55 +00:00
|
|
|
|
2018-09-24 11:36:47 +00:00
|
|
|
virtual bool
|
2018-11-07 15:30:22 +00:00
|
|
|
MarkCurrentIntroBad(llarp_time_t now) = 0;
|
2018-09-14 13:43:42 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void
|
2018-09-18 17:48:26 +00:00
|
|
|
EncryptAndSendTo(llarp_buffer_t payload, ProtocolType t);
|
2018-09-14 13:43:42 +00:00
|
|
|
|
|
|
|
virtual void
|
2018-11-07 15:30:22 +00:00
|
|
|
AsyncGenIntro(llarp_buffer_t payload, ProtocolType t) = 0;
|
2018-09-14 13:43:42 +00:00
|
|
|
};
|
|
|
|
|
2018-09-17 15:32:37 +00:00
|
|
|
static void
|
|
|
|
HandlePathDead(void*);
|
|
|
|
|
2018-07-12 18:21:44 +00:00
|
|
|
/// context needed to initiate an outbound hidden service session
|
2018-09-14 13:43:42 +00:00
|
|
|
struct OutboundContext : public path::Builder, public SendContext
|
2018-07-12 18:21:44 +00:00
|
|
|
{
|
2018-07-19 21:08:11 +00:00
|
|
|
OutboundContext(const IntroSet& introSet, Endpoint* parent);
|
2018-07-12 18:21:44 +00:00
|
|
|
~OutboundContext();
|
|
|
|
|
2018-12-24 16:09:05 +00:00
|
|
|
bool
|
|
|
|
Stop() override;
|
|
|
|
|
2018-09-11 15:28:36 +00:00
|
|
|
bool
|
|
|
|
HandleDataDrop(path::Path* p, const PathID_t& dst, uint64_t s);
|
|
|
|
|
2018-09-12 13:29:42 +00:00
|
|
|
/// set to true if we are updating the remote introset right now
|
|
|
|
bool updatingIntroSet;
|
2018-07-22 23:14:29 +00:00
|
|
|
|
|
|
|
/// update the current selected intro to be a new best introduction
|
2018-09-27 16:15:40 +00:00
|
|
|
/// return true if we have changed intros
|
|
|
|
bool
|
2018-11-19 13:39:35 +00:00
|
|
|
ShiftIntroduction() override;
|
2018-07-12 18:21:44 +00:00
|
|
|
|
2018-09-18 13:02:52 +00:00
|
|
|
/// mark the current remote intro as bad
|
2018-09-24 11:36:47 +00:00
|
|
|
bool
|
2018-11-19 13:39:35 +00:00
|
|
|
MarkCurrentIntroBad(llarp_time_t now) override;
|
2018-09-18 13:02:52 +00:00
|
|
|
|
2018-09-28 12:22:50 +00:00
|
|
|
/// return true if we are ready to send
|
|
|
|
bool
|
|
|
|
ReadyToSend() const;
|
|
|
|
|
2018-09-24 19:50:52 +00:00
|
|
|
bool
|
2018-11-19 13:39:35 +00:00
|
|
|
ShouldBuildMore(llarp_time_t now) const override;
|
2018-09-24 19:50:52 +00:00
|
|
|
|
2018-07-23 07:38:29 +00:00
|
|
|
/// tick internal state
|
2018-09-24 15:52:25 +00:00
|
|
|
/// return true to mark as dead
|
2018-07-23 07:38:29 +00:00
|
|
|
bool
|
|
|
|
Tick(llarp_time_t now);
|
|
|
|
|
2018-09-24 15:52:25 +00:00
|
|
|
/// return true if it's safe to remove ourselves
|
|
|
|
bool
|
|
|
|
IsDone(llarp_time_t now) const;
|
|
|
|
|
2018-09-24 11:36:47 +00:00
|
|
|
bool
|
|
|
|
CheckPathIsDead(path::Path* p, llarp_time_t dlt);
|
|
|
|
|
2018-09-14 13:43:42 +00:00
|
|
|
void
|
2018-11-19 13:39:35 +00:00
|
|
|
AsyncGenIntro(llarp_buffer_t payload, ProtocolType t) override;
|
2018-07-12 18:21:44 +00:00
|
|
|
|
|
|
|
/// issues a lookup to find the current intro set of the remote service
|
|
|
|
void
|
2018-11-19 13:39:35 +00:00
|
|
|
UpdateIntroSet(bool randomizePath) override;
|
2018-07-12 18:21:44 +00:00
|
|
|
|
2018-09-28 15:46:47 +00:00
|
|
|
bool
|
|
|
|
BuildOneAlignedTo(const RouterID& remote);
|
|
|
|
|
2018-08-02 00:48:43 +00:00
|
|
|
void
|
2018-11-19 13:39:35 +00:00
|
|
|
HandlePathBuilt(path::Path* path) override;
|
2018-08-02 00:48:43 +00:00
|
|
|
|
2018-07-19 21:08:11 +00:00
|
|
|
bool
|
2018-08-30 18:48:43 +00:00
|
|
|
SelectHop(llarp_nodedb* db, const RouterContact& prev,
|
2018-11-19 13:39:35 +00:00
|
|
|
RouterContact& cur, size_t hop,
|
|
|
|
llarp::path::PathRole roles) override;
|
2018-07-19 21:08:11 +00:00
|
|
|
|
2018-08-02 00:48:43 +00:00
|
|
|
bool
|
2018-09-18 21:32:17 +00:00
|
|
|
HandleHiddenServiceFrame(path::Path* p, const ProtocolFrame* frame);
|
2018-08-02 00:48:43 +00:00
|
|
|
|
2018-08-04 02:59:32 +00:00
|
|
|
std::string
|
|
|
|
Name() const;
|
|
|
|
|
2018-07-12 18:21:44 +00:00
|
|
|
private:
|
2018-10-04 13:03:48 +00:00
|
|
|
/// swap remoteIntro with next intro
|
|
|
|
void
|
|
|
|
SwapIntros();
|
|
|
|
|
2018-07-19 04:58:39 +00:00
|
|
|
void
|
2018-09-14 13:43:42 +00:00
|
|
|
OnGeneratedIntroFrame(AsyncKeyExchange* k, PathID_t p);
|
2018-07-22 23:14:29 +00:00
|
|
|
|
2018-09-14 13:43:42 +00:00
|
|
|
bool
|
2018-10-15 15:43:41 +00:00
|
|
|
OnIntroSetUpdate(const Address& addr, const IntroSet* i,
|
|
|
|
const RouterID& endpoint);
|
2018-07-19 04:58:39 +00:00
|
|
|
|
2018-08-04 02:59:32 +00:00
|
|
|
uint64_t m_UpdateIntrosetTX = 0;
|
2018-09-14 13:43:42 +00:00
|
|
|
IntroSet currentIntroSet;
|
2018-10-04 13:03:48 +00:00
|
|
|
Introduction m_NextIntro;
|
2018-09-24 11:36:47 +00:00
|
|
|
std::unordered_map< Introduction, llarp_time_t, Introduction::Hash >
|
|
|
|
m_BadIntros;
|
2018-09-18 17:48:26 +00:00
|
|
|
llarp_time_t lastShift = 0;
|
2018-07-12 18:21:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// passed a sendto context when we have a path established otherwise
|
|
|
|
// nullptr if the path was not made before the timeout
|
2018-11-22 23:59:03 +00:00
|
|
|
using PathEnsureHook = std::function< void(Address, OutboundContext*) >;
|
2018-07-12 18:21:44 +00:00
|
|
|
|
|
|
|
/// return false if we have already called this function before for this
|
|
|
|
/// address
|
|
|
|
bool
|
|
|
|
EnsurePathToService(const Address& remote, PathEnsureHook h,
|
2018-10-23 18:06:55 +00:00
|
|
|
uint64_t timeoutMS, bool lookupOnRandomPath = false);
|
2018-07-12 18:21:44 +00:00
|
|
|
|
2018-12-02 18:07:07 +00:00
|
|
|
using SNodeEnsureHook =
|
|
|
|
std::function< void(RouterID, llarp::exit::BaseSession*) >;
|
2018-11-29 13:12:35 +00:00
|
|
|
|
|
|
|
/// ensure a path to a service node by public key
|
|
|
|
void
|
2018-12-02 18:07:07 +00:00
|
|
|
EnsurePathToSNode(const RouterID& remote);
|
2018-11-29 13:12:35 +00:00
|
|
|
|
|
|
|
bool
|
2018-12-02 18:07:07 +00:00
|
|
|
HasPathToSNode(const RouterID& remote) const;
|
2018-11-29 13:12:35 +00:00
|
|
|
|
2018-08-09 19:02:17 +00:00
|
|
|
void
|
2018-12-24 21:10:35 +00:00
|
|
|
PutSenderFor(const ConvoTag& tag, const ServiceInfo& info) override;
|
2018-08-09 19:02:17 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
GetCachedSessionKeyFor(const ConvoTag& remote,
|
2019-01-02 01:04:04 +00:00
|
|
|
SharedSecret& secret) const override;
|
2018-08-09 19:02:17 +00:00
|
|
|
void
|
|
|
|
PutCachedSessionKeyFor(const ConvoTag& remote,
|
2018-12-24 21:10:35 +00:00
|
|
|
const SharedSecret& secret) override;
|
2018-08-09 19:02:17 +00:00
|
|
|
|
|
|
|
bool
|
2018-12-24 21:10:35 +00:00
|
|
|
GetSenderFor(const ConvoTag& remote, ServiceInfo& si) const override;
|
2018-08-09 19:02:17 +00:00
|
|
|
|
|
|
|
void
|
2018-12-24 21:10:35 +00:00
|
|
|
PutIntroFor(const ConvoTag& remote, const Introduction& intro) override;
|
2018-08-09 19:02:17 +00:00
|
|
|
|
|
|
|
bool
|
2018-12-24 21:10:35 +00:00
|
|
|
GetIntroFor(const ConvoTag& remote, Introduction& intro) const override;
|
2018-08-09 19:02:17 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
GetConvoTagsForService(const ServiceInfo& si,
|
2018-12-24 21:10:35 +00:00
|
|
|
std::set< ConvoTag >& tag) const override;
|
2018-08-09 19:02:17 +00:00
|
|
|
|
2018-07-19 21:08:11 +00:00
|
|
|
void
|
|
|
|
PutNewOutboundContext(const IntroSet& introset);
|
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
virtual void
|
|
|
|
IntroSetPublishFail();
|
|
|
|
virtual void
|
|
|
|
IntroSetPublished();
|
|
|
|
|
2018-09-18 14:48:06 +00:00
|
|
|
protected:
|
2018-09-11 13:21:35 +00:00
|
|
|
void
|
2018-10-01 14:18:17 +00:00
|
|
|
RegenAndPublishIntroSet(llarp_time_t now, bool forceRebuild = false);
|
2018-09-11 13:21:35 +00:00
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
IServiceLookup*
|
|
|
|
GenerateLookupByTag(const Tag& tag);
|
|
|
|
|
|
|
|
void
|
|
|
|
PrefetchServicesByTag(const Tag& tag);
|
|
|
|
|
2018-08-09 19:02:17 +00:00
|
|
|
uint64_t
|
|
|
|
GetSeqNoForConvo(const ConvoTag& tag);
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsolateNetwork();
|
|
|
|
|
2018-08-16 14:34:15 +00:00
|
|
|
bool
|
|
|
|
NetworkIsIsolated() const;
|
|
|
|
|
2018-08-17 19:49:58 +00:00
|
|
|
static void
|
|
|
|
RunIsolatedMainLoop(void*);
|
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
private:
|
2018-08-10 21:34:11 +00:00
|
|
|
bool
|
2018-10-15 15:43:41 +00:00
|
|
|
OnLookup(const service::Address& addr, const IntroSet* i,
|
|
|
|
const RouterID& endpoint); /* */
|
2018-08-10 21:34:11 +00:00
|
|
|
|
2018-08-09 19:02:17 +00:00
|
|
|
static bool
|
2018-08-20 19:12:12 +00:00
|
|
|
SetupIsolatedNetwork(void* user, bool success);
|
2018-08-09 19:02:17 +00:00
|
|
|
|
|
|
|
bool
|
2018-08-18 14:01:21 +00:00
|
|
|
DoNetworkIsolation(bool failed);
|
2018-08-09 19:02:17 +00:00
|
|
|
|
2018-08-16 14:34:15 +00:00
|
|
|
virtual bool
|
|
|
|
SetupNetworking()
|
|
|
|
{
|
|
|
|
// XXX: override me
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-18 14:01:21 +00:00
|
|
|
virtual bool
|
|
|
|
IsolationFailed()
|
|
|
|
{
|
|
|
|
// XXX: override me
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
uint64_t
|
|
|
|
GenTXID();
|
|
|
|
|
2018-08-08 19:37:33 +00:00
|
|
|
protected:
|
|
|
|
IDataHandler* m_DataHandler = nullptr;
|
2018-08-09 19:02:17 +00:00
|
|
|
Identity m_Identity;
|
2018-11-14 19:34:17 +00:00
|
|
|
std::unique_ptr< llarp::exit::BaseSession > m_Exit;
|
2018-08-08 19:37:33 +00:00
|
|
|
|
2018-07-09 17:32:11 +00:00
|
|
|
private:
|
2018-12-10 16:26:46 +00:00
|
|
|
llarp::Router* m_Router;
|
2018-08-09 19:02:17 +00:00
|
|
|
llarp_threadpool* m_IsolatedWorker = nullptr;
|
2018-12-10 14:14:55 +00:00
|
|
|
llarp::Logic* m_IsolatedLogic = nullptr;
|
2018-08-17 19:49:58 +00:00
|
|
|
llarp_ev_loop* m_IsolatedNetLoop = nullptr;
|
2018-07-09 17:32:11 +00:00
|
|
|
std::string m_Keyfile;
|
2018-07-11 16:11:19 +00:00
|
|
|
std::string m_Name;
|
2018-08-09 19:02:17 +00:00
|
|
|
std::string m_NetNS;
|
|
|
|
|
2018-11-03 20:17:28 +00:00
|
|
|
using PendingTraffic =
|
|
|
|
std::unordered_map< Address, PendingBufferQueue, Address::Hash >;
|
2018-08-22 15:52:10 +00:00
|
|
|
|
2018-11-03 20:17:28 +00:00
|
|
|
PendingTraffic m_PendingTraffic;
|
2018-09-14 13:43:42 +00:00
|
|
|
|
2018-11-03 20:17:28 +00:00
|
|
|
using Sessions =
|
|
|
|
std::unordered_multimap< Address, std::unique_ptr< OutboundContext >,
|
|
|
|
Address::Hash >;
|
|
|
|
Sessions m_RemoteSessions;
|
|
|
|
|
|
|
|
Sessions m_DeadSessions;
|
2018-09-24 15:52:25 +00:00
|
|
|
|
2018-12-02 18:07:07 +00:00
|
|
|
using SNodeSessions =
|
|
|
|
std::unordered_multimap< RouterID,
|
|
|
|
std::unique_ptr< llarp::exit::BaseSession >,
|
|
|
|
RouterID::Hash >;
|
2018-11-29 13:12:35 +00:00
|
|
|
|
|
|
|
SNodeSessions m_SNodeSessions;
|
|
|
|
|
2018-09-14 13:43:42 +00:00
|
|
|
std::unordered_map< Address, ServiceInfo, Address::Hash >
|
|
|
|
m_AddressToService;
|
|
|
|
|
2018-07-22 23:14:29 +00:00
|
|
|
std::unordered_map< Address, PathEnsureHook, Address::Hash >
|
|
|
|
m_PendingServiceLookups;
|
2018-08-10 21:34:11 +00:00
|
|
|
|
2018-10-23 18:06:55 +00:00
|
|
|
std::unordered_map< RouterID, uint32_t, RouterID::Hash >
|
|
|
|
m_ServiceLookupFails;
|
|
|
|
|
2018-08-14 21:17:18 +00:00
|
|
|
struct RouterLookupJob
|
|
|
|
{
|
|
|
|
RouterLookupJob(Endpoint* p)
|
|
|
|
{
|
2018-10-29 16:48:36 +00:00
|
|
|
started = p->Now();
|
2018-08-14 21:17:18 +00:00
|
|
|
txid = p->GenTXID();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t txid;
|
|
|
|
llarp_time_t started;
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsExpired(llarp_time_t now) const
|
|
|
|
{
|
|
|
|
if(now < started)
|
|
|
|
return false;
|
|
|
|
return now - started > 5000;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unordered_map< RouterID, RouterLookupJob, RouterID::Hash >
|
|
|
|
m_PendingRouters;
|
2018-08-10 21:34:11 +00:00
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
uint64_t m_CurrentPublishTX = 0;
|
|
|
|
llarp_time_t m_LastPublish = 0;
|
|
|
|
llarp_time_t m_LastPublishAttempt = 0;
|
2018-10-04 16:48:26 +00:00
|
|
|
llarp_time_t m_MinPathLatency = (5 * 1000);
|
2018-07-18 03:10:21 +00:00
|
|
|
/// our introset
|
|
|
|
service::IntroSet m_IntroSet;
|
2018-07-19 21:08:11 +00:00
|
|
|
/// pending remote service lookups by id
|
2018-08-14 21:17:18 +00:00
|
|
|
std::unordered_map< uint64_t, std::unique_ptr< service::IServiceLookup > >
|
|
|
|
m_PendingLookups;
|
2018-08-02 00:48:43 +00:00
|
|
|
/// prefetch remote address list
|
|
|
|
std::set< Address > m_PrefetchAddrs;
|
2018-07-18 03:10:21 +00:00
|
|
|
/// hidden service tag
|
|
|
|
Tag m_Tag;
|
|
|
|
/// prefetch descriptors for these hidden service tags
|
|
|
|
std::set< Tag > m_PrefetchTags;
|
2018-08-09 19:02:17 +00:00
|
|
|
/// on initialize functions
|
|
|
|
std::list< std::function< bool(void) > > m_OnInit;
|
|
|
|
|
|
|
|
struct Session
|
|
|
|
{
|
|
|
|
SharedSecret sharedKey;
|
|
|
|
ServiceInfo remote;
|
|
|
|
Introduction intro;
|
|
|
|
llarp_time_t lastUsed = 0;
|
|
|
|
uint64_t seqno = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// sessions
|
|
|
|
std::unordered_map< ConvoTag, Session, ConvoTag::Hash > m_Sessions;
|
2018-07-18 03:10:21 +00:00
|
|
|
|
2018-08-14 21:17:18 +00:00
|
|
|
struct CachedTagResult
|
2018-07-18 03:10:21 +00:00
|
|
|
{
|
2018-07-19 04:58:39 +00:00
|
|
|
const static llarp_time_t TTL = 10000;
|
|
|
|
llarp_time_t lastRequest = 0;
|
2018-08-04 02:59:32 +00:00
|
|
|
llarp_time_t lastModified = 0;
|
2018-07-18 03:10:21 +00:00
|
|
|
std::set< IntroSet > result;
|
|
|
|
Tag tag;
|
2018-10-29 16:51:52 +00:00
|
|
|
Endpoint* parent;
|
2018-07-18 03:10:21 +00:00
|
|
|
|
2018-10-29 16:51:52 +00:00
|
|
|
CachedTagResult(const Tag& t, Endpoint* p) : tag(t), parent(p)
|
2018-07-18 03:10:21 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-08-14 21:17:18 +00:00
|
|
|
~CachedTagResult()
|
|
|
|
{
|
|
|
|
}
|
2018-07-18 03:10:21 +00:00
|
|
|
|
2018-07-18 22:50:05 +00:00
|
|
|
void
|
|
|
|
Expire(llarp_time_t now);
|
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
bool
|
|
|
|
ShouldRefresh(llarp_time_t now) const
|
|
|
|
{
|
2018-07-19 04:58:39 +00:00
|
|
|
if(now <= lastRequest)
|
|
|
|
return false;
|
2018-08-04 02:59:32 +00:00
|
|
|
return (now - lastRequest) > TTL;
|
2018-07-18 03:10:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
llarp::routing::IMessage*
|
2018-08-14 21:17:18 +00:00
|
|
|
BuildRequestMessage(uint64_t txid);
|
2018-07-18 03:10:21 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
HandleResponse(const std::set< IntroSet >& results);
|
|
|
|
};
|
|
|
|
|
2018-08-14 21:17:18 +00:00
|
|
|
struct TagLookupJob : public IServiceLookup
|
|
|
|
{
|
|
|
|
TagLookupJob(Endpoint* parent, CachedTagResult* result)
|
|
|
|
: IServiceLookup(parent, parent->GenTXID(), "taglookup")
|
|
|
|
, m_result(result)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~TagLookupJob()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
llarp::routing::IMessage*
|
|
|
|
BuildRequestMessage()
|
|
|
|
{
|
|
|
|
return m_result->BuildRequestMessage(txid);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HandleResponse(const std::set< IntroSet >& results)
|
|
|
|
{
|
|
|
|
return m_result->HandleResponse(results);
|
|
|
|
}
|
|
|
|
|
|
|
|
CachedTagResult* m_result;
|
|
|
|
};
|
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
std::unordered_map< Tag, CachedTagResult, Tag::Hash > m_PrefetchedTags;
|
2018-07-09 17:32:11 +00:00
|
|
|
};
|
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|
|
|
|
|
2018-08-16 14:34:15 +00:00
|
|
|
#endif
|