2008-03-12 00:36:25 +00:00
|
|
|
|
2012-03-07 02:25:05 +00:00
|
|
|
import time, os
|
2008-03-25 19:56:12 +00:00
|
|
|
from nevow import rend, inevow
|
2012-03-07 02:25:05 +00:00
|
|
|
from nevow.static import File as nevow_File
|
|
|
|
from nevow.util import resource_filename
|
2008-03-12 00:36:25 +00:00
|
|
|
import allmydata
|
2008-03-25 19:56:12 +00:00
|
|
|
import simplejson
|
2008-03-12 00:36:25 +00:00
|
|
|
from allmydata import get_package_versions_string
|
|
|
|
from allmydata.util import idlib
|
2010-02-26 08:14:33 +00:00
|
|
|
from allmydata.web.common import getxmlfile, get_arg
|
2008-03-12 00:36:25 +00:00
|
|
|
|
|
|
|
class IntroducerRoot(rend.Page):
|
|
|
|
|
|
|
|
addSlash = True
|
|
|
|
docFactory = getxmlfile("introducer.xhtml")
|
|
|
|
|
2008-10-22 00:03:07 +00:00
|
|
|
child_operations = None
|
|
|
|
|
2009-02-20 19:15:54 +00:00
|
|
|
def __init__(self, introducer_node):
|
|
|
|
self.introducer_node = introducer_node
|
|
|
|
self.introducer_service = introducer_node.getServiceNamed("introducer")
|
|
|
|
rend.Page.__init__(self, introducer_node)
|
2012-03-07 02:25:05 +00:00
|
|
|
static_dir = resource_filename("allmydata.web", "static")
|
|
|
|
for filen in os.listdir(static_dir):
|
|
|
|
self.putChild(filen, nevow_File(os.path.join(static_dir, filen)))
|
2009-02-20 19:15:54 +00:00
|
|
|
|
2008-03-25 19:56:12 +00:00
|
|
|
def renderHTTP(self, ctx):
|
|
|
|
t = get_arg(inevow.IRequest(ctx), "t")
|
|
|
|
if t == "json":
|
|
|
|
return self.render_JSON(ctx)
|
|
|
|
return rend.Page.renderHTTP(self, ctx)
|
|
|
|
|
|
|
|
def render_JSON(self, ctx):
|
|
|
|
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
|
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
|
|
|
res["subscription_summary"] = counts
|
2008-03-25 19:56:12 +00:00
|
|
|
|
|
|
|
announcement_summary = {}
|
2008-11-18 22:30:15 +00:00
|
|
|
service_hosts = {}
|
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
|
2008-11-18 22:30:15 +00:00
|
|
|
if service_name not in service_hosts:
|
|
|
|
service_hosts[service_name] = set()
|
|
|
|
# it's nice to know how many distinct hosts are available for
|
|
|
|
# each service. We define a "host" by a set of addresses
|
|
|
|
# (hostnames or ipv4 addresses), which we extract from the
|
|
|
|
# connection hints. In practice, this is usually close
|
|
|
|
# enough: when multiple services are run on a single host,
|
|
|
|
# they're usually either configured with the same addresses,
|
|
|
|
# or setLocationAutomatically picks up the same interfaces.
|
2012-04-23 22:02:22 +00:00
|
|
|
host = frozenset(ad.advertised_addresses)
|
2008-11-18 22:30:15 +00:00
|
|
|
service_hosts[service_name].add(host)
|
2008-03-25 19:56:12 +00:00
|
|
|
res["announcement_summary"] = announcement_summary
|
2008-11-18 22:30:15 +00:00
|
|
|
distinct_hosts = dict([(name, len(hosts))
|
|
|
|
for (name, hosts)
|
|
|
|
in service_hosts.iteritems()])
|
|
|
|
res["announcement_distinct_hosts"] = distinct_hosts
|
2008-03-25 19:56:12 +00:00
|
|
|
|
2008-09-15 20:43:14 +00:00
|
|
|
return simplejson.dumps(res, indent=1) + "\n"
|
2008-03-25 19:56:12 +00:00
|
|
|
|
2009-05-03 20:34:42 +00:00
|
|
|
# FIXME: This code is duplicated in root.py and introweb.py.
|
2008-03-12 00:36:25 +00:00
|
|
|
def data_version(self, ctx, data):
|
|
|
|
return get_package_versions_string()
|
|
|
|
def data_import_path(self, ctx, data):
|
2009-05-26 23:25:45 +00:00
|
|
|
return str(allmydata).replace("/", "/ ") # XXX kludge for wrapping
|
2008-03-12 00:36:25 +00:00
|
|
|
def data_my_nodeid(self, ctx, data):
|
2009-02-20 19:15:54 +00:00
|
|
|
return idlib.nodeid_b2a(self.introducer_node.nodeid)
|
2008-03-12 00:36:25 +00:00
|
|
|
|
2008-03-12 02:21:29 +00:00
|
|
|
def render_announcement_summary(self, ctx, data):
|
|
|
|
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()
|
|
|
|
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):
|
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
|
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
|
|
|
return ", ".join([ "%s: %d" % (name, counts[name])
|
|
|
|
for name in sorted(counts.keys()) ] )
|
2008-03-12 00:36:25 +00:00
|
|
|
|
|
|
|
def data_services(self, ctx, data):
|
2012-04-23 22:02:22 +00:00
|
|
|
services = self.introducer_service.get_announcements(False)
|
|
|
|
services.sort(key=lambda ad: (ad.service_name, ad.nickname))
|
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
|
|
|
return services
|
|
|
|
|
2012-04-23 22:02:22 +00:00
|
|
|
def render_service_row(self, ctx, ad):
|
|
|
|
ctx.fillSlots("peerid", ad.tubid)
|
|
|
|
ctx.fillSlots("nickname", ad.nickname)
|
|
|
|
ctx.fillSlots("advertised", " ".join(ad.advertised_addresses))
|
2008-03-12 00:36:25 +00:00
|
|
|
ctx.fillSlots("connected", "?")
|
2012-04-23 22:02:22 +00:00
|
|
|
when_s = time.strftime("%H:%M:%S %d-%b-%Y", time.localtime(ad.when))
|
|
|
|
ctx.fillSlots("announced", when_s)
|
|
|
|
ctx.fillSlots("version", ad.version)
|
|
|
|
ctx.fillSlots("service_name", ad.service_name)
|
2008-03-12 00:36:25 +00:00
|
|
|
return ctx.tag
|
|
|
|
|
|
|
|
def data_subscribers(self, ctx, data):
|
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
|
|
|
return self.introducer_service.get_subscribers()
|
2008-03-12 00:36:25 +00:00
|
|
|
|
|
|
|
def render_subscriber_row(self, ctx, s):
|
2012-04-23 22:02:22 +00:00
|
|
|
ctx.fillSlots("nickname", s.nickname)
|
|
|
|
ctx.fillSlots("peerid", s.tubid)
|
|
|
|
ctx.fillSlots("advertised", " ".join(s.advertised_addresses))
|
|
|
|
ctx.fillSlots("connected", s.remote_address)
|
|
|
|
since_s = time.strftime("%H:%M:%S %d-%b-%Y", time.localtime(s.when))
|
|
|
|
ctx.fillSlots("since", since_s)
|
|
|
|
ctx.fillSlots("version", s.version)
|
|
|
|
ctx.fillSlots("service_name", s.service_name)
|
2008-03-12 00:36:25 +00:00
|
|
|
return ctx.tag
|
|
|
|
|