Skip to content

Commit 73f3b5d

Browse files
author
Jonathan Warren
committed
Merge pull request #297 from mybluevan/master
Adding configuration to listen for incoming connections when connected via SOCKS proxy
2 parents 68a2069 + 922cce6 commit 73f3b5d

File tree

6 files changed

+83
-43
lines changed

6 files changed

+83
-43
lines changed

src/bitmessageqt/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,8 @@ def click_actionSettings(self):
18241824
self.settingsDialogInstance.ui.lineEditSocksUsername.text()))
18251825
shared.config.set('bitmessagesettings', 'sockspassword', str(
18261826
self.settingsDialogInstance.ui.lineEditSocksPassword.text()))
1827+
shared.config.set('bitmessagesettings', 'sockslisten', str(
1828+
self.settingsDialogInstance.ui.checkBoxSocksListen.isChecked()))
18271829
if float(self.settingsDialogInstance.ui.lineEditTotalDifficulty.text()) >= 1:
18281830
shared.config.set('bitmessagesettings', 'defaultnoncetrialsperbyte', str(int(float(
18291831
self.settingsDialogInstance.ui.lineEditTotalDifficulty.text()) * shared.networkDefaultProofOfWorkNonceTrialsPerByte)))
@@ -2778,13 +2780,16 @@ def __init__(self, parent):
27782780
shared.config.get('bitmessagesettings', 'port')))
27792781
self.ui.checkBoxAuthentication.setChecked(shared.config.getboolean(
27802782
'bitmessagesettings', 'socksauthentication'))
2783+
self.ui.checkBoxSocksListen.setChecked(shared.config.getboolean(
2784+
'bitmessagesettings', 'sockslisten'))
27812785
if str(shared.config.get('bitmessagesettings', 'socksproxytype')) == 'none':
27822786
self.ui.comboBoxProxyType.setCurrentIndex(0)
27832787
self.ui.lineEditSocksHostname.setEnabled(False)
27842788
self.ui.lineEditSocksPort.setEnabled(False)
27852789
self.ui.lineEditSocksUsername.setEnabled(False)
27862790
self.ui.lineEditSocksPassword.setEnabled(False)
27872791
self.ui.checkBoxAuthentication.setEnabled(False)
2792+
self.ui.checkBoxSocksListen.setEnabled(False)
27882793
elif str(shared.config.get('bitmessagesettings', 'socksproxytype')) == 'SOCKS4a':
27892794
self.ui.comboBoxProxyType.setCurrentIndex(1)
27902795
self.ui.lineEditTCPPort.setEnabled(False)
@@ -2841,11 +2846,13 @@ def comboBoxProxyTypeChanged(self, comboBoxIndex):
28412846
self.ui.lineEditSocksUsername.setEnabled(False)
28422847
self.ui.lineEditSocksPassword.setEnabled(False)
28432848
self.ui.checkBoxAuthentication.setEnabled(False)
2849+
self.ui.checkBoxSocksListen.setEnabled(False)
28442850
self.ui.lineEditTCPPort.setEnabled(True)
28452851
elif comboBoxIndex == 1 or comboBoxIndex == 2:
28462852
self.ui.lineEditSocksHostname.setEnabled(True)
28472853
self.ui.lineEditSocksPort.setEnabled(True)
28482854
self.ui.checkBoxAuthentication.setEnabled(True)
2855+
self.ui.checkBoxSocksListen.setEnabled(True)
28492856
if self.ui.checkBoxAuthentication.isChecked():
28502857
self.ui.lineEditSocksUsername.setEnabled(True)
28512858
self.ui.lineEditSocksPassword.setEnabled(True)

src/bitmessageqt/settings.py

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
# Form implementation generated from reading ui file 'settings.ui'
44
#
5-
# Created: Mon Jun 10 11:31:56 2013
6-
# by: PyQt4 UI code generator 4.9.4
5+
# Created: Fri Jul 12 12:37:53 2013
6+
# by: PyQt4 UI code generator 4.10.1
77
#
88
# WARNING! All changes made in this file will be lost!
99

