From 5098297a2ba65011e810aaaa3ea53c4e0061be71 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 14 May 2008 13:55:47 -0700 Subject: [PATCH] introweb.py: tolerate foolscap>=0.2.6, which changed the internals of .locationHints --- src/allmydata/web/introweb.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/allmydata/web/introweb.py b/src/allmydata/web/introweb.py index 5fab0e91..14ef9a51 100644 --- a/src/allmydata/web/introweb.py +++ b/src/allmydata/web/introweb.py @@ -78,8 +78,7 @@ class IntroducerRoot(rend.Page): (furl, service_name, ri_name, nickname, ver, oldest) = announcement sr = SturdyRef(furl) nodeid = sr.tubID - advertised = [loc.split(":")[0] for loc in sr.locationHints - if not loc.startswith("127.0.0.1:")] + advertised = self.show_location_hints(sr) ctx.fillSlots("peerid", "%s %s" % (nodeid, nickname)) ctx.fillSlots("advertised", " ".join(advertised)) ctx.fillSlots("connected", "?") @@ -124,8 +123,7 @@ class IntroducerRoot(rend.Page): # if the subscriber didn't do Tub.setLocation, nodeid will be None nodeid = sr.tubID or "?" ctx.fillSlots("peerid", "%s %s" % (nodeid, nickname)) - advertised = [loc.split(":")[0] for loc in sr.locationHints - if not loc.startswith("127.0.0.1:")] + advertised = self.show_location_hints(sr) ctx.fillSlots("advertised", " ".join(advertised)) remote_host = rref.tracker.broker.transport.getPeer() if isinstance(remote_host, address.IPv4Address): @@ -141,4 +139,21 @@ class IntroducerRoot(rend.Page): ctx.fillSlots("service_name", service_name) return ctx.tag + def show_location_hints(self, sr, ignore_localhost=True): + advertised = [] + for hint in sr.locationHints: + if isinstance(hint, str): + # Foolscap-0.2.5 and earlier used strings in .locationHints + if ignore_localhost and hint.startswith("127.0.0.1"): + continue + advertised.append(hint.split(":")[0]) + else: + # Foolscap-0.2.6 and later use tuples of ("ipv4", host, port) + if hint[0] == "ipv4": + host = hint[1] + if ignore_localhost and host == "127.0.0.1": + continue + advertised.append(hint[1]) + return advertised + -- 2.45.2