← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3381: Disallow transfer port and encrypted transfer port to be the same

 

------------------------------------------------------------
revno: 3381
committer: Fredrik Ullner <ullner@xxxxxxxxx>
branch nick: dcplusplus
timestamp: Mon 2013-12-09 23:28:12 +0100
message:
  Disallow transfer port and encrypted transfer port to be the same
modified:
  changelog.txt
  dcpp/ConnectionManager.cpp
  help/settings_connectivity_manual.html
  win32/ConnectivityManualPage.cpp
  win32/ConnectivityManualPage.h


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2013-11-29 20:41:48 +0000
+++ changelog.txt	2013-12-09 22:28:12 +0000
@@ -6,6 +6,7 @@
 * [L#721513] Transferview: Added "Remove file from queue" menu option and "Force attempt" is now only available for downloads (ullner)
 * [L#210217] Add connectivity status for hubs to the favorite hubs window (ullner)
 * [L#593613] Added /lastmessage in PMs to show the time of the last message (ullner)
+* [L#363092] Disallow transfer port and encrypted transfer port to be the same (ullner)
 
 -- 0.831 2013-11-11 --
 * [L#1249810] Fix NMDC TTH search responses (emtee)

=== modified file 'dcpp/ConnectionManager.cpp'
--- dcpp/ConnectionManager.cpp	2013-12-06 21:45:24 +0000
+++ dcpp/ConnectionManager.cpp	2013-12-09 22:28:12 +0000
@@ -76,6 +76,11 @@
 		dcdebug("Skipping secure port: %d\n", CONNSETTING(TLS_PORT));
 		return;
 	}
+	if(CONNSETTING(TCP_PORT) == CONNSETTING(TLS_PORT))
+	{
+		LogManager::getInstance()->message(_("The encrypted transfer port cannot be the same as the transfer port, encrypted transfers will be disabled"));
+		return;
+	}
 	secureServer.reset(new Server(true, Util::toString(CONNSETTING(TLS_PORT)), CONNSETTING(BIND_ADDRESS)));
 }
 

=== modified file 'help/settings_connectivity_manual.html'
--- help/settings_connectivity_manual.html	2012-10-27 14:30:14 +0000
+++ help/settings_connectivity_manual.html	2013-12-09 22:28:12 +0000
@@ -82,8 +82,8 @@
 		<dd cshelp="IDH_SETTINGS_CONNECTIVITY_PORT_TLS">This is the port that DC++ listens on for
 		incoming <a href="settings_certs.html">TLS (encrypted)</a> connections from other peers. If
 		this port is incorrectly forwarded, you won't be able to search nor to download on
-		encrypted ADC hubs. Note that <b>this port value should be different than the ones used for
-			transfers (TCP) and searches (UDP).</b></dd>
+		encrypted ADC hubs. Note that <b>this port value should be different than the one used for
+			transfers (TCP).</b></dd>
 		<dt>Search port (UDP)</dt>
 		<dd cshelp="IDH_SETTINGS_CONNECTIVITY_PORT_UDP">This is the port that DC++ listens on for
 		incoming search results. If this port is incorrectly forwarded, you won't be able to

=== modified file 'win32/ConnectivityManualPage.cpp'
--- win32/ConnectivityManualPage.cpp	2013-01-18 21:28:38 +0000
+++ win32/ConnectivityManualPage.cpp	2013-12-09 22:28:12 +0000
@@ -43,7 +43,9 @@
 active(0),
 upnp(0),
 passive(0),
-mapper(0)
+mapper(0),
+transferBox(0),
+tlstransferBox(0)
 {
 	setHelpId(IDH_CONNECTIVITYMANUALPAGE);
 
@@ -100,11 +102,18 @@
 			boxGrid->column(0).size = 40;
 			boxGrid->column(0).mode = GridInfo::STATIC;
 
-			items.emplace_back(boxGrid->addChild(WinUtil::Seeds::Dialog::intTextBox), setting, PropPage::T_INT);
+			auto inputBox = boxGrid->addChild(WinUtil::Seeds::Dialog::intTextBox);
+			items.emplace_back(inputBox, setting, PropPage::T_INT);
+
+			return inputBox;
 		};
 
-		addPortBox(T_("Transfer"), SettingsManager::TCP_PORT, IDH_SETTINGS_CONNECTIVITY_PORT_TCP);
-		addPortBox(T_("Encrypted transfer"), SettingsManager::TLS_PORT, IDH_SETTINGS_CONNECTIVITY_PORT_TLS);
+		transferBox = addPortBox(T_("Transfer"), SettingsManager::TCP_PORT, IDH_SETTINGS_CONNECTIVITY_PORT_TCP);
+		transferBox->onUpdated([this] { onTransferPortUpdated(); });
+
+		tlstransferBox = addPortBox(T_("Encrypted transfer"), SettingsManager::TLS_PORT, IDH_SETTINGS_CONNECTIVITY_PORT_TLS);
+		tlstransferBox->onUpdated([this] { onTLSTransferPortUpdated(); });
+
 		addPortBox(T_("Search"), SettingsManager::UDP_PORT, IDH_SETTINGS_CONNECTIVITY_PORT_UDP);
 	}
 
@@ -135,6 +144,11 @@
 }
 
 void ConnectivityManualPage::write() {
+	if(transferBox->getText() == tlstransferBox->getText())
+	{
+		tlstransferBox->setText(Util::emptyStringT);
+	}
+
 	PropPage::write(items);
 
 	// Set the connection mode
@@ -203,3 +217,21 @@
 		read();
 	});
 }
+
+void ConnectivityManualPage::onTransferPortUpdated()
+{
+	validatePort(transferBox, tlstransferBox, T_("Transfer"), T_("encrypted transfer"));
+}
+
+void ConnectivityManualPage::onTLSTransferPortUpdated()
+{
+	validatePort(tlstransferBox, transferBox, T_("Encrypted transfer"), T_("transfer"));
+}
+
+void ConnectivityManualPage::validatePort(TextBoxPtr sourcebox, TextBoxPtr otherbox, const tstring& source, const tstring& other)
+{
+	if(sourcebox->getText() == otherbox->getText())
+	{
+		sourcebox->showPopup(T_("Invalid value"), str(TF_("%1% port cannot be the same as the %2% port") % source % other), TTI_ERROR);
+	}
+}

=== modified file 'win32/ConnectivityManualPage.h'
--- win32/ConnectivityManualPage.h	2013-01-18 21:28:38 +0000
+++ win32/ConnectivityManualPage.h	2013-12-09 22:28:12 +0000
@@ -43,11 +43,19 @@
 
 	ComboBoxPtr mapper;
 
+	TextBoxPtr transferBox;
+	TextBoxPtr tlstransferBox;
+
 	void handleAutoClicked();
 
 	void read();
 	void updateAuto();
 
+	void onTransferPortUpdated();
+	void onTLSTransferPortUpdated();
+
+	void validatePort(TextBoxPtr sourceBox, TextBoxPtr otherBox, const tstring& source, const tstring& other);
+
 	// ConnectivityManagerListener
 	void on(SettingChanged) noexcept;
 };