@@ -12,7 +12,16 @@
1212
try:
1313
_fromUtf8 = QtCore.QString.fromUtf8
1414
except AttributeError:
15-
_fromUtf8 = lambda s: s
15+
def _fromUtf8(s):
16+
return s
17+
18+
try:
19+
_encoding = QtGui.QApplication.UnicodeUTF8
20+
def _translate(context, text, disambig):
21+
return QtGui.QApplication.translate(context, text, disambig, _encoding)
22+
except AttributeError:
23+
def _translate(context, text, disambig):
24+
return QtGui.QApplication.translate(context, text, disambig)
1625

1726
class Ui_settingsDialog(object):
1827
def setupUi(self, settingsDialog):
@@ -122,6 +131,9 @@ def setupUi(self, settingsDialog):
122131
self.lineEditSocksPassword.setEchoMode(QtGui.QLineEdit.Password)
123132
self.lineEditSocksPassword.setObjectName(_fromUtf8("lineEditSocksPassword"))
124133
self.gridLayout_2.addWidget(self.lineEditSocksPassword, 2, 5, 1, 1)
134+
self.checkBoxSocksListen = QtGui.QCheckBox(self.groupBox_2)
135+
self.checkBoxSocksListen.setObjectName(_fromUtf8("checkBoxSocksListen"))
136+
self.gridLayout_2.addWidget(self.checkBoxSocksListen, 3, 1, 1, 4)
125137
self.gridLayout_4.addWidget(self.groupBox_2, 1, 0, 1, 1)
126138
spacerItem2 = QtGui.QSpacerItem(20, 70, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
127139
self.gridLayout_4.addItem(spacerItem2, 2, 0, 1, 1)
@@ -235,38 +247,40 @@ def setupUi(self, settingsDialog):
235247
settingsDialog.setTabOrder(self.lineEditSocksPort, self.checkBoxAuthentication)
236248
settingsDialog.setTabOrder(self.checkBoxAuthentication, self.lineEditSocksUsername)
237249
settingsDialog.setTabOrder(self.lineEditSocksUsername, self.lineEditSocksPassword)
238-
settingsDialog.setTabOrder(self.lineEditSocksPassword, self.buttonBox)
250+
settingsDialog.setTabOrder(self.lineEditSocksPassword, self.checkBoxSocksListen)
251+
settingsDialog.setTabOrder(self.checkBoxSocksListen, self.buttonBox)
239252

240253
def retranslateUi(self, settingsDialog):
241-
settingsDialog.setWindowTitle(QtGui.QApplication.translate("settingsDialog", "Settings", None, QtGui.QApplication.UnicodeUTF8))
242-
self.checkBoxStartOnLogon.setText(QtGui.QApplication.translate("settingsDialog", "Start Bitmessage on user login", None, QtGui.QApplication.UnicodeUTF8))
243-
self.checkBoxStartInTray.setText(QtGui.QApplication.translate("settingsDialog", "Start Bitmessage in the tray (don\'t show main window)", None, QtGui.QApplication.UnicodeUTF8))
244-
self.checkBoxMinimizeToTray.setText(QtGui.QApplication.translate("settingsDialog", "Minimize to tray", None, QtGui.QApplication.UnicodeUTF8))
245-
self.checkBoxShowTrayNotifications.setText(QtGui.QApplication.translate("settingsDialog", "Show notification when message received", None, QtGui.QApplication.UnicodeUTF8))
246-
self.checkBoxPortableMode.setText(QtGui.QApplication.translate("settingsDialog", "Run in Portable Mode", None, QtGui.QApplication.UnicodeUTF8))
247-
self.label_7.setText(QtGui.QApplication.translate("settingsDialog", "In Portable Mode, messages and config files are stored in the same directory as the program rather than the normal application-data folder. This makes it convenient to run Bitmessage from a USB thumb drive.", None, QtGui.QApplication.UnicodeUTF8))
248-
self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabUserInterface), QtGui.QApplication.translate("settingsDialog", "User Interface", None, QtGui.QApplication.UnicodeUTF8))
249-
self.groupBox.setTitle(QtGui.QApplication.translate("settingsDialog", "Listening port", None, QtGui.QApplication.UnicodeUTF8))
250-
self.label.setText(QtGui.QApplication.translate("settingsDialog", "Listen for connections on port:", None, QtGui.QApplication.UnicodeUTF8))
251-
self.groupBox_2.setTitle(QtGui.QApplication.translate("settingsDialog", "Proxy server / Tor", None, QtGui.QApplication.UnicodeUTF8))
252-
self.label_2.setText(QtGui.QApplication.translate("settingsDialog", "Type:", None, QtGui.QApplication.UnicodeUTF8))
253-
self.comboBoxProxyType.setItemText(0, QtGui.QApplication.translate("settingsDialog", "none", None, QtGui.QApplication.UnicodeUTF8))
254-
self.comboBoxProxyType.setItemText(1, QtGui.QApplication.translate("settingsDialog", "SOCKS4a", None, QtGui.QApplication.UnicodeUTF8))
255-
self.comboBoxProxyType.setItemText(2, QtGui.QApplication.translate("settingsDialog", "SOCKS5", None, QtGui.QApplication.UnicodeUTF8))
256-
self.label_3.setText(QtGui.QApplication.translate("settingsDialog", "Server hostname:", None, QtGui.QApplication.UnicodeUTF8))
257-
self.label_4.setText(QtGui.QApplication.translate("settingsDialog", "Port:", None, QtGui.QApplication.UnicodeUTF8))
258-
self.checkBoxAuthentication.setText(QtGui.QApplication.translate("settingsDialog", "Authentication", None, QtGui.QApplication.UnicodeUTF8))
259-
self.label_5.setText(QtGui.QApplication.translate("settingsDialog", "Username:", None, QtGui.QApplication.UnicodeUTF8))
260-
self.label_6.setText(QtGui.QApplication.translate("settingsDialog", "Pass:", None, QtGui.QApplication.UnicodeUTF8))
261-
self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabNetworkSettings), QtGui.QApplication.translate("settingsDialog", "Network Settings", None, QtGui.QApplication.UnicodeUTF8))
262-
self.label_8.setText(QtGui.QApplication.translate("settingsDialog", "When someone sends you a message, their computer must first complete some work. The difficulty of this work, by default, is 1. You may raise this default for new addresses you create by changing the values here. Any new addresses you create will require senders to meet the higher difficulty. There is one exception: if you add a friend or acquaintance to your address book, Bitmessage will automatically notify them when you next send a message that they need only complete the minimum amount of work: difficulty 1. ", None, QtGui.QApplication.UnicodeUTF8))
263-
self.label_9.setText(QtGui.QApplication.translate("settingsDialog", "Total difficulty:", None, QtGui.QApplication.UnicodeUTF8))
264-
self.label_11.setText(QtGui.QApplication.translate("settingsDialog", "Small message difficulty:", None, QtGui.QApplication.UnicodeUTF8))
265-
self.label_12.setText(QtGui.QApplication.translate("settingsDialog", "The \'Small message difficulty\' mostly only affects the difficulty of sending small messages. Doubling this value makes it almost twice as difficult to send a small message but doesn\'t really affect large messages.", None, QtGui.QApplication.UnicodeUTF8))
266-
self.label_10.setText(QtGui.QApplication.translate("settingsDialog", "The \'Total difficulty\' affects the absolute amount of work the sender must complete. Doubling this value doubles the amount of work.", None, QtGui.QApplication.UnicodeUTF8))
267-
self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tab), QtGui.QApplication.translate("settingsDialog", "Demanded difficulty", None, QtGui.QApplication.UnicodeUTF8))
268-
self.label_15.setText(QtGui.QApplication.translate("settingsDialog", "Here you may set the maximum amount of work you are willing to do to send a message to another person. Setting these values to 0 means that any value is acceptable.", None, QtGui.QApplication.UnicodeUTF8))
269-
self.label_13.setText(QtGui.QApplication.translate("settingsDialog", "Maximum acceptable total difficulty:", None, QtGui.QApplication.UnicodeUTF8))
270-
self.label_14.setText(QtGui.QApplication.translate("settingsDialog", "Maximum acceptable small message difficulty:", None, QtGui.QApplication.UnicodeUTF8))
271-
self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tab_2), QtGui.QApplication.translate("settingsDialog", "Max acceptable difficulty", None, QtGui.QApplication.UnicodeUTF8))
254+
settingsDialog.setWindowTitle(_translate("settingsDialog", "Settings", None))
255+
self.checkBoxStartOnLogon.setText(_translate("settingsDialog", "Start Bitmessage on user login", None))
256+
self.checkBoxStartInTray.setText(_translate("settingsDialog", "Start Bitmessage in the tray (don\'t show main window)", None))
257+
self.checkBoxMinimizeToTray.setText(_translate("settingsDialog", "Minimize to tray", None))
258+
self.checkBoxShowTrayNotifications.setText(_translate("settingsDialog", "Show notification when message received", None))
259+
self.checkBoxPortableMode.setText(_translate("settingsDialog", "Run in Portable Mode", None))
260+
self.label_7.setText(_translate("settingsDialog", "In Portable Mode, messages and config files are stored in the same directory as the program rather than the normal application-data folder. This makes it convenient to run Bitmessage from a USB thumb drive.", None))
261+
self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabUserInterface), _translate("settingsDialog", "User Interface", None))
262+
self.groupBox.setTitle(_translate("settingsDialog", "Listening port", None))
263+
self.label.setText(_translate("settingsDialog", "Listen for connections on port:", None))
264+
self.groupBox_2.setTitle(_translate("settingsDialog", "Proxy server / Tor", None))
265+
self.label_2.setText(_translate("settingsDialog", "Type:", None))
266+
self.comboBoxProxyType.setItemText(0, _translate("settingsDialog", "none", None))
267+
self.comboBoxProxyType.setItemText(1, _translate("settingsDialog", "SOCKS4a", None))
268+
self.comboBoxProxyType.setItemText(2, _translate("settingsDialog", "SOCKS5", None))
269+
self.label_3.setText(_translate("settingsDialog", "Server hostname:", None))
270+
self.label_4.setText(_translate("settingsDialog", "Port:", None))
271+
self.checkBoxAuthentication.setText(_translate("settingsDialog", "Authentication", None))
272+
self.label_5.setText(_translate("settingsDialog", "Username:", None))
273+
self.label_6.setText(_translate("settingsDialog", "Pass:", None))
274+
self.checkBoxSocksListen.setText(_translate("settingsDialog", "Listen for incoming connections when using proxy", None))
275+
self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabNetworkSettings), _translate("settingsDialog", "Network Settings", None))
276+
self.label_8.setText(_translate("settingsDialog", "When someone sends you a message, their computer must first complete some work. The difficulty of this work, by default, is 1. You may raise this default for new addresses you create by changing the values here. Any new addresses you create will require senders to meet the higher difficulty. There is one exception: if you add a friend or acquaintance to your address book, Bitmessage will automatically notify them when you next send a message that they need only complete the minimum amount of work: difficulty 1. ", None))
277+
self.label_9.setText(_translate("settingsDialog", "Total difficulty:", None))
278+
self.label_11.setText(_translate("settingsDialog", "Small message difficulty:", None))
279+
self.label_12.setText(_translate("settingsDialog", "The \'Small message difficulty\' mostly only affects the difficulty of sending small messages. Doubling this value makes it almost twice as difficult to send a small message but doesn\'t really affect large messages.", None))
280+
self.label_10.setText(_translate("settingsDialog", "The \'Total difficulty\' affects the absolute amount of work the sender must complete. Doubling this value doubles the amount of work.", None))
281+
self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tab), _translate("settingsDialog", "Demanded difficulty", None))
282+
self.label_15.setText(_translate("settingsDialog", "Here you may set the maximum amount of work you are willing to do to send a message to another person. Setting these values to 0 means that any value is acceptable.", None))
283+
self.label_13.setText(_translate("settingsDialog", "Maximum acceptable total difficulty:", None))
284+
self.label_14.setText(_translate("settingsDialog", "Maximum acceptable small message difficulty:", None))
285+
self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tab_2), _translate("settingsDialog", "Max acceptable difficulty", None))
272286

src/bitmessageqt/settings.ui

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@
247247
</property>
248248
</widget>
249249
</item>
250+
<item row="3" column="1" colspan="4">
251+
<widget class="QCheckBox" name="checkBoxSocksListen">
252+
<property name="text">
253+
<string>Listen for incoming connections when using proxy</string>
254+
</property>
255+
</widget>
256+
</item>
250257
</layout>
251258
</widget>
252259
</item>
@@ -508,6 +515,7 @@
508515
<tabstop>checkBoxAuthentication</tabstop>
509516
<tabstop>lineEditSocksUsername</tabstop>
510517
<tabstop>lineEditSocksPassword</tabstop>
518+
<tabstop>checkBoxSocksListen</tabstop>
511519
<tabstop>buttonBox</tabstop>
512520
</tabstops>
513521
<resources/>

src/class_singleListener.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ def setup(self, selfInitiatedConnections):
2121
self.selfInitiatedConnections = selfInitiatedConnections
2222

2323
def run(self):
24-
# We don't want to accept incoming connections if the user is using a
25-
# SOCKS proxy. If they eventually select proxy 'none' then this will
26-
# start listening for connections.
27-
while shared.config.get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS':
24+
# We typically don't want to accept incoming connections if the user is using a
25+
# SOCKS proxy, unless they have configured otherwise. If they eventually select
26+
# proxy 'none' or configure SOCKS listening then this will start listening for
27+
# connections.
28+
while shared.config.get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS' and not shared.config.getboolean('bitmessagesettings', 'sockslisten'):
2829
time.sleep(300)
2930

