2018-12-03 21:53:26 +00:00
|
|
|
import subprocess
|
2018-11-18 15:05:13 +00:00
|
|
|
import urllib.parse
|
|
|
|
|
|
|
|
import aiohttp.web
|
|
|
|
|
|
|
|
from . import app
|
|
|
|
from .database import DATABASE
|
|
|
|
|
|
|
|
|
2018-12-03 21:53:26 +00:00
|
|
|
try:
|
|
|
|
commit_label = subprocess.check_output(["git", "rev-parse", "HEAD"]).strip().decode('ascii')
|
|
|
|
except:
|
|
|
|
commit_label = '???'
|
|
|
|
|
|
|
|
|
2018-11-18 15:05:13 +00:00
|
|
|
nodeinfo_template = {
|
|
|
|
# XXX - is this valid for a relay?
|
|
|
|
'openRegistrations': True,
|
|
|
|
'protocols': ['activitypub'],
|
|
|
|
'services': {
|
|
|
|
'inbound': [],
|
|
|
|
'outbound': []
|
|
|
|
},
|
|
|
|
'software': {
|
2018-11-18 15:25:46 +00:00
|
|
|
'name': 'activityrelay',
|
2018-12-03 21:53:26 +00:00
|
|
|
'version': '0.1 {}'.format(commit_label)
|
2018-11-18 15:05:13 +00:00
|
|
|
},
|
|
|
|
'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)
|