From 29e23626ad9ef6a60a59b1dc5e52be6141d25e43 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 11 Mar 2008 19:28:37 -0700 Subject: [PATCH] introducer: record a timestamp with each subscriber, and display it on the introducer's web page --- src/allmydata/introducer.py | 8 ++++---- src/allmydata/web/introweb.py | 11 +++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/allmydata/introducer.py b/src/allmydata/introducer.py index 5c9d210a..98d969c4 100644 --- a/src/allmydata/introducer.py +++ b/src/allmydata/introducer.py @@ -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 diff --git a/src/allmydata/web/introweb.py b/src/allmydata/web/introweb.py index 43e08e9b..7bee1631 100644 --- a/src/allmydata/web/introweb.py +++ b/src/allmydata/web/introweb.py @@ -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 -- 2.45.2