|
|
|
@ -3,12 +3,11 @@
@@ -3,12 +3,11 @@
|
|
|
|
|
#include "src/core/icoresettings.h" |
|
|
|
|
#include "src/core/toxlogger.h" |
|
|
|
|
|
|
|
|
|
#include <tox/tox.h> |
|
|
|
|
|
|
|
|
|
#include <QByteArray> |
|
|
|
|
#include <QDebug> |
|
|
|
|
|
|
|
|
|
// TODO(sudden6): replace this constant with the function from toxcore 0.2.3
|
|
|
|
|
static const int MAX_PROXY_ADDRESS_LENGTH = 255; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief The ToxOptions class wraps the Tox_Options struct and the matching |
|
|
|
|
* proxy address data. This is needed to ensure both have equal lifetime and |
|
|
|
@ -51,6 +50,31 @@ ToxOptions::operator Tox_Options*()
@@ -51,6 +50,31 @@ ToxOptions::operator Tox_Options*()
|
|
|
|
|
std::unique_ptr<ToxOptions> ToxOptions::makeToxOptions(const QByteArray& savedata, |
|
|
|
|
const ICoreSettings* s) |
|
|
|
|
{ |
|
|
|
|
Tox_Options* tox_opts = tox_options_new(nullptr); |
|
|
|
|
|
|
|
|
|
if (!tox_opts) { |
|
|
|
|
qWarning() << "failed to create Tox_Options"; |
|
|
|
|
return {}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// need to init proxyAddr here, because we need it to construct ToxOptions
|
|
|
|
|
const QString proxyAddr = s == nullptr ? QString{} : s->getProxyAddr(); |
|
|
|
|
|
|
|
|
|
auto toxOptions = std::unique_ptr<ToxOptions>(new ToxOptions(tox_opts, proxyAddr.toUtf8())); |
|
|
|
|
// register log first, to get messages as early as possible
|
|
|
|
|
tox_options_set_log_callback(*toxOptions, ToxLogger::onLogMessage); |
|
|
|
|
|
|
|
|
|
// savedata
|
|
|
|
|
tox_options_set_savedata_type(*toxOptions, savedata.isNull() ? TOX_SAVEDATA_TYPE_NONE |
|
|
|
|
: TOX_SAVEDATA_TYPE_TOX_SAVE); |
|
|
|
|
tox_options_set_savedata_data(*toxOptions, reinterpret_cast<const uint8_t*>(savedata.data()), |
|
|
|
|
savedata.size()); |
|
|
|
|
|
|
|
|
|
if(s == nullptr) { |
|
|
|
|
qDebug() << "Using Tox default settings"; |
|
|
|
|
return toxOptions; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// IPv6 needed for LAN discovery, but can crash some weird routers. On by default, can be
|
|
|
|
|
// disabled in options.
|
|
|
|
|
const bool enableIPv6 = s->getEnableIPv6(); |
|
|
|
@ -59,7 +83,6 @@ std::unique_ptr<ToxOptions> ToxOptions::makeToxOptions(const QByteArray& savedat
@@ -59,7 +83,6 @@ std::unique_ptr<ToxOptions> ToxOptions::makeToxOptions(const QByteArray& savedat
|
|
|
|
|
const bool enableLanDiscovery = s->getEnableLanDiscovery() && !forceTCP; |
|
|
|
|
ICoreSettings::ProxyType proxyType = s->getProxyType(); |
|
|
|
|
quint16 proxyPort = s->getProxyPort(); |
|
|
|
|
QString proxyAddr = s->getProxyAddr(); |
|
|
|
|
|
|
|
|
|
if (!enableLanDiscovery) { |
|
|
|
|
qWarning() << "Core starting without LAN discovery. Peers can only be found through DHT."; |
|
|
|
@ -70,28 +93,13 @@ std::unique_ptr<ToxOptions> ToxOptions::makeToxOptions(const QByteArray& savedat
@@ -70,28 +93,13 @@ std::unique_ptr<ToxOptions> ToxOptions::makeToxOptions(const QByteArray& savedat
|
|
|
|
|
qWarning() << "Core starting with IPv6 disabled. LAN discovery may not work properly."; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Tox_Options* tox_opts = tox_options_new(nullptr); |
|
|
|
|
|
|
|
|
|
if (!tox_opts) { |
|
|
|
|
return {}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto toxOptions = std::unique_ptr<ToxOptions>(new ToxOptions(tox_opts, proxyAddr.toUtf8())); |
|
|
|
|
// register log first, to get messages as early as possible
|
|
|
|
|
tox_options_set_log_callback(*toxOptions, ToxLogger::onLogMessage); |
|
|
|
|
|
|
|
|
|
// savedata
|
|
|
|
|
tox_options_set_savedata_type(*toxOptions, !savedata.isNull() ? TOX_SAVEDATA_TYPE_TOX_SAVE |
|
|
|
|
: TOX_SAVEDATA_TYPE_NONE); |
|
|
|
|
tox_options_set_savedata_data(*toxOptions, reinterpret_cast<const uint8_t*>(savedata.data()), |
|
|
|
|
savedata.size()); |
|
|
|
|
// No proxy by default
|
|
|
|
|
tox_options_set_proxy_type(*toxOptions, TOX_PROXY_TYPE_NONE); |
|
|
|
|
tox_options_set_proxy_host(*toxOptions, nullptr); |
|
|
|
|
tox_options_set_proxy_port(*toxOptions, 0); |
|
|
|
|
|
|
|
|
|
if (proxyType != ICoreSettings::ProxyType::ptNone) { |
|
|
|
|
if (proxyAddr.length() > MAX_PROXY_ADDRESS_LENGTH) { |
|
|
|
|
if (static_cast<uint32_t>(proxyAddr.length()) > tox_max_hostname_length()) { |
|
|
|
|
qWarning() << "proxy address" << proxyAddr << "is too long"; |
|
|
|
|
} else if (!proxyAddr.isEmpty() && proxyPort > 0) { |
|
|
|
|
qDebug() << "using proxy" << proxyAddr << ":" << proxyPort; |
|
|
|
|