Ticket #1130: 0001-Support-IPv6-literal-for-daemon-connection-in-gtkui-1.3.patch

File 0001-Support-IPv6-literal-for-daemon-connection-in-gtkui-1.3.patch, 2.3 KB (added by Tydus, 7 years ago)
  • deluge/ui/gtkui/connectionmanager.py

    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  
    3939import time
    4040import hashlib
    4141from twisted.internet import reactor
    42 from socket import gaierror, gethostbyname
     42from socket import gaierror, getaddrinfo, AF_INET, AF_INET6
    4343
    4444import deluge.component as component
    4545import deluge.common
    def add_host(self, host, port, username="", password=""):  
    205205                raise Exception("Host already in list!")
    206206
    207207        try:
    208             gethostbyname(host)
     208            getaddrinfo(host, port)
    209209        except gaierror, ex:
    210210            raise Exception("Host '%s': %s" % (host, ex.args[1]))
    211211
    def on_connect_failed(reason, host_id):  
    309309            user = row[HOSTLIST_COL_USER]
    310310            password = row[HOSTLIST_COL_PASS]
    311311
     312            # Try to resolve to IPv4 first, for backward compatibility
    312313            try:
    313                 ip = gethostbyname(host)
     314                ip = getaddrinfo(host, port, AF_INET)[0][4][0]
    314315            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
    317321
    318322            if client.connected() and (
    319323                ip,