diff --git a/CMakeLists.txt b/CMakeLists.txt index 47b2f4b37..368363875 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 2.8.10) set(PROJECT_NAME lokinet) project(${PROJECT_NAME} C CXX ASM) +option(USE_LIBABYSS "enable libabyss" OFF) + macro(add_cflags) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARGN}") endmacro(add_cflags) @@ -486,24 +488,27 @@ include_directories(llarp) set(RC_EXE rcutil) set(DNS_EXE dns) -set(ABYSS libabyss) -set(ABYSS_LIB abyss) +set(ALL_SRC ${CLIENT_SRC} ${RC_SRC} ${EXE_SRC} ${DNS_SRC} ${LIB_PLATFORM_SRC} ${LIB_SRC} ${TEST_SRC}) -set(ABYSS_EXE ${ABYSS_LIB}-main) +if(USE_LIBABYSS) + set(ABYSS libabyss) -include_directories(${ABYSS}/include) + set(ABYSS_LIB abyss) -set(ABYSS_SRC - ${ABYSS}/src/http.cpp - ${ABYSS}/src/client.cpp - ${ABYSS}/src/server.cpp - ${ABYSS}/src/json.cpp) + set(ABYSS_EXE ${ABYSS_LIB}-main) -add_library(${ABYSS_LIB} ${ABYSS_SRC}) + include_directories(${ABYSS}/include) + set(ABYSS_SRC + ${ABYSS}/src/http.cpp + ${ABYSS}/src/client.cpp + ${ABYSS}/src/server.cpp + ${ABYSS}/src/json.cpp) -set(ALL_SRC ${CLIENT_SRC} ${RC_SRC} ${EXE_SRC} ${DNS_SRC} ${LIB_PLATFORM_SRC} ${LIB_SRC} ${TEST_SRC} ${ABYSS_SRC} ${ABYSS}/main.cpp) + add_library(${ABYSS_LIB} ${ABYSS_SRC}) + set(ALL_SRC ${ALL_SRC} ${ABYSS_SRC} ${ABYSS}/main.cpp) +endif() foreach(F ${ALL_SRC}) set_source_files_properties(${F} PROPERTIES COMPILE_FLAGS -DLOG_TAG=\\\"${F}\\\") @@ -517,8 +522,6 @@ else() add_executable(${RC_EXE} ${RC_SRC}) add_executable(${EXE} ${EXE_SRC}) add_executable(${CLIENT_EXE} ${CLIENT_SRC}) -add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp) - add_executable(${DNS_EXE} ${DNS_SRC}) add_subdirectory(${GTEST_DIR}) include_directories(${GTEST_DIR}/include ${GTEST_DIR}) @@ -528,12 +531,15 @@ add_executable(${TEST_EXE} ${TEST_SRC}) if(WITH_STATIC) add_library(${STATIC_LIB} STATIC ${LIB_SRC}) add_library(${PLATFORM_LIB} STATIC ${LIB_PLATFORM_SRC}) - target_link_libraries(${PLATFORM_LIB} ${THREAD_LIB} ${ABYSS_LIB}) + if(USE_LIBABYSS) + target_link_libraries(${PLATFORM_LIB} ${THREAD_LIB} ${ABYSS_LIB}) + else() + target_link_libraries(${PLATFORM_LIB} ${THREAD_LIB}) + endif() if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") target_link_libraries(${PLATFORM_LIB} -lcap) endif() target_link_libraries(${STATIC_LIB} ${CRYPTOGRAPHY_LIB} ${LIBS} ${PLATFORM_LIB}) - target_link_libraries(${ABYSS_EXE} ${STATIC_LIB}) if(NOT WITH_SHARED) target_link_libraries(${EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${PLATFORM_LIB}) diff --git a/Makefile b/Makefile index 3c337c7d5..74f4fbf66 100644 --- a/Makefile +++ b/Makefile @@ -29,9 +29,11 @@ TESTNET_CLIENTS ?= 50 TESTNET_SERVERS ?= 50 TESTNET_DEBUG ?= 0 +JSONRPC = OFF + BUILD_ROOT = $(REPO)/build -CONFIG_CMD = $(shell /bin/echo -n "cd '$(BUILD_ROOT)' && " ; /bin/echo -n "cmake '$(REPO)'") +CONFIG_CMD = $(shell /bin/echo -n "cd '$(BUILD_ROOT)' && " ; /bin/echo -n "cmake -DUSE_LIBABYSS=$(JSONRPC) '$(REPO)'") TARGETS = $(REPO)/lokinet SIGS = $(TARGETS:=.sig) diff --git a/daemon/main.cpp b/daemon/main.cpp index 0be488849..f1ef79f73 100644 --- a/daemon/main.cpp +++ b/daemon/main.cpp @@ -69,9 +69,9 @@ main(int argc, char *argv[]) int opt = 0; bool genconfigOnly = false; - bool asRouter = true; + bool asRouter = false; bool overWrite = false; - while((opt = getopt(argc, argv, "hgcf")) != -1) + while((opt = getopt(argc, argv, "hgcfr")) != -1) { switch(opt) { @@ -82,7 +82,13 @@ main(int argc, char *argv[]) break; case 'c': genconfigOnly = true; - asRouter = false; + break; + case 'r': +#ifdef _WIN32 + llarp::LogError("we will not run as relay because you're running windows, install a real operating system please"); + return 1; +#endif + asRouter = true; break; case 'f': overWrite = true; diff --git a/libabyss/src/json.cpp b/libabyss/src/json.cpp index 46e6169d8..5b6069b0e 100644 --- a/libabyss/src/json.cpp +++ b/libabyss/src/json.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace abyss { @@ -56,4 +57,4 @@ namespace abyss } } // namespace json -} // namespace abyss \ No newline at end of file +} // namespace abyss diff --git a/llarp/ev.cpp b/llarp/ev.cpp index 53ebb4f46..ae5a53a4a 100644 --- a/llarp/ev.cpp +++ b/llarp/ev.cpp @@ -222,4 +222,36 @@ namespace llarp delete connimpl; return -1; } -} // namespace llarp \ No newline at end of file + +} // namespace llarp + + +llarp::ev_io* +llarp_ev_loop::bind_tcp(llarp_tcp_acceptor* tcp, const sockaddr* bindaddr) +{ + int fd = ::socket(bindaddr->sa_family, SOCK_STREAM, 0); + if(fd == -1) + return nullptr; + socklen_t sz = sizeof(sockaddr_in); + if(bindaddr->sa_family == AF_INET6) + { + sz = sizeof(sockaddr_in6); + } + else if(bindaddr->sa_family == AF_UNIX) + { + sz = sizeof(sockaddr_un); + } + if(::bind(fd, bindaddr, sz) == -1) + { + ::close(fd); + return nullptr; + } + if(::listen(fd, 5) == -1) + { + ::close(fd); + return nullptr; + } + llarp::ev_io* serv = new llarp::tcp_serv(this, fd, tcp); + tcp->impl = serv; + return serv; +} diff --git a/llarp/ev.hpp b/llarp/ev.hpp index 921f7e910..8c04f0030 100644 --- a/llarp/ev.hpp +++ b/llarp/ev.hpp @@ -236,7 +236,11 @@ namespace llarp { if(_shouldClose) return -1; + #ifdef __linux__ return ::send(fd, buf, sz, MSG_NOSIGNAL); // ignore sigpipe + #else + return ::send(fd, buf, sz, 0 ); + #endif } int @@ -335,8 +339,8 @@ struct llarp_ev_loop virtual llarp::ev_io* create_tun(llarp_tun_io* tun) = 0; - virtual llarp::ev_io* - bind_tcp(llarp_tcp_acceptor* tcp, const sockaddr* addr) = 0; + llarp::ev_io* + bind_tcp(llarp_tcp_acceptor* tcp, const sockaddr* addr); /// register event listener virtual bool diff --git a/llarp/ev_epoll.hpp b/llarp/ev_epoll.hpp index 6e247527f..d6f1f3869 100644 --- a/llarp/ev_epoll.hpp +++ b/llarp/ev_epoll.hpp @@ -306,36 +306,6 @@ struct llarp_epoll_loop : public llarp_ev_loop return epoll_ctl(epollfd, EPOLL_CTL_DEL, ev->fd, nullptr) != -1; } - llarp::ev_io* - bind_tcp(llarp_tcp_acceptor* tcp, const sockaddr* bindaddr) - { - int fd = ::socket(bindaddr->sa_family, SOCK_STREAM, 0); - if(fd == -1) - return nullptr; - socklen_t sz = sizeof(sockaddr_in); - if(bindaddr->sa_family == AF_INET6) - { - sz = sizeof(sockaddr_in6); - } - else if(bindaddr->sa_family == AF_UNIX) - { - sz = sizeof(sockaddr_un); - } - if(::bind(fd, bindaddr, sz) == -1) - { - ::close(fd); - return nullptr; - } - if(::listen(fd, 5) == -1) - { - ::close(fd); - return nullptr; - } - llarp::ev_io* serv = new llarp::tcp_serv(this, fd, tcp); - tcp->impl = serv; - return serv; - } - llarp::ev_io* create_tun(llarp_tun_io* tun) { diff --git a/llarp/ev_kqueue.hpp b/llarp/ev_kqueue.hpp index f225b383e..c21a72ad5 100644 --- a/llarp/ev_kqueue.hpp +++ b/llarp/ev_kqueue.hpp @@ -3,6 +3,8 @@ #include #include +#include + #if __FreeBSD__ || __OpenBSD__ || __NetBSD__ || (__APPLE__ && __MACH__) // kqueue / kevent #include diff --git a/llarp/rpc.cpp b/llarp/rpc.cpp index e0644cfa5..8a0b1da74 100644 --- a/llarp/rpc.cpp +++ b/llarp/rpc.cpp @@ -1,12 +1,14 @@ #include -#include #include "router.hpp" - +#ifdef USE_ABYSS +#include +#endif namespace llarp { namespace rpc { +#ifdef USE_ABYSS struct Handler : public ::abyss::http::IRPCHandler { llarp_router* router; @@ -103,7 +105,18 @@ namespace llarp (const sockaddr*)&saddr); } }; +#else + struct ServerImpl + { + ServerImpl(llarp_router * r) {}; + bool Start(const std::string & addr) + { + return true; + } + }; +#endif + Server::Server(llarp_router* r) : m_Impl(new ServerImpl(r)) { } diff --git a/readme.md b/readme.md index 5fd69fc5a..2d99282d5 100644 --- a/readme.md +++ b/readme.md @@ -15,24 +15,32 @@ Build requirements: * GNU Make * CMake * C++ 17 capable C++ compiler -* rapidjson +* rapidjson (if enabling jsonrpc server) To build: $ sudo apt install build-essential cmake git libcap-dev wget rapidjson-dev $ git clone https://github.com/loki-project/loki-network $ cd loki-network - $ make -j8 + $ make -j8 JSONRPC=ON $ sudo make install ## Running **DO NOT RUN AS ROOT**, run as normal user. +to run as client: + $ lokinet -g $ lokinet-bootstrap $ lokinet +to run as relay: + + $ lokinet -r -g + $ lokinet-bootstrap + $ lokinet + ## Usage see the [documentation](https://loki-project.github.io/loki-docs/Lokinet/LokinetOverview/) on how to get started.