Merge pull request #315 from michael-loki:move_json

Move abyss/json to llarp/util/json
pull/318/head
Jeff 5 years ago committed by GitHub
commit 524cb3138c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -316,11 +316,8 @@ if(USE_LIBABYSS)
set(ABYSS_SRC set(ABYSS_SRC
${ABYSS}/src/http.cpp ${ABYSS}/src/http.cpp
${ABYSS}/src/client.cpp ${ABYSS}/src/client.cpp
${ABYSS}/src/server.cpp ${ABYSS}/src/server.cpp)
${ABYSS}/src/json.cpp)
add_library(${ABYSS_LIB} STATIC ${ABYSS_SRC}) add_library(${ABYSS_LIB} STATIC ${ABYSS_SRC})
endif(USE_LIBABYSS) endif(USE_LIBABYSS)
add_subdirectory(crypto) add_subdirectory(crypto)
@ -337,7 +334,6 @@ if(USE_LIBABYSS)
add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp llarp/win32/abyss.rc) add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp llarp/win32/abyss.rc)
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32) target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32)
endif(NOT WIN32) endif(NOT WIN32)
target_include_directories(${UTIL_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include")
target_include_directories(${ABYSS_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include") target_include_directories(${ABYSS_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include")
target_include_directories(${ABYSS_EXE} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include") target_include_directories(${ABYSS_EXE} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include")
# for freebsd # for freebsd

@ -1,8 +1,8 @@
#ifndef __ABYSS_CLIENT_HPP__ #ifndef __ABYSS_CLIENT_HPP__
#define __ABYSS_CLIENT_HPP__ #define __ABYSS_CLIENT_HPP__
#include <abyss/json.hpp>
#include <ev/ev.h> #include <ev/ev.h>
#include <util/json.hpp>
#include <util/string_view.hpp> #include <util/string_view.hpp>
#include <deque> #include <deque>
@ -18,8 +18,8 @@ namespace abyss
namespace http namespace http
{ {
using RPC_Method_t = std::string; using RPC_Method_t = std::string;
using RPC_Params = json::Value; using RPC_Params = llarp::json::Value;
using RPC_Response = json::Document; using RPC_Response = llarp::json::Document;
using Headers_t = std::unordered_multimap< std::string, std::string >; using Headers_t = std::unordered_multimap< std::string, std::string >;
struct ConnImpl; struct ConnImpl;

@ -1,6 +1,6 @@
#ifndef __ABYSS_HTTP_HPP__ #ifndef __ABYSS_HTTP_HPP__
#define __ABYSS_HTTP_HPP__ #define __ABYSS_HTTP_HPP__
#include <abyss/json.hpp> #include <util/json.hpp>
#include <util/string_view.hpp> #include <util/string_view.hpp>
#include <string> #include <string>
@ -20,16 +20,18 @@ namespace abyss
struct HeaderReader struct HeaderReader
{ {
using string_view = llarp::string_view;
RequestHeader Header; RequestHeader Header;
virtual ~HeaderReader() virtual ~HeaderReader()
{ {
} }
bool bool
ProcessHeaderLine(abyss::string_view line, bool& done); ProcessHeaderLine(string_view line, bool& done);
virtual bool virtual bool
ShouldProcessHeader(const abyss::string_view& line) const = 0; ShouldProcessHeader(const string_view& line) const = 0;
}; };
} // namespace http } // namespace http

@ -1,8 +1,8 @@
#ifndef __ABYSS_SERVER_HPP__ #ifndef __ABYSS_SERVER_HPP__
#define __ABYSS_SERVER_HPP__ #define __ABYSS_SERVER_HPP__
#include <abyss/json.hpp>
#include <ev/ev.h> #include <ev/ev.h>
#include <util/json.hpp>
#include <util/logic.hpp> #include <util/logic.hpp>
#include <util/string_view.hpp> #include <util/string_view.hpp>
#include <util/time.hpp> #include <util/time.hpp>
@ -21,8 +21,8 @@ namespace abyss
struct IRPCHandler struct IRPCHandler
{ {
using Method_t = std::string; using Method_t = std::string;
using Params = json::Value; using Params = llarp::json::Value;
using Response = json::Writer; using Response = llarp::json::Writer;
IRPCHandler(ConnImpl* impl); IRPCHandler(ConnImpl* impl);

@ -32,7 +32,7 @@ struct DemoCall : public abyss::http::IRPCClientHandler
bool bool
HandleResponse(abyss::http::RPC_Response resp) override HandleResponse(abyss::http::RPC_Response resp) override
{ {
abyss::json::ToString(resp, std::cout); llarp::json::ToString(resp, std::cout);
return true; return true;
} }
@ -60,7 +60,7 @@ struct DemoClient : public abyss::http::JSONRPC
void void
DoDemoRequest() DoDemoRequest()
{ {
abyss::json::Value params; llarp::json::Value params;
params.SetObject(); params.SetObject();
QueueRPC("test", std::move(params), QueueRPC("test", std::move(params),
std::bind(&DemoClient::NewConn, this, std::placeholders::_1)); std::bind(&DemoClient::NewConn, this, std::placeholders::_1));

@ -8,6 +8,7 @@ namespace abyss
{ {
namespace http namespace http
{ {
namespace json = llarp::json;
struct ConnImpl : HeaderReader struct ConnImpl : HeaderReader
{ {
// big // big
@ -16,7 +17,7 @@ namespace abyss
json::Document m_RequestBody; json::Document m_RequestBody;
Headers_t m_SendHeaders; Headers_t m_SendHeaders;
IRPCClientHandler* handler; IRPCClientHandler* handler;
std::unique_ptr< abyss::json::IParser > m_BodyParser; std::unique_ptr< json::IParser > m_BodyParser;
json::Document m_Response; json::Document m_Response;
enum State enum State
@ -94,7 +95,7 @@ namespace abyss
} }
bool bool
ShouldProcessHeader(const abyss::string_view& name) const ShouldProcessHeader(const llarp::string_view& name) const
{ {
return name == "content-length" || name == "content-type"; return name == "content-length" || name == "content-type";
} }
@ -123,7 +124,7 @@ namespace abyss
if(contentSize > MAX_BODY_SIZE) if(contentSize > MAX_BODY_SIZE)
return false; return false;
m_BodyParser.reset(abyss::json::MakeParser(contentSize)); m_BodyParser.reset(json::MakeParser(contentSize));
} }
if(m_BodyParser && m_BodyParser->FeedData(buf, sz)) if(m_BodyParser && m_BodyParser->FeedData(buf, sz))
{ {

@ -14,6 +14,7 @@ namespace abyss
{ {
namespace httpd namespace httpd
{ {
namespace json = llarp::json;
struct ConnImpl : abyss::http::HeaderReader struct ConnImpl : abyss::http::HeaderReader
{ {
llarp_tcp_conn* _conn; llarp_tcp_conn* _conn;
@ -22,11 +23,11 @@ namespace abyss
llarp_time_t m_LastActive; llarp_time_t m_LastActive;
llarp_time_t m_ReadTimeout; llarp_time_t m_ReadTimeout;
bool m_Bad; bool m_Bad;
std::unique_ptr< abyss::json::IParser > m_BodyParser; std::unique_ptr< json::IParser > m_BodyParser;
json::Document m_Request; json::Document m_Request;
std::stringstream m_ResponseBuffer; std::stringstream m_ResponseBuffer;
abyss::json::Stream m_ResponseStream; json::Stream m_ResponseStream;
abyss::json::Writer m_Response; json::Writer m_Response;
enum HTTPState enum HTTPState
{ {
@ -167,7 +168,7 @@ namespace abyss
} }
else else
{ {
m_BodyParser.reset(abyss::json::MakeParser(contentLength)); m_BodyParser.reset(json::MakeParser(contentLength));
} }
} }
if(!m_BodyParser->FeedData(buf, sz)) if(!m_BodyParser->FeedData(buf, sz))

@ -13,6 +13,7 @@ set(LIB_UTIL_SRC
util/endian.cpp util/endian.cpp
util/fs.cpp util/fs.cpp
util/ini.cpp util/ini.cpp
util/json.cpp
util/logger.cpp util/logger.cpp
util/logic.cpp util/logic.cpp
util/mem.cpp util/mem.cpp
@ -78,7 +79,6 @@ if(WIN32)
target_link_libraries(${PLATFORM_LIB} PUBLIC iphlpapi) target_link_libraries(${PLATFORM_LIB} PUBLIC iphlpapi)
endif() endif()
set(DNSLIB_SRC set(DNSLIB_SRC
dns/dotlokilookup.cpp dns/dotlokilookup.cpp
dns/dns.cpp dns/dns.cpp
@ -206,8 +206,6 @@ target_link_libraries(${STATIC_LIB} PUBLIC ${PLATFORM_LIB} ${UTIL_LIB} ${CRYPTOG
if(USE_LIBABYSS) if(USE_LIBABYSS)
add_definitions(-DUSE_ABYSS=1) add_definitions(-DUSE_ABYSS=1)
target_link_libraries(${UTIL_LIB} PUBLIC ${ABYSS_LIB})
target_link_libraries(${PLATFORM_LIB} PUBLIC ${ABYSS_LIB})
target_link_libraries(${STATIC_LIB} PUBLIC ${ABYSS_LIB}) target_link_libraries(${STATIC_LIB} PUBLIC ${ABYSS_LIB})
endif() endif()

@ -28,6 +28,13 @@ namespace llarp
const AddressInfo &ai); const AddressInfo &ai);
~Session(); ~Session();
util::StatusObject
ExtractStatus() const override
{
// TODO: fill me in.
return {};
}
void void
PumpIO(); PumpIO();

@ -29,7 +29,7 @@ namespace llarp
} }
virtual bool virtual bool
HandleJSONResult(const ::abyss::json::Value& val) = 0; HandleJSONResult(const json::Value& val) = 0;
bool bool
HandleResponse(::abyss::http::RPC_Response response) HandleResponse(::abyss::http::RPC_Response response)
@ -69,7 +69,7 @@ namespace llarp
} }
bool bool
HandleJSONResult(const ::abyss::json::Value& result) override HandleJSONResult(const json::Value& result) override
{ {
PubkeyList_t keys; PubkeyList_t keys;
if(!result.IsObject()) if(!result.IsObject())
@ -153,7 +153,7 @@ namespace llarp
AsyncUpdatePubkeyList() AsyncUpdatePubkeyList()
{ {
LogInfo("Updating service node list"); LogInfo("Updating service node list");
::abyss::json::Value params; json::Value params;
params.SetObject(); params.SetObject();
QueueRPC("get_all_service_nodes_keys", std::move(params), QueueRPC("get_all_service_nodes_keys", std::move(params),
std::bind(&CallerImpl::NewAsyncUpdatePubkeyListConn, this, std::bind(&CallerImpl::NewAsyncUpdatePubkeyListConn, this,

@ -1,11 +1,11 @@
#include <abyss/json.hpp> #include <util/json.hpp>
#include <util/string_view.hpp> #include <util/string_view.hpp>
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <vector> #include <vector>
namespace abyss namespace llarp
{ {
namespace json namespace json
{ {
@ -56,4 +56,4 @@ namespace abyss
} }
} // namespace json } // namespace json
} // namespace abyss } // namespace llarp

@ -1,12 +1,13 @@
#ifndef __ABYSS_JSON_JSON_HPP #ifndef LLARP_UTIL_JSON_HPP
#define __ABYSS_JSON_JSON_HPP #define LLARP_UTIL_JSON_HPP
#include <memory>
#include <rapidjson/document.h> #include <rapidjson/document.h>
#include <rapidjson/writer.h> #include <rapidjson/writer.h>
#include <memory>
#include <iostream> #include <iostream>
namespace abyss namespace llarp
{ {
namespace json namespace json
{ {
@ -116,6 +117,6 @@ namespace abyss
ToString(const json::Document& obj, std::ostream& out); ToString(const json::Document& obj, std::ostream& out);
} // namespace json } // namespace json
} // namespace abyss } // namespace llarp
#endif #endif

@ -1,7 +1,7 @@
#ifndef LLARP_UTIL_STATUS_HPP #ifndef LLARP_UTIL_STATUS_HPP
#define LLARP_UTIL_STATUS_HPP #define LLARP_UTIL_STATUS_HPP
#ifdef USE_ABYSS #ifdef USE_ABYSS
#include <abyss/json.hpp> #include <util/json.hpp>
#endif #endif
#include <util/string_view.hpp> #include <util/string_view.hpp>
#include <vector> #include <vector>
@ -14,8 +14,8 @@ namespace llarp
namespace util namespace util
{ {
#ifdef USE_ABYSS #ifdef USE_ABYSS
using StatusObject_Impl = ::abyss::json::Document; using StatusObject_Impl = json::Document;
using Value_t = ::abyss::json::Value; using Value_t = json::Value;
#else #else
struct StatusObject_Impl struct StatusObject_Impl
{ {
@ -27,7 +27,7 @@ namespace llarp
struct StatusObject struct StatusObject
{ {
using String_t = llarp::string_view; using String_t = string_view;
using Variant = absl::variant< uint64_t, std::string, bool, StatusObject, using Variant = absl::variant< uint64_t, std::string, bool, StatusObject,
std::vector< std::string >, std::vector< std::string >,
std::vector< StatusObject > >; std::vector< StatusObject > >;

@ -200,7 +200,7 @@ struct AbyssTest : public AbyssTestBase,
TEST_F(AbyssTest, TestClientAndServer) TEST_F(AbyssTest, TestClientAndServer)
{ {
Start(); Start();
abyss::json::Value params; llarp::json::Value params;
params.SetObject(); params.SetObject();
QueueRPC(method, std::move(params), QueueRPC(method, std::move(params),
std::bind(&AbyssTest::NewConn, this, std::placeholders::_1)); std::bind(&AbyssTest::NewConn, this, std::placeholders::_1));

Loading…
Cancel
Save