lokinet/llarp/service/handler.hpp

99 lines
2.4 KiB
C++
Raw Normal View History

#ifndef LLARP_SERVICE_HANDLER_HPP
#define LLARP_SERVICE_HANDLER_HPP
2018-12-12 02:15:08 +00:00
#include <crypto/types.hpp>
2019-06-14 13:13:06 +00:00
#include <path/path.hpp>
#include <service/intro_set.hpp>
#include <util/aligned.hpp>
2019-05-03 13:15:03 +00:00
#include <memory>
#include <set>
namespace llarp
{
namespace service
{
using ConvoTag = AlignedBuffer<16>;
2019-11-28 23:08:02 +00:00
struct ProtocolMessage;
struct RecvDataEvent
{
path::Path_ptr fromPath;
PathID_t pathid;
std::shared_ptr<ProtocolMessage> msg;
2019-11-28 23:08:02 +00:00
};
2018-08-09 19:02:17 +00:00
struct ProtocolMessage;
struct IDataHandler
{
virtual bool
HandleDataMessage(
path::Path_ptr path, const PathID_t from, std::shared_ptr<ProtocolMessage> msg) = 0;
2018-08-09 19:02:17 +00:00
virtual bool
GetCachedSessionKeyFor(const ConvoTag& remote, SharedSecret& secret) const = 0;
2018-08-09 19:02:17 +00:00
virtual void
PutCachedSessionKeyFor(const ConvoTag& remote, const SharedSecret& secret) = 0;
2018-08-09 19:02:17 +00:00
2019-09-19 20:28:12 +00:00
virtual void
MarkConvoTagActive(const ConvoTag& tag) = 0;
2019-03-08 16:00:45 +00:00
virtual void
RemoveConvoTag(const ConvoTag& remote) = 0;
2019-03-08 17:00:13 +00:00
virtual bool
HasConvoTag(const ConvoTag& remote) const = 0;
2018-08-09 19:02:17 +00:00
virtual void
PutSenderFor(const ConvoTag& remote, const ServiceInfo& si, bool inbound) = 0;
2018-08-09 19:02:17 +00:00
virtual bool
GetSenderFor(const ConvoTag& remote, ServiceInfo& si) const = 0;
virtual void
PutIntroFor(const ConvoTag& remote, const Introduction& intro) = 0;
virtual bool
GetIntroFor(const ConvoTag& remote, Introduction& intro) const = 0;
virtual void
PutReplyIntroFor(const ConvoTag& remote, const Introduction& intro) = 0;
virtual bool
GetReplyIntroFor(const ConvoTag& remote, Introduction& intro) const = 0;
2018-08-09 19:02:17 +00:00
virtual bool
GetConvoTagsForService(const Address& si, std::set<ConvoTag>& tag) const = 0;
virtual bool
HasInboundConvo(const Address& addr) const = 0;
2019-11-28 23:08:02 +00:00
2020-02-18 16:00:45 +00:00
/// do we want a session outbound to addr
virtual bool
WantsOutboundSession(const Address& addr) const = 0;
virtual void
MarkAddressOutbound(const Address& addr) = 0;
2019-11-28 23:08:02 +00:00
virtual void
QueueRecvData(RecvDataEvent ev) = 0;
};
} // namespace service
} // namespace llarp
2021-01-01 18:55:31 +00:00
namespace std
{
template <>
struct hash<llarp::service::ConvoTag>
{
size_t
operator()(const llarp::service::ConvoTag& tag) const
{
std::hash<std::string_view> h{};
return h(std::string_view{reinterpret_cast<const char*>(tag.data()), tag.size()});
}
};
} // namespace std
#endif