introweb: combine announcement and subscriber information to show version+nickname for each client

This commit is contained in:
Brian Warner 2008-03-11 19:21:29 -07:00
parent c21d30c320
commit 89be2e1bea
3 changed files with 56 additions and 29 deletions

View File

@ -880,7 +880,7 @@ class SystemTest(testutil.SignalMixin, testutil.PollMixin, unittest.TestCase):
try:
self.failUnless("allmydata: %s" % str(allmydata.__version__)
in res)
self.failUnless("Clients:" in res)
self.failUnless("Summary: storage: 5, stub_client: 5" in res)
except unittest.FailTest:
print
print "GET %s output was:" % self.introweb_url

View File

@ -1,6 +1,6 @@
<html xmlns:n="http://nevow.com/ns/nevow/0.1">
<head>
<title>AllMyData - Tahoe</title>
<title>Introducer Status - AllMyData Tahoe</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
@ -15,9 +15,8 @@
<br />
<div>Storage Servers: <span n:render="string" n:data="known_storage_servers" /> known</div>
<div>Clients: <span n:render="string" n:data="num_clients" /> subscribed</div>
<div>Announcement Summary: <span n:render="announcement_summary" /></div>
<div>Subscription Summary: <span n:render="client_summary" /></div>
<h2>Service Announcements</h2>
@ -46,10 +45,11 @@
<div>
<table n:render="sequence" n:data="subscribers" border="1">
<tr n:pattern="header">
<td>PeerID</td>
<td>PeerID / Nickname</td>
<td>Advertised IPs</td>
<td>Connected From</td>
<td>Since</td>
<td>Version</td>
<td>Subscribed To</td>
</tr>
<tr n:pattern="item" n:render="subscriber_row">
@ -57,6 +57,7 @@
<td><tt><n:slot name="advertised"/></tt></td>
<td><tt><n:slot name="connected"/></tt></td>
<td><tt><n:slot name="since"/></tt></td>
<td><tt><n:slot name="version"/></tt></td>
<td><tt><n:slot name="service_name"/></tt></td>
</tr>
<tr n:pattern="empty"><td>no peers!</td></tr>

View File

@ -19,25 +19,32 @@ class IntroducerRoot(rend.Page):
def data_my_nodeid(self, ctx, data):
return idlib.nodeid_b2a(IClient(ctx).nodeid)
def data_known_storage_servers(self, ctx, data):
def render_announcement_summary(self, ctx, data):
i = IClient(ctx).getServiceNamed("introducer")
storage = [1
for (furl, service_name, ri_name, nickname, ver, oldest)
in i.get_announcements()
if service_name == "storage"]
return len(storage)
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])
def data_num_clients(self, ctx, data):
def render_client_summary(self, ctx, data):
i = IClient(ctx).getServiceNamed("introducer")
num_clients = 0
subscribers = i.get_subscribers()
for service_name,who in subscribers.items():
num_clients += len(who)
return num_clients
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])
def data_services(self, ctx, data):
i = IClient(ctx).getServiceNamed("introducer")
ann = list(i.get_announcements())
ann = [a
for a in i.get_announcements()
if a[1] != "stub_client"]
ann.sort(lambda a,b: cmp( (a[1], a), (b[1], b) ) )
return ann
@ -45,8 +52,9 @@ class IntroducerRoot(rend.Page):
(furl, service_name, ri_name, nickname, ver, oldest) = announcement
sr = SturdyRef(furl)
nodeid = sr.tubID
advertised = [loc.split(":")[0] for loc in sr.locationHints]
ctx.fillSlots("peerid", "%s %s" % (idlib.nodeid_b2a(nodeid), nickname))
advertised = [loc.split(":")[0] for loc in sr.locationHints
if not loc.startswith("127.0.0.1:")]
ctx.fillSlots("peerid", "%s %s" % (nodeid, nickname))
ctx.fillSlots("advertised", " ".join(advertised))
ctx.fillSlots("connected", "?")
ctx.fillSlots("since", "?")
@ -57,23 +65,40 @@ class IntroducerRoot(rend.Page):
def data_subscribers(self, ctx, data):
i = IClient(ctx).getServiceNamed("introducer")
# 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
s = []
for service_name, subscribers in i.get_subscribers().items():
for rref in subscribers:
s.append( (service_name, rref) )
sr = rref.getSturdyRef()
nodeid = sr.tubID
ann = clients.get(nodeid)
s.append( (service_name, rref, ann) )
s.sort()
return s
def render_subscriber_row(self, ctx, s):
(service_name, rref) = s
(service_name, rref, ann) = s
nickname = "?"
version = "?"
if ann:
(furl, service_name_2, ri_name, nickname, version, oldest) = ann
sr = rref.getSturdyRef()
nodeid = sr.tubID
# if the subscriber didn't do Tub.setLocation, nodeid will be None
nodeid_s = "?"
if nodeid:
nodeid_s = idlib.nodeid_b2a(nodeid)
ctx.fillSlots("peerid", nodeid_s)
advertised = [loc.split(":")[0] for loc in sr.locationHints]
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:")]
ctx.fillSlots("advertised", " ".join(advertised))
remote_host = rref.tracker.broker.transport.getPeer()
if isinstance(remote_host, address.IPv4Address):
@ -83,6 +108,7 @@ class IntroducerRoot(rend.Page):
remote_host_s = str(remote_host)
ctx.fillSlots("connected", remote_host_s)
ctx.fillSlots("since", "?")
ctx.fillSlots("version", version)
ctx.fillSlots("service_name", service_name)
return ctx.tag