nodeinfo: fix capitalization
[relay.git/.git] / relay / nodeinfo.py
1 import urllib.parse
2
3 import aiohttp.web
4
5 from . import app
6 from .database import DATABASE
7
8
9 nodeinfo_template = {
10     # XXX - is this valid for a relay?
11     'openRegistrations': True,
12     'protocols': ['activitypub'],
13     'services': {
14         'inbound': [],
15         'outbound': []
16     },
17     'software': {
18         'name': 'activityrelay',
19         'version': '0.1'
20     },
21     'usage': {
22         'localPosts': 0,
23         'users': {
24             'total': 1
25         }
26     },
27     'version': '2.0'
28 }
29
30
31 def get_peers():
32     global DATABASE
33
34     return [urllib.parse.urlsplit(inbox).hostname for inbox in DATABASE.get('relay-list', [])]
35
36
37 async def nodeinfo_2_0(request):
38     data = nodeinfo_template.copy()
39     data['metadata'] = {
40         'peers': get_peers()
41     }
42     return aiohttp.web.json_response(data)
43
44
45 app.router.add_get('/nodeinfo/2.0.json', nodeinfo_2_0)
46
47
48 async def nodeinfo_wellknown(request):
49     data = {
50         'links': [
51              {
52                  'rel': 'http://nodeinfo.diaspora.software/ns/schema/2.0',
53                  'href': 'https://{}/nodeinfo/2.0.json'.format(request.host)
54              }
55         ]
56     }
57     return aiohttp.web.json_response(data)
58
59
60 app.router.add_get('/.well-known/nodeinfo', nodeinfo_wellknown)