Skip to content
Snippets Groups Projects
Commit 45db7765 authored by Amna Snene's avatar Amna Snene Committed by Louis Maillard
Browse files

tools: add upnp

dnc: upnp can be disabled via dnc.yaml only
dsh and dvpn : upnp cannot be disabled

Change-Id: Ic1a53b049eace145ebdc7ac186ab92a4a0df3635
parent c03c4b57
Branches
No related tags found
No related merge requests found
......@@ -60,6 +60,9 @@ configure_yaml() {
echo "# When verbose is set to true, the server logs all incoming connections"
echo "verbose: false"
echo ""
echo "# If true, will send request to use UPNP if available"
echo "enable_upnp: true"
echo ""
echo "# On server, identities are saved in /etc/dhtnet/id/"
echo "certificate: \"/etc/dhtnet/id/id-server.crt\""
echo "privateKey: \"/etc/dhtnet/id/id-server.pem\""
......
......@@ -53,7 +53,8 @@ connectionManagerConfig(dht::crypto::Identity identity,
const std::string& turn_host,
const std::string& turn_user,
const std::string& turn_pass,
const std::string& turn_realm)
const std::string& turn_realm,
const bool enable_upnp)
{
// DHT node creation: To make a connection manager at first a DHT node should be created
dht::DhtRunner::Config dhtConfig;
......@@ -93,6 +94,15 @@ connectionManagerConfig(dht::crypto::Identity identity,
config->turnServerPwd = turn_pass;
config->turnServerRealm = turn_realm;
}
if (enable_upnp) {
// UPnP configuration
auto upnpContext = std::make_shared<dhtnet::upnp::UPnPContext>(ioContext, logger);
auto controller = std::make_shared<dhtnet::upnp::Controller>(upnpContext);
config->upnpEnabled = true;
config->upnpCtrl = controller;
}
return std::move(config);
}
template<typename T>
......
......@@ -21,6 +21,9 @@
#include "ice_transport_factory.h"
#include "certstore.h"
#include "upnp/upnp_control.h"
#include "upnp/upnp_context.h"
namespace dhtnet {
#define Log(...) do { fmt::print(__VA_ARGS__); std::fflush(stdout); } while (0)
......@@ -40,7 +43,8 @@ std::unique_ptr<ConnectionManager::Config> connectionManagerConfig(
const std::string& turn_host ="",
const std::string& turn_user="",
const std::string& turn_pass="",
const std::string& turn_realm="");
const std::string& turn_realm="",
const bool enable_upnp=true);
// add ioContext to readFromStdin
template<typename T>
......
......@@ -122,6 +122,9 @@ int create_yaml_config(std::filesystem::path file, std::filesystem::path certifi
yaml_file << "\n# When verbose is set to true, the server logs all incoming connections\n";
yaml_file << "verbose: false\n";
yaml_file << "\n# If true, will send request to use UPNP if available\n";
yaml_file << "enable_upnp: true\n";
yaml_file << "\n# On server, identities are saved in /etc/dhtnet/id/\n";
yaml_file << "# On client, they are generaly saved in ~/.dnc/\n";
yaml_file << "certificate: " << certificate << "\n";
......
......@@ -61,7 +61,8 @@ Dnc::Dnc(dht::crypto::Identity identity,
const std::string& turn_realm,
const bool anonymous,
const bool verbose,
const std::map<std::string, std::vector<int>> authorized_services)
const std::map<std::string, std::vector<int>> authorized_services,
const bool enable_upnp)
:logger(verbose ? dht::log::getStdLogger() : nullptr),
ioContext(std::make_shared<asio::io_context>()),
iceFactory(std::make_shared<IceTransportFactory>(logger))
......@@ -91,7 +92,8 @@ Dnc::Dnc(dht::crypto::Identity identity,
turn_host,
turn_user,
turn_pass,
turn_realm);
turn_realm,
enable_upnp);
// create a connection manager
connectionManager = std::make_unique<ConnectionManager>(std::move(config));
......@@ -206,8 +208,9 @@ Dnc::Dnc(dht::crypto::Identity identity,
const std::string& turn_user,
const std::string& turn_pass,
const std::string& turn_realm,
const bool verbose)
: Dnc(identity, bootstrap,turn_host,turn_user,turn_pass, turn_realm, true, verbose, {})
const bool verbose,
const bool enable_upnp)
: Dnc(identity, bootstrap,turn_host,turn_user,turn_pass, turn_realm, true, verbose, {}, enable_upnp)
{
std::condition_variable cv;
auto name = fmt::format("nc://{:s}:{:d}", remote_host, remote_port);
......
......@@ -41,7 +41,8 @@ public:
const std::string& turn_realm,
const bool anonymous,
const bool verbose,
const std::map<std::string, std::vector<int>> authorized_services);
const std::map<std::string, std::vector<int>> authorized_services,
const bool enable_upnp);
// Build a client
Dnc(
dht::crypto::Identity identity,
......@@ -53,7 +54,8 @@ public:
const std::string& turn_user,
const std::string& turn_pass,
const std::string& turn_realm,
const bool verbose);
const bool verbose,
const bool enable_upnp);
~Dnc();
void run();
......
......@@ -16,6 +16,9 @@ turn_realm: "ring"
# When verbose is set to true, the server logs all incoming connections
verbose: false
# If true, will send request to use UPNP if available
enable_upnp: true
# On server, identities are saved in /etc/dhtnet/id/
# On client, identities are saved in ~/.dnc/
#certificate: "to/your/certificate.crt"
......
......@@ -51,6 +51,7 @@ struct dhtnc_params
bool anonymous_cnx {false};
bool verbose {false};
std::map<std::string, std::vector<int>> authorizedServices {};
bool enable_upnp {true};
};
static const constexpr struct option long_options[]
......@@ -201,6 +202,9 @@ parse_args(int argc, char** argv)
params.authorizedServices[ip].push_back(port);
}
}
if (config["enable_upnp"]) {
params.enable_upnp = config["enable_upnp"].as<bool>();
}
}
}
return params;
......@@ -272,7 +276,8 @@ main(int argc, char** argv)
params.turn_realm,
params.anonymous_cnx,
params.verbose,
params.authorizedServices);
params.authorizedServices,
params.enable_upnp);
} else {
dhtnc = std::make_unique<dhtnet::Dnc>(identity,
params.bootstrap,
......@@ -283,7 +288,8 @@ main(int argc, char** argv)
params.turn_user,
params.turn_pass,
params.turn_realm,
params.verbose);
params.verbose,
params.enable_upnp);
}
dhtnc->run();
return EXIT_SUCCESS;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment