diff --git a/tools/dsh/dsh.cpp b/tools/dsh/dsh.cpp index 51b80a55c75689d969d8b755a755ce50b89c0266..92f30b1d9f0734cbb55e56d4f19158b632a84232 100644 --- a/tools/dsh/dsh.cpp +++ b/tools/dsh/dsh.cpp @@ -87,7 +87,11 @@ child_proc(const int in_pipe[2], dhtnet::Dsh::Dsh(const std::filesystem::path& path, dht::crypto::Identity identity, - const std::string& bootstrap) + const std::string& bootstrap, + const std::string& turn_host, + const std::string& turn_user, + const std::string& turn_pass, + const std::string& turn_realm) : logger(dht::log::getStdLogger()) // , std::shared_ptr<tls::CertificateStore>(path / "certstore", logger) { @@ -218,8 +222,12 @@ dhtnet::Dsh::Dsh(const std::filesystem::path& path, dht::crypto::Identity identity, const std::string& bootstrap, dht::InfoHash peer_id, - const std::string& binary) - : Dsh(path, identity, bootstrap) + const std::string& binary, + const std::string& turn_host, + const std::string& turn_user, + const std::string& turn_pass, + const std::string& turn_realm) + : Dsh(path, identity, bootstrap, turn_host, turn_user, turn_pass, turn_realm) { // Build a client std::condition_variable cv; diff --git a/tools/dsh/dsh.h b/tools/dsh/dsh.h index 09ab147a23b09977dd29741b60da4e66383df951..c349619abb73e22e6bb343cb254238631b5ba4e7 100644 --- a/tools/dsh/dsh.h +++ b/tools/dsh/dsh.h @@ -29,13 +29,21 @@ public: // Build a server Dsh(const std::filesystem::path& path, dht::crypto::Identity identity, - const std::string& bootstrap); + const std::string& bootstrap, + const std::string& turn_host, + const std::string& turn_user, + const std::string& turn_pass, + const std::string& turn_realm); // Build a client Dsh(const std::filesystem::path& path, dht::crypto::Identity identity, const std::string& bootstrap, dht::InfoHash peer_id, - const std::string& binary); + const std::string& binary, + const std::string& turn_host, + const std::string& turn_user, + const std::string& turn_pass, + const std::string& turn_realm); ~Dsh(); void run(); diff --git a/tools/dsh/main.cpp b/tools/dsh/main.cpp index a259cdce8b68e84fd049e248dc5bbc4e90d8002e..b6697a3842d0f9e12392b729e2297f207cd079ce 100644 --- a/tools/dsh/main.cpp +++ b/tools/dsh/main.cpp @@ -28,7 +28,8 @@ #else #include <fmt/ostream.h> #endif - +#include <yaml-cpp/yaml.h> +#include <fstream> struct dhtsh_params { @@ -39,22 +40,35 @@ struct dhtsh_params std::string bootstrap {}; dht::InfoHash peer_id {}; std::string binary {}; + std::string ca {}; + std::string turn_host {}; + std::string turn_user {}; + std::string turn_pass {}; + std::string turn_realm {}; + std::string dsh_configuration {}; }; -static const constexpr struct option long_options[] = {{"help", no_argument, nullptr, 'h'}, - {"version", no_argument, nullptr, 'v'}, - {"listen", no_argument, nullptr, 'l'}, - {"bootstrap", required_argument, nullptr, 'b'}, - {"binary", required_argument, nullptr, 's'}, - {"id_path", required_argument, nullptr, 'I'}, - {nullptr, 0, nullptr, 0}}; +static const constexpr struct option long_options[] + = {{"help", no_argument, nullptr, 'h'}, + {"version", no_argument, nullptr, 'v'}, + {"listen", no_argument, nullptr, 'l'}, + {"bootstrap", required_argument, nullptr, 'b'}, + {"binary", required_argument, nullptr, 's'}, + {"id_path", required_argument, nullptr, 'I'}, + {"CA", required_argument, nullptr, 'C'}, + {"turn_host", required_argument, nullptr, 't'}, + {"turn_user", required_argument, nullptr, 'u'}, + {"turn_pass", required_argument, nullptr, 'w'}, + {"turn_realm", required_argument, nullptr, 'r'}, + {"dsh_configuration", required_argument, nullptr, 'd'}, + {nullptr, 0, nullptr, 0}}; dhtsh_params parse_args(int argc, char** argv) { dhtsh_params params; int opt; - while ((opt = getopt_long(argc, argv, "hvls:I:p:i:", long_options, nullptr)) != -1) { + while ((opt = getopt_long(argc, argv, "hvls:I:p:i:C:r:w:u:t:d:", long_options, nullptr)) != -1) { switch (opt) { case 'h': params.help = true; @@ -74,6 +88,23 @@ parse_args(int argc, char** argv) case 'I': params.path = optarg; break; + case 't': + params.turn_host = optarg; + break; + case 'u': + params.turn_user = optarg; + break; + case 'w': + params.turn_pass = optarg; + break; + case 'r': + params.turn_realm = optarg; + break; + case 'C': + params.ca = optarg; + break; + case 'd': + params.dsh_configuration = optarg; default: std::cerr << "Invalid option" << std::endl; exit(EXIT_FAILURE); @@ -127,13 +158,18 @@ main(int argc, char** argv) if (params.help){ fmt::print("Usage: dsh [OPTIONS] [PEER_ID]\n" - "\nOptions:\n" - " -h, --help Show this help message and exit.\n" - " -v, --version Display the program version.\n" - " -l, --listen Start the program in listen mode.\n" - " -b, --bootstrap Specify the bootstrap option with an argument.\n" - " -s, --binary Specify the binary option with an argument.\n" - " -I, --id_path Specify the id_path option with an argument.\n"); + "\nOptions:\n" + " -h, --help Show this help message and exit.\n" + " -v, --version Display the program version.\n" + " -l, --listen Start the program in listen mode.\n" + " -b, --bootstrap Specify the bootstrap option with an argument.\n" + " -s, --binary Specify the binary option with an argument.\n" + " -I, --id_path Specify the id_path option with an argument.\n" + " -C, --CA Specify the CA option with an argument.\n" + " -t, --turn_host Specify the turn_host option with an argument.\n" + " -u, --turn_user Specify the turn_user option with an argument.\n" + " -w, --turn_pass Specify the turn_pass option with an argument.\n" + " -r, --turn_realm Specify the turn_realm option with an argument.\n"); return EXIT_SUCCESS; } if (params.version){ @@ -149,16 +185,25 @@ main(int argc, char** argv) std::unique_ptr<dhtnet::Dsh> dhtsh; if (params.listen) { // create dnc instance - dhtsh = std::make_unique<dhtnet::Dsh>(params.path, identity, params.bootstrap); + dhtsh = std::make_unique<dhtnet::Dsh>(params.path, + identity, + params.bootstrap, + params.turn_host, + params.turn_user, + params.turn_pass, + params.turn_realm); } else { dhtsh = std::make_unique<dhtnet::Dsh>(params.path, identity, params.bootstrap, params.peer_id, - params.binary); + params.binary, + params.turn_host, + params.turn_user, + params.turn_pass, + params.turn_realm); } dhtsh->run(); return EXIT_SUCCESS; - }