import aiohttp.web
import urllib.parse
import time
import datetime
from . import app, CONFIG
from .database import DATABASE
host = CONFIG['ap']['host']
note = CONFIG['note']
START_TIME=time.time()
async def default(request):
from .actor import INBOUND_STATS
inboxes = DATABASE.get('relay-list', [])
target = []
for t in inboxes:
if urllib.parse.urlsplit(t).hostname not in DATABASE.get('backoff-instances',{}):
target.append('%s' % (urllib.parse.urlsplit(t).hostname,urllib.parse.urlsplit(t).hostname))
targets = '
'.join(target)
err=[]
warn=[]
not_subd = ''.join(['%s' % (s,s) for s in DATABASE.get('not-subscribed',[])])
for instance,val in DATABASE.get('backoff-instances',{}).items():
if time.time() - val['ts'] > 86400:
err.append('%s' % (instance,instance))
else:
warn.append("%s' (%s left before stopping attempts)" % (instance,instance,str(datetime.timedelta(seconds=86400-(time.time()-val['ts']))).split(".")[0])) errs=''.join(err)
warns=''.join(warn)
banned=''.join(CONFIG['ap']['blocked_instances'])
return aiohttp.web.Response(
status=200,
content_type="text/html",
charset="utf-8",
text="""
ActivityPub Relay at {host}
List of {count} registered and active instances:
List of {countw} instances with errors (last failure to deliver a post is less than a day, not all posts are sent, only periodic retries):
List of {countn} instances trying to send posts and not following the relay (those posts are ignored and nothing is sent to those instances):
List of {counte} unreachable instances (not being delivered anything anymore till we receive a post from them again):
There are currently {countb} instances banned in the configuration file of this relay.
""".format(host=host, note=note,targets=targets,count=len(target),warnings=warns,countw=len(warn),errors=errs,counte=len(err),nosub=not_subd,countn=len(DATABASE.get('not-subscribed',[])),starttime=str(datetime.timede
lta(seconds=(time.time()-START_TIME))).split(".")[0],statuscounts=INBOUND_STATS['processed']+INBOUND_STATS['rejected'],rejectcount=INBOUND_STATS['rejected'],countb=len(CONFIG['ap']['blocked_instances']),banned=banned))
app.router.add_get('/', default)