2008-03-12 00:36:25 +00:00
|
|
|
|
2012-03-07 02:25:05 +00:00
|
|
|
import time, os
|
2019-08-14 10:50:27 +00:00
|
|
|
from pkg_resources import resource_filename
|
2019-08-14 19:16:18 +00:00
|
|
|
from twisted.web.template import Element, XMLFile, renderElement, renderer
|
2019-08-14 09:37:56 +00:00
|
|
|
from twisted.python.filepath import FilePath
|
2019-08-14 19:35:15 +00:00
|
|
|
from twisted.web import static
|
2008-03-12 00:36:25 +00:00
|
|
|
import allmydata
|
2017-01-19 22:39:53 +00:00
|
|
|
import json
|
2019-08-13 19:11:01 +00:00
|
|
|
from allmydata.version_checks import get_package_versions_string
|
2008-03-12 00:36:25 +00:00
|
|
|
from allmydata.util import idlib
|
2017-07-25 15:15:31 +00:00
|
|
|
from allmydata.web.common import (
|
|
|
|
render_time,
|
2019-08-14 10:31:50 +00:00
|
|
|
MultiFormatResource,
|
2019-08-14 09:37:56 +00:00
|
|
|
SlotsSequenceElement,
|
2017-07-25 15:15:31 +00:00
|
|
|
)
|
2013-05-19 22:27:23 +00:00
|
|
|
|
2008-03-12 00:36:25 +00:00
|
|
|
|
2019-08-14 10:31:50 +00:00
|
|
|
class IntroducerRoot(MultiFormatResource):
|
2019-08-16 16:43:31 +00:00
|
|
|
"""
|
|
|
|
A ``Resource`` intended as the root resource for introducers.
|
|
|
|
|
|
|
|
:param _IntroducerNode introducer_node: The introducer node to template
|
|
|
|
information about.
|
|
|
|
"""
|
2019-08-14 19:16:18 +00:00
|
|
|
|
2009-02-20 19:15:54 +00:00
|
|
|
def __init__(self, introducer_node):
|
2019-08-14 10:31:50 +00:00
|
|
|
super(IntroducerRoot, self).__init__()
|
2009-02-20 19:15:54 +00:00
|
|
|
self.introducer_node = introducer_node
|
|
|
|
self.introducer_service = introducer_node.getServiceNamed("introducer")
|
2019-08-14 09:37:56 +00:00
|
|
|
# necessary as a root Resource
|
2019-08-14 19:16:18 +00:00
|
|
|
self.putChild("", self)
|
2012-03-07 02:25:05 +00:00
|
|
|
static_dir = resource_filename("allmydata.web", "static")
|
|
|
|
for filen in os.listdir(static_dir):
|
2019-08-14 10:50:27 +00:00
|
|
|
self.putChild(filen, static.File(os.path.join(static_dir, filen)))
|
2009-02-20 19:15:54 +00:00
|
|
|
|
2019-08-16 16:43:31 +00:00
|
|
|
def _create_element(self):
|
|
|
|
"""
|
|
|
|
Create a ``IntroducerRootElement`` which can be flattened into an HTML
|
|
|
|
response.
|
|
|
|
"""
|
|
|
|
return IntroducerRootElement(
|
|
|
|
self.introducer_node, self.introducer_service)
|
|
|
|
|
2019-08-14 10:31:50 +00:00
|
|
|
def render_HTML(self, req):
|
2019-08-16 16:43:31 +00:00
|
|
|
"""
|
|
|
|
Render an HTML template describing this introducer node.
|
|
|
|
"""
|
|
|
|
return renderElement(req, self._create_element())
|
2019-08-14 09:37:56 +00:00
|
|
|
|
2017-07-25 15:15:31 +00:00
|
|
|
def render_JSON(self, req):
|
2019-08-16 16:43:31 +00:00
|
|
|
"""
|
|
|
|
Render JSON describing this introducer node.
|
|
|
|
"""
|
2008-03-25 19:56:12 +00:00
|
|
|
res = {}
|
new introducer: signed extensible dictionary-based messages! refs #466
This introduces new client and server halves to the Introducer (renaming the
old one with a _V1 suffix). Both have fallbacks to accomodate talking to a
different version: the publishing client switches on whether the server's
.get_version() advertises V2 support, the server switches on which
subscription method was invoked by the subscribing client.
The V2 protocol sends a three-tuple of (serialized announcement dictionary,
signature, pubkey) for each announcement. The V2 server dispatches messages
to subscribers according to the service-name, and throws errors for invalid
signatures, but does not otherwise examine the messages. The V2 receiver's
subscription callback will receive a (serverid, ann_dict) pair. The
'serverid' will be equal to the pubkey if all of the following are true:
the originating client is V2, and was told a privkey to use
the announcement went through a V2 server
the signature is valid
If not, 'serverid' will be equal to the tubid portion of the announced FURL,
as was the case for V1 receivers.
Servers will create a keypair if one does not exist yet, stored in
private/server.privkey .
The signed announcement dictionary puts the server FURL in a key named
"anonymous-storage-FURL", which anticipates upcoming Accounting-related
changes in the server advertisements. It also provides a key named
"permutation-seed-base32" to tell clients what permutation seed to use. This
is computed at startup, using tubid if there are existing shares, otherwise
the pubkey, to retain share-order compatibility for existing servers.
2011-11-20 10:21:32 +00:00
|
|
|
|
|
|
|
counts = {}
|
2012-04-23 22:02:22 +00:00
|
|
|
for s in self.introducer_service.get_subscribers():
|
|
|
|
if s.service_name not in counts:
|
|
|
|
counts[s.service_name] = 0
|
|
|
|
counts[s.service_name] += 1
|
2019-08-16 15:51:57 +00:00
|
|
|
res[u"subscription_summary"] = counts
|
2008-03-25 19:56:12 +00:00
|
|
|
|
|
|
|
announcement_summary = {}
|
2012-04-23 22:02:22 +00:00
|
|
|
for ad in self.introducer_service.get_announcements():
|
|
|
|
service_name = ad.service_name
|
2008-03-25 19:56:12 +00:00
|
|
|
if service_name not in announcement_summary:
|
|
|
|
announcement_summary[service_name] = 0
|
|
|
|
announcement_summary[service_name] += 1
|
2019-08-16 15:51:57 +00:00
|
|
|
res[u"announcement_summary"] = announcement_summary
|
2008-03-25 19:56:12 +00:00
|
|
|
|
2019-08-16 15:51:57 +00:00
|
|
|
return json.dumps(res, indent=1) + b"\n"
|
2008-03-25 19:56:12 +00:00
|
|
|
|
2019-08-14 09:37:56 +00:00
|
|
|
|
|
|
|
class IntroducerRootElement(Element):
|
2019-08-16 16:49:39 +00:00
|
|
|
"""
|
|
|
|
An ``Element`` HTML template which can be flattened to describe this
|
|
|
|
introducer node.
|
|
|
|
|
|
|
|
:param _IntroducerNode introducer_node: The introducer node to describe.
|
|
|
|
:param IntroducerService introducer_service: The introducer service created
|
|
|
|
by the node.
|
|
|
|
"""
|
2019-08-14 09:37:56 +00:00
|
|
|
|
|
|
|
loader = XMLFile(FilePath(__file__).sibling("introducer.xhtml"))
|
|
|
|
|
|
|
|
def __init__(self, introducer_node, introducer_service):
|
|
|
|
super(IntroducerRootElement, self).__init__()
|
|
|
|
self.introducer_node = introducer_node
|
|
|
|
self.introducer_service = introducer_service
|
|
|
|
self.node_data_dict = {
|
2019-08-14 19:16:18 +00:00
|
|
|
"my_nodeid": idlib.nodeid_b2a(self.introducer_node.nodeid),
|
|
|
|
"version": get_package_versions_string(),
|
|
|
|
"import_path": str(allmydata).replace("/", "/ "), # XXX kludge for wrapping
|
|
|
|
"rendered_at": render_time(time.time()),
|
2019-08-14 09:37:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@renderer
|
|
|
|
def node_data(self, req, tag):
|
|
|
|
return tag.fillSlots(**self.node_data_dict)
|
|
|
|
|
|
|
|
@renderer
|
2019-08-14 19:16:18 +00:00
|
|
|
def announcement_summary(self, req, tag):
|
2008-03-12 02:21:29 +00:00
|
|
|
services = {}
|
2012-04-23 22:02:22 +00:00
|
|
|
for ad in self.introducer_service.get_announcements():
|
|
|
|
if ad.service_name not in services:
|
|
|
|
services[ad.service_name] = 0
|
|
|
|
services[ad.service_name] += 1
|
2008-03-12 02:21:29 +00:00
|
|
|
service_names = services.keys()
|
|
|
|
service_names.sort()
|
2019-08-16 15:51:57 +00:00
|
|
|
return u", ".join(u"{}: {}".format(service_name, services[service_name])
|
|
|
|
for service_name in service_names)
|
2008-03-12 00:36:25 +00:00
|
|
|
|
2019-08-14 09:37:56 +00:00
|
|
|
@renderer
|
2019-08-14 19:16:18 +00:00
|
|
|
def client_summary(self, req, tag):
|
new introducer: signed extensible dictionary-based messages! refs #466
This introduces new client and server halves to the Introducer (renaming the
old one with a _V1 suffix). Both have fallbacks to accomodate talking to a
different version: the publishing client switches on whether the server's
.get_version() advertises V2 support, the server switches on which
subscription method was invoked by the subscribing client.
The V2 protocol sends a three-tuple of (serialized announcement dictionary,
signature, pubkey) for each announcement. The V2 server dispatches messages
to subscribers according to the service-name, and throws errors for invalid
signatures, but does not otherwise examine the messages. The V2 receiver's
subscription callback will receive a (serverid, ann_dict) pair. The
'serverid' will be equal to the pubkey if all of the following are true:
the originating client is V2, and was told a privkey to use
the announcement went through a V2 server
the signature is valid
If not, 'serverid' will be equal to the tubid portion of the announced FURL,
as was the case for V1 receivers.
Servers will create a keypair if one does not exist yet, stored in
private/server.privkey .
The signed announcement dictionary puts the server FURL in a key named
"anonymous-storage-FURL", which anticipates upcoming Accounting-related
changes in the server advertisements. It also provides a key named
"permutation-seed-base32" to tell clients what permutation seed to use. This
is computed at startup, using tubid if there are existing shares, otherwise
the pubkey, to retain share-order compatibility for existing servers.
2011-11-20 10:21:32 +00:00
|
|
|
counts = {}
|
2012-04-23 22:02:22 +00:00
|
|
|
for s in self.introducer_service.get_subscribers():
|
|
|
|
if s.service_name not in counts:
|
|
|
|
counts[s.service_name] = 0
|
|
|
|
counts[s.service_name] += 1
|
2019-08-16 15:51:57 +00:00
|
|
|
return u", ".join(u"{}: {}".format(name, counts[name])
|
|
|
|
for name in sorted(counts.keys()))
|
2008-03-12 00:36:25 +00:00
|
|
|
|
2019-08-14 09:37:56 +00:00
|
|
|
@renderer
|
|
|
|
def services(self, req, tag):
|
2016-06-30 05:58:14 +00:00
|
|
|
services = self.introducer_service.get_announcements()
|
2012-04-23 22:02:22 +00:00
|
|
|
services.sort(key=lambda ad: (ad.service_name, ad.nickname))
|
2019-08-14 09:37:56 +00:00
|
|
|
services = [{
|
|
|
|
"serverid": ad.serverid,
|
|
|
|
"nickname": ad.nickname,
|
|
|
|
"connection-hints":
|
2019-08-16 15:51:57 +00:00
|
|
|
u"connection hints: " + u" ".join(ad.connection_hints),
|
|
|
|
"connected": u"?",
|
2019-08-14 09:37:56 +00:00
|
|
|
"announced": render_time(ad.when),
|
|
|
|
"version": ad.version,
|
|
|
|
"service_name": ad.service_name,
|
|
|
|
} for ad in services]
|
|
|
|
return SlotsSequenceElement(tag, services)
|
|
|
|
|
|
|
|
@renderer
|
2019-08-14 19:16:18 +00:00
|
|
|
def subscribers(self, req, tag):
|
2019-08-14 09:37:56 +00:00
|
|
|
subscribers = [{
|
|
|
|
"nickname": s.nickname,
|
|
|
|
"tubid": s.tubid,
|
|
|
|
"connected": s.remote_address,
|
|
|
|
"since": render_time(s.when),
|
|
|
|
"version": s.version,
|
|
|
|
"service_name": s.service_name,
|
|
|
|
} for s in self.introducer_service.get_subscribers()]
|
|
|
|
return SlotsSequenceElement(tag, subscribers)
|