Move abyss/json to llarp/util/json

pull/315/head
Michael 5 years ago
parent 7df2a227d3
commit a0125ffe86
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

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

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

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

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

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

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

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

@ -13,6 +13,7 @@ set(LIB_UTIL_SRC
util/endian.cpp
util/fs.cpp
util/ini.cpp
util/json.cpp
util/logger.cpp
util/logic.cpp
util/mem.cpp
@ -78,7 +79,6 @@ if(WIN32)
target_link_libraries(${PLATFORM_LIB} PUBLIC iphlpapi)
endif()
set(DNSLIB_SRC
dns/dotlokilookup.cpp
dns/dns.cpp
@ -206,8 +206,6 @@ target_link_libraries(${STATIC_LIB} PUBLIC ${PLATFORM_LIB} ${UTIL_LIB} ${CRYPTOG
if(USE_LIBABYSS)
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})
endif()

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

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

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

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

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

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

Loading…
Cancel
Save