try making compatable with older versions of rapidjson

add toy munin plugin
pull/35/head
Jeff Becker 6 years ago
parent 6e1761eb05
commit b3e7fee982
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -0,0 +1,38 @@
#!/usr/bin/env python3
#
# requires python3-requests
#
import requests
import json
import sys
def jsonrpc(method, **args):
return requests.post('http://127.0.0.1:1190/', data=json.dumps(
{'method': method, 'params': args, 'id': 0}), headers={'content-type': 'application/json'}).json()
def main():
if len(sys.argv) == 2 and sys.argv[1] == 'config':
print("graph_title lokinet peers")
print("lokinet.peers.outbound Number of outbound lokinet peers")
print("lokinet.peers.inbound Number of inbound lokinet peers")
else:
inbound = 0
outbound = 0
try:
j = jsonrpc("llarp.admin.link.neighboors")
for peer in j['result']:
if peer["outbound"]:
outbound += 1
else:
inbound += 1
except:
pass
print("lokinet.peers.outboud {}".format(outbound))
print("lokinet.peers.inboud {}".format(inbound))
if __name__ == '__main__':
main()

@ -26,6 +26,11 @@ namespace abyss
#endif
namespace abyss
{
#if __cplusplus >= 201703L
typedef std::string_view string_view;
#else
typedef std::string string_view;
#endif
namespace json
{
struct IParser

@ -25,7 +25,8 @@ namespace abyss
IRPCHandler(ConnImpl* impl);
virtual bool
HandleJSONRPC(Method_t method, Params params, Response& response) = 0;
HandleJSONRPC(Method_t method, const Params& params,
Response& response) = 0;
~IRPCHandler();

@ -9,7 +9,7 @@ struct DemoHandler : public abyss::http::IRPCHandler
}
bool
HandleJSONRPC(Method_t method, Params params, Response& resp)
HandleJSONRPC(Method_t method, const Params& params, Response& resp)
{
llarp::LogInfo("method: ", method);
resp.AddMember("result", abyss::json::Value().SetInt(1),

@ -10,7 +10,7 @@ namespace abyss
{
struct RapidJSONParser : public IParser
{
RapidJSONParser(size_t contentSize) : m_Buf(contentSize), m_Offset(0)
RapidJSONParser(size_t contentSize) : m_Buf(contentSize + 1), m_Offset(0)
{
}
@ -24,15 +24,16 @@ namespace abyss
return false;
memcpy(m_Buf.data() + m_Offset, buf, sz);
m_Offset += sz;
m_Buf[m_Offset] = 0;
return true;
}
Result
Parse(Document& obj) const
{
if(m_Offset < m_Buf.size())
if(m_Offset < m_Buf.size() - 1)
return eNeedData;
obj.Parse(m_Buf.data(), m_Buf.size());
obj.Parse(m_Buf.data());
if(obj.HasParseError())
return eParseError;
return eDone;

@ -10,11 +10,6 @@ namespace abyss
{
namespace http
{
#if __cplusplus >= 201703L
typedef std::string_view string_view;
#else
typedef std::string string_view;
#endif
struct RequestHeader
{
typedef std::unordered_multimap< std::string, std::string > Headers_t;
@ -219,6 +214,7 @@ namespace abyss
return WriteResponseSimple(400, "Bad Request", "text/plain",
"invalid body size");
}
switch(m_BodyParser->Parse(m_Request))
{
case json::IParser::eNeedData:
@ -240,8 +236,7 @@ namespace abyss
m_Response.AddMember("id", m_Request["id"],
m_Response.GetAllocator());
if(handler->HandleJSONRPC(m_Request["method"].GetString(),
m_Request["params"].GetObject(),
m_Response))
m_Request["params"], m_Response))
{
return WriteResponseJSON();
}

@ -47,7 +47,7 @@ namespace llarp
}
bool
HandleJSONRPC(Method_t method, Params params, Response& response)
HandleJSONRPC(Method_t method, const Params& params, Response& response)
{
if(method == "llarp.admin.link.neighboors")
{

Loading…
Cancel
Save