From: kaniini Date: Sun, 18 Nov 2018 15:05:13 +0000 (+0000) Subject: relay: add support for nodeinfo protocol X-Git-Tag: 0.1.0~40 X-Git-Url: https://reisub.nsupdate.info/git/?p=relay.git%2F.git;a=commitdiff_plain;h=db52dd4af950d6a90ff569b1dc41b980ef176ed7 relay: add support for nodeinfo protocol --- diff --git a/relay/__init__.py b/relay/__init__.py index cf12bd0..c90fbb2 100644 --- a/relay/__init__.py +++ b/relay/__init__.py @@ -27,3 +27,4 @@ from . import database from . import actor from . import webfinger from . import default +from . import nodeinfo diff --git a/relay/nodeinfo.py b/relay/nodeinfo.py new file mode 100644 index 0000000..8dd9da6 --- /dev/null +++ b/relay/nodeinfo.py @@ -0,0 +1,60 @@ +import urllib.parse + +import aiohttp.web + +from . import app +from .database import DATABASE + + +nodeinfo_template = { + # XXX - is this valid for a relay? + 'openRegistrations': True, + 'protocols': ['activitypub'], + 'services': { + 'inbound': [], + 'outbound': [] + }, + 'software': { + 'name': 'ActivityRelay', + 'version': '0.1' + }, + 'usage': { + 'localPosts': 0, + 'users': { + 'total': 1 + } + }, + 'version': '2.0' +} + + +def get_peers(): + global DATABASE + + return [urllib.parse.urlsplit(inbox).hostname for inbox in DATABASE.get('relay-list', [])] + + +async def nodeinfo_2_0(request): + data = nodeinfo_template.copy() + data['metadata'] = { + 'peers': get_peers() + } + return aiohttp.web.json_response(data) + + +app.router.add_get('/nodeinfo/2.0.json', nodeinfo_2_0) + + +async def nodeinfo_wellknown(request): + data = { + 'links': [ + { + 'rel': 'http://nodeinfo.diaspora.software/ns/schema/2.0', + 'href': 'https://{}/nodeinfo/2.0.json'.format(request.host) + } + ] + } + return aiohttp.web.json_response(data) + + +app.router.add_get('/.well-known/nodeinfo', nodeinfo_wellknown)