Skip to content
Snippets Groups Projects
Commit 2b5b07f5 authored by Amna Snene's avatar Amna Snene
Browse files

tools: add turn to dsh

Change-Id: I6c252a9f9d6de1c4f6d85043d3ed238eec747244
parent 05eb28dd
No related branches found
No related tags found
No related merge requests found
...@@ -87,7 +87,11 @@ child_proc(const int in_pipe[2], ...@@ -87,7 +87,11 @@ child_proc(const int in_pipe[2],
dhtnet::Dsh::Dsh(const std::filesystem::path& path, dhtnet::Dsh::Dsh(const std::filesystem::path& path,
dht::crypto::Identity identity, 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()) : logger(dht::log::getStdLogger())
// , std::shared_ptr<tls::CertificateStore>(path / "certstore", logger) // , std::shared_ptr<tls::CertificateStore>(path / "certstore", logger)
{ {
...@@ -218,8 +222,12 @@ dhtnet::Dsh::Dsh(const std::filesystem::path& path, ...@@ -218,8 +222,12 @@ dhtnet::Dsh::Dsh(const std::filesystem::path& path,
dht::crypto::Identity identity, dht::crypto::Identity identity,
const std::string& bootstrap, const std::string& bootstrap,
dht::InfoHash peer_id, dht::InfoHash peer_id,
const std::string& binary) const std::string& binary,
: Dsh(path, identity, bootstrap) 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 // Build a client
std::condition_variable cv; std::condition_variable cv;
......
...@@ -29,13 +29,21 @@ public: ...@@ -29,13 +29,21 @@ public:
// Build a server // Build a server
Dsh(const std::filesystem::path& path, Dsh(const std::filesystem::path& path,
dht::crypto::Identity identity, 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 // Build a client
Dsh(const std::filesystem::path& path, Dsh(const std::filesystem::path& path,
dht::crypto::Identity identity, dht::crypto::Identity identity,
const std::string& bootstrap, const std::string& bootstrap,
dht::InfoHash peer_id, 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(); ~Dsh();
void run(); void run();
......
...@@ -28,7 +28,8 @@ ...@@ -28,7 +28,8 @@
#else #else
#include <fmt/ostream.h> #include <fmt/ostream.h>
#endif #endif
#include <yaml-cpp/yaml.h>
#include <fstream>
struct dhtsh_params struct dhtsh_params
{ {
...@@ -39,22 +40,35 @@ struct dhtsh_params ...@@ -39,22 +40,35 @@ struct dhtsh_params
std::string bootstrap {}; std::string bootstrap {};
dht::InfoHash peer_id {}; dht::InfoHash peer_id {};
std::string binary {}; 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'}, static const constexpr struct option long_options[]
{"version", no_argument, nullptr, 'v'}, = {{"help", no_argument, nullptr, 'h'},
{"listen", no_argument, nullptr, 'l'}, {"version", no_argument, nullptr, 'v'},
{"bootstrap", required_argument, nullptr, 'b'}, {"listen", no_argument, nullptr, 'l'},
{"binary", required_argument, nullptr, 's'}, {"bootstrap", required_argument, nullptr, 'b'},
{"id_path", required_argument, nullptr, 'I'}, {"binary", required_argument, nullptr, 's'},
{nullptr, 0, nullptr, 0}}; {"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 dhtsh_params
parse_args(int argc, char** argv) parse_args(int argc, char** argv)
{ {
dhtsh_params params; dhtsh_params params;
int opt; 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) { switch (opt) {
case 'h': case 'h':
params.help = true; params.help = true;
...@@ -74,6 +88,23 @@ parse_args(int argc, char** argv) ...@@ -74,6 +88,23 @@ parse_args(int argc, char** argv)
case 'I': case 'I':
params.path = optarg; params.path = optarg;
break; 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: default:
std::cerr << "Invalid option" << std::endl; std::cerr << "Invalid option" << std::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -127,13 +158,18 @@ main(int argc, char** argv) ...@@ -127,13 +158,18 @@ main(int argc, char** argv)
if (params.help){ if (params.help){
fmt::print("Usage: dsh [OPTIONS] [PEER_ID]\n" fmt::print("Usage: dsh [OPTIONS] [PEER_ID]\n"
"\nOptions:\n" "\nOptions:\n"
" -h, --help Show this help message and exit.\n" " -h, --help Show this help message and exit.\n"
" -v, --version Display the program version.\n" " -v, --version Display the program version.\n"
" -l, --listen Start the program in listen mode.\n" " -l, --listen Start the program in listen mode.\n"
" -b, --bootstrap Specify the bootstrap option with an argument.\n" " -b, --bootstrap Specify the bootstrap option with an argument.\n"
" -s, --binary Specify the binary 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"); " -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; return EXIT_SUCCESS;
} }
if (params.version){ if (params.version){
...@@ -149,16 +185,25 @@ main(int argc, char** argv) ...@@ -149,16 +185,25 @@ main(int argc, char** argv)
std::unique_ptr<dhtnet::Dsh> dhtsh; std::unique_ptr<dhtnet::Dsh> dhtsh;
if (params.listen) { if (params.listen) {
// create dnc instance // 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 { } else {
dhtsh = std::make_unique<dhtnet::Dsh>(params.path, dhtsh = std::make_unique<dhtnet::Dsh>(params.path,
identity, identity,
params.bootstrap, params.bootstrap,
params.peer_id, params.peer_id,
params.binary); params.binary,
params.turn_host,
params.turn_user,
params.turn_pass,
params.turn_realm);
} }
dhtsh->run(); dhtsh->run();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment