very simple blocklist
authorTristan Mahé <gled@remote-shell.net>
Wed, 31 Oct 2018 19:29:30 +0000 (12:29 -0700)
committerTristan Mahé <gled@remote-shell.net>
Wed, 31 Oct 2018 19:29:30 +0000 (12:29 -0700)
relay.yaml.example
relay/actor.py
relay/database.py

index 22195d6..4f0b69c 100644 (file)
@@ -14,3 +14,7 @@ ap:
   # this is used for generating activitypub messages, as well as instructions for
   # linking AP identities.  it should be an SSL-enabled domain reachable by https.
   host: 'relay.example.com'
+  blocked_instances:
+  - 'bad-instance.example.com'
+  - 'another-bad-instance.example.com'
+  
index b8ff942..49abc38 100644 (file)
@@ -32,7 +32,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):
@@ -186,6 +186,9 @@ async def handle_follow(actor, data, request):
     following = DATABASE.get('relay-list', [])
     inbox = get_actor_inbox(actor)
 
+    if re.search('https://(.*)/inbox',inbox).group(1) in AP_CONFIG['blocked_instances']:
+        return
+
     if inbox not in following:
         following += [inbox]
         DATABASE['relay-list'] = following
index 857af93..b60f9bb 100644 (file)
@@ -13,6 +13,11 @@ except:
     logging.info('No database was found, making a new one.')
     DATABASE = {}
 
+following = DATABASE.get('relay-list', [])
+for inbox in following:
+    if re.search('https://(.*)/inbox',inbox).group(1) in CONFIG['ap']['blocked_instances']:
+        following.remove(inbox)
+        DATABASE['relay-list'] = following
 
 async def database_save():
     while True: