|
|
|
@ -3,6 +3,7 @@
|
|
|
|
|
#include <router/router.hpp>
|
|
|
|
|
|
|
|
|
|
#ifdef USE_ABYSS
|
|
|
|
|
#include <util/encode.hpp>
|
|
|
|
|
#include <libabyss.hpp>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
@ -14,8 +15,9 @@ namespace llarp
|
|
|
|
|
|
|
|
|
|
struct CallerHandler : public ::abyss::http::IRPCClientHandler
|
|
|
|
|
{
|
|
|
|
|
CallerHandler(::abyss::http::ConnImpl* impl)
|
|
|
|
|
: ::abyss::http::IRPCClientHandler(impl)
|
|
|
|
|
CallerImpl* m_Parent;
|
|
|
|
|
CallerHandler(::abyss::http::ConnImpl* impl, CallerImpl* parent)
|
|
|
|
|
: ::abyss::http::IRPCClientHandler(impl), m_Parent(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -44,11 +46,7 @@ namespace llarp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PopulateReqHeaders(abyss::http::Headers_t& hdr)
|
|
|
|
|
{
|
|
|
|
|
(void)hdr;
|
|
|
|
|
// TODO: add http auth (?)
|
|
|
|
|
}
|
|
|
|
|
PopulateReqHeaders(abyss::http::Headers_t& hdr);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct GetServiceNodeListHandler final : public CallerHandler
|
|
|
|
@ -61,8 +59,9 @@ namespace llarp
|
|
|
|
|
}
|
|
|
|
|
Callback_t handler;
|
|
|
|
|
|
|
|
|
|
GetServiceNodeListHandler(::abyss::http::ConnImpl* impl, Callback_t h)
|
|
|
|
|
: CallerHandler(impl), handler(h)
|
|
|
|
|
GetServiceNodeListHandler(::abyss::http::ConnImpl* impl,
|
|
|
|
|
CallerImpl* parent, Callback_t h)
|
|
|
|
|
: CallerHandler(impl, parent), handler(h)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -96,7 +95,7 @@ namespace llarp
|
|
|
|
|
if(str.size() != Base32DecodeSize(keys.back().size()))
|
|
|
|
|
{
|
|
|
|
|
keys.pop_back();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(!Base32Decode(str, keys.back()))
|
|
|
|
|
{
|
|
|
|
|
keys.pop_back();
|
|
|
|
@ -118,10 +117,13 @@ namespace llarp
|
|
|
|
|
struct CallerImpl : public ::abyss::http::JSONRPC
|
|
|
|
|
{
|
|
|
|
|
Router* router;
|
|
|
|
|
llarp_time_t m_NextKeyUpdate = 0;
|
|
|
|
|
llarp_time_t m_NextKeyUpdate = 0;
|
|
|
|
|
const llarp_time_t KeyUpdateInterval = 1000 * 60 * 2;
|
|
|
|
|
using PubkeyList_t = GetServiceNodeListHandler::PubkeyList_t;
|
|
|
|
|
|
|
|
|
|
std::string username;
|
|
|
|
|
std::string password;
|
|
|
|
|
|
|
|
|
|
CallerImpl(Router* r) : ::abyss::http::JSONRPC(), router(r)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
@ -137,6 +139,13 @@ namespace llarp
|
|
|
|
|
Flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
SetBasicAuth(const std::string& user, const std::string& passwd)
|
|
|
|
|
{
|
|
|
|
|
username = user;
|
|
|
|
|
password = passwd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
AsyncUpdatePubkeyList()
|
|
|
|
|
{
|
|
|
|
@ -158,7 +167,7 @@ namespace llarp
|
|
|
|
|
NewAsyncUpdatePubkeyListConn(abyss::http::ConnImpl* impl)
|
|
|
|
|
{
|
|
|
|
|
return new GetServiceNodeListHandler(
|
|
|
|
|
impl,
|
|
|
|
|
impl, this,
|
|
|
|
|
std::bind(&CallerImpl::HandleServiceNodeListUpdated, this,
|
|
|
|
|
std::placeholders::_1, std::placeholders::_2));
|
|
|
|
|
}
|
|
|
|
@ -184,6 +193,18 @@ namespace llarp
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
CallerHandler::PopulateReqHeaders(abyss::http::Headers_t& hdr)
|
|
|
|
|
{
|
|
|
|
|
if(m_Parent->username.empty() || m_Parent->password.empty())
|
|
|
|
|
return;
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << "Basic ";
|
|
|
|
|
std::string cred = m_Parent->username + ":" + m_Parent->password;
|
|
|
|
|
llarp::Base64Encode(ss, (const byte_t*)cred.c_str(), cred.size());
|
|
|
|
|
hdr.emplace("Authorization", ss.str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Handler : public ::abyss::httpd::IRPCHandler
|
|
|
|
|
{
|
|
|
|
|
Router* router;
|
|
|
|
@ -358,6 +379,11 @@ namespace llarp
|
|
|
|
|
{
|
|
|
|
|
(void)now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
SetBasicAuth(const std::string&, const std::string&)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
@ -389,6 +415,12 @@ namespace llarp
|
|
|
|
|
m_Impl->Tick(now);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Caller::SetBasicAuth(const std::string& user, const std::string& passwd)
|
|
|
|
|
{
|
|
|
|
|
m_Impl->SetBasicAuth(user, passwd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Server::Server(Router* r) : m_Impl(new ServerImpl(r))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|