IPv6: GUI and client fixes

This commit is contained in:
Alberto Sottile 2018-11-09 19:38:43 +01:00
parent 83d12eca9f
commit a78c646556
3 changed files with 31 additions and 15 deletions

View File

@ -11,7 +11,6 @@ import time
from copy import deepcopy from copy import deepcopy
from functools import wraps from functools import wraps
from twisted.internet.endpoints import HostnameEndpoint
from twisted.internet.protocol import ClientFactory from twisted.internet.protocol import ClientFactory
from twisted.internet import reactor, task, defer, threads from twisted.internet import reactor, task, defer, threads
@ -726,9 +725,10 @@ class SyncplayClient(object):
reactor.callLater(0.1, self._playerClass.run, self, self._config['playerPath'], self._config['file'], self._config['playerArgs'], ) reactor.callLater(0.1, self._playerClass.run, self, self._config['playerPath'], self._config['file'], self._config['playerArgs'], )
self._playerClass = None self._playerClass = None
self.protocolFactory = SyncClientFactory(self) self.protocolFactory = SyncClientFactory(self)
if '[' in host:
host = host.strip('[]')
port = int(port) port = int(port)
self._endpoint = HostnameEndpoint(reactor, host, port) reactor.connectTCP(host, port, self.protocolFactory)
self._endpoint.connect(self.protocolFactory)
reactor.run() reactor.run()
def stop(self, promptForAction=False): def stop(self, promptForAction=False):

View File

@ -313,16 +313,32 @@ class ConfigurationGetter(object):
port = constants.DEFAULT_PORT if not self._config["port"] else self._config["port"] port = constants.DEFAULT_PORT if not self._config["port"] else self._config["port"]
if host: if host:
if ':' in host: if ':' in host:
host, port = host.rsplit(':', 1) if host.count(':') == 1:
if '[' in host: #IPv4 address or hostname, with port
host = host.strip('[]') host, port = host.rsplit(':', 1)
try:
port = int(port)
except ValueError:
try: try:
port = port.encode('ascii', 'ignore') port = int(port)
except: except ValueError:
port = "" try:
port = port.encode('ascii', 'ignore')
except:
port = ""
else:
#IPv6 address
if ']' in host:
#IPv6 address in brackets
endBracket = host.index(']')
try:
#port explicitely indicated
port = int(host[endBracket+2:])
except ValueError:
#no port after the bracket
pass
host = host[:endBracket+1]
else:
#IPv6 address with no port and no brackets
#add brackets to correctly store IPv6 addresses in configs
host = '[' + host + ']'
return host, port return host, port
def _checkForPortableFile(self): def _checkForPortableFile(self):

View File

@ -556,7 +556,7 @@ class ConfigDialog(QtWidgets.QDialog):
self.error = error self.error = error
if config['host'] is None: if config['host'] is None:
host = "" host = ""
elif ":" in config['host']: elif ":" in config['host'] and '[' not in config['host']:
host = config['host'] host = config['host']
else: else:
host = config['host'] + ":" + str(config['port']) host = config['host'] + ":" + str(config['port'])
@ -580,7 +580,7 @@ class ConfigDialog(QtWidgets.QDialog):
i += 1 i += 1
self.hostCombobox.setEditable(True) self.hostCombobox.setEditable(True)
self.hostCombobox.setEditText(host) self.hostCombobox.setEditText(host)
self.hostCombobox.setFixedWidth(165) self.hostCombobox.setFixedWidth(250)
self.hostLabel = QLabel(getMessage("host-label"), self) self.hostLabel = QLabel(getMessage("host-label"), self)
self.findServerButton = QtWidgets.QPushButton(QtGui.QIcon(resourcespath + 'arrow_refresh.png'), getMessage("update-server-list-label")) self.findServerButton = QtWidgets.QPushButton(QtGui.QIcon(resourcespath + 'arrow_refresh.png'), getMessage("update-server-list-label"))
self.findServerButton.clicked.connect(self.updateServerList) self.findServerButton.clicked.connect(self.updateServerList)
@ -634,7 +634,7 @@ class ConfigDialog(QtWidgets.QDialog):
self.executablepathCombobox.setEditable(True) self.executablepathCombobox.setEditable(True)
self.executablepathCombobox.currentIndexChanged.connect(self.updateExecutableIcon) self.executablepathCombobox.currentIndexChanged.connect(self.updateExecutableIcon)
self.executablepathCombobox.setEditText(self._tryToFillPlayerPath(config['playerPath'], playerpaths)) self.executablepathCombobox.setEditText(self._tryToFillPlayerPath(config['playerPath'], playerpaths))
self.executablepathCombobox.setFixedWidth(250) self.executablepathCombobox.setFixedWidth(330)
self.executablepathCombobox.editTextChanged.connect(self.updateExecutableIcon) self.executablepathCombobox.editTextChanged.connect(self.updateExecutableIcon)
self.executablepathLabel = QLabel(getMessage("executable-path-label"), self) self.executablepathLabel = QLabel(getMessage("executable-path-label"), self)