diff --git a/CMakeLists.txt b/CMakeLists.txt index 0be0b1a9d..34ba8046b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/libabyss/include/abyss/client.hpp b/libabyss/include/abyss/client.hpp index 8a6bd3aea..302418fd2 100644 --- a/libabyss/include/abyss/client.hpp +++ b/libabyss/include/abyss/client.hpp @@ -1,8 +1,8 @@ #ifndef __ABYSS_CLIENT_HPP__ #define __ABYSS_CLIENT_HPP__ -#include #include +#include #include #include @@ -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; diff --git a/libabyss/include/abyss/http.hpp b/libabyss/include/abyss/http.hpp index 2298ba782..0ac3abfb5 100644 --- a/libabyss/include/abyss/http.hpp +++ b/libabyss/include/abyss/http.hpp @@ -1,6 +1,6 @@ #ifndef __ABYSS_HTTP_HPP__ #define __ABYSS_HTTP_HPP__ -#include +#include #include #include @@ -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 diff --git a/libabyss/include/abyss/server.hpp b/libabyss/include/abyss/server.hpp index f6891bb2a..5a3046afa 100644 --- a/libabyss/include/abyss/server.hpp +++ b/libabyss/include/abyss/server.hpp @@ -1,8 +1,8 @@ #ifndef __ABYSS_SERVER_HPP__ #define __ABYSS_SERVER_HPP__ -#include #include +#include #include #include #include @@ -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); diff --git a/libabyss/main.cpp b/libabyss/main.cpp index 3ef0faad3..5d4d174d1 100644 --- a/libabyss/main.cpp +++ b/libabyss/main.cpp @@ -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)); diff --git a/libabyss/src/client.cpp b/libabyss/src/client.cpp index f291ee621..a8bb99d2d 100644 --- a/libabyss/src/client.cpp +++ b/libabyss/src/client.cpp @@ -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)) { diff --git a/libabyss/src/server.cpp b/libabyss/src/server.cpp index cdfa62cd4..75a7c757b 100644 --- a/libabyss/src/server.cpp +++ b/libabyss/src/server.cpp @@ -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)) diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index 043bf1882..c2122a09c 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -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() diff --git a/llarp/link/iwp_internal.hpp b/llarp/link/iwp_internal.hpp index 96dfb7a68..579f8ed99 100644 --- a/llarp/link/iwp_internal.hpp +++ b/llarp/link/iwp_internal.hpp @@ -28,6 +28,13 @@ namespace llarp const AddressInfo &ai); ~Session(); + util::StatusObject + ExtractStatus() const override + { + // TODO: fill me in. + return {}; + } + void PumpIO(); diff --git a/llarp/rpc/rpc.cpp b/llarp/rpc/rpc.cpp index 134f6cca3..19f29702e 100644 --- a/llarp/rpc/rpc.cpp +++ b/llarp/rpc/rpc.cpp @@ -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, diff --git a/libabyss/src/json.cpp b/llarp/util/json.cpp similarity index 94% rename from libabyss/src/json.cpp rename to llarp/util/json.cpp index 8bfc8d070..36882971d 100644 --- a/libabyss/src/json.cpp +++ b/llarp/util/json.cpp @@ -1,11 +1,11 @@ -#include +#include #include #include #include #include -namespace abyss +namespace llarp { namespace json { @@ -56,4 +56,4 @@ namespace abyss } } // namespace json -} // namespace abyss +} // namespace llarp diff --git a/libabyss/include/abyss/json.hpp b/llarp/util/json.hpp similarity index 95% rename from libabyss/include/abyss/json.hpp rename to llarp/util/json.hpp index 022e6e7f3..0bfa1b2e9 100644 --- a/libabyss/include/abyss/json.hpp +++ b/llarp/util/json.hpp @@ -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 #include #include + +#include #include -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 diff --git a/llarp/util/status.hpp b/llarp/util/status.hpp index 12ed47671..02e06ea42 100644 --- a/llarp/util/status.hpp +++ b/llarp/util/status.hpp @@ -1,7 +1,7 @@ #ifndef LLARP_UTIL_STATUS_HPP #define LLARP_UTIL_STATUS_HPP #ifdef USE_ABYSS -#include +#include #endif #include #include @@ -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 > >; diff --git a/test/test_libabyss.cpp b/test/test_libabyss.cpp index ae36de93f..8eff239f3 100644 --- a/test/test_libabyss.cpp +++ b/test/test_libabyss.cpp @@ -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));