fetch nodeinfo software name on inbox request instead of startup

This commit is contained in:
Izalia Mae 2022-11-20 05:22:57 -05:00
parent ffe14bead3
commit c049657765
4 changed files with 15 additions and 8 deletions

View file

@ -134,6 +134,11 @@ def request_actor(self):
except KeyError: pass except KeyError: pass
def request_instance(self):
try: return self['instance']
except KeyError: pass
def request_message(self): def request_message(self):
try: return self['message'] try: return self['message']
except KeyError: pass except KeyError: pass
@ -148,6 +153,7 @@ def request_signature(self):
setattr(web.Request, 'actor', property(request_actor)) setattr(web.Request, 'actor', property(request_actor))
setattr(web.Request, 'instance', property(request_instance))
setattr(web.Request, 'message', property(request_message)) setattr(web.Request, 'message', property(request_message))
setattr(web.Request, 'signature', property(request_signature)) setattr(web.Request, 'signature', property(request_signature))

View file

@ -83,14 +83,6 @@ class RelayDatabase(dict):
self.del_inbox(domain) self.del_inbox(domain)
continue continue
if not instance.get('software'):
nodeinfo = asyncio.run(fetch_nodeinfo(domain))
if not nodeinfo:
continue
instance['software'] = nodeinfo.swname
new_db = False new_db = False
except FileNotFoundError: except FileNotFoundError:

View file

@ -113,5 +113,12 @@ async def run_processor(request):
if request.message.type not in processors: if request.message.type not in processors:
return return
if request.instance and not request.instance.get('software'):
nodeinfo = await misc.fetch_nodeinfo(request.instance.domain)
if nodeinfo:
request.instance[nodeinfo] = nodeinfo.swname
request.database.save()
logging.verbose(f'New "{request.message.type}" from actor: {request.actor.id}') logging.verbose(f'New "{request.message.type}" from actor: {request.actor.id}')
return await processors[request.message.type](request) return await processors[request.message.type](request)

View file

@ -113,6 +113,8 @@ async def inbox(request):
logging.verbose(f'Failed to fetch actor: {request.signature.keyid}') logging.verbose(f'Failed to fetch actor: {request.signature.keyid}')
return Response.new_error(400, 'failed to fetch actor', 'json') return Response.new_error(400, 'failed to fetch actor', 'json')
request['instance'] = request.database.get_inbox(request['actor'].inbox)
## reject if the actor isn't whitelisted while the whiltelist is enabled ## reject if the actor isn't whitelisted while the whiltelist is enabled
if config.whitelist_enabled and not config.is_whitelisted(request.actor.domain): if config.whitelist_enabled and not config.is_whitelisted(request.actor.domain):
logging.verbose(f'Rejected actor for not being in the whitelist: {request.actor.id}') logging.verbose(f'Rejected actor for not being in the whitelist: {request.actor.id}')