add rpc method for llarp.admin.link.neighboors

pull/35/head
Jeff Becker 6 years ago
parent 04d55b94c5
commit 48e4f676cc
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -4,96 +4,12 @@ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in RFC 2119 [RFC2119].
message format is jsonrpc 2.0 like api serialized with bittorrent encoding (BEncode) over
TCP
messages are prefixed with big endian 16 bit length field indicating how many bytes the next
message is.
a version 1 aRPC message is structured as the following message:
{
"aRPC-method": "llarp",
"id" : "some-id-here",
"params": {
"key1": "val1",
"key2": "val2"
},
"v" : version_integer,
"z-key" : "<optional 32 bytes public key>",
"z-sig" : "<64 bytes siganture of the entire message requried if z-key is provided>"
}
serialzied it would be:
d13:aRPC-method5:llarp2:id12:some-id-here6:paramsd4:key14:val14:key24:val2e5:z-key32:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA5:z-sig64:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAe
given the signature is 64 bytes of 'A' and the public key is 32 bytes of 'A'
responses are signed by the identity key and MUST be verified by the caller.
an example of a call to llarp.nodedb.getrc:
{
"aRPC-method": "llarp.nodedb.rc.getbykey",
"id" : "<12 bytes random>",
"params": {
"key" : "<32 bytes identity key>"
}
}
the reply MUST be signed by the router's identity key
{
"aRPC-method" : "llarp.nodedb.rc.getbykey",
"id" : "<12 bytes from before>",
"return": {
"value" : [RC, RC, RC]
}
"time": uint64_milliseconds_since_epoch_timestamp_now,
"z-key": "<32 bytes identity public key>",
"z-sig": "<64 bytes sig>"
}
and on error:
{
"aRPC-method" : "llarp.nodedb.rc.getbykey",
"id" : "<12 bytes from before>",
"return": {
"error": "error message goes here"
},
"time": uint64_milliseconds_since_epoch_timestamp_now,
"z-key": "<32 bytes identity public key>",
"z-sig": "<64 bytes sig>"
}
if requests are signed then they are authenticated by the signer's public key
requesters can be granted access based on their public key, some methods MAY
require this in order to be called.
------
the admin api currently uses jsonrpc 2.0 over http
the methods currently provided are:
llarp.rpc.ping
get a pong back
required parameters:
ping: integer
returns:
ping
llarp.nodedb.rc.getbykey
get rc by public identity key
@ -134,7 +50,7 @@ llarp.admin.sys.uptime (authentication required)
an integer milliseconds since unix epoch we've been online
llarp.admin.link.neighboors (authentication required)
llarp.admin.link.neighboors
get a list of connected service nodes on all links
@ -148,7 +64,7 @@ llarp.admin.link.neighboors (authentication required)
{
"connected" : uint64_milliseconds_timestamp_connected_at
"ident" : "<32 bytes public identity key>",
"ident" : "<64 hex encoded public identity key>",
"laddr" : "local address",
"raddr" : "remote address"
}

@ -211,6 +211,13 @@ namespace llarp
return true;
}
std::string
ToHex() const
{
char strbuf[(1 + sz) * 2] = {0};
return HexEncode(*this, strbuf);
}
struct Hash
{
size_t

@ -25,6 +25,9 @@ namespace llarp
bool
HasSessionVia(const Addr& addr);
void
ForEachSession(std::function< void(const ILinkSession*) > visit) const;
static void
udp_tick(llarp_udp_io* udp)
{

@ -511,6 +511,14 @@ namespace llarp
}
}
std::string
ToString() const
{
std::stringstream ss;
ss << *this;
return ss.str();
}
friend std::ostream&
operator<<(std::ostream& out, const Addr& a)
{

@ -14,6 +14,18 @@ namespace llarp
return m_AuthedLinks.find(pk) != m_AuthedLinks.end();
}
void
ILinkLayer::ForEachSession(
std::function< void(const ILinkSession*) > visit) const
{
auto itr = m_AuthedLinks.begin();
while(itr != m_AuthedLinks.end())
{
visit(itr->second.get());
++itr;
}
}
bool
ILinkLayer::Configure(llarp_ev_loop* loop, const std::string& ifname, int af,
uint16_t port)

@ -243,6 +243,19 @@ llarp_router::HandleDHTLookupForSendTo(
}
}
void
llarp_router::ForEachPeer(
std::function< void(const llarp::ILinkSession *, bool) > visit) const
{
outboundLink->ForEachSession(
[visit](const llarp::ILinkSession *peer) { visit(peer, true); });
for(const auto &link : inboundLinks)
{
link->ForEachSession(
[visit](const llarp::ILinkSession *peer) { visit(peer, false); });
}
}
void
llarp_router::try_connect(fs::path rcfile)
{

@ -226,6 +226,10 @@ struct llarp_router
void
TryEstablishTo(const llarp::RouterID &remote);
void
ForEachPeer(
std::function< void(const llarp::ILinkSession *, bool) > visit) const;
/// flush outbound message queue
void
FlushOutbound();

@ -19,9 +19,36 @@ namespace llarp
{
}
bool
ListNeighboors(Response& resp) const
{
auto& alloc = resp.GetAllocator();
auto& peers = abyss::json::Value().SetArray();
router->ForEachPeer([&](const llarp::ILinkSession* session,
bool outbound) {
auto& peer = abyss::json::Value().SetObject();
auto ident = session->GetPubKey().ToHex();
auto addr = session->GetRemoteEndpoint().ToString();
peer.AddMember("addr",
abyss::json::Value(addr.data(), addr.size(), alloc),
alloc);
peer.AddMember("ident",
abyss::json::Value(ident.data(), ident.size(), alloc),
alloc);
peer.AddMember("outbound", abyss::json::Value(outbound), alloc);
peers.PushBack(peer, alloc);
});
resp.AddMember("result", peers, alloc);
return true;
}
bool
HandleJSONRPC(Method_t method, Params params, Response& response)
{
if(method == "llarp.admin.link.neighboors")
{
return ListNeighboors(response);
}
return false;
}
};

Loading…
Cancel
Save