relay: add http request debugger
[relay.git/.git] / relay / actor.py
index 4e010d7..99a7dda 100644 (file)
@@ -3,12 +3,13 @@ import aiohttp.web
 import asyncio
 import logging
 import uuid
+import re
 import urllib.parse
 import simplejson as json
-import re
 import cgi
 from Crypto.PublicKey import RSA
 from .database import DATABASE
+from .http_debug import http_debug
 
 
 # generate actor keys if not present
@@ -32,7 +33,7 @@ from . import app, CONFIG
 from .remote_actor import fetch_actor
 
 
-AP_CONFIG = CONFIG.get('ap', {'host': 'localhost'})
+AP_CONFIG = CONFIG.get('ap', {'host': 'localhost','blocked_instances':[]})
 
 
 async def actor(request):
@@ -86,7 +87,7 @@ async def push_message_to_actor(actor, message, our_key_id):
 
     logging.debug('%r >> %r', inbox, message)
 
-    async with aiohttp.ClientSession() as session:
+    async with aiohttp.ClientSession(trace_configs=[http_debug()]) as session:
         async with session.post(inbox, data=data, headers=headers) as resp:
             resp_payload = await resp.text()
             logging.debug('%r >> resp %r', inbox, resp_payload)
@@ -159,6 +160,10 @@ def distill_object_id(activity):
 async def handle_relay(actor, data, request):
     object_id = distill_object_id(data)
 
+    # don't relay mastodon announces -- causes LRP fake direction issues
+    if data['type'] == 'Announce' and len(data.get('cc', [])) > 0:
+        return
+
     message = {
         "@context": "https://www.w3.org/ns/activitystreams",
         "type": "Announce",
@@ -182,6 +187,9 @@ async def handle_follow(actor, data, request):
     following = DATABASE.get('relay-list', [])
     inbox = get_actor_inbox(actor)
 
+    if urllib.parse.urlsplit(inbox).hostname in AP_CONFIG['blocked_instances']:
+        return
+
     if inbox not in following:
         following += [inbox]
         DATABASE['relay-list'] = following