introducer: record a timestamp with each announcement, and display it on the introduc...
authorBrian Warner <warner@allmydata.com>
Wed, 12 Mar 2008 02:33:19 +0000 (19:33 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 12 Mar 2008 02:33:19 +0000 (19:33 -0700)
src/allmydata/introducer.py
src/allmydata/web/introweb.py

index 98d969c4f2111b4fa942c73f12db011a3541671e..4968d9977a107519f541890a0786b79e6dee878b 100644 (file)
@@ -48,7 +48,7 @@ class IntroducerService(service.MultiService, Referenceable):
     def __init__(self, basedir="."):
         service.MultiService.__init__(self)
         self.introducer_url = None
-        self._announcements = set()
+        self._announcements = {} # dict of (announcement)->timestamp
         self._subscribers = {} # dict of (rref->timestamp) dicts
 
     def log(self, *args, **kwargs):
@@ -57,7 +57,7 @@ class IntroducerService(service.MultiService, Referenceable):
         return log.msg(*args, **kwargs)
 
     def get_announcements(self):
-        return frozenset(self._announcements)
+        return self._announcements
     def get_subscribers(self):
         return self._subscribers
 
@@ -67,7 +67,7 @@ class IntroducerService(service.MultiService, Referenceable):
         if announcement in self._announcements:
             self.log("but we already knew it, ignoring", level=log.NOISY)
             return
-        self._announcements.add(announcement)
+        self._announcements[announcement] = time.time()
         for s in self._subscribers.get(service_name, []):
             s.callRemote("announce", set([announcement]))
 
index 7bee16311616088d94ce0b1c17eacd3a62703f79..9722357346a3b3e4fb8849785dc9aab3fe833779 100644 (file)
@@ -43,13 +43,13 @@ class IntroducerRoot(rend.Page):
 
     def data_services(self, ctx, data):
         i = IClient(ctx).getServiceNamed("introducer")
-        ann = [a
-               for a in i.get_announcements()
+        ann = [(since,a)
+               for (a,since) in i.get_announcements().items()
                if a[1] != "stub_client"]
-        ann.sort(lambda a,b: cmp( (a[1], a), (b[1], b) ) )
+        ann.sort(lambda a,b: cmp( (a[1][1], a), (b[1][1], b) ) )
         return ann
 
-    def render_service_row(self, ctx, announcement):
+    def render_service_row(self, ctx, (since,announcement)):
         (furl, service_name, ri_name, nickname, ver, oldest) = announcement
         sr = SturdyRef(furl)
         nodeid = sr.tubID
@@ -58,8 +58,9 @@ class IntroducerRoot(rend.Page):
         ctx.fillSlots("peerid", "%s %s" % (nodeid, nickname))
         ctx.fillSlots("advertised", " ".join(advertised))
         ctx.fillSlots("connected", "?")
-        ctx.fillSlots("since", "?")
-        ctx.fillSlots("announced", "?")
+        TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
+        ctx.fillSlots("announced",
+                      time.strftime(TIME_FORMAT, time.localtime(since)))
         ctx.fillSlots("version", ver)
         ctx.fillSlots("service_name", service_name)
         return ctx.tag