2008-03-12 00:36:25 +00:00
|
|
|
|
2008-03-12 02:28:37 +00:00
|
|
|
import time
|
2008-03-12 00:36:25 +00:00
|
|
|
from nevow import rend
|
|
|
|
from foolscap.referenceable import SturdyRef
|
|
|
|
from twisted.internet import address
|
|
|
|
import allmydata
|
|
|
|
from allmydata import get_package_versions_string
|
|
|
|
from allmydata.util import idlib
|
|
|
|
from common import getxmlfile, IClient
|
|
|
|
|
|
|
|
class IntroducerRoot(rend.Page):
|
|
|
|
|
|
|
|
addSlash = True
|
|
|
|
docFactory = getxmlfile("introducer.xhtml")
|
|
|
|
|
|
|
|
def data_version(self, ctx, data):
|
|
|
|
return get_package_versions_string()
|
|
|
|
def data_import_path(self, ctx, data):
|
|
|
|
return str(allmydata)
|
|
|
|
def data_my_nodeid(self, ctx, data):
|
|
|
|
return idlib.nodeid_b2a(IClient(ctx).nodeid)
|
|
|
|
|
2008-03-12 02:21:29 +00:00
|
|
|
def render_announcement_summary(self, ctx, data):
|
2008-03-12 00:36:25 +00:00
|
|
|
i = IClient(ctx).getServiceNamed("introducer")
|
2008-03-12 02:21:29 +00:00
|
|
|
services = {}
|
|
|
|
for ann in i.get_announcements():
|
|
|
|
(furl, service_name, ri_name, nickname, ver, oldest) = ann
|
|
|
|
if service_name not in services:
|
|
|
|
services[service_name] = 0
|
|
|
|
services[service_name] += 1
|
|
|
|
service_names = services.keys()
|
|
|
|
service_names.sort()
|
|
|
|
return ", ".join(["%s: %d" % (service_name, services[service_name])
|
|
|
|
for service_name in service_names])
|
2008-03-12 00:36:25 +00:00
|
|
|
|
2008-03-12 02:21:29 +00:00
|
|
|
def render_client_summary(self, ctx, data):
|
2008-03-12 00:36:25 +00:00
|
|
|
i = IClient(ctx).getServiceNamed("introducer")
|
2008-03-12 02:21:29 +00:00
|
|
|
clients = i.get_subscribers()
|
|
|
|
service_names = clients.keys()
|
|
|
|
service_names.sort()
|
|
|
|
return ", ".join(["%s: %d" % (service_name, len(clients[service_name]))
|
|
|
|
for service_name in service_names])
|
2008-03-12 00:36:25 +00:00
|
|
|
|
|
|
|
def data_services(self, ctx, data):
|
|
|
|
i = IClient(ctx).getServiceNamed("introducer")
|
2008-03-12 02:33:19 +00:00
|
|
|
ann = [(since,a)
|
|
|
|
for (a,since) in i.get_announcements().items()
|
2008-03-12 02:21:29 +00:00
|
|
|
if a[1] != "stub_client"]
|
2008-03-12 02:33:19 +00:00
|
|
|
ann.sort(lambda a,b: cmp( (a[1][1], a), (b[1][1], b) ) )
|
2008-03-12 00:36:25 +00:00
|
|
|
return ann
|
|
|
|
|
2008-03-12 02:33:19 +00:00
|
|
|
def render_service_row(self, ctx, (since,announcement)):
|
2008-03-12 00:36:25 +00:00
|
|
|
(furl, service_name, ri_name, nickname, ver, oldest) = announcement
|
|
|
|
sr = SturdyRef(furl)
|
|
|
|
nodeid = sr.tubID
|
2008-03-12 02:21:29 +00:00
|
|
|
advertised = [loc.split(":")[0] for loc in sr.locationHints
|
|
|
|
if not loc.startswith("127.0.0.1:")]
|
|
|
|
ctx.fillSlots("peerid", "%s %s" % (nodeid, nickname))
|
2008-03-12 00:36:25 +00:00
|
|
|
ctx.fillSlots("advertised", " ".join(advertised))
|
|
|
|
ctx.fillSlots("connected", "?")
|
2008-03-12 02:33:19 +00:00
|
|
|
TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
|
|
|
|
ctx.fillSlots("announced",
|
|
|
|
time.strftime(TIME_FORMAT, time.localtime(since)))
|
2008-03-12 00:36:25 +00:00
|
|
|
ctx.fillSlots("version", ver)
|
|
|
|
ctx.fillSlots("service_name", service_name)
|
|
|
|
return ctx.tag
|
|
|
|
|
|
|
|
def data_subscribers(self, ctx, data):
|
|
|
|
i = IClient(ctx).getServiceNamed("introducer")
|
2008-03-12 02:21:29 +00:00
|
|
|
# use the "stub_client" announcements to get information per nodeid
|
|
|
|
clients = {}
|
|
|
|
for ann in i.get_announcements():
|
|
|
|
if ann[1] != "stub_client":
|
|
|
|
continue
|
|
|
|
(furl, service_name, ri_name, nickname, ver, oldest) = ann
|
|
|
|
sr = SturdyRef(furl)
|
|
|
|
nodeid = sr.tubID
|
|
|
|
clients[nodeid] = ann
|
|
|
|
|
|
|
|
# then we actually provide information per subscriber
|
2008-03-12 00:36:25 +00:00
|
|
|
s = []
|
|
|
|
for service_name, subscribers in i.get_subscribers().items():
|
2008-03-12 02:28:37 +00:00
|
|
|
for (rref, timestamp) in subscribers.items():
|
2008-03-12 02:21:29 +00:00
|
|
|
sr = rref.getSturdyRef()
|
|
|
|
nodeid = sr.tubID
|
|
|
|
ann = clients.get(nodeid)
|
2008-03-12 02:28:37 +00:00
|
|
|
s.append( (service_name, rref, timestamp, ann) )
|
2008-03-12 00:36:25 +00:00
|
|
|
s.sort()
|
|
|
|
return s
|
|
|
|
|
|
|
|
def render_subscriber_row(self, ctx, s):
|
2008-03-12 02:28:37 +00:00
|
|
|
(service_name, rref, since, ann) = s
|
2008-03-12 02:21:29 +00:00
|
|
|
nickname = "?"
|
|
|
|
version = "?"
|
|
|
|
if ann:
|
|
|
|
(furl, service_name_2, ri_name, nickname, version, oldest) = ann
|
|
|
|
|
2008-03-12 00:36:25 +00:00
|
|
|
sr = rref.getSturdyRef()
|
2008-03-12 01:09:13 +00:00
|
|
|
# if the subscriber didn't do Tub.setLocation, nodeid will be None
|
2008-03-12 02:21:29 +00:00
|
|
|
nodeid = sr.tubID or "?"
|
|
|
|
ctx.fillSlots("peerid", "%s %s" % (nodeid, nickname))
|
|
|
|
advertised = [loc.split(":")[0] for loc in sr.locationHints
|
|
|
|
if not loc.startswith("127.0.0.1:")]
|
2008-03-12 00:36:25 +00:00
|
|
|
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)
|
2008-03-12 02:28:37 +00:00
|
|
|
TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
|
|
|
|
ctx.fillSlots("since",
|
|
|
|
time.strftime(TIME_FORMAT, time.localtime(since)))
|
2008-03-12 02:21:29 +00:00
|
|
|
ctx.fillSlots("version", version)
|
2008-03-12 00:36:25 +00:00
|
|
|
ctx.fillSlots("service_name", service_name)
|
|
|
|
return ctx.tag
|
|
|
|
|
|
|
|
|