Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(ui): Add ability to disable LAN discovery
Browse files Browse the repository at this point in the history
Fix #4074
  • Loading branch information
anthonybilinski committed Apr 6, 2018
1 parent cfdc1cd commit 9f8b0fe
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions src/core/icoresettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions src/persistence/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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<int>(dbSyncType));
}
s.endGroup();
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/persistence/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down Expand Up @@ -583,6 +587,7 @@ public slots:
bool groupAlwaysNotify;

bool forceTCP;
bool enableLanDiscovery;

ICoreSettings::ProxyType proxyType;
QString proxyAddr;
Expand Down
9 changes: 7 additions & 2 deletions src/widget/form/settings/advancedform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 14 additions & 0 deletions src/widget/form/settings/advancedsettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<property name="leftMargin">
<number>40</number>
</property>
<item>
<widget class="QCheckBox" name="cbEnableLanDiscovery">
<property name="text">
<string>Enable LAN discovery</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit 9f8b0fe

Please sign in to comment.