Skip to content

Commit

Permalink
libc++-19 misc
Browse files Browse the repository at this point in the history
- cmake configuration to force fmt > 10 when compiling with clang-19
- misc
  • Loading branch information
dr7ana committed Dec 5, 2024
1 parent d52f394 commit d90185d
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .drone.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ local mac_builder(name,
debian_pipeline('Debian sid/Debug', docker_base + 'debian-sid', build_type='Debug'),
clang(16),
full_llvm(16),
clang(19),
full_llvm(19),
debian_pipeline('Debian sid -GSO', docker_base + 'debian-sid', cmake_extra='-DLIBQUIC_SEND=sendmmsg'),
debian_pipeline('Debian sid -mmsg', docker_base + 'debian-sid', cmake_extra='-DLIBQUIC_SEND=sendmsg -DLIBQUIC_RECVMMSG=OFF'),
debian_pipeline('Debian sid -GSO/Debug', docker_base + 'debian-sid', build_type='Debug', cmake_extra='-DLIBQUIC_SEND=sendmmsg'),
Expand Down
23 changes: 17 additions & 6 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,31 @@ if(NOT NGTCP2_FOUND OR NOT NGTCP2_GNUTLS_FOUND)
endif()

# oxen-logging
if (NOT TARGET oxen::logging)
if(BUILD_STATIC_DEPS)
message(STATUS "Building static dependencies; using oxen-logging submodule")
set(OXEN_LOGGING_FORCE_SUBMODULES ON CACHE INTERNAL "")
endif()

if(NOT OXEN_LOGGING_FORCE_SUBMODULES AND CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 19.0.0)
message(STATUS "Forcing oxen-logging submodules; Clang version > 19 requires fmt version > 10")
set(OXEN_LOGGING_FORCE_SUBMODULES ON CACHE INTERNAL "")
endif()

if (NOT OXEN_LOGGING_FORCE_SUBMODULES AND NOT TARGET oxen::logging)
message(STATUS "Target oxen::logging not found; using submodule")
if(BUILD_STATIC_DEPS)
set(OXEN_LOGGING_FORCE_SUBMODULES ON CACHE INTERNAL "")
endif()
add_subdirectory(oxen-logging)
set(OXEN_LOGGING_FORCE_SUBMODULES ON CACHE INTERNAL "")
else()
message(STATUS "Target oxen::logging already found!")
endif()

if (OXEN_LOGGING_FORCE_SUBMODULES)
add_subdirectory(oxen-logging)
endif()
oxen_logging_add_source_dir("${PROJECT_SOURCE_DIR}")

# oxenc
if (NOT TARGET oxenc)
system_or_submodule(OXENC oxenc liboxenc>=1.1.0 oxen-encoding)
system_or_submodule(OXENC oxenc liboxenc>=1.2.0 oxen-encoding)
endif()

# libevent
Expand Down
2 changes: 1 addition & 1 deletion include/oxen/quic/btstream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace oxen::quic
explicit operator bool() const { return !timed_out && !is_error(); }

template <oxenc::basic_char Char = char>
std::basic_string_view<Char> view() const
const_span<Char> span() const
{
return {reinterpret_cast<const Char*>(data.data()), data.size()};
}
Expand Down
10 changes: 8 additions & 2 deletions include/oxen/quic/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ namespace oxen::quic
void send_datagram(std::vector<Char>&& buf)
{
auto keep_alive = std::make_shared<std::vector<Char>>(std::move(buf));
std::basic_string_view<Char> view{keep_alive->data(), keep_alive->size()};
send_datagram(str_to_bspan(view), std::move(keep_alive));
auto bsp = vec_to_span<std::byte>(*keep_alive);
send_datagram(bsp, std::move(keep_alive));
}

template <oxenc::basic_char CharType>
Expand All @@ -138,6 +138,12 @@ namespace oxen::quic
send_datagram(str_to_bspan(view), std::move(keep_alive));
}

template <oxenc::basic_char CharType>
void send_datagram(const_span<CharType> data, std::shared_ptr<void> keep_alive = nullptr)
{
send_datagram(span_to_span<std::byte>(data), std::move(keep_alive));
}

virtual void send_datagram(bspan data, std::shared_ptr<void> keep_alive = nullptr) = 0;

virtual Endpoint& endpoint() = 0;
Expand Down
13 changes: 7 additions & 6 deletions include/oxen/quic/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
// library).

#include "formattable.hpp"
#include "utils.hpp"

#include <oxenc/span.h>

#include <fmt/format.h>

#include <iostream>
#include <version>

namespace oxen::quic
{
struct buffer_printer
{
private:
std::basic_string_view<std::byte> buf;
bspan buf;

public:
template <oxenc::basic_char T>
Expand Down Expand Up @@ -64,14 +66,13 @@ namespace fmt
}
};

template <oxenc::const_span_type T>
struct formatter<T, char> : formatter<std::string_view>
template <>
struct formatter<oxen::quic::cspan, char> : formatter<std::string_view>
{
template <typename FormatContext>
auto format(const T& val, FormatContext& ctx) const
auto format(const oxen::quic::cspan& val, FormatContext& ctx) const
{
return formatter<std::string_view>::format(
std::string_view{reinterpret_cast<const char*>(val.data()), val.size()}, ctx);
return formatter<std::string_view>::format({val.data(), val.size()}, ctx);
}
};
} // namespace fmt
5 changes: 3 additions & 2 deletions include/oxen/quic/opt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ namespace oxen::quic
const DIR direction;
std::vector<std::vector<unsigned char>> protos;

constexpr alpns(DIR d, std::vector<std::vector<unsigned char>>&& alpns) : direction{d}, protos{std::move(alpns)}
{}
// constexpr alpns(DIR d, std::vector<std::vector<unsigned char>>&& alpns) : direction{d},
// protos{std::move(alpns)}
// {}

template <typename... arg>
requires(std::same_as<uspan, arg> && ...)
Expand Down
4 changes: 2 additions & 2 deletions include/oxen/quic/udp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ namespace oxen::quic

// Return a string_view type, starting from index `pos`
template <oxenc::basic_char Char = std::byte>
std::basic_string_view<Char> data(size_t pos = 0) const
const_span<Char> data(size_t pos = 0) const
{
return std::basic_string_view<Char>{reinterpret_cast<const Char*>(data_sp.data() + pos), data_sp.size() - pos};
return const_span<Char>{reinterpret_cast<const Char*>(data_sp.data() + pos), data_sp.size() - pos};
}

/// Constructs a packet from a path and data view:
Expand Down
2 changes: 1 addition & 1 deletion src/gnutls_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ namespace oxen::quic

if (auto rv = gnutls_alpn_get_selected_protocol(session, &_alpn); rv < 0)
{
auto err = fmt::format("{} called, but ALPN negotiation incomplete.", __PRETTY_FUNCTION__);
auto err = "{} called, but ALPN negotiation incomplete."_format(__PRETTY_FUNCTION__);
log::error(log_cat, "{}", err);
throw std::logic_error(err);
}
Expand Down
5 changes: 2 additions & 3 deletions tests/001-handshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,8 @@ namespace oxen::quic::test

auto [client_tls, server_tls] = defaults::tls_creds_from_ed_keys();

server_tls->set_key_verify_callback([](const uspan& key, const uspan&) {
return key == convert_sv<unsigned char>(std::string_view{defaults::CLIENT_PUBKEY});
});
server_tls->set_key_verify_callback(
[](const uspan& key, const uspan&) { return key == str_to_uspan(defaults::CLIENT_PUBKEY); });

