Application to act as a relay for public posts using the Diaspora protocol. Keeps track of nodes and their subscription preferences, receives payloads and forwards the payloads to subscribers. The aim is to pass public posts around in an efficient way so any new node in the network can quickly subscribe to lots of public activity, without having to wait a long time to create social relationships.
See relay design concept.
Original idea for the relay system can be found in the diaspora* project wiki.
- Python 3.x (tested on 3.4/3.5)
- Redis
- SQLite3
- Packages for building LXML (required by
federation
library):- libxml2-dev
- libxslt-dev
- lib32z1-dev
- python3-dev
- Alternatively, install
python-lxml
package, for example, if you don't want to install everything in a virtual env.
- Alternatively, install
Create a Python 3.3+ virtualenv and activate it.
Ensure pip
and setuptools
are up to date.
pip install -U pip setuptools
Production requirements (for uWSGI deployment):
pip install -r requirements/production.txt
Development requirements:
pip install -r requirements/development.txt
Ensure also to install things like uWSGI
if you use them in your deployment.
Create local config:
cp social_relay/local_config.py.example social_relay/local_config.py
Edit the local_config.py
file as instructed in the file.
The SQLite database needs an initial schema creation. Do this with:
arnold up 0
The same command should always be run when fetching new relay code. It will migrate any new schema changes.
An RQ dashboard can be found at /rq
. Enable it in social_relay/local_config.py
by setting RQ_DASHBOARD = True
.
You must also set a username and password in the same file.
Bower is used to pull in some JavaScript libs. Install it first if needed. Then run bower install
.
Statics are server under the /static
path which should be server by the web server.
For normal operation, scheduled jobs should always be running. They take care of refreshing the pod list and polling pods for their subscription preferences. Without these scheduled jobs, the relay will not be able to function.
Keep this running:
python -m tasks.schedule_jobs
Incoming posts are stored in Redis and processed using RQ workers. Keep one or more worker running always.
To make use of the app configuration for Redis in social_relay/local_config.py
, use the provided runworker.py
wrapper, as follows:
python runworker.py receive
If you do run a worker via rqworker
command directly, make sure to use the same Redis database as set in app configuration.
Pretty much normal Python + WSGI setup, just install the requirements and serve app using WSGI and statics via the web server. See the following sections for platform specific helpers.
An Apache2 site example can be found here. The same folder also has examples for upstart init jobs.
An Ansible role written for Ubuntu is provided in ansible
directory. The role uses uWSGI and Apache to serve the app. It will run also the scheduled jobs and a worker. Everything is handled by upstart.
Tested with Ubuntu 14.04 LTS.
There are example systemd service files in the 'extra' directory. The examples use a specific user and utilize gunicorn. They have been tested on CentOS 7.
To use, modify as needed (user, group, and path), copy to /etc/systemd/service
and start/enable as such:
systemctl start social-relay_server.service
systemctl start social-relay_tasks.service
systemctl start social-relay_rqworker@receive.service
systemctl start social-relay.target
systemctl enable social-relay_server.service
systemctl enable social-relay_tasks.service
systemctl enable social-relay_rqworker@receive.service
systemctl enable social-relay.target
The rqworker service file can also be used to start the optional failed
queue as well.
systemctl start social-relay_rqworker@failed.service
This is not the recommended way for a production server. For testing and development, run the server:
python devserver.py
The app will be running at http://127.0.0.1:5000.
Execute py.test
to run the tests.
Jason Robinson / @jaywink / https://jasonrobinson.me
Awesome contributors listed in CONTRIBUTORS
file.
AGPLv3