Module: deluge
Branch: 1.3-stable
Commit: ba1cc6ef1fa52fb40d8c5e010d92f5fc4cb6c901

Author: Calum Lind <[email protected]>
Date:   Wed Jun 29 21:10:49 2011 +0100

Fix #1232: Improve display of Peers Tab IPv6 addresses

---

 deluge/ui/console/commands/info.py              |    8 +++++++-
 deluge/ui/gtkui/peers_tab.py                    |    4 +++-
 deluge/ui/web/js/deluge-all/details/PeersTab.js |    9 ++++++++-
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/deluge/ui/console/commands/info.py 
b/deluge/ui/console/commands/info.py
index f748178..1937f56 100644
--- a/deluge/ui/console/commands/info.py
+++ b/deluge/ui/console/commands/info.py
@@ -247,7 +247,13 @@ class Command(BaseCommand):
                         s += "%sPeer\t{!input!}" % 
colors.state_color["Downloading"]
 
                     s += peer["country"] + "\t"
-                    s += peer["ip"]
+
+                    if peer["ip"].count(":") == 1:
+                        # IPv4
+                        s += peer["ip"]
+                    else:
+                        # IPv6
+                        s += "[%s]:%s" % 
(":".join(peer["ip"].split(":")[:-1]), peer["ip"].split(":")[-1])
 
                     c = peer["client"]
                     s += "\t" + c
diff --git a/deluge/ui/gtkui/peers_tab.py b/deluge/ui/gtkui/peers_tab.py
index 7f4ad17..bb2316f 100644
--- a/deluge/ui/gtkui/peers_tab.py
+++ b/deluge/ui/gtkui/peers_tab.py
@@ -315,6 +315,7 @@ class PeersTab(Tab):
                     # This is an IPv4 address
                     ip_int = sum([int(byte) << shift
                         for byte, shift in 
izip(peer["ip"].split(":")[0].split("."), (24, 16, 8, 0))])
+                    peer_ip = peer["ip"]
                 else:
                     # This is an IPv6 address
                     import socket
@@ -322,6 +323,7 @@ class PeersTab(Tab):
                     # Split out the :port
                     ip = ":".join(peer["ip"].split(":")[:-1])
                     ip_int = 
long(binascii.hexlify(socket.inet_pton(socket.AF_INET6, ip)), 16)
+                    peer_ip = "[%s]:%s" % (ip, peer["ip"].split(":")[-1])
 
                 if peer["seed"]:
                     icon = self.seed_pixbuf
@@ -330,7 +332,7 @@ class PeersTab(Tab):
 
                 row = self.liststore.append([
                     self.get_flag_pixbuf(peer["country"]),
-                    peer["ip"],
+                    peer_ip,
                     peer["client"],
                     peer["down_speed"],
                     peer["up_speed"],
diff --git a/deluge/ui/web/js/deluge-all/details/PeersTab.js 
b/deluge/ui/web/js/deluge-all/details/PeersTab.js
index f972893..cff33c5 100644
--- a/deluge/ui/web/js/deluge-all/details/PeersTab.js
+++ b/deluge/ui/web/js/deluge-all/details/PeersTab.js
@@ -38,7 +38,14 @@
                return String.format('<img src="flag/{0}" />', value);
        }
        function peerAddressRenderer(value, p, record) {
-               var seed = (record.data['seed'] == 1024) ? 'x-deluge-seed' : 
'x-deluge-peer'
+               var seed = (record.data['seed'] == 1024) ? 'x-deluge-seed' : 
'x-deluge-peer';
+               // Modify display of IPv6 to include brackets
+               var peer_ip = value.split(':');
+               if (peer_ip.length > 2) {
+                       var port = peer_ip.pop();
+                       var ip = peer_ip.join(":");
+                       value = "[" + ip + "]:" + port;
+               }
                return String.format('<div class="{0}">{1}</div>', seed, value);
        }
        function peerProgressRenderer(value) {

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to