2020-05-28 11:07:32 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/service/auth.hpp>
|
2023-10-19 11:49:46 +00:00
|
|
|
#include <llarp/service/convotag.hpp>
|
2023-10-24 13:18:03 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
#include <oxenmq/oxenmq.h>
|
2020-05-28 11:07:32 +00:00
|
|
|
|
|
|
|
namespace llarp::service
|
|
|
|
{
|
2024-02-01 12:43:43 +00:00
|
|
|
struct Endpoint;
|
2020-05-28 11:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace llarp::rpc
|
|
|
|
{
|
2024-02-01 12:43:43 +00:00
|
|
|
struct EndpointAuthRPC : public llarp::service::IAuthPolicy,
|
|
|
|
public std::enable_shared_from_this<EndpointAuthRPC>
|
|
|
|
{
|
|
|
|
using LMQ_ptr = std::shared_ptr<oxenmq::OxenMQ>;
|
|
|
|
using Endpoint_ptr = std::shared_ptr<llarp::service::Endpoint>;
|
|
|
|
using Whitelist_t = std::unordered_set<llarp::service::Address>;
|
|
|
|
|
|
|
|
explicit EndpointAuthRPC(
|
|
|
|
std::string url,
|
|
|
|
std::string method,
|
|
|
|
Whitelist_t addr_whitelist,
|
|
|
|
std::unordered_set<std::string> token_whitelist,
|
|
|
|
LMQ_ptr lmq,
|
|
|
|
Endpoint_ptr endpoint);
|
|
|
|
|
|
|
|
~EndpointAuthRPC() override = default;
|
|
|
|
|
|
|
|
void Start();
|
|
|
|
|
|
|
|
void authenticate_async(
|
|
|
|
std::shared_ptr<llarp::service::ProtocolMessage> msg,
|
|
|
|
std::function<void(std::string, bool)> hook) override;
|
|
|
|
|
|
|
|
bool auth_async_pending(service::ConvoTag tag) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::string m_AuthURL;
|
|
|
|
const std::string m_AuthMethod;
|
|
|
|
const Whitelist_t m_AuthWhitelist;
|
|
|
|
const std::unordered_set<std::string> m_AuthStaticTokens;
|
|
|
|
LMQ_ptr m_LMQ;
|
|
|
|
Endpoint_ptr m_Endpoint;
|
|
|
|
std::optional<oxenmq::ConnectionID> m_Conn;
|
|
|
|
std::unordered_set<service::ConvoTag> m_PendingAuths;
|
|
|
|
};
|
2020-05-28 11:07:32 +00:00
|
|
|
} // namespace llarp::rpc
|