From 1a7abb4ecb76bfc1292ca2bc46b37876b89186c6 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Tue, 29 Nov 2022 17:41:04 -0500 Subject: [PATCH] fix distill_inboxes --- relay/database.py | 11 +++++++++++ relay/misc.py | 6 ------ relay/processors.py | 6 +++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/relay/database.py b/relay/database.py index d9cbe07..4f83db0 100644 --- a/relay/database.py +++ b/relay/database.py @@ -184,3 +184,14 @@ class RelayDatabase(dict): domain = urlparse(inbox).hostname del self['follow-requests'][domain] + + + def distill_inboxes(self, message): + src_domains = { + message.domain, + urlparse(message.objectid).netloc + } + + for domain, instance in self['relay-list'].items(): + if domain not in src_domains: + yield instance['inbox'] diff --git a/relay/misc.py b/relay/misc.py index c243a7d..c155cfe 100644 --- a/relay/misc.py +++ b/relay/misc.py @@ -84,12 +84,6 @@ def check_open_port(host, port): return False -def distill_inboxes(actor, object_id): - for inbox in app.database.inboxes: - if inbox != actor.shared_inbox and urlparse(inbox).hostname != urlparse(object_id).hostname: - yield inbox - - class DotDict(dict): def __init__(self, _data, **kwargs): dict.__init__(self) diff --git a/relay/processors.py b/relay/processors.py index 5b76485..1af7ed0 100644 --- a/relay/processors.py +++ b/relay/processors.py @@ -4,7 +4,7 @@ import logging from cachetools import LRUCache from uuid import uuid4 -from .misc import Message, distill_inboxes +from .misc import Message cache = LRUCache(1024) @@ -23,7 +23,7 @@ async def handle_relay(request): cache[request.message.objectid] = message.id logging.debug(f'>> relay: {message}') - inboxes = distill_inboxes(request.actor, request.message.objectid) + niboxes = request.database.distill_inboxes(request.message) for inbox in inboxes: request.app.push_message(inbox, message) @@ -42,7 +42,7 @@ async def handle_forward(request): cache[request.message.id] = message.id logging.debug(f'>> forward: {message}') - inboxes = distill_inboxes(request.actor, request.message.objectid) + inboxes = request.database.distill_inboxes(request.message) for inbox in inboxes: request.app.push_message(inbox, message)