]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/web/introweb.py
introducer: stop tracking hints for subscribed clients
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / web / introweb.py
index 783b2beec8fc8089604aeb38e1cedab42bb85175..bbe42d0bb9da1dbfd41b2b211d80ef377181eac0 100644 (file)
@@ -3,13 +3,12 @@ import time, os
 from nevow import rend, inevow
 from nevow.static import File as nevow_File
 from nevow.util import resource_filename
-from foolscap.api import SturdyRef
-from twisted.internet import address
 import allmydata
 import simplejson
 from allmydata import get_package_versions_string
 from allmydata.util import idlib
-from allmydata.web.common import getxmlfile, get_arg
+from allmydata.web.common import getxmlfile, get_arg, TIME_FORMAT
+
 
 class IntroducerRoot(rend.Page):
 
@@ -36,18 +35,16 @@ class IntroducerRoot(rend.Page):
         res = {}
 
         counts = {}
-        subscribers = self.introducer_service.get_subscribers()
-        for (service_name, ign, ign, ign) in subscribers:
-            if service_name not in counts:
-                counts[service_name] = 0
-            counts[service_name] += 1
+        for s in self.introducer_service.get_subscribers():
+            if s.service_name not in counts:
+                counts[s.service_name] = 0
+            counts[s.service_name] += 1
         res["subscription_summary"] = counts
 
         announcement_summary = {}
         service_hosts = {}
-        for a in self.introducer_service.get_announcements().values():
-            (_, _, ann, when) = a
-            service_name = ann["service-name"]
+        for ad in self.introducer_service.get_announcements():
+            service_name = ad.service_name
             if service_name not in announcement_summary:
                 announcement_summary[service_name] = 0
             announcement_summary[service_name] += 1
@@ -60,12 +57,7 @@ class IntroducerRoot(rend.Page):
             # enough: when multiple services are run on a single host,
             # they're usually either configured with the same addresses,
             # or setLocationAutomatically picks up the same interfaces.
