cmake tweaks for redundant dependencies (WIP)

pull/2196/head
dr7ana 10 months ago committed by Thomas Winget
parent 22ac3cd26e
commit ad5055b85f

@ -1,2 +1,8 @@
HeaderFilterRegex: 'llarp/.*' HeaderFilterRegex: 'llarp/.*'
Checks: 'readability-else-after-return,clang-analyzer-core-*,modernize-*,-modernize-use-trailing-return-type,-modernize-use-nodiscard,bugprone-*,-bugprone-easily-swappable-parameters' Checks:
'readability-else-after-return,
clang-analyzer-core-*,modernize-*,
-modernize-use-trailing-return-type,
-modernize-use-nodiscard,
bugprone-*,
-bugprone-easily-swappable-parameters'

6
.gitmodules vendored

@ -27,12 +27,6 @@
path = external/ngtcp2 path = external/ngtcp2
url = https://github.com/ngtcp2/ngtcp2.git url = https://github.com/ngtcp2/ngtcp2.git
branch = v0.1.0 branch = v0.1.0
[submodule "external/oxen-encoding"]
path = external/oxen-encoding
url = https://github.com/oxen-io/oxen-encoding.git
[submodule "external/oxen-logging"]
path = external/oxen-logging
url = https://github.com/oxen-io/oxen-logging.git
[submodule "gui"] [submodule "gui"]
path = gui path = gui
url = https://github.com/oxen-io/lokinet-gui.git url = https://github.com/oxen-io/lokinet-gui.git

@ -130,7 +130,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(cmake/unix.cmake) include(cmake/unix.cmake)
include(cmake/check_for_std_optional.cmake) include(cmake/check_for_std_optional.cmake)
include(cmake/check_for_std_filesystem.cmake) #include(cmake/check_for_std_filesystem.cmake)
if(NOT WIN32) if(NOT WIN32)
if(IOS OR ANDROID) if(IOS OR ANDROID)

@ -25,12 +25,11 @@ if(SUBMODULE_CHECK)
message(STATUS "Checking submodules") message(STATUS "Checking submodules")
check_submodule(nlohmann) check_submodule(nlohmann)
check_submodule(ghc-filesystem) # check_submodule(ghc-filesystem)
check_submodule(oxen-logging fmt spdlog) # check_submodule(oxen-logging fmt spdlog)
check_submodule(pybind11) check_submodule(pybind11)
check_submodule(sqlite_orm) check_submodule(sqlite_orm)
check_submodule(oxen-mq) check_submodule(oxen-mq)
check_submodule(oxen-encoding)
check_submodule(uvw) check_submodule(uvw)
check_submodule(cpr) check_submodule(cpr)
check_submodule(oxen-libquic) check_submodule(oxen-libquic)
@ -60,18 +59,17 @@ macro(system_or_submodule BIGNAME smallname pkgconf subdir)
endif() endif()
endmacro() endmacro()
system_or_submodule(OXENC oxenc liboxenc>=1.0.4 oxen-encoding)
system_or_submodule(OXENMQ oxenmq liboxenmq>=1.2.14 oxen-mq) system_or_submodule(OXENMQ oxenmq liboxenmq>=1.2.14 oxen-mq)
set(JSON_BuildTests OFF CACHE INTERNAL "") set(JSON_BuildTests OFF CACHE INTERNAL "")
set(JSON_Install OFF CACHE INTERNAL "") set(JSON_Install OFF CACHE INTERNAL "")
system_or_submodule(NLOHMANN nlohmann_json nlohmann_json>=3.7.0 nlohmann) system_or_submodule(NLOHMANN nlohmann_json nlohmann_json>=3.7.0 nlohmann)
if (STATIC OR FORCE_SPDLOG_SUBMODULE OR FORCE_FMT_SUBMODULE) #if (STATIC OR FORCE_SPDLOG_SUBMODULE OR FORCE_FMT_SUBMODULE)
set(OXEN_LOGGING_FORCE_SUBMODULES ON CACHE INTERNAL "") # set(OXEN_LOGGING_FORCE_SUBMODULES ON CACHE INTERNAL "")
endif() #endif()
set(OXEN_LOGGING_SOURCE_ROOT "${PROJECT_SOURCE_DIR}" CACHE INTERNAL "") #set(OXEN_LOGGING_SOURCE_ROOT "${PROJECT_SOURCE_DIR}" CACHE INTERNAL "")
add_subdirectory(oxen-logging) #add_subdirectory(oxen-logging)
if(WITH_HIVE) if(WITH_HIVE)
add_subdirectory(pybind11 EXCLUDE_FROM_ALL) add_subdirectory(pybind11 EXCLUDE_FROM_ALL)
@ -98,6 +96,8 @@ target_link_libraries(uvw INTERFACE libuv)
#include(ngtcp2_lib) #include(ngtcp2_lib)
#add_ngtcp2_lib() #add_ngtcp2_lib()
add_subdirectory(oxen-libquic)
# cpr configuration. Ideally we'd just do this via add_subdirectory, but cpr's cmake requires # cpr configuration. Ideally we'd just do this via add_subdirectory, but cpr's cmake requires
# 3.15+, and we target lower than that (and this is fairly simple to build). # 3.15+, and we target lower than that (and this is fairly simple to build).
if(WITH_BOOTSTRAP) if(WITH_BOOTSTRAP)

