1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(settings): automatically disable UDP when a proxy is set

fixes: #5174
This commit is contained in:
sudden6 2018-06-23 15:18:12 +02:00
parent 40d30153ae
commit 977b7fc9a0
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
2 changed files with 33 additions and 16 deletions

View File

@ -49,7 +49,7 @@ std::unique_ptr<ToxOptions> ToxOptions::makeToxOptions(const QByteArray& savedat
// IPv6 needed for LAN discovery, but can crash some weird routers. On by default, can be // IPv6 needed for LAN discovery, but can crash some weird routers. On by default, can be
// disabled in options. // disabled in options.
const bool enableIPv6 = s->getEnableIPv6(); const bool enableIPv6 = s->getEnableIPv6();
const bool forceTCP = s->getForceTCP(); bool forceTCP = s->getForceTCP();
// LAN requiring UDP is a toxcore limitation, ideally wouldn't be related // LAN requiring UDP is a toxcore limitation, ideally wouldn't be related
const bool enableLanDiscovery = s->getEnableLanDiscovery() && !forceTCP; const bool enableLanDiscovery = s->getEnableLanDiscovery() && !forceTCP;
ICoreSettings::ProxyType proxyType = s->getProxyType(); ICoreSettings::ProxyType proxyType = s->getProxyType();
@ -75,18 +75,14 @@ std::unique_ptr<ToxOptions> ToxOptions::makeToxOptions(const QByteArray& savedat
// register log first, to get messages as early as possible // register log first, to get messages as early as possible
tox_options_set_log_callback(*toxOptions, ToxLogger::onLogMessage); tox_options_set_log_callback(*toxOptions, ToxLogger::onLogMessage);
tox_options_set_ipv6_enabled(*toxOptions, enableIPv6); // savedata
tox_options_set_udp_enabled(*toxOptions, !forceTCP); tox_options_set_savedata_type(*toxOptions, !savedata.isNull() ? TOX_SAVEDATA_TYPE_TOX_SAVE : TOX_SAVEDATA_TYPE_NONE);
tox_options_set_local_discovery_enabled(*toxOptions, enableLanDiscovery); tox_options_set_savedata_data(*toxOptions, reinterpret_cast<const uint8_t*>(savedata.data()), savedata.size());
tox_options_set_start_port(*toxOptions, 0);
tox_options_set_end_port(*toxOptions, 0);
// No proxy by default // No proxy by default
tox_options_set_proxy_type(*toxOptions, TOX_PROXY_TYPE_NONE); tox_options_set_proxy_type(*toxOptions, TOX_PROXY_TYPE_NONE);
tox_options_set_proxy_host(*toxOptions, nullptr); tox_options_set_proxy_host(*toxOptions, nullptr);
tox_options_set_proxy_port(*toxOptions, 0); tox_options_set_proxy_port(*toxOptions, 0);
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());
if (proxyType != ICoreSettings::ProxyType::ptNone) { if (proxyType != ICoreSettings::ProxyType::ptNone) {
if (proxyAddr.length() > MAX_PROXY_ADDRESS_LENGTH) { if (proxyAddr.length() > MAX_PROXY_ADDRESS_LENGTH) {
@ -102,8 +98,20 @@ std::unique_ptr<ToxOptions> ToxOptions::makeToxOptions(const QByteArray& savedat
tox_options_set_proxy_host(*toxOptions, toxOptions->getProxyAddrData()); tox_options_set_proxy_host(*toxOptions, toxOptions->getProxyAddrData());
tox_options_set_proxy_port(*toxOptions, proxyPort); tox_options_set_proxy_port(*toxOptions, proxyPort);
if (!forceTCP) {
qDebug() << "Proxy and UDP enabled, this is a security risk, forcing TCP only";
forceTCP = true;
}
} }
} }
// network options
tox_options_set_udp_enabled(*toxOptions, !forceTCP);
tox_options_set_ipv6_enabled(*toxOptions, enableIPv6);
tox_options_set_local_discovery_enabled(*toxOptions, enableLanDiscovery);
tox_options_set_start_port(*toxOptions, 0);
tox_options_set_end_port(*toxOptions, 0);
return toxOptions; return toxOptions;
} }

View File

