From 94d75f7643847e3d2d02c6ec958fdfa69ec5e342 Mon Sep 17 00:00:00 2001
From: Tydus <Tydus@Tydus.org>
Date: Fri, 15 Sep 2017 14:40:42 +0900
Subject: [PATCH] Support IPv6 literal for daemon connection in gtkui
If a daemon is listening to "::" (i.e. invoked by deluged -u "::") or
a specific IPv6 address, the client could connect to it with IPv6
address literal (e.g. "2001:db8::1234", but not domain names).
The domain name is not supported since twisted could not yet handle
concurrent connection attempts for dual-stack domain names.
Therefore, currently, we need to manually handle the concurrent
attempts in deluge.ui.client. This will be a non-trivial modification
for all the clients.
---
deluge/ui/gtkui/connectionmanager.py | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/deluge/ui/gtkui/connectionmanager.py b/deluge/ui/gtkui/connectionmanager.py
index faa2e8f..69fcf6d 100644
a
|
b
|
|
39 | 39 | import time |
40 | 40 | import hashlib |
41 | 41 | from twisted.internet import reactor |
42 | | from socket import gaierror, gethostbyname |
| 42 | from socket import gaierror, getaddrinfo, AF_INET, AF_INET6 |
43 | 43 | |
44 | 44 | import deluge.component as component |
45 | 45 | import deluge.common |
… |
… |
def add_host(self, host, port, username="", password=""):
|
205 | 205 | raise Exception("Host already in list!") |
206 | 206 | |
207 | 207 | try: |
208 | | gethostbyname(host) |
| 208 | getaddrinfo(host, port) |
209 | 209 | except gaierror, ex: |
210 | 210 | raise Exception("Host '%s': %s" % (host, ex.args[1])) |
211 | 211 | |
… |
… |
def on_connect_failed(reason, host_id):
|
309 | 309 | user = row[HOSTLIST_COL_USER] |
310 | 310 | password = row[HOSTLIST_COL_PASS] |
311 | 311 | |
| 312 | # Try to resolve to IPv4 first, for backward compatibility |
312 | 313 | try: |
313 | | ip = gethostbyname(host) |
| 314 | ip = getaddrinfo(host, port, AF_INET)[0][4][0] |
314 | 315 | except gaierror, ex: |
315 | | log.error("Error resolving host %s to ip: %s", host, ex.args[1]) |
316 | | continue |
| 316 | try: |
| 317 | ip = getaddrinfo(host, port, AF_INET6)[0][4][0] |
| 318 | except gaierror, ex: |
| 319 | log.error("Error resolving host %s to ip: %s", host, ex.args[1]) |
| 320 | continue |
317 | 321 | |
318 | 322 | if client.connected() and ( |
319 | 323 | ip, |