diff --git a/src/core/core.cpp b/src/core/core.cpp index 2b59ecc96f..f9e3cddb52 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -132,22 +132,28 @@ ToxOptionsPtr initToxOptions(const QByteArray& savedata, const ICoreSettings* s) { // IPv6 needed for LAN discovery, but can crash some weird routers. On by default, can be // disabled in options. - bool enableIPv6 = s->getEnableIPv6(); - bool forceTCP = s->getForceTCP(); + const bool enableIPv6 = s->getEnableIPv6(); + const bool forceTCP = s->getForceTCP(); + // LAN requiring UDP is a toxcore limitation, ideally wouldn't be related + const bool enableLanDiscovery = s->getEnableLanDiscovery() && !forceTCP; ICoreSettings::ProxyType proxyType = s->getProxyType(); quint16 proxyPort = s->getProxyPort(); QString proxyAddr = s->getProxyAddr(); QByteArray proxyAddrData = proxyAddr.toUtf8(); + if (!enableLanDiscovery) { + qWarning() << "Core starting without LAN discovery. Peers can only be found through DHT."; + } if (enableIPv6) { qDebug() << "Core starting with IPv6 enabled"; - } else { + } else if(enableLanDiscovery) { qWarning() << "Core starting with IPv6 disabled. LAN discovery may not work properly."; } ToxOptionsPtr toxOptions = ToxOptionsPtr(tox_options_new(NULL)); tox_options_set_ipv6_enabled(toxOptions.get(), enableIPv6); tox_options_set_udp_enabled(toxOptions.get(), !forceTCP); + tox_options_set_local_discovery_enabled(toxOptions.get(), enableLanDiscovery); tox_options_set_start_port(toxOptions.get(), 0); tox_options_set_end_port(toxOptions.get(), 0); diff --git a/src/core/icoresettings.h b/src/core/icoresettings.h index 099dee9401..b4a561ceb7 100644 --- a/src/core/icoresettings.h +++ b/src/core/icoresettings.h @@ -23,6 +23,9 @@ class ICoreSettings { virtual bool getForceTCP() const = 0; virtual void setForceTCP(bool enable) = 0; + virtual bool getEnableLanDiscovery() const = 0; + virtual void setEnableLanDiscovery(bool enable) = 0; + virtual QString getProxyAddr() const = 0; virtual void setProxyAddr(const QString& address) = 0; @@ -39,6 +42,7 @@ class ICoreSettings { DECLARE_SIGNAL(enableIPv6Changed, bool enabled); DECLARE_SIGNAL(forceTCPChanged, bool enabled); + DECLARE_SIGNAL(enableLanDiscoveryChanged, bool enabled); DECLARE_SIGNAL(proxyTypeChanged, ICoreSettings::ProxyType type); DECLARE_SIGNAL(proxyAddressChanged, const QString& address); DECLARE_SIGNAL(proxyPortChanged, quint16 port); diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 1c86615b45..7ba3d276ff 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -192,6 +192,7 @@ void Settings::loadGlobal() makeToxPortable = s.value("makeToxPortable", false).toBool(); enableIPv6 = s.value("enableIPv6", true).toBool(); forceTCP = s.value("forceTCP", false).toBool(); + enableLanDiscovery = s.value("enableLanDiscovery", true).toBool(); } s.endGroup(); @@ -508,6 +509,7 @@ void Settings::saveGlobal() s.setValue("makeToxPortable", makeToxPortable); s.setValue("enableIPv6", enableIPv6); s.setValue("forceTCP", forceTCP); + s.setValue("enableLanDiscovery", enableLanDiscovery); s.setValue("dbSyncType", static_cast(dbSyncType)); } s.endGroup(); @@ -1225,6 +1227,22 @@ void Settings::setForceTCP(bool enabled) } } +bool Settings::getEnableLanDiscovery() const +{ + QMutexLocker locker{&bigLock}; + return enableLanDiscovery; +} + +void Settings::setEnableLanDiscovery(bool enabled) +{ + QMutexLocker locker{&bigLock}; + + if (enabled != enableLanDiscovery) { + enableLanDiscovery = enabled; + emit enableLanDiscoveryChanged(enableLanDiscovery); + } +} + QNetworkProxy Settings::getProxy() const { QNetworkProxy proxy; diff --git a/src/persistence/settings.h b/src/persistence/settings.h index 3a7a865627..542ca0f0af 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -281,6 +281,9 @@ public slots: bool getForceTCP() const override; void setForceTCP(bool enabled) override; + bool getEnableLanDiscovery() const override; + void setEnableLanDiscovery(bool enabled) override; + QString getProxyAddr() const override; void setProxyAddr(const QString& address) override; @@ -294,6 +297,7 @@ public slots: SIGNAL_IMPL(Settings, enableIPv6Changed, bool enabled) SIGNAL_IMPL(Settings, forceTCPChanged, bool enabled) + SIGNAL_IMPL(Settings, enableLanDiscoveryChanged, bool enabled) SIGNAL_IMPL(Settings, proxyTypeChanged, ICoreSettings::ProxyType type) SIGNAL_IMPL(Settings, proxyAddressChanged, const QString& address) SIGNAL_IMPL(Settings, proxyPortChanged, quint16 port) @@ -583,6 +587,7 @@ public slots: bool groupAlwaysNotify; bool forceTCP; + bool enableLanDiscovery; ICoreSettings::ProxyType proxyType; QString proxyAddr; diff --git a/src/widget/form/settings/advancedform.cpp b/src/widget/form/settings/advancedform.cpp index 752ed4d3c5..9f5f870000 100644 --- a/src/widget/form/settings/advancedform.cpp +++ b/src/widget/form/settings/advancedform.cpp @@ -55,7 +55,10 @@ AdvancedForm::AdvancedForm() Settings& s = Settings::getInstance(); bodyUI->cbEnableIPv6->setChecked(s.getEnableIPv6()); bodyUI->cbMakeToxPortable->setChecked(Settings::getInstance().getMakeToxPortable()); - bodyUI->cbEnableUDP->setChecked(!s.getForceTCP()); + const bool udpEnabled = !s.getForceTCP(); + bodyUI->cbEnableUDP->setChecked(udpEnabled); + bodyUI->cbEnableLanDiscovery->setChecked(s.getEnableLanDiscovery()); + bodyUI->cbEnableLanDiscovery->setEnabled(udpEnabled); bodyUI->proxyAddr->setText(s.getProxyAddr()); quint16 port = s.getProxyPort(); if (port > 0) @@ -172,7 +175,9 @@ void AdvancedForm::on_cbEnableIPv6_stateChanged() void AdvancedForm::on_cbEnableUDP_stateChanged() { - Settings::getInstance().setForceTCP(!bodyUI->cbEnableUDP->isChecked()); + const bool enableUdp = bodyUI->cbEnableUDP->isChecked(); + Settings::getInstance().setForceTCP(!enableUdp); + bodyUI->cbEnableLanDiscovery->setEnabled(enableUdp); } void AdvancedForm::on_proxyAddr_editingFinished() diff --git a/src/widget/form/settings/advancedsettings.ui b/src/widget/form/settings/advancedsettings.ui index a1830cc896..aa0be25a80 100644 --- a/src/widget/form/settings/advancedsettings.ui +++ b/src/widget/form/settings/advancedsettings.ui @@ -121,6 +121,20 @@ + + + + 40 + + + + + Enable LAN discovery + + + + +