1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00

tmp, squash

This commit is contained in:
Thomas Winget 2022-11-03 12:04:41 -04:00
parent 80b74ad97d
commit 50e507ad8d
8 changed files with 231 additions and 6 deletions

View file

@ -50,6 +50,7 @@ option(USE_AVX2 "enable avx2 code" OFF)
option(USE_NETNS "enable networking namespace support. Linux only" OFF)
option(NATIVE_BUILD "optimise for host system and FPU" ON)
option(WITH_EMBEDDED_LOKINET "build liblokinet.so for embedded lokinet" OFF)
option(LIBLOKINET_TEST_UTILS "build test utils in contrib/liblokinet" OFF)
option(XSAN "use sanitiser, if your system has it (requires -DCMAKE_BUILD_TYPE=Debug)" OFF)
option(USE_JEMALLOC "Link to jemalloc for memory allocations, if found" ON)
option(TESTNET "testnet build" OFF)
@ -313,6 +314,10 @@ if(ANDROID)
add_subdirectory(jni)
endif()
if(BUILD_LIBLOKINET AND LIBLOKINET_TEST_UTILS)
add_subdirectory(contrib/liblokinet)
endif()
add_subdirectory(docs)
include(cmake/gui.cmake)

View file

@ -1,10 +1,14 @@
cmake_minimum_required(VERSION 3.10)
#[[
project(udptest LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
add_executable(udptest udptest.cpp)
include_directories(../../include)
target_link_libraries(udptest PUBLIC lokinet)
]]
add_executable(tcp_listen
tcp_listen.cpp)
target_link_libraries(tcp_listen PUBLIC lokinet-shared)
add_executable(tcp_connect
tcp_connect.cpp)
target_link_libraries(tcp_connect PUBLIC lokinet-shared)

View file

@ -0,0 +1,108 @@
// Test utility to bind a local tcp socket listener with liblokinet
#include <lokinet.h>
#include <llarp/util/logging.hpp>
#include <signal.h>
#include <memory>
#include <stdexcept>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
#include <chrono>
#include <thread>
bool _run{true};
void
signal_handler(int)
{
_run = false;
}
int
main(int argc, char* argv[])
{
if (argc != 2)
{
std::cout << "Usage: " << argv[0] << " something.loki\n";
return 0;
}
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
if (auto* loglevel = getenv("LOKINET_LOG"))
lokinet_log_level(loglevel);
else
lokinet_log_level("info");
// log level debug for quic
llarp::log::set_level("quic", llarp::log::Level::debug);
std::cout << "starting up\n";
auto shared_ctx = std::shared_ptr<lokinet_context>(lokinet_context_new(), lokinet_context_free);
auto* ctx = shared_ctx.get();
if (lokinet_context_start(ctx))
throw std::runtime_error{"could not start context"};
int status;
for (status = lokinet_status(ctx); _run and status == -1; status = lokinet_status(ctx))
{
std::cout << "waiting for lokinet to be ready..." << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds{500});
}
if (not _run)
{
std::cout << "exit requested before context was ready.\n";
return 0;
}
if (status != 0)
{
std::cout << "lokinet_status = " << status << " after waiting for ready.\n";
return 0;
}
auto addr_c = lokinet_address(ctx);
std::string addr{addr_c};
free(addr_c);
std::cout << "lokinet address: " << addr << "\n";
// wait a bit just so log output calms down so we can see stuff
// printed from here
std::this_thread::sleep_for(std::chrono::milliseconds{3000});
lokinet_stream_result stream_res;
std::string target{argv[1]};
target += ":12345";
lokinet_outbound_stream(&stream_res, target.c_str(), nullptr, ctx);
if (stream_res.error)
{
std::cout << "failed to prepare outbound tcp: " << strerror(stream_res.error) << "\n";
return 0;
}
size_t counter = 0;
do
{
std::this_thread::sleep_for(std::chrono::milliseconds{100});
if (counter++ % 30 == 0)
std::cout << "outbound tcp ready on " << stream_res.local_address << ":" << stream_res.local_port << "\n";
} while (_run);
std::cout << "tcp_connect shutting down...\n";
lokinet_close_stream(stream_res.stream_id, ctx);
return 0;
}