@ -1 +0,0 @@
Subproject commit a869ae2b0152ad70855e3774a425c39a25ae1ca6

@ -1 +0,0 @@
Subproject commit b6e70ad3aa3b2d718f8607599864cd50a951166a

@ -509,12 +509,13 @@ target_link_libraries(lokinet-platform PUBLIC
target_link_libraries(lokinet-util PUBLIC target_link_libraries(lokinet-util PUBLIC
nlohmann_json::nlohmann_json nlohmann_json::nlohmann_json
filesystem # filesystem
oxenc::oxenc oxenc::oxenc
) )
target_link_libraries(lokinet-plainquic PUBLIC target_link_libraries(lokinet-plainquic PUBLIC
ngtcp2_static ngtcp2_crypto
libquic
uvw uvw
) )

@ -3,7 +3,7 @@
#include <llarp/router_id.hpp> #include <llarp/router_id.hpp>
#include <llarp/router_contact.hpp> #include <llarp/router_contact.hpp>
#include <oxen-libquic/include/quic.hpp> #include <external/oxen-libquic/include/quic.hpp>
namespace llarp::link namespace llarp::link
{ {

@ -1,8 +1,11 @@
#pragma once #pragma once
#include "connection.hpp"
#include <llarp/router/abstractrouter.hpp>
#include <llarp/router_id.hpp> #include <llarp/router_id.hpp>
#include <oxen-libquic/include/quic.hpp> #include <external/oxen-libquic/include/quic.hpp>
namespace llarp::link namespace llarp::link
{ {

@ -19,7 +19,7 @@ namespace llarp
/// As a convenience, it can produce a SockAddr for dealing with network libraries which depend /// As a convenience, it can produce a SockAddr for dealing with network libraries which depend
/// sockaddr structs. However, it does not keep this as a member variable and isn't responsible /// sockaddr structs. However, it does not keep this as a member variable and isn't responsible
/// for its lifetime/memory/etc. /// for its lifetime/memory/etc.
struct [[deprecated("use llarp::SockAddr instead")]] IpAddress struct /* [[deprecated("use llarp::SockAddr instead")]] */ IpAddress
{ {
/// Empty constructor. /// Empty constructor.
IpAddress() = default; IpAddress() = default;

@ -256,25 +256,25 @@ namespace llarp
template <> template <>
inline constexpr bool IsToStringFormattable<net::port_t> = true; inline constexpr bool IsToStringFormattable<net::port_t> = true;
using nuint16_t [[deprecated("use llarp::net::port_t instead")]] = llarp::net::port_t; using nuint16_t /* [[deprecated("use llarp::net::port_t instead")]] */ = llarp::net::port_t;
using nuint32_t [[deprecated("use llarp::net::ipv4addr_t instead")]] = llarp::net::ipv4addr_t; using nuint32_t /* [[deprecated("use llarp::net::ipv4addr_t instead")]] */ = llarp::net::ipv4addr_t;
using nuint128_t [[deprecated("use llarp::net::ipv6addr_t instead")]] = llarp::net::ipv6addr_t; using nuint128_t /* [[deprecated("use llarp::net::ipv6addr_t instead")]] */ = llarp::net::ipv6addr_t;
template <typename UInt_t> template <typename UInt_t>
[[deprecated("use llarp::net::ToNet instead")]] inline llarp::nuint_t<UInt_t> /* [[deprecated("use llarp::net::ToNet instead")]] */ inline llarp::nuint_t<UInt_t>
ToNet(llarp::huint_t<UInt_t> x) ToNet(llarp::huint_t<UInt_t> x)
{ {
return llarp::net::ToNet(x); return llarp::net::ToNet(x);
} }
template <typename UInt_t> template <typename UInt_t>
[[deprecated("use llarp::net::ToHost instead")]] inline llarp::huint_t<UInt_t> /* [[deprecated("use llarp::net::ToHost instead")]] */ inline llarp::huint_t<UInt_t>
ToHost(llarp::nuint_t<UInt_t> x) ToHost(llarp::nuint_t<UInt_t> x)
{ {
return llarp::net::ToHost(x); return llarp::net::ToHost(x);
} }
[[deprecated("use llarp::net::ToHost instead")]] inline net::ipv4addr_t /* [[deprecated("use llarp::net::ToHost instead")]] */ inline net::ipv4addr_t
xhtonl(huint32_t x) xhtonl(huint32_t x)
{ {
return ToNet(x); return ToNet(x);

@ -83,7 +83,7 @@ namespace llarp::quic
int int
recv_crypto_data( recv_crypto_data(
ngtcp2_conn* conn_, ngtcp2_conn* conn_,
ngtcp2_crypto_level crypto_level, ngtcp2_encryption_level crypto_level,
uint64_t offset, uint64_t offset,
const uint8_t* rawdata, const uint8_t* rawdata,
size_t rawdatalen, size_t rawdatalen,
@ -95,12 +95,12 @@ namespace llarp::quic
auto& conn = *static_cast<Connection*>(user_data); auto& conn = *static_cast<Connection*>(user_data);
switch (crypto_level) switch (crypto_level)
{ {
case NGTCP2_CRYPTO_LEVEL_EARLY: // case NGTCP2_CRYPTO_LEVEL_EARLY:
// We don't currently use or support 0rtt // // We don't currently use or support 0rtt
LogWarn("Invalid EARLY crypto level"); // LogWarn("Invalid EARLY crypto level");
return FAIL; // return FAIL;
case NGTCP2_CRYPTO_LEVEL_INITIAL: case NGTCP2_ENCRYPTION_LEVEL_INITIAL:
log::trace(log_cat, "Receiving initial crypto..."); log::trace(log_cat, "Receiving initial crypto...");
// "Initial" level means we are still handshaking; if we are server then we receive // "Initial" level means we are still handshaking; if we are server then we receive
// the client's transport params (sent in client_initial, above) and blast ours // the client's transport params (sent in client_initial, above) and blast ours
@ -112,15 +112,15 @@ namespace llarp::quic
if (ngtcp2_conn_is_server(conn)) if (ngtcp2_conn_is_server(conn))
{ {
if (auto rv = conn.send_magic(NGTCP2_CRYPTO_LEVEL_INITIAL); rv != 0) if (auto rv = conn.send_magic(NGTCP2_ENCRYPTION_LEVEL_INITIAL); rv != 0)
return rv; return rv;
if (auto rv = conn.send_transport_params(NGTCP2_CRYPTO_LEVEL_HANDSHAKE); rv != 0) if (auto rv = conn.send_transport_params(NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE); rv != 0)
return rv; return rv;
} }
break; break;
case NGTCP2_CRYPTO_LEVEL_HANDSHAKE: case NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE:
log::trace(log_cat, "Receiving handshake crypto..."); log::trace(log_cat, "Receiving handshake crypto...");
if (!ngtcp2_conn_is_server(conn)) if (!ngtcp2_conn_is_server(conn))
{ {
@ -130,7 +130,7 @@ namespace llarp::quic
// the server can install our rx key; we have to send *something* back to invoke // the server can install our rx key; we have to send *something* back to invoke
// the server's HANDSHAKE callback (so that it knows handshake is complete) so // the server's HANDSHAKE callback (so that it knows handshake is complete) so
// send the magic again. // send the magic again.
if (auto rv = conn.send_magic(NGTCP2_CRYPTO_LEVEL_HANDSHAKE); rv != 0) if (auto rv = conn.send_magic(NGTCP2_ENCRYPTION_LEVEL_HANDSHAKE); rv != 0)
return rv; return rv;
} }
else else
@ -398,7 +398,7 @@ namespace llarp::quic
settings.initial_ts = get_timestamp(); settings.initial_ts = get_timestamp();
// FIXME: IPv6 // FIXME: IPv6
settings.max_udp_payload_size = Endpoint::max_pkt_size_v4; settings.max_tx_udp_payload_size = Endpoint::max_pkt_size_v4;
settings.cc_algo = NGTCP2_CC_ALGO_CUBIC; settings.cc_algo = NGTCP2_CC_ALGO_CUBIC;
// settings.initial_rtt = ???; # NGTCP2's default is 333ms // settings.initial_rtt = ???; # NGTCP2's default is 333ms
@ -719,9 +719,6 @@ namespace llarp::quic
if (nwrite == 0) if (nwrite == 0)
{ {
LogTrace("Nothing else to write for non-stream data for now (or we are congested)"); LogTrace("Nothing else to write for non-stream data for now (or we are congested)");
ngtcp2_conn_stat cstat;
ngtcp2_conn_get_conn_stat(*this, &cstat);
LogTrace("Current unacked bytes in flight: ", cstat.bytes_in_flight);
break; break;
} }
@ -773,7 +770,7 @@ namespace llarp::quic
if (!good) if (!good)
{ {
LogDebug("stream_open_callback returned failure, dropping stream ", id); LogDebug("stream_open_callback returned failure, dropping stream ", id);
ngtcp2_conn_shutdown_stream(*this, id.id, 1); ngtcp2_conn_shutdown_stream(*this, 0, id.id, 1);
io_ready(); io_ready();
return NGTCP2_ERR_CALLBACK_FAILURE; return NGTCP2_ERR_CALLBACK_FAILURE;
} }
@ -944,9 +941,9 @@ namespace llarp::quic
{ {
endpoint.null_crypto.client_initial(*this); endpoint.null_crypto.client_initial(*this);
if (int rv = send_magic(NGTCP2_CRYPTO_LEVEL_INITIAL); rv != 0) if (int rv = send_magic(NGTCP2_ENCRYPTION_LEVEL_INITIAL); rv != 0)
return rv; return rv;
if (int rv = send_transport_params(NGTCP2_CRYPTO_LEVEL_INITIAL); rv != 0) if (int rv = send_transport_params(NGTCP2_ENCRYPTION_LEVEL_INITIAL); rv != 0)
return rv; return rv;
io_ready(); io_ready();
@ -997,7 +994,7 @@ namespace llarp::quic
endpoint.null_crypto.install_rx_key(*this); endpoint.null_crypto.install_rx_key(*this);
if (!ngtcp2_conn_is_server(*this)) if (!ngtcp2_conn_is_server(*this))
endpoint.null_crypto.install_tx_key(*this); endpoint.null_crypto.install_tx_key(*this);
ngtcp2_conn_handshake_completed(*this); ngtcp2_conn_tls_handshake_completed(*this);
if (on_handshake_complete) if (on_handshake_complete)
{ {
@ -1125,21 +1122,22 @@ namespace llarp::quic
} }
} }
ngtcp2_transport_params params; // ngtcp2_transport_params params;
auto exttype = is_server ? NGTCP2_TRANSPORT_PARAMS_TYPE_CLIENT_HELLO // auto exttype = is_server ? NGTCP2_TRANSPORT_PARAMS_TYPE_CLIENT_HELLO
: NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS; // : NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS;
auto rv = ngtcp2_decode_transport_params(&params, exttype, data.data(), data.size()); auto rv = ngtcp2_conn_decode_and_set_remote_transport_params(*this, data.data(), data.size());
LogDebug("Decode transport params ", rv == 0 ? "success" : "fail: "s + ngtcp2_strerror(rv)); // auto rv = ngtcp2_decode_transport_params(&params, exttype, data.data(), data.size());
LogTrace("params orig dcid = ", ConnectionID(params.original_dcid)); // LogDebug("Decode transport params ", rv == 0 ? "success" : "fail: "s + ngtcp2_strerror(rv));
LogTrace("params init scid = ", ConnectionID(params.initial_scid)); // LogTrace("params orig dcid = ", ConnectionID(params.original_dcid));
if (rv == 0) // LogTrace("params init scid = ", ConnectionID(params.initial_scid));
{ // if (rv == 0)
rv = ngtcp2_conn_set_remote_transport_params(*this, &params); // {
LogDebug( // rv = ngtcp2_conn_set_remote_transport_params(*this, &params);
"Set remote transport params ", rv == 0 ? "success" : "fail: "s + ngtcp2_strerror(rv)); // LogDebug(
} // "Set remote transport params ", rv == 0 ? "success" : "fail: "s + ngtcp2_strerror(rv));
// }
if (rv != 0) if (rv != 0)
{ {
@ -1153,7 +1151,7 @@ namespace llarp::quic
// Sends our magic string at the given level. This fixed magic string is taking the place of TLS // Sends our magic string at the given level. This fixed magic string is taking the place of TLS
// parameters in full QUIC. // parameters in full QUIC.
int int
Connection::send_magic(ngtcp2_crypto_level level) Connection::send_magic(ngtcp2_encryption_level level)
{ {
return ngtcp2_conn_submit_crypto_data( return ngtcp2_conn_submit_crypto_data(
*this, level, handshake_magic.data(), handshake_magic.size()); *this, level, handshake_magic.data(), handshake_magic.size());
@ -1171,10 +1169,9 @@ namespace llarp::quic
// Sends transport parameters. `level` is expected to be INITIAL for clients (which send the // Sends transport parameters. `level` is expected to be INITIAL for clients (which send the
// transport parameters in the initial packet), or HANDSHAKE for servers. // transport parameters in the initial packet), or HANDSHAKE for servers.
int int
Connection::send_transport_params(ngtcp2_crypto_level level) Connection::send_transport_params(ngtcp2_encryption_level level)
{ {
ngtcp2_transport_params tparams; ngtcp2_transport_params tparams = *ngtcp2_conn_get_local_transport_params(*this);
ngtcp2_conn_get_local_transport_params(*this, &tparams);
assert(conn_buffer.empty()); assert(conn_buffer.empty());
conn_buffer.resize(Endpoint::max_pkt_size_v4); conn_buffer.resize(Endpoint::max_pkt_size_v4);
@ -1196,12 +1193,11 @@ namespace llarp::quic
assert(buf < bufend); assert(buf < bufend);
} }
const bool is_server = ngtcp2_conn_is_server(*this); // const bool is_server = ngtcp2_conn_is_server(*this);
auto exttype = is_server ? NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS // auto exttype = is_server ? NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS
: NGTCP2_TRANSPORT_PARAMS_TYPE_CLIENT_HELLO; // : NGTCP2_TRANSPORT_PARAMS_TYPE_CLIENT_HELLO;
if (ngtcp2_ssize nwrite = ngtcp2_encode_transport_params(buf, bufend - buf, exttype, &tparams); if (ngtcp2_ssize nwrite = ngtcp2_conn_encode_local_transport_params(*this, buf, bufend-buf); nwrite >= 0)
nwrite >= 0)
{ {
assert(nwrite > 0); assert(nwrite > 0);
conn_buffer.resize(buf - u8data(conn_buffer) + nwrite); conn_buffer.resize(buf - u8data(conn_buffer) + nwrite);
@ -1211,6 +1207,7 @@ namespace llarp::quic
conn_buffer.clear(); conn_buffer.clear();
return nwrite; return nwrite;
} }
LogDebug("encoded transport params: ", buffer_printer{conn_buffer}); LogDebug("encoded transport params: ", buffer_printer{conn_buffer});
return ngtcp2_conn_submit_crypto_data(*this, level, u8data(conn_buffer), conn_buffer.size()); return ngtcp2_conn_submit_crypto_data(*this, level, u8data(conn_buffer), conn_buffer.size());
} }

@ -324,9 +324,9 @@ namespace llarp::quic
int int
recv_transport_params(std::basic_string_view<uint8_t> data); recv_transport_params(std::basic_string_view<uint8_t> data);
int int
send_magic(ngtcp2_crypto_level level); send_magic(ngtcp2_encryption_level level);
int int
send_transport_params(ngtcp2_crypto_level level); send_transport_params(ngtcp2_encryption_level level);
void void
complete_handshake(); complete_handshake();
}; };

@ -130,7 +130,7 @@ namespace llarp::quic
void void
Endpoint::handle_conn_packet(Connection& conn, const Packet& p) Endpoint::handle_conn_packet(Connection& conn, const Packet& p)
{ {
if (ngtcp2_conn_is_in_closing_period(conn)) if (ngtcp2_conn_in_closing_period(conn))
{ {
LogDebug("Connection is in closing period, dropping"); LogDebug("Connection is in closing period, dropping");
close_connection(conn); close_connection(conn);

@ -47,6 +47,8 @@
#include <oxenmq/address.h> #include <oxenmq/address.h>
#include <external/oxen-libquic/include/quic.hpp>
namespace llarp namespace llarp
{ {
struct Router : public AbstractRouter struct Router : public AbstractRouter
@ -233,6 +235,7 @@ namespace llarp
std::shared_ptr<NodeDB> _nodedb; std::shared_ptr<NodeDB> _nodedb;
llarp_time_t _startedAt; llarp_time_t _startedAt;
const oxenmq::TaggedThreadID m_DiskThread; const oxenmq::TaggedThreadID m_DiskThread;
oxen::quic::Network _net;
llarp_time_t llarp_time_t
Uptime() const override; Uptime() const override;

@ -27,7 +27,7 @@ struct ManagedBuffer;
/// TODO: replace usage of these with std::span (via a backport until we move to C++20). That's a /// TODO: replace usage of these with std::span (via a backport until we move to C++20). That's a
/// fairly big job, though, as llarp_buffer_t is currently used a bit differently (i.e. maintains /// fairly big job, though, as llarp_buffer_t is currently used a bit differently (i.e. maintains
/// both start and current position, plus has some value reading/writing methods). /// both start and current position, plus has some value reading/writing methods).
struct [[deprecated("this type is stupid, use something else")]] llarp_buffer_t struct /* [[deprecated("this type is stupid, use something else")]] */ llarp_buffer_t
{ {
/// starting memory address /// starting memory address
byte_t* base{nullptr}; byte_t* base{nullptr};

Loading…
Cancel
Save