self._nodeid_s = idlib.shortnodeid_b2a(self._nodeid)
self._index = (self._nodeid, service_name)
- self._service_name = service_name
+ self.service_name = service_name
self.log("attempting to connect to %s" % self._nodeid_s)
self.announcement_time = time.time()
self.rref = None
self.remote_host = None
self.last_connect_time = None
- self.version = None
- self.oldest_supported = None
+ self.version = ver
+ self.oldest_supported = oldest
def log(self, *args, **kwargs):
return self._ic.log(*args, **kwargs)
def _got_service(self, rref):
self.last_connect_time = time.time()
- self.remote_host = str(rref.tracker.broker.transport.getPeer())
+ self.remote_host = rref.tracker.broker.transport.getPeer()
self.rref = rref
self.log("connected to %s" % self._nodeid_s)
- self._ic.add_connection(self._nodeid, self._service_name, rref)
+ self._ic.add_connection(self._nodeid, self.service_name, rref)
rref.notifyOnDisconnect(self._lost, rref)
self.last_loss_time = time.time()
self.rref = None
self.remote_host = None
- self._ic.remove_connection(self._nodeid, self._service_name, rref)
+ self._ic.remove_connection(self._nodeid, self.service_name, rref)
<div>Helper: <span n:render="string" n:data="helper_furl" /></div>
<div>Connected to helper?: <span n:render="string" n:data="connected_to_helper" /></div>
-<div>Known+Connected Peers: <span n:render="string" n:data="num_peers" /></div>
+<div>Known Storage Servers: <span n:render="string" n:data="known_storage_servers" /></div>
+<div>Connected Storage Servers: <span n:render="string" n:data="connected_storage_servers" /></div>
<div>
-<table n:render="sequence" n:data="peers" border="1">
+<table n:render="sequence" n:data="services" border="1">
<tr n:pattern="header">
<td>PeerID</td>
+ <td>Connected?</td>
+ <td>Since</td>
+ <td>Announced</td>
+ <td>Version</td>
+ <td>Service Name</td>
</tr>
- <tr n:pattern="item" n:render="row">
+ <tr n:pattern="item" n:render="service_row">
<td><tt><n:slot name="peerid"/></tt></td>
+ <td><tt><n:slot name="connected"/></tt></td>
+ <td><tt><n:slot name="since"/></tt></td>
+ <td><tt><n:slot name="announced"/></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>
</table>
-from base64 import b32encode
-import os.path
+import time, os.path
from twisted.application import service, strports, internet
from twisted.web import static, resource, server, html, http
from twisted.python import log
-from twisted.internet import defer
+from twisted.internet import defer, address
from twisted.internet.interfaces import IConsumer
from nevow import inevow, rend, loaders, appserver, url, tags as T
from nevow.static import File as nevow_File # TODO: merge with static.File?
-from allmydata.util import fileutil
+from allmydata.util import fileutil, idlib
import simplejson
from allmydata.interfaces import IDownloadTarget, IDirectoryNode, IFileNode, \
IMutableFileNode
return get_package_versions_string()
def data_my_nodeid(self, ctx, data):
- return b32encode(IClient(ctx).nodeid).lower()
+ return idlib.nodeid_b2a(IClient(ctx).nodeid)
def data_introducer_furl(self, ctx, data):
return IClient(ctx).introducer_furl
def data_connected_to_introducer(self, ctx, data):
return "yes"
return "no"
- def data_num_peers(self, ctx, data):
- #client = inevow.ISite(ctx)._client
- client = IClient(ctx)
- return len(list(client.get_all_peerids()))
+ def data_known_storage_servers(self, ctx, data):
+ ic = IClient(ctx).introducer_client
+ servers = [c
+ for c in ic.get_all_connectors().values()
+ if c.service_name == "storage"]
+ return len(servers)
+
+ def data_connected_storage_servers(self, ctx, data):
+ ic = IClient(ctx).introducer_client
+ return len(ic.get_all_connections_for("storage"))
+
+ def data_services(self, ctx, data):
+ ic = IClient(ctx).introducer_client
+ c = [ (service_name, nodeid, rsc)
+ for (nodeid, service_name), rsc
+ in ic.get_all_connectors().items() ]
+ c.sort()
+ return c
+
+ def render_service_row(self, ctx, data):
+ (service_name, nodeid, rsc) = data
+ ctx.fillSlots("peerid", idlib.nodeid_b2a(nodeid))
+ if rsc.rref:
+ rhost = rsc.remote_host
+ if nodeid == IClient(ctx).nodeid:
+ rhost_s = "(loopback)"
+ elif isinstance(rhost, address.IPv4Address):
+ rhost_s = "%s:%d" % (rhost.host, rhost.port)
+ else:
+ rhost_s = str(rhost)
+ connected = "Yes: to " + rhost_s
+ since = rsc.last_connect_time
+ else:
+ connected = "No"
+ since = rsc.last_loss_time
- def data_peers(self, ctx, data):
- d = []
- client = IClient(ctx)
- for nodeid in sorted(client.get_all_peerids()):
- row = (b32encode(nodeid).lower(),)
- d.append(row)
- return d
+ TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
+ ctx.fillSlots("connected", connected)
+ ctx.fillSlots("since", time.strftime(TIME_FORMAT, time.localtime(since)))
+ ctx.fillSlots("announced", time.strftime(TIME_FORMAT,
+ time.localtime(rsc.announcement_time)))
+ ctx.fillSlots("version", rsc.version)
+ ctx.fillSlots("service_name", rsc.service_name)
- def render_row(self, ctx, data):
- (nodeid_a,) = data
- ctx.fillSlots("peerid", nodeid_a)
return ctx.tag
# this is a form where users can download files by URI