@ -55,18 +55,19 @@ AdvancedForm::AdvancedForm()
Settings& s = Settings::getInstance(); Settings& s = Settings::getInstance();
bodyUI->cbEnableIPv6->setChecked(s.getEnableIPv6()); bodyUI->cbEnableIPv6->setChecked(s.getEnableIPv6());
bodyUI->cbMakeToxPortable->setChecked(Settings::getInstance().getMakeToxPortable()); bodyUI->cbMakeToxPortable->setChecked(Settings::getInstance().getMakeToxPortable());
const bool udpEnabled = !s.getForceTCP();
bodyUI->cbEnableUDP->setChecked(udpEnabled);
bodyUI->cbEnableLanDiscovery->setChecked(s.getEnableLanDiscovery());
bodyUI->cbEnableLanDiscovery->setEnabled(udpEnabled);
bodyUI->proxyAddr->setText(s.getProxyAddr()); bodyUI->proxyAddr->setText(s.getProxyAddr());
quint16 port = s.getProxyPort(); quint16 port = s.getProxyPort();
if (port > 0) if (port > 0) {
bodyUI->proxyPort->setValue(port); bodyUI->proxyPort->setValue(port);
}
int index = static_cast<int>(s.getProxyType()); int index = static_cast<int>(s.getProxyType());
bodyUI->proxyType->setCurrentIndex(index); bodyUI->proxyType->setCurrentIndex(index);
on_proxyType_currentIndexChanged(index); on_proxyType_currentIndexChanged(index);
const bool udpEnabled = !s.getForceTCP() && (s.getProxyType() == Settings::ProxyType::ptNone);
bodyUI->cbEnableUDP->setChecked(udpEnabled);
bodyUI->cbEnableLanDiscovery->setChecked(s.getEnableLanDiscovery() && udpEnabled);
bodyUI->cbEnableLanDiscovery->setEnabled(udpEnabled);
QString warningBody = tr("Unless you %1 know what you are doing, " QString warningBody = tr("Unless you %1 know what you are doing, "
"please do %2 change anything here. Changes " "please do %2 change anything here. Changes "
@ -176,7 +177,9 @@ void AdvancedForm::on_cbEnableUDP_stateChanged()
{ {
const bool enableUdp = bodyUI->cbEnableUDP->isChecked(); const bool enableUdp = bodyUI->cbEnableUDP->isChecked();
Settings::getInstance().setForceTCP(!enableUdp); Settings::getInstance().setForceTCP(!enableUdp);
const bool enableLanDiscovery = Settings::getInstance().getEnableLanDiscovery();
bodyUI->cbEnableLanDiscovery->setEnabled(enableUdp); bodyUI->cbEnableLanDiscovery->setEnabled(enableUdp);
bodyUI->cbEnableLanDiscovery->setChecked(enableUdp && enableLanDiscovery);
} }
void AdvancedForm::on_cbEnableLanDiscovery_stateChanged() void AdvancedForm::on_cbEnableLanDiscovery_stateChanged()
@ -191,8 +194,9 @@ void AdvancedForm::on_proxyAddr_editingFinished()
void AdvancedForm::on_proxyPort_valueChanged(int port) void AdvancedForm::on_proxyPort_valueChanged(int port)
{ {
if (port <= 0) if (port <= 0) {
port = 0; port = 0;
}
Settings::getInstance().setProxyPort(port); Settings::getInstance().setProxyPort(port);
} }
@ -200,9 +204,14 @@ void AdvancedForm::on_proxyPort_valueChanged(int port)
void AdvancedForm::on_proxyType_currentIndexChanged(int index) void AdvancedForm::on_proxyType_currentIndexChanged(int index)
{ {
Settings::ProxyType proxytype = static_cast<Settings::ProxyType>(index); Settings::ProxyType proxytype = static_cast<Settings::ProxyType>(index);
const bool proxyEnabled = proxytype != Settings::ProxyType::ptNone;
bodyUI->proxyAddr->setEnabled(proxyEnabled);
bodyUI->proxyPort->setEnabled(proxyEnabled);
// enabling UDP and proxy can be a privacy issue
bodyUI->cbEnableUDP->setEnabled(!proxyEnabled);
bodyUI->cbEnableUDP->setChecked(!proxyEnabled);
bodyUI->proxyAddr->setEnabled(proxytype != Settings::ProxyType::ptNone);
bodyUI->proxyPort->setEnabled(proxytype != Settings::ProxyType::ptNone);
Settings::getInstance().setProxyType(proxytype); Settings::getInstance().setProxyType(proxytype);
} }