lokinet/llarp/rpc/endpoint_rpc.hpp

45 lines
1.1 KiB
C++
Raw Normal View History

2020-05-28 11:07:32 +00:00
#pragma once
#include <service/auth.hpp>
2020-06-02 21:10:42 +00:00
#include <lokimq/lokimq.h>
2020-05-28 11:07:32 +00:00
namespace llarp::service
{
struct Endpoint;
}
namespace llarp::rpc
{
struct EndpointAuthRPC : public llarp::service::IAuthPolicy,
public std::enable_shared_from_this<EndpointAuthRPC>
{
using LMQ_ptr = std::shared_ptr<lokimq::LokiMQ>;
using Endpoint_ptr = std::shared_ptr<llarp::service::Endpoint>;
2020-06-05 19:01:42 +00:00
using Whitelist_t = std::unordered_set<llarp::service::Address, llarp::service::Address::Hash>;
2020-05-28 11:07:32 +00:00
explicit EndpointAuthRPC(
2020-06-05 19:01:42 +00:00
std::string url,
std::string method,
Whitelist_t whitelist,
LMQ_ptr lmq,
Endpoint_ptr endpoint);
2020-06-11 12:01:38 +00:00
virtual ~EndpointAuthRPC() = default;
2020-05-28 11:07:32 +00:00
2020-06-02 21:10:42 +00:00
void
Start();
2020-05-28 11:07:32 +00:00
void
AuthenticateAsync(
2020-06-17 13:07:05 +00:00
std::shared_ptr<llarp::service::ProtocolMessage> msg,
2020-05-28 11:07:32 +00:00
std::function<void(service::AuthResult)> hook) override;
private:
const std::string m_AuthURL;
const std::string m_AuthMethod;
2020-06-05 19:01:42 +00:00
const Whitelist_t m_AuthWhitelist;
2020-05-28 11:07:32 +00:00
LMQ_ptr m_LMQ;
Endpoint_ptr m_Endpoint;
std::optional<lokimq::ConnectionID> m_Conn;
};
} // namespace llarp::rpc