2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <llarp/crypto/types.hpp>
|
|
|
|
#include <llarp/util/types.hpp>
|
|
|
|
#include <llarp/crypto/encrypted_frame.hpp>
|
|
|
|
#include <llarp/util/decaying_hashset.hpp>
|
|
|
|
#include <llarp/messages/relay.hpp>
|
2019-09-05 17:39:09 +00:00
|
|
|
#include <vector>
|
2019-06-17 23:19:39 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
struct llarp_buffer_t;
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
struct AbstractRouter;
|
|
|
|
|
|
|
|
namespace routing
|
|
|
|
{
|
|
|
|
struct IMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace path
|
|
|
|
{
|
|
|
|
struct IHopHandler
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
using TrafficEvent_t = std::pair<std::vector<byte_t>, TunnelNonce>;
|
2020-05-24 12:51:17 +00:00
|
|
|
using TrafficQueue_t = std::list<TrafficEvent_t>;
|
2019-09-05 17:39:09 +00:00
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
virtual ~IHopHandler() = default;
|
2019-06-17 23:19:39 +00:00
|
|
|
|
2021-04-07 12:52:17 +00:00
|
|
|
virtual PathID_t
|
|
|
|
RXID() const = 0;
|
|
|
|
|
2020-05-21 14:23:54 +00:00
|
|
|
void
|
|
|
|
DecayFilters(llarp_time_t now);
|
|
|
|
|
2019-06-17 23:19:39 +00:00
|
|
|
virtual bool
|
|
|
|
Expired(llarp_time_t now) const = 0;
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
ExpiresSoon(llarp_time_t now, llarp_time_t dlt) const = 0;
|
|
|
|
|
|
|
|
/// send routing message and increment sequence number
|
|
|
|
virtual bool
|
|
|
|
SendRoutingMessage(const routing::IMessage& msg, AbstractRouter* r) = 0;
|
|
|
|
|
|
|
|
// handle data in upstream direction
|
2020-01-03 11:04:47 +00:00
|
|
|
virtual bool
|
2020-04-07 18:38:56 +00:00
|
|
|
HandleUpstream(const llarp_buffer_t& X, const TunnelNonce& Y, AbstractRouter*);
|
2019-06-17 23:19:39 +00:00
|
|
|
// handle data in downstream direction
|
2020-01-03 11:04:47 +00:00
|
|
|
virtual bool
|
2020-04-07 18:38:56 +00:00
|
|
|
HandleDownstream(const llarp_buffer_t& X, const TunnelNonce& Y, AbstractRouter*);
|
2019-06-17 23:19:39 +00:00
|
|
|
|
|
|
|
/// return timestamp last remote activity happened at
|
|
|
|
virtual llarp_time_t
|
|
|
|
LastRemoteActivityAt() const = 0;
|
|
|
|
|
2019-06-04 18:31:17 +00:00
|
|
|
virtual bool
|
2020-04-07 18:38:56 +00:00
|
|
|
HandleLRSM(uint64_t status, std::array<EncryptedFrame, 8>& frames, AbstractRouter* r) = 0;
|
2019-06-04 18:31:17 +00:00
|
|
|
|
2019-06-17 23:19:39 +00:00
|
|
|
uint64_t
|
|
|
|
NextSeqNo()
|
|
|
|
{
|
|
|
|
return m_SequenceNum++;
|
|
|
|
}
|
2020-01-03 11:04:47 +00:00
|
|
|
|
2019-09-05 17:39:09 +00:00
|
|
|
virtual void
|
2019-09-16 10:21:12 +00:00
|
|
|
FlushUpstream(AbstractRouter* r) = 0;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
FlushDownstream(AbstractRouter* r) = 0;
|
2019-06-17 23:19:39 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
uint64_t m_SequenceNum = 0;
|
2021-11-15 14:20:57 +00:00
|
|
|
TrafficQueue_t m_UpstreamQueue;
|
|
|
|
TrafficQueue_t m_DownstreamQueue;
|
2020-05-21 14:23:54 +00:00
|
|
|
util::DecayingHashSet<TunnelNonce> m_UpstreamReplayFilter;
|
|
|
|
util::DecayingHashSet<TunnelNonce> m_DownstreamReplayFilter;
|
2019-09-05 17:39:09 +00:00
|
|
|
|
|
|
|
virtual void
|
2021-11-15 14:20:57 +00:00
|
|
|
UpstreamWork(TrafficQueue_t queue, AbstractRouter* r) = 0;
|
2019-09-05 17:39:09 +00:00
|
|
|
|
|
|
|
virtual void
|
2021-11-15 14:20:57 +00:00
|
|
|
DownstreamWork(TrafficQueue_t queue, AbstractRouter* r) = 0;
|
2019-09-05 17:39:09 +00:00
|
|
|
|
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
HandleAllUpstream(std::vector<RelayUpstreamMessage> msgs, AbstractRouter* r) = 0;
|
2019-09-05 17:39:09 +00:00
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
HandleAllDownstream(std::vector<RelayDownstreamMessage> msgs, AbstractRouter* r) = 0;
|
2019-06-17 23:19:39 +00:00
|
|
|
};
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
using HopHandler_ptr = std::shared_ptr<IHopHandler>;
|
2019-06-17 23:19:39 +00:00
|
|
|
} // namespace path
|
|
|
|
} // namespace llarp
|