mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-19 09:25:28 +00:00
Merge pull request #857 from michael-loki/rcutil_curl
Add rpc call to get current addresses for our node
This commit is contained in:
commit
2cf10450c5
@ -133,6 +133,7 @@ addons:
|
||||
- gcc-mingw-w64-base
|
||||
- git
|
||||
- libcap-dev
|
||||
- libcurl4-openssl-dev
|
||||
- libuv1-dev
|
||||
- mingw-w64 mingw-w64-common
|
||||
- ninja-build
|
||||
@ -140,6 +141,7 @@ addons:
|
||||
packages:
|
||||
- ccache
|
||||
- cmake
|
||||
- curl
|
||||
- libuv
|
||||
- llvm
|
||||
- make
|
||||
@ -148,7 +150,7 @@ addons:
|
||||
|
||||
before_install:
|
||||
- if [ "$TRAVIS_OS_NAME" == "windows" ]; then
|
||||
choco install make ninja;
|
||||
choco install curl make ninja;
|
||||
choco upgrade cmake.install;
|
||||
export CC="/c/Program Files/LLVM/bin/clang-cl";
|
||||
export CXX="/c/Program Files/LLVM/bin/clang-cl";
|
||||
|
@ -1,5 +1,7 @@
|
||||
set(EXE lokinet)
|
||||
set(EXE_SRC main.cpp)
|
||||
set(CTL lokinetctl)
|
||||
set(CTL_SRC lokinetctl.cpp)
|
||||
|
||||
if(TRACY_ROOT)
|
||||
list(APPEND EXE_SRC ${TRACY_ROOT}/TracyClient.cpp)
|
||||
@ -12,22 +14,19 @@ if(SHADOW)
|
||||
target_link_libraries(${LOKINET_SHADOW} ${LOKINET_SHADOW_LIBS})
|
||||
target_include_directories(${LOKINET_SHADOW} PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/llarp ${PROJECT_SOURCE_DIR}/crypto/include)
|
||||
else()
|
||||
if(NOT WIN32)
|
||||
if(WIN32 AND NOT MSVC_VERSION)
|
||||
list(APPEND ${EXE_SRC} llarp/win32/version.rc)
|
||||
list(APPEND ${CTL_SRC} llarp/win32/version.rc)
|
||||
endif()
|
||||
|
||||
add_executable(${EXE} ${EXE_SRC})
|
||||
add_executable(lokinet-rcutil rcutil.cpp)
|
||||
elseif(NOT MSVC_VERSION)
|
||||
add_executable(${EXE} ${EXE_SRC} llarp/win32/version.rc)
|
||||
add_executable(lokinet-rcutil rcutil.cpp llarp/win32/version.rc)
|
||||
else()
|
||||
add_executable(${EXE} ${EXE_SRC})
|
||||
add_executable(lokinet-rcutil rcutil.cpp)
|
||||
endif(NOT WIN32)
|
||||
add_executable(${CTL} ${CTL_SRC})
|
||||
|
||||
add_log_tag(${EXE})
|
||||
add_log_tag(lokinet-rcutil)
|
||||
add_log_tag(${CTL})
|
||||
|
||||
install(TARGETS ${EXE} RUNTIME DESTINATION bin)
|
||||
install(TARGETS lokinet-rcutil RUNTIME DESTINATION bin)
|
||||
install(TARGETS ${CTL} RUNTIME DESTINATION bin)
|
||||
if(WIN32)
|
||||
install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap.exe DESTINATION bin)
|
||||
else()
|
||||
@ -38,8 +37,17 @@ else()
|
||||
install(CODE "execute_process(COMMAND setcap cap_net_admin,cap_net_bind_service=+eip ${CMAKE_INSTALL_PREFIX}/bin/lokinet)")
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
||||
target_link_directories(${EXE} PRIVATE /usr/local/lib)
|
||||
target_link_directories(lokinet-rcutil PRIVATE /usr/local/lib)
|
||||
target_link_directories(${CTL} PRIVATE /usr/local/lib)
|
||||
endif()
|
||||
target_link_libraries(${EXE} PUBLIC ${EXE_LIBS} ${LIBS})
|
||||
target_link_libraries(lokinet-rcutil PUBLIC ${EXE_LIBS} ${LIBS})
|
||||
target_link_libraries(${CTL} PUBLIC ${EXE_LIBS} ${LIBS})
|
||||
|
||||
find_package(CURL)
|
||||
|
||||
if(CURL_FOUND)
|
||||
target_include_directories(${CTL} PRIVATE ${CURL_INCLUDE_DIRS})
|
||||
target_link_libraries(${CTL} PRIVATE ${CURL_LIBRARIES})
|
||||
target_compile_definitions(${CTL} PRIVATE -DWITH_CURL=1)
|
||||
endif(CURL_FOUND)
|
||||
|
||||
endif(SHADOW)
|
||||
|
301
daemon/dns.cpp
301
daemon/dns.cpp
@ -1,301 +0,0 @@
|
||||
#include <config.hpp>
|
||||
#include <dns_dotlokilookup.hpp>
|
||||
#include <dns_iptracker.hpp>
|
||||
#include <dnsd.hpp>
|
||||
#include <llarp.h>
|
||||
#include <threading.hpp> // for multithreaded version (multiplatorm)
|
||||
|
||||
#include <signal.h> // Linux needs this for SIGINT
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define uint UINT
|
||||
#endif
|
||||
|
||||
#if(__FreeBSD__) || (__OpenBSD__) || (__NetBSD__)
|
||||
#include <pthread_np.h>
|
||||
#endif
|
||||
|
||||
// CHECK: is multiprocess still a thing?
|
||||
#ifndef TESTNET
|
||||
#define TESTNET 0
|
||||
#endif
|
||||
|
||||
struct llarp_main *ctx = 0;
|
||||
bool done = false;
|
||||
|
||||
void
|
||||
handle_signal(int sig)
|
||||
{
|
||||
printf("got SIGINT\n");
|
||||
done = true;
|
||||
// if using router, signal it
|
||||
if(ctx)
|
||||
llarp_main_signal(ctx, sig);
|
||||
}
|
||||
|
||||
struct dns_relay_config
|
||||
{
|
||||
std::string upstream_host;
|
||||
uint16_t upstream_port;
|
||||
|
||||
void
|
||||
dns_iter_config(const char *section, const char *key, const char *val)
|
||||
{
|
||||
if(!strcmp(section, "dns"))
|
||||
{
|
||||
if(!strcmp(key, "upstream-server"))
|
||||
{
|
||||
upstream_host = strdup(val);
|
||||
llarp::LogDebug("Config file setting dns server to ", upstream_host);
|
||||
}
|
||||
if(!strcmp(key, "upstream-port"))
|
||||
{
|
||||
upstream_port = atoi(val);
|
||||
llarp::LogDebug("Config file setting dns server port to ",
|
||||
upstream_port);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int code = 1;
|
||||
char cwd[1024];
|
||||
char *ptr = getcwd(cwd, sizeof(cwd));
|
||||
llarp::LogInfo("Starting up server at ", ptr);
|
||||
|
||||
const char *conffname = handleBaseCmdLineArgs(argc, argv);
|
||||
dns_relay_config dnsr_config;
|
||||
dnsr_config.upstream_host = "8.8.8.8";
|
||||
dnsr_config.upstream_port = 53;
|
||||
llarp::Config config_reader;
|
||||
|
||||
if(config_reader.load(conffname))
|
||||
{
|
||||
llarp::LogError("failed to load config file ", conffname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
using namespace std::placeholders;
|
||||
config_reader.visit(
|
||||
std::bind(&dns_relay_config::dns_iter_config, &dnsr_config, _1, _2, _3));
|
||||
llarp::LogInfo("config [", conffname, "] loaded");
|
||||
|
||||
const uint16_t server_port = 53;
|
||||
|
||||
dns_iptracker_init();
|
||||
|
||||
// llarp::SetLogLevel(llarp::eLogDebug);
|
||||
|
||||
bool enableDLL = false;
|
||||
bool useLlarp = true;
|
||||
|
||||
if(enableDLL)
|
||||
{
|
||||
// libev version w/router context
|
||||
ctx = llarp_main_init(conffname, !TESTNET);
|
||||
if(!ctx)
|
||||
{
|
||||
llarp::LogError("Cant set up context");
|
||||
return 0;
|
||||
}
|
||||
llarp_main_setup(ctx);
|
||||
signal(SIGINT, handle_signal);
|
||||
|
||||
// we can't programmatic force a client
|
||||
// but we'll need to be one...
|
||||
|
||||
/*
|
||||
struct dnsd_context dnsd;
|
||||
llarp::Addr dnsd_sockaddr(127, 0, 0, 1, 53);
|
||||
llarp::Addr dnsc_sockaddr(dnsr_config.upstream_host,
|
||||
dnsr_config.upstream_port);
|
||||
// server_port, (const char *)dnsr_config.upstream_host.c_str(),
|
||||
// dnsr_config.upstream_port
|
||||
if(!llarp_main_init_dnsd(ctx, &dnsd, dnsd_sockaddr, dnsc_sockaddr))
|
||||
{
|
||||
llarp::LogError("Couldnt init dns daemon");
|
||||
}
|
||||
// Configure intercept
|
||||
dnsd.intercept = &llarp_dotlokilookup_handler;
|
||||
dotLokiLookup dll;
|
||||
*/
|
||||
// should be a function...
|
||||
// dll.tunEndpoint = main_router_getFirstTunEndpoint(ctx);
|
||||
// dll.ip_tracker = &g_dns_iptracker;
|
||||
/*
|
||||
llarp_main_init_dotLokiLookup(ctx, &dll);
|
||||
dnsd.user = &dll;
|
||||
|
||||
// check tun set up
|
||||
llarp_tun_io *tun = main_router_getRange(ctx);
|
||||
llarp::LogDebug("TunNetmask: ", tun->netmask);
|
||||
llarp::LogDebug("TunIfAddr: ", tun->ifaddr);
|
||||
|
||||
// configure dns_ip_tracker to use this
|
||||
// well our routes table should already be set up
|
||||
|
||||
// mark our TunIfAddr as used
|
||||
if(tun)
|
||||
{
|
||||
dll.user = tun;
|
||||
struct sockaddr_in addr;
|
||||
addr.sin_addr.s_addr = inet_addr(tun->ifaddr);
|
||||
addr.sin_family = AF_INET;
|
||||
|
||||
llarp::Addr tunIp(addr);
|
||||
llarp::LogDebug("llarp::TunIfAddr: ", tunIp);
|
||||
dns_iptracker_setup_dotLokiLookup(&dll, tunIp);
|
||||
dns_iptracker_setup(tunIp);
|
||||
}
|
||||
else
|
||||
{
|
||||
llarp::LogWarn("No tun interface, can't look up .loki");
|
||||
}
|
||||
*/
|
||||
|
||||
// run system and wait
|
||||
llarp_main_run(ctx);
|
||||
llarp_main_free(ctx);
|
||||
}
|
||||
else if(useLlarp)
|
||||
{
|
||||
// libev version
|
||||
llarp_ev_loop *netloop = nullptr;
|
||||
llarp_threadpool *worker = nullptr;
|
||||
llarp::Logic *logic = nullptr;
|
||||
|
||||
llarp_ev_loop_alloc(&netloop); // set up netio worker
|
||||
worker = llarp_init_same_process_threadpool();
|
||||
logic = new llarp::Logic(worker); // set up logic worker
|
||||
|
||||
// configure main netloop
|
||||
struct dnsd_context dnsd;
|
||||
llarp::Addr dnsd_sockaddr(127, 0, 0, 1, 53);
|
||||
llarp::Addr dnsc_sockaddr(dnsr_config.upstream_host,
|
||||
dnsr_config.upstream_port);
|
||||
llarp::LogInfo("dnsd_sockaddr init: ", dnsd_sockaddr);
|
||||
llarp::LogInfo("dnsc_sockaddr init: ", dnsc_sockaddr);
|
||||
if(!llarp_dnsd_init(&dnsd, logic, netloop, dnsd_sockaddr, dnsc_sockaddr))
|
||||
{
|
||||
// llarp::LogError("failed to initialize dns subsystem");
|
||||
llarp::LogError("Couldnt init dns daemon");
|
||||
return 0;
|
||||
}
|
||||
// Configure intercept
|
||||
dnsd.intercept = &llarp_dotlokilookup_handler;
|
||||
|
||||
llarp::LogInfo("singlethread start");
|
||||
llarp_ev_loop_run_single_process(netloop, worker, logic);
|
||||
llarp::LogInfo("singlethread end");
|
||||
|
||||
llarp_ev_loop_free(&netloop);
|
||||
}
|
||||
else
|
||||
{
|
||||
// need this for timer stuff
|
||||
llarp_threadpool *worker = llarp_init_same_process_threadpool();
|
||||
llarp::Logic *logic = new llarp::Logic(worker);
|
||||
|
||||
// configure main netloop
|
||||
struct dnsd_context dnsd;
|
||||
llarp::Addr dnsd_sockaddr(127, 0, 0, 1, 53);
|
||||
llarp::Addr dnsc_sockaddr(dnsr_config.upstream_host,
|
||||
dnsr_config.upstream_port);
|
||||
if(!llarp_dnsd_init(&dnsd, logic, nullptr, dnsd_sockaddr, dnsc_sockaddr))
|
||||
{
|
||||
// llarp::LogError("failed to initialize dns subsystem");
|
||||
llarp::LogError("Couldnt init dns daemon");
|
||||
return 0;
|
||||
}
|
||||
// Configure intercept
|
||||
dnsd.intercept = &llarp_dotlokilookup_handler;
|
||||
|
||||
struct sockaddr_in m_address;
|
||||
int m_sockfd;
|
||||
|
||||
#ifndef _WIN32
|
||||
m_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
#else
|
||||
m_sockfd =
|
||||
WSASocket(AF_INET, SOCK_DGRAM, 0, nullptr, 0, WSA_FLAG_OVERLAPPED);
|
||||
#endif
|
||||
m_address.sin_family = AF_INET;
|
||||
m_address.sin_addr.s_addr = INADDR_ANY;
|
||||
m_address.sin_port = htons(server_port);
|
||||
int rbind = bind(m_sockfd, (struct sockaddr *)&m_address,
|
||||
sizeof(struct sockaddr_in));
|
||||
|
||||
if(rbind != 0)
|
||||
{
|
||||
llarp::LogError("Could not bind: ", strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
const size_t BUFFER_SIZE = 1024;
|
||||
char buffer[BUFFER_SIZE]; // 1024 is buffer size
|
||||
struct sockaddr_in clientAddress;
|
||||
socklen_t addrLen = sizeof(struct sockaddr_in);
|
||||
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 100 * 1000; // 1 sec
|
||||
#ifndef _WIN32
|
||||
if(setsockopt(m_sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0)
|
||||
#else
|
||||
if(setsockopt(m_sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv,
|
||||
sizeof(tv))
|
||||
< 0)
|
||||
#endif
|
||||
{
|
||||
perror("Error");
|
||||
}
|
||||
|
||||
signal(SIGINT, handle_signal);
|
||||
while(!done)
|
||||
{
|
||||
// sigint quits after next packet
|
||||
int nbytes = recvfrom(m_sockfd, buffer, BUFFER_SIZE, 0,
|
||||
(struct sockaddr *)&clientAddress, &addrLen);
|
||||
if(nbytes == -1)
|
||||
continue;
|
||||
llarp::LogInfo("Received Bytes ", nbytes);
|
||||
|
||||
llarp_buffer_t lbuffer;
|
||||
lbuffer.base = (byte_t *)buffer;
|
||||
lbuffer.cur = lbuffer.base;
|
||||
lbuffer.sz = nbytes;
|
||||
|
||||
dns_msg_header hdr;
|
||||
if(!decode_hdr(&lbuffer, &hdr))
|
||||
{
|
||||
llarp::LogError("failed to decode dns header");
|
||||
continue;
|
||||
}
|
||||
|
||||
// if we sent this out, then there's an id
|
||||
struct dns_tracker *tracker = (struct dns_tracker *)dnsd.client.tracker;
|
||||
struct dnsc_answer_request *request =
|
||||
tracker->client_request[hdr.id].get();
|
||||
|
||||
if(request)
|
||||
{
|
||||
request->packet.header = hdr;
|
||||
generic_handle_dnsc_recvfrom(tracker->client_request[hdr.id].get(),
|
||||
lbuffer, &hdr);
|
||||
}
|
||||
else
|
||||
{
|
||||
llarp::LogWarn("Ignoring multiple responses on ID #", hdr.id);
|
||||
}
|
||||
|
||||
// raw_handle_recvfrom(&m_sockfd, (const struct sockaddr *)&clientAddress,
|
||||
// buffer, nbytes);
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
184
daemon/lokinetctl.cpp
Normal file
184
daemon/lokinetctl.cpp
Normal file
@ -0,0 +1,184 @@
|
||||
#include <config/config.hpp>
|
||||
#include <router_contact.hpp>
|
||||
#include <util/logging/logger.hpp>
|
||||
#include <util/logging/ostream_logger.hpp>
|
||||
|
||||
#include <absl/synchronization/mutex.h>
|
||||
#include <cxxopts.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifdef WITH_CURL
|
||||
#include <curl/curl.h>
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
bool
|
||||
dumpRc(const std::vector< std::string >& files)
|
||||
{
|
||||
nlohmann::json result;
|
||||
for(const auto& file : files)
|
||||
{
|
||||
llarp::RouterContact rc;
|
||||
const bool ret = rc.Read(file.c_str());
|
||||
|
||||
if(ret)
|
||||
{
|
||||
result[file] = rc.ToJson();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "file = " << file << " was not a valid rc file\n";
|
||||
}
|
||||
}
|
||||
std::cout << result << "\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef WITH_CURL
|
||||
|
||||
size_t
|
||||
curlCallback(void* contents, size_t size, size_t nmemb, void* userp) noexcept
|
||||
{
|
||||
auto* str = static_cast< std::string* >(userp);
|
||||
size_t realsize = size * nmemb;
|
||||
|
||||
char* asChar = static_cast< char* >(contents);
|
||||
|
||||
std::copy(asChar, asChar + realsize, std::back_inserter(*str));
|
||||
|
||||
return realsize;
|
||||
}
|
||||
|
||||
bool
|
||||
executeJsonRpc(const std::string& command, const std::string& configFile)
|
||||
{
|
||||
// Do init (on windows this will do socket initialisation)
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
llarp::Config config;
|
||||
if(!config.Load(configFile.c_str()))
|
||||
{
|
||||
llarp::LogError("Failed to load from config file: ", configFile);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!config.api.enableRPCServer())
|
||||
{
|
||||
llarp::LogError("Config does not have RPC enabled");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string address = config.api.rpcBindAddr() + "/jsonrpc";
|
||||
|
||||
const nlohmann::json request{{"method", command},
|
||||
{"params", nlohmann::json::object()},
|
||||
{"id", "foo"}};
|
||||
|
||||
const std::string requestStr = request.dump();
|
||||
|
||||
std::unique_ptr< curl_slist, void (*)(curl_slist*) > chunk(
|
||||
curl_slist_append(nullptr, "content-type: application/json"),
|
||||
&curl_slist_free_all);
|
||||
|
||||
std::unique_ptr< CURL, void (*)(CURL*) > curl(curl_easy_init(),
|
||||
&curl_easy_cleanup);
|
||||
curl_easy_setopt(curl.get(), CURLOPT_URL, address.c_str());
|
||||
curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDS, requestStr.c_str());
|
||||
curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDSIZE, requestStr.size());
|
||||
curl_easy_setopt(curl.get(), CURLOPT_HTTPHEADER, chunk.get());
|
||||
|
||||
std::string result;
|
||||
curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, curlCallback);
|
||||
curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &result);
|
||||
|
||||
auto res = curl_easy_perform(curl.get());
|
||||
if(res != CURLE_OK)
|
||||
{
|
||||
llarp::LogError("Failed to curl endpoint, ", curl_easy_strerror(res));
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << result << "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
#ifdef LOKINET_DEBUG
|
||||
absl::SetMutexDeadlockDetectionMode(absl::OnDeadlockCycle::kAbort);
|
||||
#endif
|
||||
|
||||
// clang-format off
|
||||
cxxopts::Options options(
|
||||
"lokinetctl",
|
||||
"LokiNET is a free, open source, private, decentralized, \"market based sybil resistant\" and IP based onion routing network"
|
||||
);
|
||||
|
||||
options.add_options()
|
||||
("v,verbose", "Verbose", cxxopts::value<bool>())
|
||||
("h,help", "help", cxxopts::value<bool>())
|
||||
("c,config", "config file", cxxopts::value<std::string>()->default_value(llarp::GetDefaultConfigPath().string()))
|
||||
#ifdef WITH_CURL
|
||||
("j,jsonrpc", "hit json rpc endpoint", cxxopts::value<std::string>())
|
||||
#endif
|
||||
("dump", "dump rc file", cxxopts::value<std::vector<std::string> >(), "FILE");
|
||||
// clang-format on
|
||||
|
||||
try
|
||||
{
|
||||
const auto result = options.parse(argc, argv);
|
||||
|
||||
if(result.count("verbose") > 0)
|
||||
{
|
||||
SetLogLevel(llarp::eLogDebug);
|
||||
llarp::LogContext::Instance().logStream =
|
||||
std::make_unique< llarp::OStreamLogStream >(true, std::cerr);
|
||||
llarp::LogDebug("debug logging activated");
|
||||
}
|
||||
else
|
||||
{
|
||||
SetLogLevel(llarp::eLogError);
|
||||
llarp::LogContext::Instance().logStream =
|
||||
std::make_unique< llarp::OStreamLogStream >(true, std::cerr);
|
||||
}
|
||||
|
||||
if(result.count("help") > 0)
|
||||
{
|
||||
std::cout << options.help() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(result.count("dump") > 0)
|
||||
{
|
||||
if(!dumpRc(result["dump"].as< std::vector< std::string > >()))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_CURL
|
||||
if(result.count("jsonrpc") > 0)
|
||||
{
|
||||
if(!executeJsonRpc(result["jsonrpc"].as< std::string >(),
|
||||
result["config"].as< std::string >()))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
catch(const cxxopts::OptionParseException& ex)
|
||||
{
|
||||
std::cerr << ex.what() << std::endl;
|
||||
std::cout << options.help() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -283,14 +283,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
// no explicit config file provided
|
||||
#ifdef _WIN32
|
||||
fs::path homedir = fs::path(getenv("APPDATA"));
|
||||
#else
|
||||
fs::path homedir = fs::path(getenv("HOME"));
|
||||
#endif
|
||||
fs::path basepath = homedir / fs::path(".lokinet");
|
||||
fs::path fpath = basepath / "lokinet.ini";
|
||||
auto basepath = llarp::GetDefaultConfigDir();
|
||||
// I don't think this is necessary with this condition
|
||||
// conffname = resolvePath(conffname);
|
||||
|
||||
@ -308,6 +301,8 @@ main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
auto fpath = llarp::GetDefaultConfigPath();
|
||||
|
||||
// if using default INI file, we're create it even if you don't ask us too
|
||||
if(!llarp_ensure_config(fpath.string().c_str(), basepath.string().c_str(),
|
||||
overWrite, asRouter))
|
||||
|
@ -1,101 +0,0 @@
|
||||
#include <router_contact.hpp>
|
||||
#include <util/logging/logger.hpp>
|
||||
#include <util/logging/ostream_logger.hpp>
|
||||
|
||||
#include <absl/synchronization/mutex.h>
|
||||
#include <cxxopts.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
bool
|
||||
dumpRc(const std::vector< std::string >& files, bool json)
|
||||
{
|
||||
nlohmann::json result;
|
||||
for(const auto& file : files)
|
||||
{
|
||||
llarp::RouterContact rc;
|
||||
const bool ret = rc.Read(file.c_str());
|
||||
|
||||
if(ret)
|
||||
{
|
||||
if(json)
|
||||
{
|
||||
result[file] = rc.ToJson();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "file = " << file << "\n";
|
||||
std::cout << rc << "\n\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "file = " << file << " was not a valid rc file\n";
|
||||
}
|
||||
}
|
||||
|
||||
if(json)
|
||||
std::cout << result << "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
#ifdef LOKINET_DEBUG
|
||||
absl::SetMutexDeadlockDetectionMode(absl::OnDeadlockCycle::kAbort);
|
||||
#endif
|
||||
|
||||
// clang-format off
|
||||
cxxopts::Options options(
|
||||
"lokinet-rcutil",
|
||||
"LokiNET is a free, open source, private, decentralized, \"market based sybil resistant\" and IP based onion routing network"
|
||||
);
|
||||
|
||||
options.add_options()
|
||||
("v,verbose", "Verbose", cxxopts::value<bool>())
|
||||
("c,colour", "colour output", cxxopts::value<bool>()->default_value("true"))
|
||||
("h,help", "help", cxxopts::value<bool>())
|
||||
("j,json", "output in json", cxxopts::value<bool>())
|
||||
("dump", "dump rc file", cxxopts::value<std::vector<std::string> >(), "FILE");
|
||||
// clang-format on
|
||||
|
||||
try
|
||||
{
|
||||
const auto result = options.parse(argc, argv);
|
||||
|
||||
const bool json = result["json"].as< bool >();
|
||||
|
||||
if(result.count("verbose") > 0)
|
||||
{
|
||||
SetLogLevel(llarp::eLogDebug);
|
||||
llarp::LogContext::Instance().logStream =
|
||||
std::make_unique< llarp::OStreamLogStream >(
|
||||
result["colour"].as< bool >(), std::cerr);
|
||||
llarp::LogDebug("debug logging activated");
|
||||
}
|
||||
|
||||
if(result.count("help") > 0)
|
||||
{
|
||||
std::cout << options.help() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(result.count("dump") > 0)
|
||||
{
|
||||
if(!dumpRc(result["dump"].as< std::vector< std::string > >(), json))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(const cxxopts::OptionParseException& ex)
|
||||
{
|
||||
std::cerr << ex.what() << std::endl;
|
||||
std::cout << options.help() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -13,4 +13,4 @@ RUN make NINJA=ninja STATIC_LINK=ON BUILD_TYPE=Release
|
||||
FROM alpine:latest
|
||||
|
||||
COPY --from=builder /src/build/daemon/lokinet /
|
||||
COPY --from=builder /src/build/daemon/lokinet-rcutil /
|
||||
COPY --from=builder /src/build/daemon/lokinet-ctl /
|
||||
|
@ -475,6 +475,23 @@ namespace llarp
|
||||
return true;
|
||||
}
|
||||
|
||||
fs::path
|
||||
GetDefaultConfigDir()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const fs::path homedir = fs::path(getenv("APPDATA"));
|
||||
#else
|
||||
const fs::path homedir = fs::path(getenv("HOME"));
|
||||
#endif
|
||||
return homedir / fs::path(".lokinet");
|
||||
}
|
||||
|
||||
fs::path
|
||||
GetDefaultConfigPath()
|
||||
{
|
||||
return GetDefaultConfigDir() / "lokinet.ini";
|
||||
}
|
||||
|
||||
} // namespace llarp
|
||||
|
||||
/// fname should be a relative path (from CWD) or absolute path to the config
|
||||
|
@ -326,6 +326,12 @@ namespace llarp
|
||||
LoadFromStr(string_view str);
|
||||
};
|
||||
|
||||
fs::path
|
||||
GetDefaultConfigDir();
|
||||
|
||||
fs::path
|
||||
GetDefaultConfigPath();
|
||||
|
||||
} // namespace llarp
|
||||
|
||||
void
|
||||
|
@ -188,8 +188,21 @@ namespace llarp
|
||||
struct Handler : public ::abyss::httpd::IRPCHandler
|
||||
{
|
||||
AbstractRouter* router;
|
||||
std::unordered_map< absl::string_view, std::function< Response() >,
|
||||
absl::Hash< absl::string_view > >
|
||||
m_dispatch;
|
||||
Handler(::abyss::httpd::ConnImpl* conn, AbstractRouter* r)
|
||||
: ::abyss::httpd::IRPCHandler(conn), router(r)
|
||||
: ::abyss::httpd::IRPCHandler(conn)
|
||||
, router(r)
|
||||
, m_dispatch{
|
||||
{"llarp.admin.wakeup", [=]() { return StartRouter(); }},
|
||||
{"llarp.admin.link.neighbor",
|
||||
[=]() { return ListNeighbors(); }},
|
||||
{"llarp.admin.exit.list", [=]() { return ListExitLevels(); }},
|
||||
{"llarp.admin.dumpstate", [=]() { return DumpState(); }},
|
||||
{"llarp.admin.status", [=]() { return DumpStatus(); }},
|
||||
{"llarp.our.addresses", [=]() { return OurAddresses(); }},
|
||||
{"llarp.version", [=]() { return DumpVersion(); }}}
|
||||
{
|
||||
}
|
||||
|
||||
@ -227,7 +240,7 @@ namespace llarp
|
||||
}
|
||||
|
||||
Response
|
||||
ListNeighboors() const
|
||||
ListNeighbors() const
|
||||
{
|
||||
Response resp = Response::array();
|
||||
router->ForEachPeer(
|
||||
@ -267,6 +280,21 @@ namespace llarp
|
||||
return resp;
|
||||
}
|
||||
|
||||
Response
|
||||
OurAddresses() const
|
||||
{
|
||||
Response services;
|
||||
router->hiddenServiceContext().ForEachService(
|
||||
[&](const std::string&,
|
||||
const std::shared_ptr< service::Endpoint >& service) {
|
||||
const service::Address addr = service->GetIdentity().pub.Addr();
|
||||
services.push_back(addr.ToString());
|
||||
return true;
|
||||
});
|
||||
|
||||
return Response{{"services", services}};
|
||||
}
|
||||
|
||||
Response
|
||||
DumpVersion() const
|
||||
{
|
||||
@ -278,29 +306,10 @@ namespace llarp
|
||||
HandleJSONRPC(Method_t method,
|
||||
ABSL_ATTRIBUTE_UNUSED const Params& params) override
|
||||
{
|
||||
if(method == "llarp.admin.wakeup")
|
||||
auto it = m_dispatch.find(method);
|
||||
if(it != m_dispatch.end())
|
||||
{
|
||||
return StartRouter();
|
||||
}
|
||||
if(method == "llarp.admin.link.neighboors")
|
||||
{
|
||||
return ListNeighboors();
|
||||
}
|
||||
if(method == "llarp.admin.exit.list")
|
||||
{
|
||||
return ListExitLevels();
|
||||
}
|
||||
if(method == "llarp.admin.dumpstate")
|
||||
{
|
||||
return DumpState();
|
||||
}
|
||||
if(method == "llarp.admin.status")
|
||||
{
|
||||
return DumpStatus();
|
||||
}
|
||||
if(method == "llarp.version")
|
||||
{
|
||||
return DumpVersion();
|
||||
return it->second();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ Compression=lzma2/ultra64
|
||||
SolidCompression=yes
|
||||
VersionInfoVersion=0.5.2
|
||||
VersionInfoCompany=Loki Project
|
||||
VersionInfoDescription=LokiNET for Microsoft® Windows® NT™
|
||||
VersionInfoDescription=LokiNET for Microsoft<EFBFBD> Windows<77> NT<4E>
|
||||
#ifndef RELEASE
|
||||
VersionInfoTextVersion=0.5.2-dev-{#VCSRev}
|
||||
VersionInfoProductTextVersion=0.5.2-dev-{#VCSRev}
|
||||
@ -54,7 +54,7 @@ VersionInfoProductVersion=0.5.2
|
||||
InternalCompressLevel=ultra64
|
||||
MinVersion=0,5.0
|
||||
ArchitecturesInstallIn64BitMode=x64
|
||||
VersionInfoCopyright=Copyright ©2018-2019 Loki Project
|
||||
VersionInfoCopyright=Copyright <EFBFBD>2018-2019 Loki Project
|
||||
|
||||
[Languages]
|
||||
Name: "english"; MessagesFile: "compiler:Default.isl"
|
||||
@ -89,7 +89,7 @@ Source: "{#DevPath}ui-win32\bin\release\lokinetui.pdb"; DestDir: "{app}"; Flags:
|
||||
#endif
|
||||
; eh, might as well ship the 32-bit port of everything else
|
||||
Source: "{#DevPath}build\testAll.exe"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "{#DevPath}build\lokinet-rcutil.exe"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "{#DevPath}build\lokinetctl.exe"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "LICENSE"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "lokinet-bootstrap.exe"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "rootcerts.pem"; DestDir: "{app}"; Flags: ignoreversion
|
||||
|
Loading…
Reference in New Issue
Block a user