View file

@ -0,0 +1,96 @@
// Test utility to bind a local tcp socket listener with liblokinet
#include <lokinet.h>
#include <signal.h>
#include <memory>
#include <stdexcept>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
#include <chrono>
#include <thread>
bool _run{true};
void
signal_handler(int)
{
_run = false;
}
int
main(int argc, char* argv[])
{
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
if (auto* loglevel = getenv("LOKINET_LOG"))
lokinet_log_level(loglevel);
else
lokinet_log_level("info");
std::cout << "starting up\n";
auto shared_ctx = std::shared_ptr<lokinet_context>(lokinet_context_new(), lokinet_context_free);
auto* ctx = shared_ctx.get();
if (lokinet_context_start(ctx))
throw std::runtime_error{"could not start context"};
int status;
for (status = lokinet_status(ctx); _run and status == -1; status = lokinet_status(ctx))
{
std::cout << "waiting for lokinet to be ready..." << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds{500});
}
if (not _run)
{
std::cout << "exit requested before context was ready.\n";
return 0;
}
if (status != 0)
{
std::cout << "lokinet_status = " << status << " after waiting for ready.\n";
return 0;
}
// wait a bit just so log output calms down so we can see stuff
// printed from here
std::this_thread::sleep_for(std::chrono::milliseconds{3000});
const auto port = 10000;
auto id = lokinet_inbound_stream(port, ctx);
if (id < 0)
{
std::cout << "failed to bind tcp socket\n";
return 0;
}
std::cout << "bound tcp on localhost port: " << port << "\n";
auto addr_c = lokinet_address(ctx);
std::string addr{addr_c};
free(addr_c);
std::cout << "lokinet address: " << addr << "\n";
size_t counter = 0;
do
{
std::this_thread::sleep_for(std::chrono::milliseconds{100});
if (++counter % 30 == 0)
std::cout << "lokinet address: " << addr << "\n";
} while (_run);
std::cout << "tcp_listen shutting down...\n";
lokinet_close_stream(id, ctx);
return 0;
}

View file

@ -1654,7 +1654,7 @@ namespace llarp
{
auto config = std::make_shared<Config>();
config->Load();
config->logging.m_logLevel = log::Level::off;
config->logging.m_logLevel = log::Level::debug;
config->api.m_enableRPCServer = false;
config->network.m_endpointType = "null";
config->network.m_saveProfiles = false;

View file

@ -483,6 +483,8 @@ extern "C"
int EXPORT
lokinet_add_bootstrap_rc(const char* data, size_t datalen, struct lokinet_context* ctx)
{
// FIXME: bootstrap loading was rewritten but this code needs updated to do
// it how Router does now.
if (data == nullptr or datalen == 0)
return -3;
llarp_buffer_t buf{data, datalen};

View file

@ -18,6 +18,8 @@
namespace llarp
{
static auto logcat = log::Cat("rc-lookup");
void
RCLookupHandler::AddValidRouter(const RouterID& router)
{
@ -91,6 +93,11 @@ namespace llarp
{
itr_pair.first->second.push_back(callback);
}
log::trace(
logcat,
"RC Lookup for {} has {} pending callbacks.",
router,
itr_pair.first->second.size());
shouldDoLookup = itr_pair.second;
}

View file

@ -148,7 +148,10 @@ namespace llarp
if (auto* quic = GetQUICTunnel())
{
if (quic->hasListeners())
{
log::debug(logcat, "IntroSet setting QUIC as available protocol.");
introSet().supportedProtocols.push_back(ProtocolType::QUIC);
}
}
introSet().intros.clear();