diff --git a/relay.yaml.example b/relay.yaml.example
index 22195d6..4f0b69c 100644
--- a/relay.yaml.example
+++ b/relay.yaml.example
@@ -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'
+
diff --git a/relay/actor.py b/relay/actor.py
index b8ff942..8ddcf0e 100644
--- a/relay/actor.py
+++ b/relay/actor.py
@@ -3,9 +3,9 @@ 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
@@ -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 urllib.parse.urlsplit(inbox).hostname in AP_CONFIG['blocked_instances']:
+ return
+
if inbox not in following:
following += [inbox]
DATABASE['relay-list'] = following
diff --git a/relay/database.py b/relay/database.py
index 857af93..0d171a0 100644
--- a/relay/database.py
+++ b/relay/database.py
@@ -1,5 +1,6 @@
import asyncio
import logging
+import urllib.parse
import simplejson as json
@@ -13,6 +14,11 @@ except:
logging.info('No database was found, making a new one.')
DATABASE = {}
+following = DATABASE.get('relay-list', [])
+for inbox in following:
+ if urllib.parse.urlsplit(inbox).hostname in CONFIG['ap']['blocked_instances']:
+ following.remove(inbox)
+ DATABASE['relay-list'] = following
async def database_save():
while True:
diff --git a/relay/default.py b/relay/default.py
index 172c9d3..638e0c7 100644
--- a/relay/default.py
+++ b/relay/default.py
@@ -1,11 +1,13 @@
import aiohttp.web
-import re
+import urllib.parse
from . import app, CONFIG
from .database import DATABASE
host = CONFIG['ap']['host']
note = CONFIG['note']
-targets = '
'.join([re.search('https://(.*)/inbox',target).group(1) for target in DATABASE.get('relay-list', [])])
+
+inboxes = DATABASE.get('relay-list', [])
+targets = '
'.join([urllib.parse.urlsplit(target).hostname for target in inboxes])
async def default(request):
return aiohttp.web.Response(
@@ -26,9 +28,9 @@ async def default(request):
For Mastodon instances, you may subscribe to this relay with the address: https://{host}/inbox
For Pleroma and other instances, you may subscribe to this relay with the address: https://{host}/actor
To host your own relay, you may download the code at this address: https://git.pleroma.social/pleroma/relay
-List of registered instances:
{targets}
List of {count} registered instances:
{targets}