2020-05-28 11:07:32 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/service/auth.hpp>
|
2021-02-02 14:35:40 +00:00
|
|
|
#include <oxenmq/oxenmq.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>
|
|
|
|
{
|
2021-02-02 14:35:40 +00:00
|
|
|
using LMQ_ptr = std::shared_ptr<oxenmq::OxenMQ>;
|
2020-05-28 11:07:32 +00:00
|
|
|
using Endpoint_ptr = std::shared_ptr<llarp::service::Endpoint>;
|
2021-03-09 18:39:40 +00:00
|
|
|
using Whitelist_t = std::unordered_set<llarp::service::Address>;
|
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;
|
|
|
|
|
2021-01-01 18:55:31 +00:00
|
|
|
bool
|
|
|
|
AsyncAuthPending(service::ConvoTag tag) const override;
|
|
|
|
|
2020-05-28 11:07:32 +00:00
|
|
|
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;
|
2021-02-02 14:35:40 +00:00
|
|
|
std::optional<oxenmq::ConnectionID> m_Conn;
|
2021-01-01 18:55:31 +00:00
|
|
|
std::unordered_set<service::ConvoTag> m_PendingAuths;
|
2020-05-28 11:07:32 +00:00
|
|
|
};
|
|
|
|
} // namespace llarp::rpc
|