mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-16 07:06:43 +00:00
introducer: record a timestamp with each subscriber, and display it on the introducer's web page
This commit is contained in:
parent
89be2e1bea
commit
29e23626ad
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user