From ee9fbefd76b0182ce812bd35bc32f0a19476db8a Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 27 Feb 2017 22:29:01 +0100 Subject: [PATCH] added signal blockign trick for widgets, and fixed the bug causing wrong values to be displayed in server settings --- libretroshare/src/pqi/p3peermgr.cc | 10 +- libretroshare/src/rsserver/p3peers.cc | 5 + .../src/gui/settings/ServerPage.cpp | 99 +++++++++---------- retroshare-gui/src/gui/settings/ServerPage.ui | 10 +- retroshare-gui/src/util/misc.h | 15 +++ 5 files changed, 78 insertions(+), 61 deletions(-) diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index b458b1a47..2263fd9dd 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -2259,7 +2259,10 @@ bool p3PeerMgrIMPL::loadList(std::list& load) } else if (kit->key == kConfigKeyProxyServerPortTor) { - proxyPortTor = atoi(kit->value.c_str()); + uint16_t p = atoi(kit->value.c_str()); + + if(p >= 1024) + proxyPortTor = p; #ifdef PEER_DEBUG std::cerr << "Loaded proxyPort for Tor: " << proxyPortTor; std::cerr << std::endl ; @@ -2276,7 +2279,10 @@ bool p3PeerMgrIMPL::loadList(std::list& load) } else if (kit->key == kConfigKeyProxyServerPortI2P) { - proxyPortI2P = atoi(kit->value.c_str()); + uint16_t p = atoi(kit->value.c_str()); + + if(p >= 1024) + proxyPortI2P = p; #ifdef PEER_DEBUG std::cerr << "Loaded proxyPort for I2P: " << proxyPortI2P; std::cerr << std::endl ; diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 20420ccf5..d6d6f9f03 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -1020,6 +1020,11 @@ bool p3Peers::setProxyServer(const uint32_t type, const std::string &addr_str, c std::cerr << "p3Peers::setProxyServer() " << std::endl; #endif + if(port < 1024) + { + std::cerr << "(EE) attempt to set proxy server address to something not allowed: " << addr_str << ":" << port << std::endl; + return false ; + } struct sockaddr_storage addr; struct sockaddr_in *addrv4p = (struct sockaddr_in *) &addr; addrv4p->sin_family = AF_INET; diff --git a/retroshare-gui/src/gui/settings/ServerPage.cpp b/retroshare-gui/src/gui/settings/ServerPage.cpp index 0aaac99cc..49814483a 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.cpp +++ b/retroshare-gui/src/gui/settings/ServerPage.cpp @@ -24,6 +24,7 @@ #include "rshare.h" #include "rsharesettings.h" #include "util/RsNetUtil.h" +#include "util/misc.h" #include @@ -123,9 +124,9 @@ ServerPage::ServerPage(QWidget * parent, Qt::WindowFlags flags) connect(ui.dynDNS, SIGNAL(textChanged(QString)),this,SLOT(saveAddresses())); connect(ui.hiddenpage_proxyAddress_tor, SIGNAL(textChanged(QString)),this,SLOT(saveAddresses())); - connect(ui.hiddenpage_proxyPort_tor, SIGNAL(textChanged(QString)),this,SLOT(saveAddresses())); + connect(ui.hiddenpage_proxyPort_tor, SIGNAL(valueChanged(int)),this,SLOT(saveAddresses())); connect(ui.hiddenpage_proxyAddress_i2p, SIGNAL(textChanged(QString)),this,SLOT(saveAddresses())); - connect(ui.hiddenpage_proxyPort_i2p, SIGNAL(textChanged(QString)),this,SLOT(saveAddresses())); + connect(ui.hiddenpage_proxyPort_i2p, SIGNAL(valueChanged(int)),this,SLOT(saveAddresses())); connect(ui.totalDownloadRate,SIGNAL(valueChanged(int)),this,SLOT(saveRates())); connect(ui.totalUploadRate, SIGNAL(valueChanged(int)),this,SLOT(saveRates())); @@ -231,11 +232,6 @@ void ServerPage::load() // (csoler) Disabling some signals in this block in order to avoid // some nasty feedback. { - ui.localPort->blockSignals(true); - ui.extPort->blockSignals(true); - ui.localAddress->blockSignals(true); - ui.extAddress->blockSignals(true); - loadFilteredIps() ; ui.netModeComboBox->show() ; @@ -261,7 +257,7 @@ void ServerPage::load() netIndex = 0; break; } - ui.netModeComboBox->setCurrentIndex(netIndex); + whileBlocking(ui.netModeComboBox)->setCurrentIndex(netIndex); /* DHT + Discovery: (public) * Discovery only: (private) @@ -285,31 +281,31 @@ void ServerPage::load() netIndex = 3; // NONE } - ui.discComboBox->setCurrentIndex(netIndex); + whileBlocking(ui.discComboBox)->setCurrentIndex(netIndex); int dlrate = 0; int ulrate = 0; rsConfig->GetMaxDataRates(dlrate, ulrate); - ui.totalDownloadRate->setValue(dlrate); - ui.totalUploadRate->setValue(ulrate); + whileBlocking(ui.totalDownloadRate)->setValue(dlrate); + whileBlocking(ui.totalUploadRate)->setValue(ulrate); toggleUPnP(); /* Addresses must be set here - otherwise can't edit it */ /* set local address */ - ui.localAddress->setText(QString::fromStdString(detail.localAddr)); - ui.localPort -> setValue(detail.localPort); + whileBlocking(ui.localAddress)->setText(QString::fromStdString(detail.localAddr)); + whileBlocking(ui.localPort )-> setValue(detail.localPort); /* set the server address */ - ui.extAddress->setText(QString::fromStdString(detail.extAddr)); - ui.extPort -> setValue(detail.extPort); + whileBlocking(ui.extAddress)->setText(QString::fromStdString(detail.extAddr)); + whileBlocking(ui.extPort) -> setValue(detail.extPort); /* set DynDNS */ - ui.dynDNS -> setText(QString::fromStdString(detail.dyndns)); + whileBlocking(ui.dynDNS) -> setText(QString::fromStdString(detail.dyndns)); - ui.showDiscStatusBar->setChecked(Settings->getStatusBarFlags() & STATUSBAR_DISC); + whileBlocking(ui.showDiscStatusBar)->setChecked(Settings->getStatusBarFlags() & STATUSBAR_DISC); - ui.ipAddressList->clear(); + whileBlocking(ui.ipAddressList)->clear(); for(std::list::const_iterator it(detail.ipAddressList.begin());it!=detail.ipAddressList.end();++it) - ui.ipAddressList->addItem(QString::fromStdString(*it)); + whileBlocking(ui.ipAddressList)->addItem(QString::fromStdString(*it)); /* HIDDEN PAGE SETTINGS - only Proxy (outgoing) */ std::string proxyaddr; @@ -317,19 +313,14 @@ void ServerPage::load() uint32_t status ; // Tor rsPeers->getProxyServer(RS_HIDDEN_TYPE_TOR, proxyaddr, proxyport, status); - ui.hiddenpage_proxyAddress_tor -> setText(QString::fromStdString(proxyaddr)); - ui.hiddenpage_proxyPort_tor -> setValue(proxyport); + whileBlocking(ui.hiddenpage_proxyAddress_tor) -> setText(QString::fromStdString(proxyaddr)); + whileBlocking(ui.hiddenpage_proxyPort_tor) -> setValue(proxyport); // I2P rsPeers->getProxyServer(RS_HIDDEN_TYPE_I2P, proxyaddr, proxyport, status); - ui.hiddenpage_proxyAddress_i2p -> setText(QString::fromStdString(proxyaddr)); - ui.hiddenpage_proxyPort_i2p -> setValue(proxyport); + whileBlocking(ui.hiddenpage_proxyAddress_i2p) -> setText(QString::fromStdString(proxyaddr)); + whileBlocking(ui.hiddenpage_proxyPort_i2p) -> setValue(proxyport); updateOutProxyIndicator(); - - ui.localPort->blockSignals(false); - ui.extPort->blockSignals(false); - ui.localAddress->blockSignals(false); - ui.extAddress->blockSignals(false); } } @@ -352,37 +343,37 @@ void ServerPage::loadFilteredIps() { if(rsBanList->ipFilteringEnabled()) { - ui.denyAll_CB->setChecked(true) ; - ui.filteredIpsTable->setEnabled(true) ; - ui.includeFromFriends_CB->setEnabled(true) ; - ui.includeFromDHT_CB->setEnabled(true) ; - ui.ipInput_LE->setEnabled(true) ; - ui.ipInputRange_SB->setEnabled(true) ; - ui.ipInputComment_LE->setEnabled(true) ; - ui.ipInputAddBlackList_PB->setEnabled(true) ; - ui.ipInputAddWhiteList_PB->setEnabled(true) ; - ui.groupIPRanges_CB->setEnabled(true) ; - ui.groupIPRanges_SB->setEnabled(true) ; + whileBlocking(ui.denyAll_CB)->setChecked(true) ; + whileBlocking(ui.filteredIpsTable)->setEnabled(true) ; + whileBlocking(ui.includeFromFriends_CB)->setEnabled(true) ; + whileBlocking(ui.includeFromDHT_CB)->setEnabled(true) ; + whileBlocking(ui.ipInput_LE)->setEnabled(true) ; + whileBlocking(ui.ipInputRange_SB)->setEnabled(true) ; + whileBlocking(ui.ipInputComment_LE)->setEnabled(true) ; + whileBlocking(ui.ipInputAddBlackList_PB)->setEnabled(true) ; + whileBlocking(ui.ipInputAddWhiteList_PB)->setEnabled(true) ; + whileBlocking(ui.groupIPRanges_CB)->setEnabled(true) ; + whileBlocking(ui.groupIPRanges_SB)->setEnabled(true) ; } else { - ui.denyAll_CB->setChecked(false) ; - ui.filteredIpsTable->setEnabled(false) ; - ui.includeFromFriends_CB->setEnabled(false) ; - ui.includeFromDHT_CB->setEnabled(false) ; - ui.ipInput_LE->setEnabled(false) ; - ui.ipInputRange_SB->setEnabled(false) ; - ui.ipInputComment_LE->setEnabled(false) ; - ui.ipInputAddBlackList_PB->setEnabled(false) ; - ui.ipInputAddWhiteList_PB->setEnabled(true) ; - ui.groupIPRanges_CB->setEnabled(false) ; - ui.groupIPRanges_SB->setEnabled(false) ; + whileBlocking(ui.denyAll_CB)->setChecked(false) ; + whileBlocking(ui.filteredIpsTable)->setEnabled(false) ; + whileBlocking(ui.includeFromFriends_CB)->setEnabled(false) ; + whileBlocking(ui.includeFromDHT_CB)->setEnabled(false) ; + whileBlocking(ui.ipInput_LE)->setEnabled(false) ; + whileBlocking(ui.ipInputRange_SB)->setEnabled(false) ; + whileBlocking(ui.ipInputComment_LE)->setEnabled(false) ; + whileBlocking(ui.ipInputAddBlackList_PB)->setEnabled(false) ; + whileBlocking(ui.ipInputAddWhiteList_PB)->setEnabled(true) ; + whileBlocking(ui.groupIPRanges_CB)->setEnabled(false) ; + whileBlocking(ui.groupIPRanges_SB)->setEnabled(false) ; } - ui.includeFromFriends_CB->setChecked(rsBanList->IPsFromFriendsEnabled()) ; - ui.includeFromDHT_CB->setChecked(rsBanList->iPsFromDHTEnabled()) ; - ui.groupIPRanges_CB->setChecked(rsBanList->autoRangeEnabled()) ; - ui.groupIPRanges_SB->setValue(rsBanList->autoRangeLimit()) ; + whileBlocking(ui.includeFromFriends_CB)->setChecked(rsBanList->IPsFromFriendsEnabled()) ; + whileBlocking(ui.includeFromDHT_CB)->setChecked(rsBanList->iPsFromDHTEnabled()) ; + whileBlocking(ui.groupIPRanges_CB)->setChecked(rsBanList->autoRangeEnabled()) ; + whileBlocking(ui.groupIPRanges_SB)->setValue(rsBanList->autoRangeLimit()) ; ui.whiteListIpsTable->setColumnHidden(COLUMN_STATUS,true); ui.filteredIpsTable->setColumnHidden(COLUMN_STATUS,true); diff --git a/retroshare-gui/src/gui/settings/ServerPage.ui b/retroshare-gui/src/gui/settings/ServerPage.ui index fe2a638e2..24fa59838 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.ui +++ b/retroshare-gui/src/gui/settings/ServerPage.ui @@ -26,7 +26,7 @@ - 0 + 2 @@ -828,7 +828,7 @@ behind a firewall or a VPN. <html><head/><body><p>This is the port of the Tor Socks proxy. Your Retroshare node can use this port to connect to</p><p>Hidden nodes. The led at right turns green when this port is active on your computer. </p><p>This does not mean however that your Retroshare traffic transits though Tor. It does only if </p><p>you connect to Hidden nodes, or if you are running a Hidden node yourself.</p></body></html> - 10 + 1024 65535 @@ -895,7 +895,7 @@ behind a firewall or a VPN. <html><head/><body><p>This is the port of the I2P Socks proxy. Your Retroshare node can use this port to connect to</p><p>Hidden nodes. The led at right turns green when this port is active on your computer. </p><p>This does not mean however that your Retroshare traffic transits though I2P. It does only if </p><p>you connect to Hidden nodes, or if you are running a Hidden node yourself.</p></body></html> - 10 + 1024 65535 @@ -975,7 +975,7 @@ You can connect to Hidden Nodes, even if you are running a standard Node, so why - 10 + 1024 65535 @@ -999,7 +999,7 @@ You can connect to Hidden Nodes, even if you are running a standard Node, so why - 10 + 1024 65535 diff --git a/retroshare-gui/src/util/misc.h b/retroshare-gui/src/util/misc.h index 6b68293db..205b284a8 100644 --- a/retroshare-gui/src/util/misc.h +++ b/retroshare-gui/src/util/misc.h @@ -185,4 +185,19 @@ class SleeperThread : public QThread{ } }; +template class SignalsBlocker +{ +public: + SignalsBlocker(T *blocked) : blocked(blocked), previous(blocked->blockSignals(true)) {} + ~SignalsBlocker() { blocked->blockSignals(previous); } + + T *operator->() { return blocked; } + +private: + T *blocked; + bool previous; +}; + +template inline SignalsBlocker whileBlocking(T *blocked) { return SignalsBlocker(blocked); } + #endif