From: Brian Warner Date: Wed, 14 May 2008 20:55:47 +0000 (-0700) Subject: introweb.py: tolerate foolscap>=0.2.6, which changed the internals of .locationHints X-Git-Tag: allmydata-tahoe-1.1.0~134 X-Git-Url: https://git.rkrishnan.org/components/%22news.html/architecture.txt?a=commitdiff_plain;h=5098297a2ba65011e810aaaa3ea53c4e0061be71;p=tahoe-lafs%2Ftahoe-lafs.git introweb.py: tolerate foolscap>=0.2.6, which changed the internals of .locationHints --- 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 +