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

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

    From 63a83458abcbb4893b903784b2bb3c57817bea04 Mon Sep 17 00:00:00 2001
    From: Tydus <Tydus@Tydus.org>
    Date: Fri, 15 Sep 2017 15:03:57 +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 |  4 ++--
     deluge/ui/hostlist.py                | 14 +++++++++-----
     2 files changed, 11 insertions(+), 7 deletions(-)
    
    diff --git a/deluge/ui/gtkui/connectionmanager.py b/deluge/ui/gtkui/connectionmanager.py
    index ba791ee..ab7fec1 100644
    a b  
    1111
    1212import logging
    1313import os
    14 from socket import gaierror, gethostbyname
     14from socket import gaierror, getaddrinfo
    1515
    1616import gtk
    1717from twisted.internet import defer, reactor
    def _update_widget_buttons(self):  
    218218        # Get selected host info.
    219219        __, host, port, __, __, status, __ = model[row]
    220220        try:
    221             gethostbyname(host)
     221            getaddrinfo(host, port)
    222222        except gaierror as ex:
    223223            log.error('Error resolving host %s to ip: %s', row[HOSTLIST_COL_HOST], ex.args[1])
    224224            self.builder.get_object('button_connect').set_sensitive(False)
  • deluge/ui/hostlist.py

    diff --git a/deluge/ui/hostlist.py b/deluge/ui/hostlist.py
    index fa61555..ddc86c1 100644
    a b  
    1313import os
    1414import time
    1515from hashlib import sha1
    16 from socket import gaierror, gethostbyname
     16from socket import gaierror, getaddrinfo, AF_INET, AF_INET6
    1717
    1818from twisted.internet import defer
    1919
    def validate_host_info(hostname, port):  
    4848    """
    4949
    5050    try:
    51         gethostbyname(hostname)
     51        getaddrinfo(hostname, port)
    5252    except gaierror as ex:
    5353        raise ValueError('Host %s: %s', hostname, ex.args[1])
    5454
    def on_connect_failed(reason, host_id):  
    197197            log.warning('Problem getting host_id info from hostlist')
    198198            return status_offline
    199199
     200        # Try to resolve to IPv4 first, for backward compatibility
    200201        try:
    201             ip = gethostbyname(host)
     202            ip = getaddrinfo(host, port, AF_INET)[0][4][0]
    202203        except gaierror as ex:
    203             log.error('Error resolving host %s to ip: %s', host, ex.args[1])
    204             return status_offline
     204            try:
     205                ip = getaddrinfo(host, port, AF_INET6)[0][4][0]
     206            except gaierror as ex:
     207                log.error('Error resolving host %s to ip: %s', host, ex.args[1])
     208                return status_offline
    205209
    206210        host_conn_info = (ip, port, 'localclient' if not user and host in LOCALHOST else user)
    207211        if client.connected() and host_conn_info == client.connection_info():