[Pkg-privacy-commits] [onioncircuits] 17/39: Display circuit details when using bridges

Sascha Steinbiss sascha at steinbiss.name
Sun May 15 16:40:45 UTC 2016


This is an automated email from the git hooks/post-receive script.

sascha-guest pushed a commit to branch master
in repository onioncircuits.

commit 9043a5a8248e71a35dafed49f397d701d9a7c42c
Author: Alan <alan at boum.org>
Date:   Fri Apr 1 20:05:48 2016 +0200

    Display circuit details when using bridges
    
    When using a bridge, the first node in the path doesn't have a
    ServerDescriptor. We now handle this case gracefully.
---
 onioncircuits | 51 +++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 37 insertions(+), 14 deletions(-)

diff --git a/onioncircuits b/onioncircuits
index 02858cc..a10dc0e 100755
--- a/onioncircuits
+++ b/onioncircuits
@@ -531,19 +531,20 @@ class OnionCircuitsWindow(Gtk.ApplicationWindow):
         """
         self.clear_circuit_details()
 
-        for fp in [fp for fp, nick in circuit.path]:
-            self.display_node(self.controller.get_network_status(fp))
+        for fp, nick in circuit.path:
+            self.display_node(fp, nick)
 
         self._path.show_all()
 
-    def display_node(self, status_entry):
-        """Display details for a node
+    def get_country(self, address):
+        """Get the country corresponding to an IP address
+
+        :var str address: an ip address
 
-        :var stem.descriptor.router_status_entry.RouterStatusEntryMicroV3
-        status_entry: the status entry for the node
+        :returns: a string containing the country name, or **None**
         """
         try:
-            country = self.controller.get_info("ip-to-country/%s" % status_entry.address)
+            country = self.controller.get_info("ip-to-country/%s" % address)
         except stem.ProtocolError:
             country = None
             if not self._geoip_message_shown:
@@ -560,12 +561,34 @@ class OnionCircuitsWindow(Gtk.ApplicationWindow):
                 # If pycountry can't find the country, just display the string
                 # returned by Tor.
                 pass
+        return country
+
+    def display_node(self, fingerprint, nickname):
+        """Display details for a node
 
-        # if we couldn't get a country, just display the IP
-        if country:
+        :var string fingerprint: the fingerprint of the node
+
+        :var string nickname: the nickname of the node
+        """
+        try:
+            status_entry = self.controller.get_network_status(fingerprint)
+        except stem.DescriptorUnavailable:
+            status_entry = None
+
+        if status_entry:
+            country = self.get_country(status_entry.address)
+            if country:
+                ip_with_country = _("%s (%s)") % (status_entry.address, country)
+            else: # we couldn't get a country, just display the IP
+                ip_with_country = str(status_entry.address)
+
+            published = status_entry.published
             ip_with_country = _("%s (%s)") % (status_entry.address, country)
+            bandwidth = _("%.2f Mb/s") % (status_entry.bandwidth/1024.)
         else:
-            ip_with_country = str(status_entry.address)
+            published = _("Unknown")
+            ip_with_country = _("Unknown")
+            bandwidth = _("Unknown")
 
         grid = Gtk.Grid()
         grid.set_property('row-spacing', 6)
@@ -573,15 +596,15 @@ class OnionCircuitsWindow(Gtk.ApplicationWindow):
         grid.set_property('margin', 12)
 
         title = Gtk.Label()
-        title.set_markup("<b>%s</b>" % status_entry.nickname)
+        title.set_markup("<b>%s</b>" % nickname)
         title.set_halign(Gtk.Align.START)
         grid.attach(title, 0, 0, 2, 1)
 
         line = 1
-        for l, v in [(_("Fingerprint:"), status_entry.fingerprint),
-                     (_("Published:"), status_entry.published),
+        for l, v in [(_("Fingerprint:"), fingerprint),
+                     (_("Published:"), published),
                      (_("IP:"), ip_with_country),
-                     (_("Bandwidth:"), _("%.2f Mb/s") % (status_entry.bandwidth/1024.)),
+                     (_("Bandwidth:"), bandwidth),
                     ]:
             label = Gtk.Label(l)
             label.set_halign(Gtk.Align.START)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onioncircuits.git



More information about the Pkg-privacy-commits mailing list