-            furl = ann["anonymous-storage-FURL"]
-            locations = SturdyRef(furl).getTubRef().getLocations()
-            # list of tuples, ("ipv4", host, port)
-            host = frozenset([hint[1]
-                              for hint in locations
-                              if hint[0] == "ipv4"])
+            host = frozenset(ad.advertised_addresses)
             service_hosts[service_name].add(host)
         res["announcement_summary"] = announcement_summary
         distinct_hosts = dict([(name, len(hosts))
@@ -76,6 +68,8 @@ class IntroducerRoot(rend.Page):
         return simplejson.dumps(res, indent=1) + "\n"
 
     # FIXME: This code is duplicated in root.py and introweb.py.
+    def data_rendered_at(self, ctx, data):
+        return time.strftime(TIME_FORMAT, time.localtime())
     def data_version(self, ctx, data):
         return get_package_versions_string()
     def data_import_path(self, ctx, data):
@@ -85,12 +79,10 @@ class IntroducerRoot(rend.Page):
 
     def render_announcement_summary(self, ctx, data):
         services = {}
-        for a in self.introducer_service.get_announcements().values():
-            (_, _, ann, when) = a
-            service_name = ann["service-name"]
-            if service_name not in services:
-                services[service_name] = 0
-            services[service_name] += 1
+        for ad in self.introducer_service.get_announcements():
+            if ad.service_name not in services:
+                services[ad.service_name] = 0
+            services[ad.service_name] += 1
         service_names = services.keys()
         service_names.sort()
         return ", ".join(["%s: %d" % (service_name, services[service_name])
@@ -98,88 +90,39 @@ class IntroducerRoot(rend.Page):
 
     def render_client_summary(self, ctx, data):
         counts = {}
-        clients = self.introducer_service.get_subscribers()
-        for (service_name, ign, ign, ign) in clients:
-            if service_name not in counts:
-                counts[service_name] = 0
-            counts[service_name] += 1
+        for s in self.introducer_service.get_subscribers():
+            if s.service_name not in counts:
+                counts[s.service_name] = 0
+            counts[s.service_name] += 1
         return ", ".join([ "%s: %d" % (name, counts[name])
                            for name in sorted(counts.keys()) ] )
 
     def data_services(self, ctx, data):
-        introsvc = self.introducer_service
-        services = []
-        for a in introsvc.get_announcements().values():
-            (_, _, ann, when) = a
-            if ann["service-name"] == "stub_client":
-                continue
-            services.append( (when, ann) )
-        services.sort(key=lambda x: (x[1]["service-name"], x[1]["nickname"]))
-        # this used to be:
-        #services.sort(lambda a,b: cmp( (a[1][1], a), (b[1][1], b) ) )
-        # service_name was the primary key, then the whole tuple (starting
-        # with the furl) was the secondary key
+        services = self.introducer_service.get_announcements(False)
+        services.sort(key=lambda ad: (ad.service_name, ad.nickname))
         return services
 
-    def render_service_row(self, ctx, (since,ann)):
-        sr = SturdyRef(ann["anonymous-storage-FURL"])
-        nodeid = sr.tubID
-        advertised = self.show_location_hints(sr)
-        ctx.fillSlots("peerid", nodeid)
-        ctx.fillSlots("nickname", ann["nickname"])
-        ctx.fillSlots("advertised", " ".join(advertised))
+    def render_service_row(self, ctx, ad):
+        ctx.fillSlots("serverid", ad.serverid)
+        ctx.fillSlots("nickname", ad.nickname)
+        ctx.fillSlots("advertised", " ".join(ad.advertised_addresses))
         ctx.fillSlots("connected", "?")
-        TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
-        ctx.fillSlots("announced",
-                      time.strftime(TIME_FORMAT, time.localtime(since)))
-        ctx.fillSlots("version", ann["my-version"])
-        ctx.fillSlots("service_name", ann["service-name"])
+        when_s = time.strftime("%H:%M:%S %d-%b-%Y", time.localtime(ad.when))
+        ctx.fillSlots("announced", when_s)
+        ctx.fillSlots("version", ad.version)
+        ctx.fillSlots("service_name", ad.service_name)
         return ctx.tag
 
     def data_subscribers(self, ctx, data):
         return self.introducer_service.get_subscribers()
 
     def render_subscriber_row(self, ctx, s):
-        (service_name, since, info, rref) = s
-        nickname = info.get("nickname", "?")
-        version = info.get("my-version", "?")
-
-        sr = rref.getSturdyRef()
-        # if the subscriber didn't do Tub.setLocation, nodeid will be None
-        nodeid = sr.tubID or "?"
-        ctx.fillSlots("peerid", nodeid)
-        ctx.fillSlots("nickname", nickname)
-        advertised = self.show_location_hints(sr)
-        ctx.fillSlots("advertised", " ".join(advertised))
-        remote_host = rref.tracker.broker.transport.getPeer()
-        if isinstance(remote_host, address.IPv4Address):
-            remote_host_s = "%s:%d" % (remote_host.host, remote_host.port)
-        else:
-            # loopback is a non-IPv4Address
-            remote_host_s = str(remote_host)
-        ctx.fillSlots("connected", remote_host_s)
-        TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
-        ctx.fillSlots("since",
-                      time.strftime(TIME_FORMAT, time.localtime(since)))
-        ctx.fillSlots("version", version)
-        ctx.fillSlots("service_name", service_name)
+        ctx.fillSlots("nickname", s.nickname)
+        ctx.fillSlots("tubid", s.tubid)
+        ctx.fillSlots("connected", s.remote_address)
+        since_s = time.strftime("%H:%M:%S %d-%b-%Y", time.localtime(s.when))
+        ctx.fillSlots("since", since_s)
+        ctx.fillSlots("version", s.version)
+        ctx.fillSlots("service_name", s.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
-
-