From b911967168683e332559c54d3332f26d8903d5b0 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Wed, 22 May 2024 06:29:28 +1200 Subject: [PATCH] empty uri --- app/activitypub/signature.py | 31 ++++++++++++++++++------------- app/community/util.py | 21 +++++++++++---------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/app/activitypub/signature.py b/app/activitypub/signature.py index 7ac022e2..1ba5e1db 100644 --- a/app/activitypub/signature.py +++ b/app/activitypub/signature.py @@ -94,20 +94,25 @@ def post_request(uri: str, body: dict | None, private_key: str, key_id: str, con log.activity_json=json.dumps(body) db.session.add(log) db.session.commit() - try: - result = HttpSignature.signed_request(uri, body, private_key, key_id, content_type, method, timeout) - if result.status_code != 200 and result.status_code != 202: - log.result = 'failure' - log.exception_message += f' Response status code was {result.status_code}' - current_app.logger.error('Response code for post attempt was ' + - str(result.status_code) + ' ' + result.text) - log.exception_message += uri - if result.status_code == 202: - log.exception_message += ' 202' - except Exception as e: + + if uri is None or uri == '': log.result = 'failure' - log.exception_message='could not send:' + str(e) - current_app.logger.error(f'Exception while sending post to {uri}') + log.exception_message = 'empty uri' + else: + try: + result = HttpSignature.signed_request(uri, body, private_key, key_id, content_type, method, timeout) + if result.status_code != 200 and result.status_code != 202: + log.result = 'failure' + log.exception_message += f' Response status code was {result.status_code}' + current_app.logger.error('Response code for post attempt was ' + + str(result.status_code) + ' ' + result.text) + log.exception_message += uri + if result.status_code == 202: + log.exception_message += ' 202' + except Exception as e: + log.result = 'failure' + log.exception_message='could not send:' + str(e) + current_app.logger.error(f'Exception while sending post to {uri}') if log.result == 'processing': log.result = 'success' db.session.commit() diff --git a/app/community/util.py b/app/community/util.py index 5f9af78f..38b5dcfe 100644 --- a/app/community/util.py +++ b/app/community/util.py @@ -689,16 +689,17 @@ def send_to_remote_instance_task(instance_id: int, community_id: int, payload): community = Community.query.get(community_id) if community: instance = Instance.query.get(instance_id) - if post_request(instance.inbox, payload, community.private_key, community.ap_profile_id + '#main-key'): - instance.last_successful_send = utcnow() - instance.failures = 0 - else: - instance.failures += 1 - instance.most_recent_attempt = utcnow() - instance.start_trying_again = utcnow() + timedelta(seconds=instance.failures ** 4) - if instance.failures > 10: - instance.dormant = True - db.session.commit() + if instance.inbox: + if post_request(instance.inbox, payload, community.private_key, community.ap_profile_id + '#main-key'): + instance.last_successful_send = utcnow() + instance.failures = 0 + else: + instance.failures += 1 + instance.most_recent_attempt = utcnow() + instance.start_trying_again = utcnow() + timedelta(seconds=instance.failures ** 4) + if instance.failures > 10: + instance.dormant = True + db.session.commit() def community_in_list(community_id, community_list):