Remove entry for followers synchronization when a follower change occurs

main
Bob Mottram 2023-03-18 21:06:10 +00:00
parent 9c7d3c615b
commit 28943c3ef7
6 changed files with 60 additions and 18 deletions

View File

@ -9900,6 +9900,8 @@ class PubServer(BaseHTTPRequestHandler):
return return
signing_priv_key_pem = \ signing_priv_key_pem = \
self.server.signing_priv_key_pem self.server.signing_priv_key_pem
followers_sync_cache = \
self.server.followers_sync_cache
manual_approve_follow_request_thread(self.server.session, manual_approve_follow_request_thread(self.server.session,
self.server.session_onion, self.server.session_onion,
self.server.session_i2p, self.server.session_i2p,
@ -9917,7 +9919,8 @@ class PubServer(BaseHTTPRequestHandler):
debug, debug,
self.server.project_version, self.server.project_version,
signing_priv_key_pem, signing_priv_key_pem,
proxy_type) proxy_type,
followers_sync_cache)
origin_path_str_absolute = \ origin_path_str_absolute = \
http_prefix + '://' + domain_full + origin_path_str http_prefix + '://' + domain_full + origin_path_str
if calling_domain.endswith('.onion') and onion_domain: if calling_domain.endswith('.onion') and onion_domain:
@ -10077,7 +10080,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.person_cache, self.server.person_cache,
debug, debug,
self.server.project_version, self.server.project_version,
self.server.signing_priv_key_pem) self.server.signing_priv_key_pem,
self.server.followers_sync_cache)
origin_path_str_absolute = \ origin_path_str_absolute = \
http_prefix + '://' + domain_full + origin_path_str http_prefix + '://' + domain_full + origin_path_str
if calling_domain.endswith('.onion') and onion_domain: if calling_domain.endswith('.onion') and onion_domain:
@ -16904,7 +16908,7 @@ class PubServer(BaseHTTPRequestHandler):
'_GET', '_security_txt[calling_domain]', '_GET', '_security_txt[calling_domain]',
self.server.debug) self.server.debug)
# followers synchronization # followers synchronization request
# See https://github.com/mastodon/mastodon/pull/14510 # See https://github.com/mastodon/mastodon/pull/14510
# https://codeberg.org/fediverse/fep/src/branch/main/feps/fep-8fcf.md # https://codeberg.org/fediverse/fep/src/branch/main/feps/fep-8fcf.md
if self.path.startswith('/users/') and \ if self.path.startswith('/users/') and \

View File

@ -1544,6 +1544,7 @@ def _command_options() -> None:
i2p_domain = argb.i2p_domain i2p_domain = argb.i2p_domain
if i2p_domain: if i2p_domain:
session_i2p = create_session('i2p') session_i2p = create_session('i2p')
followers_sync_cache = {}
manual_approve_follow_request(session, session_onion, session_i2p, manual_approve_follow_request(session, session_onion, session_i2p,
onion_domain, i2p_domain, onion_domain, i2p_domain,
base_dir, http_prefix, base_dir, http_prefix,
@ -1553,7 +1554,8 @@ def _command_options() -> None:
send_threads, post_log, send_threads, post_log,
cached_webfingers, person_cache, cached_webfingers, person_cache,
debug, __version__, debug, __version__,
signing_priv_key_pem, proxy_type) signing_priv_key_pem, proxy_type,
followers_sync_cache)
sys.exit() sys.exit()
if argb.deny: if argb.deny:
@ -1585,6 +1587,7 @@ def _command_options() -> None:
i2p_domain = argb.i2p_domain i2p_domain = argb.i2p_domain
if i2p_domain: if i2p_domain:
session_i2p = create_session('i2p') session_i2p = create_session('i2p')
followers_sync_cache = {}
manual_deny_follow_request(session, session_onion, session_i2p, manual_deny_follow_request(session, session_onion, session_i2p,
onion_domain, i2p_domain, onion_domain, i2p_domain,
base_dir, http_prefix, base_dir, http_prefix,
@ -1594,7 +1597,8 @@ def _command_options() -> None:
send_threads, post_log, send_threads, post_log,
cached_webfingers, person_cache, cached_webfingers, person_cache,
debug, __version__, debug, __version__,
signing_priv_key_pem) signing_priv_key_pem,
followers_sync_cache)
sys.exit() sys.exit()
if argb.followerspending: if argb.followerspending:

View File

