diff --git a/src/main.cpp b/src/main.cpp index e0e8a2c..93aaffb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -189,7 +189,7 @@ int main(int argc, char** argv) { ToxEventLogger tel{std::cout}; // TODO: config // TODO: password? - ToxClient tc{conf.get_string("tox", "save_file_path").value(), ""}; + ToxClient tc{conf, conf.get_string("tox", "save_file_path").value(), ""}; tel.subscribeAll(tc); { // name stuff auto name = tc.toxSelfGetName(); diff --git a/src/tox_client.cpp b/src/tox_client.cpp index e015a1d..42c1290 100644 --- a/src/tox_client.cpp +++ b/src/tox_client.cpp @@ -2,6 +2,7 @@ // meh, change this #include +#include #include #include @@ -18,12 +19,13 @@ static void eee(std::string& mod) { } } -ToxClient::ToxClient(std::string_view save_path, std::string_view save_password) : +ToxClient::ToxClient(ConfigModelI& conf, std::string_view save_path, std::string_view save_password) : _tox_profile_path(save_path), _tox_profile_password(save_password) { TOX_ERR_OPTIONS_NEW err_opt_new; Tox_Options* options = tox_options_new(&err_opt_new); assert(err_opt_new == TOX_ERR_OPTIONS_NEW::TOX_ERR_OPTIONS_NEW_OK); + std::string tmp_proxy_host; // the string needs to survive until options is freed std::vector profile_data{}; if (!_tox_profile_path.empty()) { @@ -67,6 +69,40 @@ ToxClient::ToxClient(std::string_view save_path, std::string_view save_password) } } + tox_options_set_ipv6_enabled(options, conf.get_bool("tox", "ipv6_enabled").value_or(true)); + tox_options_set_udp_enabled(options, conf.get_bool("tox", "udp_enabled").value_or(true)); + tox_options_set_local_discovery_enabled(options, conf.get_bool("tox", "local_discovery_enabled").value_or(true)); + // TODO: should this be exposed? + tox_options_set_dht_announcements_enabled(options, conf.get_bool("tox", "dht_announcements_enabled").value_or(true)); + + const size_t proxy_conf_sum = conf.has_string("tox", "proxy_type") + + conf.has_string("tox", "proxy_host") + + conf.has_int("tox", "proxy_port") + ; + // if all proxy parts defined + if (proxy_conf_sum == 3) { + const std::string_view proxy_type_str = conf.get_string("tox", "proxy_type").value(); + if (proxy_type_str == "HTTP") { + tox_options_set_proxy_type(options, Tox_Proxy_Type::TOX_PROXY_TYPE_HTTP); + } else if (proxy_type_str == "SOCKS5") { + tox_options_set_proxy_type(options, Tox_Proxy_Type::TOX_PROXY_TYPE_SOCKS5); + } else { + throw std::runtime_error("invalid proxy type in config, terminating to be safe"); + } + + tmp_proxy_host = conf.get_string("tox", "proxy_host").value(); + tox_options_set_proxy_host(options, tmp_proxy_host.c_str()); + + tox_options_set_proxy_port(options, conf.get_int("tox", "proxy_port").value()); + } else if (proxy_conf_sum > 0) { + throw std::runtime_error("config only partly specified proxy, terminating to be safe"); + } + + tox_options_set_start_port(options, conf.get_int("tox", "start_port").value_or(0)); + tox_options_set_end_port(options, conf.get_int("tox", "end_port").value_or(0)); + tox_options_set_tcp_port(options, conf.get_int("tox", "tcp_port").value_or(0)); + tox_options_set_hole_punching_enabled(options, conf.get_bool("tox", "hole_punching_enabled").value_or(true)); + TOX_ERR_NEW err_new; _tox = tox_new(options, &err_new); tox_options_free(options); diff --git a/src/tox_client.hpp b/src/tox_client.hpp index 208c95b..12d5750 100644 --- a/src/tox_client.hpp +++ b/src/tox_client.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include #include #include @@ -24,8 +26,7 @@ class ToxClient : public ToxDefaultImpl, public ToxEventProviderBase { bool _tox_profile_dirty {true}; // set in callbacks public: - //ToxClient(/*const CommandLine& cl*/); - ToxClient(std::string_view save_path, std::string_view save_password); + ToxClient(ConfigModelI& conf, std::string_view save_path, std::string_view save_password); ~ToxClient(void); public: // tox stuff diff --git a/src/tox_commands.cpp b/src/tox_commands.cpp index d796a2d..7f02272 100644 --- a/src/tox_commands.cpp +++ b/src/tox_commands.cpp @@ -38,7 +38,6 @@ void registerToxCommands( reply += "tcp-relayed"; } - reply += "\ndht-closenum:"; reply += std::to_string(tp.toxDHTGetNumCloselist()); reply += "\ndht-closenum-announce-capable:";