Address server_local{};
Address client_local{};
Expand Down
18 changes: 9 additions & 9 deletions tests/002-send-receive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ namespace oxen::quic::test
{
auto server_bp_cb = callback_waiter{[&](message msg) {
if (msg)
log::info(test_cat, "Server bparser received: {}", msg.view());
log::info(test_cat, "Server bparser received: {}", msg.span());
}};

stream_constructor_callback server_constructor = [&](Connection& c, Endpoint& e, std::optional<int64_t>) {
Expand Down Expand Up @@ -271,15 +271,15 @@ namespace oxen::quic::test
auto server_bp_cb = callback_waiter{[&](message msg) {
if (msg)
{
log::info(test_cat, "Server bparser received: {}", msg.view());
log::info(test_cat, "Server bparser received: {}", msg.span());
msg.respond("test_response"s);
}
}};

auto client_bp_cb = callback_waiter{[&](message msg) {
if (msg)
{
log::info(test_cat, "Client bparser received: {}", msg.view());
log::info(test_cat, "Client bparser received: {}", msg.span());
msg.respond("test_response"s);
}
}};
Expand Down Expand Up @@ -315,15 +315,15 @@ namespace oxen::quic::test
auto server_bp_cb = callback_waiter{[&](message msg) {
if (msg)
{
log::info(test_cat, "Server bparser received: {}", msg.view());
log::info(test_cat, "Server bparser received: {}", msg.span());
msg.respond("test_response"s);
}
}};

auto client_bp_cb = callback_waiter{[&](message msg) {
if (msg)
{
log::info(test_cat, "Client bparser received: {}", msg.view());
log::info(test_cat, "Client bparser received: {}", msg.span());
msg.respond("test_response"s);
}
}};
Expand Down Expand Up @@ -443,7 +443,7 @@ namespace oxen::quic::test
auto server_handler = [&](message msg) {
if (msg)
{
log::info(test_cat, "Server bparser received: {}", msg.view());
log::info(test_cat, "Server bparser received: {}", msg.span());
if (msg.body() == req_msg)
msg.respond(res_msg);
else
Expand All @@ -456,7 +456,7 @@ namespace oxen::quic::test
{
std::lock_guard lock{mut};
responses++;
log::debug(test_cat, "Client bparser received response {}: {}", responses, msg.view());
log::debug(test_cat, "Client bparser received response {}: {}", responses, msg.span());
if (msg.body() == res_msg)
good_responses++;
if (responses == num_requests)
Expand Down Expand Up @@ -534,7 +534,7 @@ namespace oxen::quic::test
if (msg)
{
++responses;
log::debug(test_cat, "Client bparser received response {}: {}", responses.load(), msg.view());
log::debug(test_cat, "Client bparser received response {}: {}", responses.load(), msg.span());
if (msg.body() == res_msg)
++good_responses;
if (responses == num_requests)
Expand Down Expand Up @@ -582,7 +582,7 @@ namespace oxen::quic::test

auto client_reply_handler = [&](message msg) mutable {
if (msg)
log::debug(test_cat, "Client bparser received response: {}", msg.view());
log::debug(test_cat, "Client bparser received response: {}", msg.span());
else
log::debug(test_cat, "got back a failed message response");
};
Expand Down
14 changes: 7 additions & 7 deletions tests/004-streams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ namespace oxen::quic::test
stream_data_callback server_data_cb = [&](Stream& s, bspan) {
std::lock_guard lock{mut};
server_seen[s.stream_id()]++;
s.send("🤔 {}"_format(s.stream_id()));
s.send("stupid emojis {}"_format(s.stream_id()));
};

Address server_local{};
Expand Down Expand Up @@ -662,7 +662,7 @@ namespace oxen::quic::test

auto s3 = client_ci->open_stream();
CHECK(client_stream_ctor_count.load() == 2);
REQUIRE(std::dynamic_pointer_cast<CustomStreamA>(s1));
REQUIRE(std::dynamic_pointer_cast<CustomStreamC>(s3));

auto s4 = client_ci->open_stream();
CHECK(client_stream_ctor_count.load() == 3);
Expand All @@ -678,10 +678,10 @@ namespace oxen::quic::test
require_future(cf2);
require_future(cf3);
require_future(cf4);
CHECK(cf1.get() == "🤔 0"_bsp);
CHECK(cf2.get() == "🤔 4"_bsp);
CHECK(cf3.get() == "🤔 8"_bsp);
CHECK(cf4.get() == "🤔 12"_bsp);
CHECK(cf1.get() == "stupid emojis 0"_bsp);
CHECK(cf2.get() == "stupid emojis 4"_bsp);
CHECK(cf3.get() == "stupid emojis 8"_bsp);
CHECK(cf4.get() == "stupid emojis 12"_bsp);

{
std::lock_guard lock{mut};
Expand Down Expand Up @@ -915,7 +915,7 @@ namespace oxen::quic::test
auto server_endpoint = test_net.endpoint(server_local);
server_endpoint->listen(server_tls, [&](Stream& s, bspan data) {
count += data.size();
log::debug(test_cat, "Got some data {}, replying with '{}'", data, count);
log::debug(test_cat, "Got some data {}, replying with '{}'", buffer_printer{data}, count);
s.send("{}"_format(count));
});

Expand Down
56 changes: 28 additions & 28 deletions tests/007-datagrams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,14 @@ namespace oxen::quic::test
std::this_thread::sleep_for(5ms);
auto max_size = conn_interface->get_max_datagram_size();

std::basic_string<uint8_t> good_msg{};
std::vector<uint8_t> good_msg{};
uint8_t v{0};

while (good_msg.size() < max_size)
good_msg += v++;
good_msg.emplace_back(v++);

for (int i = 0; i < n; ++i)
conn_interface->send_datagram(std::basic_string_view<uint8_t>{good_msg});
conn_interface->send_datagram(bspan{reinterpret_cast<const std::byte*>(good_msg.data()), good_msg.size()});

for (auto& f : data_futures)
require_future(f);
Expand Down Expand Up @@ -416,20 +416,20 @@ namespace oxen::quic::test
std::this_thread::sleep_for(5ms);
auto max_size = conn_interface->get_max_datagram_size();

std::basic_string<uint8_t> big_msg{}, small_msg{};
std::vector<uint8_t> big_msg{}, small_msg{};
uint8_t v{0};

while (big_msg.size() < max_size)
big_msg += v++;
big_msg.emplace_back(v++);

while (small_msg.size() < 500)
small_msg += v++;
small_msg.emplace_back(v++);

conn_interface->send_datagram(std::basic_string_view<uint8_t>{big_msg});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{big_msg});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{small_msg});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{big_msg});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{small_msg});
conn_interface->send_datagram(uspan{big_msg});
conn_interface->send_datagram(uspan{big_msg});
conn_interface->send_datagram(uspan{small_msg});
conn_interface->send_datagram(uspan{big_msg});
conn_interface->send_datagram(uspan{small_msg});

for (auto& f : data_futures)
require_future(f);
Expand Down Expand Up @@ -585,37 +585,37 @@ namespace oxen::quic::test
std::this_thread::sleep_for(5ms);
auto max_size = conn_interface->get_max_datagram_size();

std::basic_string<uint8_t> big{}, medium{}, small{};
std::vector<uint8_t> big{}, medium{}, small{};
uint8_t v{0};

while (big.size() < max_size * 2 / 3)
big += v++;
big.emplace_back(v++);

while (medium.size() < max_size / 2 - 100)
medium += v++;
medium.emplace_back(v++);

while (small.size() < 50)
small += v++;
small.emplace_back(v++);

TestHelper::enable_dgram_flip_flop(*conn_interface);

std::promise<void> pr;
std::future<void> ftr = pr.get_future();

client->call([&]() {
conn_interface->send_datagram(std::basic_string_view<uint8_t>{big});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{small});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{small});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{big});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{big});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{small});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{medium});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{big});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{small});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{small});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{small});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{small});
conn_interface->send_datagram(std::basic_string_view<uint8_t>{small});
conn_interface->send_datagram(uspan{big});
conn_interface->send_datagram(uspan{small});
conn_interface->send_datagram(uspan{small});
conn_interface->send_datagram(uspan{big});
conn_interface->send_datagram(uspan{big});
conn_interface->send_datagram(uspan{small});
conn_interface->send_datagram(uspan{medium});
conn_interface->send_datagram(uspan{big});
conn_interface->send_datagram(uspan{small});
conn_interface->send_datagram(uspan{small});
conn_interface->send_datagram(uspan{small});
conn_interface->send_datagram(uspan{small});
conn_interface->send_datagram(uspan{small});

pr.set_value();
});
Expand Down
Loading

0 comments on commit d90185d

Please sign in to comment.