2019-06-17 23:19:39 +00:00
|
|
|
#ifndef LLARP_PATH_IHOPHANDLER_HPP
|
|
|
|
#define LLARP_PATH_IHOPHANDLER_HPP
|
|
|
|
|
|
|
|
#include <crypto/types.hpp>
|
|
|
|
#include <util/types.hpp>
|
2019-06-04 18:31:17 +00:00
|
|
|
#include <crypto/encrypted_frame.hpp>
|
2019-09-05 17:39:09 +00:00
|
|
|
#include <messages/relay.hpp>
|
|
|
|
#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
|
|
|
|
{
|
2019-09-16 10:21:12 +00:00
|
|
|
using TrafficEvent_t = std::pair< std::vector< byte_t >, TunnelNonce >;
|
|
|
|
using TrafficQueue_t = std::vector< TrafficEvent_t >;
|
|
|
|
using TrafficQueue_ptr = std::shared_ptr< TrafficQueue_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
|
|
|
|
|
|
|
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
|
2019-09-05 17:39:09 +00:00
|
|
|
bool
|
2019-06-17 23:19:39 +00:00
|
|
|
HandleUpstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
2019-09-16 16:21:21 +00:00
|
|
|
AbstractRouter*);
|
2019-06-17 23:19:39 +00:00
|
|
|
// handle data in downstream direction
|
2019-09-05 17:39:09 +00:00
|
|
|
bool
|
2019-06-17 23:19:39 +00:00
|
|
|
HandleDownstream(const llarp_buffer_t& X, const TunnelNonce& Y,
|
2019-09-16 16:21:21 +00:00
|
|
|
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
|
|
|
|
HandleLRSM(uint64_t status, std::array< EncryptedFrame, 8 >& frames,
|
|
|
|
AbstractRouter* r) = 0;
|
|
|
|
|
2019-06-17 23:19:39 +00:00
|
|
|
uint64_t
|
|
|
|
NextSeqNo()
|
|
|
|
{
|
|
|
|
return m_SequenceNum++;
|
|
|
|
}
|
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;
|
2019-09-16 10:21:12 +00:00
|
|
|
TrafficQueue_ptr m_UpstreamQueue;
|
|
|
|
TrafficQueue_ptr m_DownstreamQueue;
|
2019-09-05 17:39:09 +00:00
|
|
|
|
|
|
|
virtual void
|
2019-09-16 10:21:12 +00:00
|
|
|
UpstreamWork(TrafficQueue_ptr queue, AbstractRouter* r) = 0;
|
2019-09-05 17:39:09 +00:00
|
|
|
|
|
|
|
virtual void
|
2019-09-16 10:21:12 +00:00
|
|
|
DownstreamWork(TrafficQueue_ptr queue, AbstractRouter* r) = 0;
|
2019-09-05 17:39:09 +00:00
|
|
|
|
|
|
|
virtual void
|
|
|
|
HandleAllUpstream(std::vector< RelayUpstreamMessage > msgs,
|
|
|
|
AbstractRouter* r) = 0;
|
|
|
|
virtual void
|
|
|
|
HandleAllDownstream(std::vector< RelayDownstreamMessage > msgs,
|
|
|
|
AbstractRouter* r) = 0;
|
2019-06-17 23:19:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using HopHandler_ptr = std::shared_ptr< IHopHandler >;
|
|
|
|
} // namespace path
|
|
|
|
} // namespace llarp
|
|
|
|
#endif
|