load tox options from config
This commit is contained in:
parent
d00b3c6f8d
commit
ee638d3a10
@ -189,7 +189,7 @@ int main(int argc, char** argv) {
|
|||||||
ToxEventLogger tel{std::cout}; // TODO: config
|
ToxEventLogger tel{std::cout}; // TODO: config
|
||||||
|
|
||||||
// TODO: password?
|
// 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);
|
tel.subscribeAll(tc);
|
||||||
{ // name stuff
|
{ // name stuff
|
||||||
auto name = tc.toxSelfGetName();
|
auto name = tc.toxSelfGetName();
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
// meh, change this
|
// meh, change this
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <stdexcept>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
#include <toxencryptsave/toxencryptsave.h>
|
#include <toxencryptsave/toxencryptsave.h>
|
||||||
|
|
||||||
@ -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_profile_path(save_path), _tox_profile_password(save_password)
|
||||||
{
|
{
|
||||||
TOX_ERR_OPTIONS_NEW err_opt_new;
|
TOX_ERR_OPTIONS_NEW err_opt_new;
|
||||||
Tox_Options* options = tox_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);
|
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<uint8_t> profile_data{};
|
std::vector<uint8_t> profile_data{};
|
||||||
if (!_tox_profile_path.empty()) {
|
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_ERR_NEW err_new;
|
||||||
_tox = tox_new(options, &err_new);
|
_tox = tox_new(options, &err_new);
|
||||||
tox_options_free(options);
|
tox_options_free(options);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <solanaceae/util/config_model.hpp>
|
||||||
|
|
||||||
#include <solanaceae/toxcore/tox_default_impl.hpp>
|
#include <solanaceae/toxcore/tox_default_impl.hpp>
|
||||||
#include <solanaceae/toxcore/tox_event_interface.hpp>
|
#include <solanaceae/toxcore/tox_event_interface.hpp>
|
||||||
#include <solanaceae/toxcore/tox_event_provider_base.hpp>
|
#include <solanaceae/toxcore/tox_event_provider_base.hpp>
|
||||||
@ -24,8 +26,7 @@ class ToxClient : public ToxDefaultImpl, public ToxEventProviderBase {
|
|||||||
bool _tox_profile_dirty {true}; // set in callbacks
|
bool _tox_profile_dirty {true}; // set in callbacks
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//ToxClient(/*const CommandLine& cl*/);
|
ToxClient(ConfigModelI& conf, std::string_view save_path, std::string_view save_password);
|
||||||
ToxClient(std::string_view save_path, std::string_view save_password);
|
|
||||||
~ToxClient(void);
|
~ToxClient(void);
|
||||||
|
|
||||||
public: // tox stuff
|
public: // tox stuff
|
||||||
|
@ -38,7 +38,6 @@ void registerToxCommands(
|
|||||||
reply += "tcp-relayed";
|
reply += "tcp-relayed";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
reply += "\ndht-closenum:";
|
reply += "\ndht-closenum:";
|
||||||
reply += std::to_string(tp.toxDHTGetNumCloselist());
|
reply += std::to_string(tp.toxDHTGetNumCloselist());
|
||||||
reply += "\ndht-closenum-announce-capable:";
|
reply += "\ndht-closenum-announce-capable:";
|
||||||
|
Loading…
Reference in New Issue
Block a user