Commit 454f46f0 authored by Izalia Mae's avatar Izalia Mae
Browse files

Merge branch 'master' into 'master'

Bugfixes and documentation clarification

See merge request !35
parents 169c7af8 d005ff8f
......@@ -5,6 +5,10 @@ any category or command to get help on that specific option (ex. `activityrelay
Note: Unless specified, it is recommended to run any commands while the relay is shutdown.
Note 2: `activityrelay` is only available via pip or pipx if `~/.local/bin` is in `$PATH`. If it
isn't, use `python3 -m relay` if installed via pip or `~/.local/bin/activityrelay` if installed
via pipx
## Run
......
......@@ -75,7 +75,7 @@ the block list, it will be removed from the inbox list on startup.
### Blocked Software
A list of ActivityPub software which cannot follow your relay. This list is empty by default, but
setting this to the above list will block all other relays and prevent relay chains
setting this to the below list will block all other relays and prevent relay chains
blocked_software:
- activityrelay
......
......@@ -24,14 +24,14 @@ Or from a cloned git repo.
Once finished, you can set up the relay via the setup command. It will ask a few questions to fill
out config options for your relay
activityrelay setup
~/.local/bin/activityrelay setup
Finally start it up with the run command.
activityrelay run
~/.local/bin/activityrelay run
Note: Pipx requires python 3.7+. If your distro doesn't have a compatible version of python, it can
be installed via
be installed via [pyenv](https://github.com/pyenv/pyenv).
## Pip
......@@ -47,11 +47,11 @@ or a cloned git repo.
Now run the configuration wizard
activityrelay setup
python3 -m relay setup
And start the relay when finished
activityrelay run
python3 -m relay run
## Docker
......
......@@ -109,13 +109,15 @@ class RelayDatabase:
def add_inbox(self, inbox):
assert inbox.startswith('https')
assert inbox not in self.inboxes
assert not self.get_inbox(inbox)
self.data['relay-list'].append(inbox)
def del_inbox(self, inbox):
if inbox not in self.inboxes:
raise KeyError(inbox)
def del_inbox(self, inbox_url):
inbox = self.get_inbox(inbox_url)
if not inbox:
raise KeyError(inbox_url)
self.data['relay-list'].remove(inbox)
......@@ -9,10 +9,9 @@ import platform
from aiohttp.web import AppRunner, TCPSite
from cachetools import LRUCache
from . import app, views, __version__
from . import app, misc, views, __version__
from .config import DotDict, RelayConfig, relay_software_names
from .database import RelayDatabase
from .misc import check_open_port, follow_remote_actor, unfollow_remote_actor
@click.group('cli', context_settings={'show_default': True}, invoke_without_command=True)
......@@ -65,7 +64,30 @@ def cli_inbox_list():
def cli_inbox_follow(actor):
'Follow an actor (Relay must be running)'
run_in_loop(handle_follow_actor, actor)
config = app['config']
database = app['database']
if config.is_banned(actor):
return click.echo(f'Error: Refusing to follow banned actor: {actor}')
if not actor.startswith('http'):
actor = f'https://{actor}/actor'
if database.get_inbox(actor):
return click.echo(f'Error: Already following actor: {actor}')
actor_data = run_in_loop(misc.request, actor, sign_headers=True)
if not actor_data:
return click.echo(f'Error: Failed to fetch actor: {actor}')
inbox = misc.get_actor_inbox(actor_data)
database.add_inbox(inbox)
database.save()
run_in_loop(misc.follow_remote_actor, actor)
click.echo(f'Sent follow message to actor: {actor}')
@cli_inbox.command('unfollow')
......@@ -73,7 +95,19 @@ def cli_inbox_follow(actor):
def cli_inbox_unfollow(actor):
'Unfollow an actor (Relay must be running)'
run_in_loop(handle_unfollow_actor(actor))
database = app['database']
if not actor.startswith('http'):
actor = f'https://{actor}/actor'
if not database.get_inbox(actor):
return click.echo(f'Error: Not following actor: {actor}')
database.del_inbox(actor)
database.save()
run_in_loop(misc.unfollow_remote_actor, actor)
click.echo(f'Sent unfollow message to: {actor}')
@cli_inbox.command('add')
......@@ -348,7 +382,7 @@ def relay_run():
click.echo('Warning: PyCrypto is old and should be replaced with pycryptodome')
return click.echo(pip_command)
if not check_open_port(config.listen, config.port):
if not misc.check_open_port(config.listen, config.port):
return click.echo(f'Error: A server is already running on port {config.port}')
# web pages
......@@ -376,32 +410,6 @@ def run_in_loop(func, *args, **kwargs):
return loop.run_until_complete(func(*args, **kwargs))
async def handle_follow_actor(app, target):
config = app['config']
if not target.startswith('http'):
target = f'https://{target}/actor'
if config.is_banned(target):
return click.echo(f'Error: Refusing to follow banned actor: {target}')
await follow_remote_actor(target)
click.echo(f'Sent follow message to: {target}')
async def handle_unfollow_actor(app, target):
database = app['database']
if not target.startswith('http'):
target = f'https://{target}/actor'
if not database.get_inbox(target):
return click.echo(f'Error: Not following actor: {target}')
await unfollow_remote_actor(target)
click.echo(f'Sent unfollow message to: {target}')
async def handle_start_webserver():
config = app['config']
runner = AppRunner(app, access_log_format='%{X-Forwarded-For}i "%r" %s %b "%{Referer}i" "%{User-Agent}i"')
......
......@@ -160,7 +160,6 @@ async def fetch_nodeinfo(domain):
async def follow_remote_actor(actor_uri):
config = app['config']
database = app['database']
actor = await request(actor_uri)
inbox = get_actor_inbox(actor)
......@@ -185,7 +184,6 @@ async def follow_remote_actor(actor_uri):
async def unfollow_remote_actor(actor_uri):
config = app['config']
database = app['database']
actor = await request(actor_uri)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment