From c04965776555d3d3f2d4a835f69626a5f969fc81 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Sun, 20 Nov 2022 05:22:57 -0500 Subject: [PATCH] fetch nodeinfo software name on inbox request instead of startup --- relay/application.py | 6 ++++++ relay/database.py | 8 -------- relay/processors.py | 7 +++++++ relay/views.py | 2 ++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/relay/application.py b/relay/application.py index f0ea4fe..52e16c9 100644 --- a/relay/application.py +++ b/relay/application.py @@ -134,6 +134,11 @@ def request_actor(self): except KeyError: pass +def request_instance(self): + try: return self['instance'] + except KeyError: pass + + def request_message(self): try: return self['message'] except KeyError: pass @@ -148,6 +153,7 @@ def request_signature(self): setattr(web.Request, 'actor', property(request_actor)) +setattr(web.Request, 'instance', property(request_instance)) setattr(web.Request, 'message', property(request_message)) setattr(web.Request, 'signature', property(request_signature)) diff --git a/relay/database.py b/relay/database.py index ca26f50..d1d64a7 100644 --- a/relay/database.py +++ b/relay/database.py @@ -83,14 +83,6 @@ class RelayDatabase(dict): self.del_inbox(domain) continue - if not instance.get('software'): - nodeinfo = asyncio.run(fetch_nodeinfo(domain)) - - if not nodeinfo: - continue - - instance['software'] = nodeinfo.swname - new_db = False except FileNotFoundError: diff --git a/relay/processors.py b/relay/processors.py index 4ccb0d1..92df00d 100644 --- a/relay/processors.py +++ b/relay/processors.py @@ -113,5 +113,12 @@ async def run_processor(request): if request.message.type not in processors: 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}') return await processors[request.message.type](request) diff --git a/relay/views.py b/relay/views.py index f39b497..c360ca2 100644 --- a/relay/views.py +++ b/relay/views.py @@ -113,6 +113,8 @@ async def inbox(request): logging.verbose(f'Failed to fetch actor: {request.signature.keyid}') 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 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}')