Giter Site home page Giter Site logo

jaywink / social-relay Goto Github PK

View Code? Open in Web Editor NEW
28.0 12.0 9.0 207 KB

Public post relay for the Diaspora federated social network protocol

Home Page: https://git.feneas.org/jaywink/social-relay

License: GNU Affero General Public License v3.0

Python 78.37% HTML 16.65% CSS 3.81% Shell 0.77% JavaScript 0.40%
relay diaspora social-networks federation

social-relay's Introduction

Build Status codecov Requirements Status

issue tracker

Social-Relay

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.

How does one integrate to the relay system? How do I write my own relay?

See relay design concept.

Original idea for the relay system can be found in the diaspora* project wiki.

Installation

System libraries

Depending on your database, you will probably need extra libraries installed.

For databases, PostgreSQL and MySQL/MariaDB are supported, choose one.

Python

Python 3.4+ is required.

Redis

# Debian / Ubuntu
sudo apt-get install redis-server

PostgreSQL

# Debian / Ubuntu
sudo apt-get install libpq-dev postgresql

MySQL/MariaDB

# Debian / Ubuntu
sudo apt-get install python3-dev libmysqlclient-dev 

# Red Hat / CentOS
sudo yum install python3-devel mysql-devel

Federation

The federation dependency lxml requires certain libraries present:

# Debian / Ubuntu
sudo apt-get install libxml2-dev libxslt-dev lib32z1-dev python3-dev

Python libraries

Create a Python 3.4+ virtualenv and activate it.

Ensure pip and setuptools are up to date.

pip install -U pip setuptools

For a production deployment, choose your database and install the requirements:

# PostgreSQL
pip install -r requirements/postgresql.txt

# MySQL/MariaDB
pip install -r requirements/mysql.txt

Configuring

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.

Database

You can set database connection settings as environment variables or in social_relay/local_config.py - see social_relay/config.py for what to override.

The 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.

RQ Dashboard

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.

Static files

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.

Running tasks and workers

Scheduled jobs handle the polling of node lists and nodes themselves, to fetch their subscription settings. Without the scheduled jobs the server will not be able to function. RQ workers on the other hand process all the incoming payloads and distribute them onwards to subscribing nodes. At least one RQ worker must be running at all times.

In production, it's easiest to use the provided circus configuration. This is installed via the provided production requirements, or pip install circus if not using the provided requirements file.

Then, export how many RQ workers you want. If you see your receive queue build up, increase this count and restart circus.

export RQWORKER_NUM=5

To start circus, virtualenv activated in the project folder:

circusd extras/circus/circus.ini

You can daemonize circus by passing an extra --daemonize flag.

Running tasks manually (without circus)

If you don't want to use circus, run the tasks manually. Keep this running:

python -m tasks.schedule_jobs

Processing receive queue (without circus)

If you don't want to use circus, run the workers manually. Run the worker(s) as follows:

rqworker -c social_relay.config receive

Deployment

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.

Ansible (Ubuntu)

An Ansible role written for Ubuntu is provided in ansible directory. The role uses PostgreSQL, uWSGI and Apache. It will run also the scheduled jobs and a worker. Everything is handled by upstart.

Tested with Ubuntu 14.04 LTS.

SystemD service files

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 [email protected]
systemctl start social-relay.target

systemctl enable social-relay_server.service
systemctl enable social-relay_tasks.service
systemctl enable [email protected]
systemctl enable social-relay.target

The rqworker service file can also be used to start the optional failed queue as well.

systemctl start [email protected]

Development

Development requirements

pip install -r requirements/development.txt

Ensure also bower is installed.

npm install bower
bower install

Running a development server

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.

Running an RQ worker

rqworker -c social_relay.config receive

Running tests

Ensure there is a test database. By default the tests try to connect to PostgreSQL with db, username and password socialrelaytest.

Then run test with:

py.test

Maintaining dependencies

When changing requirements, use pip-tools.

pip install pip-tools

To compile all

./compile-requirements.sh

Author

Jason Robinson / @jaywink / https://jasonrobinson.me

Awesome contributors listed in CONTRIBUTORS file.

License

AGPLv3

social-relay's People

Contributors

bmanojlovic avatar dmorley avatar jaywink avatar jaywinky avatar jpope777 avatar waffle-iron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.