diff --git a/src/security/certstore.cpp b/src/security/certstore.cpp index aa3e14cb35dcb1b818c88c09cd1fffdad5bd108e..ee5b9d65daec0be5f5a0b9f9b26d7482f69c5585 100644 --- a/src/security/certstore.cpp +++ b/src/security/certstore.cpp @@ -24,8 +24,11 @@ #include <gnutls/ocsp.h> +#if __has_include(<fmt/std.h>) #include <fmt/std.h> - +#else +#include <fmt/ostream.h> +#endif #include <thread> #include <sstream> #include <fmt/format.h> diff --git a/tools/benchmark/main.cpp b/tools/benchmark/main.cpp index 0a9e8d76a56466caffb6b5dd1ec98a26d8e15e89..8ec56487049dea2433a82d10f3a9956f16199d50 100644 --- a/tools/benchmark/main.cpp +++ b/tools/benchmark/main.cpp @@ -77,7 +77,7 @@ setupHandler(const std::string& name, h->connectionManager = std::make_shared<ConnectionManager>(config); h->connectionManager->onICERequest([](const DeviceId&) { return true; }); - return h; + return h; } struct BenchResult { @@ -100,7 +100,7 @@ runBench(std::shared_ptr<asio::io_context> ioContext, //auto boostrap_node = std::make_shared<dht::DhtRunner>(); //boostrap_node->run(36432); - fmt::println("Generating identities…"); + fmt::print("Generating identities…\n"); auto server = setupHandler("server", ioContext, ioContextRunner, factory, logger); auto client = setupHandler("client", ioContext, ioContextRunner, factory, logger); @@ -114,13 +114,13 @@ runBench(std::shared_ptr<asio::io_context> ioContext, }); server->connectionManager->onConnectionReady([&](const DeviceId& device, const std::string& name, std::shared_ptr<ChannelSocket> socket) { if (socket) { - fmt::println("Server: Connection succeeded"); + fmt::print("Server: Connection succeeded\n"); socket->setOnRecv([s=socket.get()](const uint8_t* data, size_t size) { std::error_code ec; return s->write(data, size, ec); }); } else { - fmt::println("Server: Connection failed"); + fmt::print("Server: Connection failed\n"); } }); @@ -133,7 +133,7 @@ runBench(std::shared_ptr<asio::io_context> ioContext, time_point start_connect, start_send; std::this_thread::sleep_for(5s); - fmt::println("Connecting…"); + fmt::println("Connecting…\n"); start_connect = clock::now(); client->connectionManager->connectDevice(server->id.second, "channelName", [&](std::shared_ptr<ChannelSocket> socket, const DeviceId&) { if (socket) { @@ -142,20 +142,20 @@ runBench(std::shared_ptr<asio::io_context> ioContext, if (rx == TX_GOAL) { auto end = clock::now(); ret.send = end - start_send; - fmt::println("Streamed {} bytes back and forth in {} ({} kBps)", rx, dht::print_duration(ret.send), (unsigned)(rx / (1000 * std::chrono::duration<double>(ret.send).count()))); + fmt::print("Streamed {} bytes back and forth in {} ({} kBps)\n", rx, dht::print_duration(ret.send), (unsigned)(rx / (1000 * std::chrono::duration<double>(ret.send).count()))); cv.notify_one(); } return size; }); ret.connection = clock::now() - start_connect; - fmt::println("Connected in {}", dht::print_duration(ret.connection)); + fmt::print("Connected in {}\n", dht::print_duration(ret.connection)); std::vector<uint8_t> data(TX_SIZE, 'y'); std::error_code ec; start_send = clock::now(); for (unsigned i = 0; i < TX_NUM; ++i) { socket->write(data.data(), data.size(), ec); if (ec) - fmt::println("error: {}", ec.message()); + fmt::print("error: {}\n", ec.message()); } } else { completed = true; @@ -179,15 +179,15 @@ bench() auto work = asio::make_work_guard(*context); context->run(); } catch (const std::exception& ex) { - fmt::println(stderr, "Exception: {}", ex.what()); + fmt::print(stderr, "Exception: {}\n", ex.what()); } }); - - BenchResult total; + + BenchResult total = {0s, 0s, false}; unsigned total_success = 0; constexpr unsigned ITERATIONS = 20; for (unsigned i = 0; i < ITERATIONS; ++i) { - fmt::println("Iteration {}", i); + fmt::print("Iteration {}\n", i); auto res = runBench(ioContext, ioContextRunner, factory, logger); if (res.success) { total.connection += res.connection; @@ -195,10 +195,10 @@ bench() total_success++; } } - fmt::println("Average connection time: {}", dht::print_duration(total.connection / total_success)); - fmt::println("Average send time: {}", dht::print_duration(total.send / total_success)); - fmt::println("Total success: {}", total_success); - + fmt::print("Average connection time: {}\n", dht::print_duration(total.connection / total_success)); + fmt::print("Average send time: {}\n", dht::print_duration(total.send / total_success)); + fmt::print("Total success: {}\n", total_success); + std::this_thread::sleep_for(500ms); ioContext->stop(); ioContextRunner->join(); diff --git a/tools/dnc/main.cpp b/tools/dnc/main.cpp index 278990bf88578cb3c010b002cb70d390f642fa5d..677477f2c3bb27c2d6c2153a569d1c97c2a0a8ad 100644 --- a/tools/dnc/main.cpp +++ b/tools/dnc/main.cpp @@ -22,7 +22,11 @@ #include <iostream> #include <unistd.h> #include <getopt.h> +#if __has_include(<fmt/std.h>) #include <fmt/std.h> +#else +#include <fmt/ostream.h> +#endif #include <netinet/in.h> struct dhtnc_params @@ -54,8 +58,8 @@ parse_args(int argc, char** argv) { dhtnc_params params; int opt; - while ((opt = getopt_long(argc, argv, "hvI:p:i:", long_options, nullptr)) != -1) { - fmt::print("opt: {} {}\n", opt, optarg); + while ((opt = getopt_long(argc, argv, "hvVlI:b:p:i:", long_options, nullptr)) != -1) { + // fmt::print("opt: {} {}\n", opt, optarg); switch (opt) { case 'h': params.help = true; @@ -100,7 +104,7 @@ parse_args(int argc, char** argv) // default values if (params.remote_port == 0) - params.remote_port = 2000; + params.remote_port = 22; if (params.remote_host.empty()) params.remote_host = "127.0.0.1"; if (params.bootstrap.empty())