]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
introducer: record a timestamp with each subscriber, and display it on the introducer...
authorBrian Warner <warner@allmydata.com>
Wed, 12 Mar 2008 02:28:37 +0000 (19:28 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 12 Mar 2008 02:28:37 +0000 (19:28 -0700)
src/allmydata/introducer.py
src/allmydata/web/introweb.py

index 5c9d210a12d22a286d43a53dedf29ba26efab195..98d969c4f2111b4fa942c73f12db011a3541671e 100644 (file)
@@ -49,7 +49,7 @@ class IntroducerService(service.MultiService, Referenceable):
         service.MultiService.__init__(self)
         self.introducer_url = None
         self._announcements = set()
-        self._subscribers = {}
+        self._subscribers = {} # dict of (rref->timestamp) dicts
 
     def log(self, *args, **kwargs):
         if "facility" not in kwargs:
@@ -75,17 +75,17 @@ class IntroducerService(service.MultiService, Referenceable):
         self.log("introducer: subscription[%s] request at %s" % (service_name,
                                                                  subscriber))
         if service_name not in self._subscribers:
-            self._subscribers[service_name] = set()
+            self._subscribers[service_name] = {}
         subscribers = self._subscribers[service_name]
         if subscriber in subscribers:
             self.log("but they're already subscribed, ignoring",
                      level=log.UNUSUAL)
             return
-        subscribers.add(subscriber)
+        subscribers[subscriber] = time.time()
         def _remove():
             self.log("introducer: unsubscribing[%s] %s" % (service_name,
                                                            subscriber))
-            subscribers.remove(subscriber)
+            subscribers.pop(subscriber, None)
         subscriber.notifyOnDisconnect(_remove)
 
         announcements = set( [ a
index 43e08e9b1c0e54bcb8f166f54f849817b9919a27..7bee16311616088d94ce0b1c17eacd3a62703f79 100644 (file)
@@ -1,4 +1,5 @@
 
+import time
 from nevow import rend
 from foolscap.referenceable import SturdyRef
 from twisted.internet import address
@@ -78,16 +79,16 @@ class IntroducerRoot(rend.Page):
         # then we actually provide information per subscriber
         s = []
         for service_name, subscribers in i.get_subscribers().items():
-            for rref in subscribers:
+            for (rref, timestamp) in subscribers.items():
                 sr = rref.getSturdyRef()
                 nodeid = sr.tubID
                 ann = clients.get(nodeid)
-                s.append( (service_name, rref, ann) )
+                s.append( (service_name, rref, timestamp, ann) )
         s.sort()
         return s
 
     def render_subscriber_row(self, ctx, s):
-        (service_name, rref, ann) = s
+        (service_name, rref, since, ann) = s
         nickname = "?"
         version = "?"
         if ann:
@@ -107,7 +108,9 @@ class IntroducerRoot(rend.Page):
             # loopback is a non-IPv4Address
             remote_host_s = str(remote_host)
         ctx.fillSlots("connected", remote_host_s)
-        ctx.fillSlots("since", "?")
+        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)
         return ctx.tag