mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-24 23:41:09 +00:00
fetch nodeinfo software name on inbox request instead of startup
This commit is contained in:
parent
ffe14bead3
commit
c049657765
|
@ -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))
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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}')
|
||||
|
|
Loading…
Reference in a new issue