3031
with shared.printLock:
@@ -40,10 +41,11 @@ def run(self):
4041
sock.listen(2)
4142

4243
while True:
43-
# We don't want to accept incoming connections if the user is using
44-
# a SOCKS proxy. If the user eventually select proxy 'none' then
45-
# this will start listening for connections.
46-
while shared.config.get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS':
44+
# We typically don't want to accept incoming connections if the user is using a
45+
# SOCKS proxy, unless they have configured otherwise. If they eventually select
46+
# proxy 'none' or configure SOCKS listening then this will start listening for
47+
# connections.
48+
while shared.config.get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS' and not shared.config.getboolean('bitmessagesettings', 'sockslisten'):
4749
time.sleep(10)
4850
while len(shared.connectedHostsList) > 220:
4951
with shared.printLock:

src/class_sqlThread.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def run(self):
8181
shared.config.set('bitmessagesettings', 'socksauthentication', 'false')
8282
shared.config.set('bitmessagesettings', 'socksusername', '')
8383
shared.config.set('bitmessagesettings', 'sockspassword', '')
84+
shared.config.set('bitmessagesettings', 'sockslisten', 'false')
8485
shared.config.set('bitmessagesettings', 'keysencrypted', 'false')
8586
shared.config.set('bitmessagesettings', 'messagesencrypted', 'false')
8687
with open(shared.appdata + 'keys.dat', 'wb') as configfile:

src/helper_startup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def loadConfig():
5050
shared.config.set('bitmessagesettings', 'socksport', '9050')
5151
shared.config.set(
5252
'bitmessagesettings', 'socksauthentication', 'false')
53+
shared.config.set(
54+
'bitmessagesettings', 'sockslisten', 'false')
5355
shared.config.set('bitmessagesettings', 'socksusername', '')
5456
shared.config.set('bitmessagesettings', 'sockspassword', '')
5557
shared.config.set('bitmessagesettings', 'keysencrypted', 'false')
@@ -78,3 +80,9 @@ def loadConfig():
7880
os.umask(0o077)
7981
with open(shared.appdata + 'keys.dat', 'wb') as configfile:
8082
shared.config.write(configfile)
83+
84+
# Initialize settings that may be missing due to upgrades and could
85+
# cause errors if missing.
86+
if not shared.config.has_option('bitmessagesettings', 'sockslisten'):
87+
shared.config.set('bitmessagesettings', 'sockslisten', 'false')
88+

0 commit comments

Comments
 (0)