2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2019-06-15 14:55:14 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/path/pathset.hpp>
|
|
|
|
#include <llarp/routing/path_transfer_message.hpp>
|
|
|
|
#include "intro.hpp"
|
|
|
|
#include "protocol.hpp"
|
|
|
|
#include <llarp/util/buffer.hpp>
|
|
|
|
#include <llarp/util/types.hpp>
|
|
|
|
#include <llarp/util/thread/queue.hpp>
|
2019-06-15 14:55:14 +00:00
|
|
|
|
2019-04-25 17:15:56 +00:00
|
|
|
#include <deque>
|
2019-04-19 16:02:32 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
|
|
|
struct ServiceInfo;
|
|
|
|
struct Endpoint;
|
|
|
|
struct Introduction;
|
|
|
|
|
|
|
|
struct SendContext
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
SendContext(ServiceInfo ident, const Introduction& intro, path::PathSet* send, Endpoint* ep);
|
2019-04-19 16:02:32 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
AsyncEncryptAndSendTo(const llarp_buffer_t& payload, ProtocolType t);
|
|
|
|
|
2019-04-25 17:15:56 +00:00
|
|
|
/// queue send a fully encrypted hidden service frame
|
2019-04-23 17:35:20 +00:00
|
|
|
/// via a path
|
2019-04-19 16:02:32 +00:00
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
Send(std::shared_ptr<ProtocolFrame> f, path::Path_ptr path);
|
2019-04-25 17:15:56 +00:00
|
|
|
|
2019-04-30 15:09:42 +00:00
|
|
|
/// flush upstream traffic when in router thread
|
2019-04-25 17:15:56 +00:00
|
|
|
void
|
2020-01-06 21:08:31 +00:00
|
|
|
FlushUpstream();
|
2019-04-19 16:02:32 +00:00
|
|
|
|
|
|
|
SharedSecret sharedKey;
|
|
|
|
ServiceInfo remoteIdent;
|
|
|
|
Introduction remoteIntro;
|
|
|
|
ConvoTag currentConvoTag;
|
2019-04-23 17:35:20 +00:00
|
|
|
path::PathSet* const m_PathSet;
|
|
|
|
IDataHandler* const m_DataHandler;
|
|
|
|
Endpoint* const m_Endpoint;
|
2020-04-07 18:38:56 +00:00
|
|
|
uint64_t sequenceNo = 0;
|
2020-02-24 19:40:45 +00:00
|
|
|
llarp_time_t lastGoodSend = 0s;
|
|
|
|
const llarp_time_t createdAt;
|
2020-04-07 18:38:56 +00:00
|
|
|
llarp_time_t sendTimeout = 40s;
|
2020-02-24 19:40:45 +00:00
|
|
|
llarp_time_t connectTimeout = 60s;
|
2021-03-31 16:06:50 +00:00
|
|
|
llarp_time_t estimatedRTT = 0s;
|
2020-04-07 18:38:56 +00:00
|
|
|
bool markedBad = false;
|
2021-03-31 16:06:50 +00:00
|
|
|
using Msg_ptr = std::shared_ptr<routing::PathTransferMessage>;
|
2020-04-07 18:38:56 +00:00
|
|
|
using SendEvent_t = std::pair<Msg_ptr, path::Path_ptr>;
|
2021-03-31 16:06:50 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
thread::Queue<SendEvent_t> m_SendQueue;
|
2019-04-19 16:02:32 +00:00
|
|
|
|
2021-01-01 18:55:31 +00:00
|
|
|
std::function<void(AuthResult)> authResultListener;
|
|
|
|
|
2019-04-19 16:02:32 +00:00
|
|
|
virtual bool
|
|
|
|
ShiftIntroduction(bool rebuild = true)
|
|
|
|
{
|
|
|
|
(void)rebuild;
|
|
|
|
return true;
|
2019-04-24 23:27:31 +00:00
|
|
|
}
|
2019-04-19 16:02:32 +00:00
|
|
|
|
|
|
|
virtual void
|
2020-02-14 20:14:43 +00:00
|
|
|
UpdateIntroSet() = 0;
|
2019-04-19 16:02:32 +00:00
|
|
|
|
2021-05-01 12:52:41 +00:00
|
|
|
virtual void
|
2019-04-19 16:02:32 +00:00
|
|
|
MarkCurrentIntroBad(llarp_time_t now) = 0;
|
|
|
|
|
2021-01-01 18:55:31 +00:00
|
|
|
void
|
|
|
|
AsyncSendAuth(std::function<void(AuthResult)> replyHandler);
|
|
|
|
|
2019-04-19 16:02:32 +00:00
|
|
|
private:
|
|
|
|
void
|
|
|
|
EncryptAndSendTo(const llarp_buffer_t& payload, ProtocolType t);
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
AsyncGenIntro(const llarp_buffer_t& payload, ProtocolType t) = 0;
|
|
|
|
};
|
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|