@ -39,6 +39,7 @@ from webfinger import webfinger_handle
from auth import create_basic_auth_header from auth import create_basic_auth_header
from session import get_json from session import get_json
from session import post_json from session import post_json
from followerSync import remove_followers_sync
def create_initial_last_seen(base_dir: str, http_prefix: str) -> None: def create_initial_last_seen(base_dir: str, http_prefix: str) -> None:
@ -747,7 +748,8 @@ def followed_account_accepts(session, base_dir: str, http_prefix: str,
remove_follow_activity: bool, remove_follow_activity: bool,
signing_priv_key_pem: str, signing_priv_key_pem: str,
curr_domain: str, curr_domain: str,
onion_domain: str, i2p_domain: str): onion_domain: str, i2p_domain: str,
followers_sync_cache: {}):
"""The person receiving a follow request accepts the new follower """The person receiving a follow request accepts the new follower
and sends back an Accept activity and sends back an Accept activity
""" """
@ -789,6 +791,10 @@ def followed_account_accepts(session, base_dir: str, http_prefix: str,
group_account = True group_account = True
extra_headers = {} extra_headers = {}
domain_full = get_full_domain(domain, from_port)
remove_followers_sync(followers_sync_cache,
nickname_to_follow,
domain_full)
return send_signed_json(accept_json, session, base_dir, return send_signed_json(accept_json, session, base_dir,
nickname_to_follow, domain_to_follow, port, nickname_to_follow, domain_to_follow, port,
nickname, domain, from_port, nickname, domain, from_port,
@ -811,7 +817,8 @@ def followed_account_rejects(session, session_onion, session_i2p,
send_threads: [], post_log: [], send_threads: [], post_log: [],
cached_webfingers: {}, person_cache: {}, cached_webfingers: {}, person_cache: {},
debug: bool, project_version: str, debug: bool, project_version: str,
signing_priv_key_pem: str): signing_priv_key_pem: str,
followers_sync_cache: {}):
"""The person receiving a follow request rejects the new follower """The person receiving a follow request rejects the new follower
and sends back a Reject activity and sends back a Reject activity
""" """
@ -865,6 +872,10 @@ def followed_account_rejects(session, session_onion, session_i2p,
elif domain.endswith('.i2p') and session_i2p: elif domain.endswith('.i2p') and session_i2p:
curr_session = session_i2p curr_session = session_i2p
extra_headers = {} extra_headers = {}
domain_full = get_full_domain(domain, from_port)
remove_followers_sync(followers_sync_cache,
nickname_to_follow,
domain_full)
# send the reject activity # send the reject activity
return send_signed_json(reject_json, curr_session, base_dir, return send_signed_json(reject_json, curr_session, base_dir,
nickname_to_follow, domain_to_follow, port, nickname_to_follow, domain_to_follow, port,

View File

@ -14,6 +14,18 @@ from utils import acct_dir
from utils import get_user_paths from utils import get_user_paths
def remove_followers_sync(followers_sync_cache: {},
nickname: str,
follower_domain: str) -> None:
"""Remove an entry within the followers synchronization cache,
so that it will subsequently be regenerated
"""
foll_sync_key = nickname + ':' + follower_domain
if not followers_sync_cache.get(foll_sync_key):
return
del followers_sync_cache[foll_sync_key]
def _get_followers_for_domain(base_dir: str, def _get_followers_for_domain(base_dir: str,
nickname: str, domain: str, nickname: str, domain: str,
search_domain: str) -> []: search_domain: str) -> []:

View File

@ -5203,7 +5203,8 @@ def _receive_follow_request(session, session_onion, session_i2p,
max_followers: int, max_followers: int,
this_domain: str, onion_domain: str, this_domain: str, onion_domain: str,
i2p_domain: str, signing_priv_key_pem: str, i2p_domain: str, signing_priv_key_pem: str,
unit_test: bool, system_language: str) -> bool: unit_test: bool, system_language: str,
followers_sync_cache: {}) -> bool:
"""Receives a follow request within the POST section of HTTPServer """Receives a follow request within the POST section of HTTPServer
""" """
if not message_json['type'].startswith('Follow'): if not message_json['type'].startswith('Follow'):
@ -5468,7 +5469,8 @@ def _receive_follow_request(session, session_onion, session_i2p,
cached_webfingers, person_cache, cached_webfingers, person_cache,
debug, project_version, True, debug, project_version, True,
signing_priv_key_pem, signing_priv_key_pem,
this_domain, onion_domain, i2p_domain) this_domain, onion_domain, i2p_domain,
followers_sync_cache)
def run_inbox_queue(server, def run_inbox_queue(server,
@ -5897,7 +5899,8 @@ def run_inbox_queue(server,
max_followers, domain, max_followers, domain,
onion_domain, i2p_domain, onion_domain, i2p_domain,
signing_priv_key_pem, unit_test, signing_priv_key_pem, unit_test,
system_language): system_language,
server.followers_sync_cache):
if os.path.isfile(queue_filename): if os.path.isfile(queue_filename):
try: try:
os.remove(queue_filename) os.remove(queue_filename)

View File

@ -34,7 +34,8 @@ def manual_deny_follow_request(session, session_onion, session_i2p,
cached_webfingers: {}, person_cache: {}, cached_webfingers: {}, person_cache: {},
debug: bool, debug: bool,
project_version: str, project_version: str,
signing_priv_key_pem: str) -> None: signing_priv_key_pem: str,
followers_sync_cache: {}) -> None:
"""Manually deny a follow request """Manually deny a follow request
""" """
accounts_dir = acct_dir(base_dir, nickname, domain) accounts_dir = acct_dir(base_dir, nickname, domain)
@ -74,7 +75,8 @@ def manual_deny_follow_request(session, session_onion, session_i2p,
send_threads, post_log, send_threads, post_log,
cached_webfingers, person_cache, cached_webfingers, person_cache,
debug, project_version, debug, project_version,
signing_priv_key_pem) signing_priv_key_pem,
followers_sync_cache)
print('Follow request from ' + deny_handle + ' was denied.') print('Follow request from ' + deny_handle + ' was denied.')
@ -89,7 +91,8 @@ def manual_deny_follow_request_thread(session, session_onion, session_i2p,
cached_webfingers: {}, person_cache: {}, cached_webfingers: {}, person_cache: {},
debug: bool, debug: bool,
project_version: str, project_version: str,
signing_priv_key_pem: str) -> None: signing_priv_key_pem: str,
followers_sync_cache: {}) -> None:
"""Manually deny a follow request, within a thread so that the """Manually deny a follow request, within a thread so that the
user interface doesn't lag user interface doesn't lag
""" """
@ -106,7 +109,8 @@ def manual_deny_follow_request_thread(session, session_onion, session_i2p,
cached_webfingers, person_cache, cached_webfingers, person_cache,
debug, debug,
project_version, project_version,
signing_priv_key_pem), daemon=True) signing_priv_key_pem,
followers_sync_cache), daemon=True)
begin_thread(thr, 'manual_deny_follow_request_thread') begin_thread(thr, 'manual_deny_follow_request_thread')
send_threads.append(thr) send_threads.append(thr)
@ -144,7 +148,8 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
debug: bool, debug: bool,
project_version: str, project_version: str,
signing_priv_key_pem: str, signing_priv_key_pem: str,
proxy_type: str) -> None: proxy_type: str,
followers_sync_cache: {}) -> None:
"""Manually approve a follow request """Manually approve a follow request
""" """
handle = nickname + '@' + domain handle = nickname + '@' + domain
@ -272,7 +277,8 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
signing_priv_key_pem, signing_priv_key_pem,
domain, domain,
onion_domain, onion_domain,
i2p_domain) i2p_domain,
followers_sync_cache)
update_approved_followers = True update_approved_followers = True
else: else:
# this isn't the approved follow so it will remain # this isn't the approved follow so it will remain
@ -344,7 +350,8 @@ def manual_approve_follow_request_thread(session, session_onion, session_i2p,
debug: bool, debug: bool,
project_version: str, project_version: str,
signing_priv_key_pem: str, signing_priv_key_pem: str,
proxy_type: str) -> None: proxy_type: str,
followers_sync_cache: {}) -> None:
"""Manually approve a follow request, in a thread so as not to cause """Manually approve a follow request, in a thread so as not to cause
the UI to lag the UI to lag
""" """
@ -362,6 +369,7 @@ def manual_approve_follow_request_thread(session, session_onion, session_i2p,
debug, debug,
project_version, project_version,
signing_priv_key_pem, signing_priv_key_pem,
proxy_type), daemon=True) proxy_type,
followers_sync_cache), daemon=True)
begin_thread(thr, 'manual_approve_follow_request_thread') begin_thread(thr, 'manual_approve_follow_request_thread')
send_threads.append(thr) send_threads.append(thr)