├── circle.yml ├── .gitignore ├── src ├── index.js ├── client.js ├── index.js.old └── server.js ├── package.json ├── README.md ├── LICENSE └── Vagrantfile /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | node: 3 | version: 4.2.2 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *sublime* 2 | node_modules/ 3 | users/ 4 | *.log 5 | Vagrantfile.local 6 | .vagrant/ 7 | dump.rdb 8 | redis.conf -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const OrbitServer = require('./server.js'); 4 | try { 5 | OrbitServer.start(); 6 | } catch(e) { 7 | console.error(e); 8 | } 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "orbit-server", 3 | "version": "0.2.3", 4 | "description": "", 5 | "author": "Haad", 6 | "license": "MIT", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/haadcode/orbit-server" 10 | }, 11 | "engines": { 12 | "node": "^4.x.x" 13 | }, 14 | "main": "src/index.js", 15 | "dependencies": { 16 | "lodash": "^4.11.1", 17 | "logplease": "^1.2.5", 18 | "redis": "^2.4.2", 19 | "socket.io": "1.3.7", 20 | "socket.io-client": "1.3.7", 21 | "socket.io-redis": "0.1.4" 22 | }, 23 | "devDependencies": {}, 24 | "scripts": { 25 | "start": "node src/index.js" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ***DEPRECATED!*** 2 | 3 | # orbit-server 4 | 5 | Server for [OrbitDB](https://github.com/haadcode/orbit-db). A simple wrapper for Redis. Requires redis server to run at `locahost:` 6 | 7 | ## Run 8 | ``` 9 | npm install 10 | export REDIS_PASSWORD= 11 | export REDIS_PORT= 12 | npm start 13 | ``` 14 | 15 | ## Test 16 | ``` 17 | npm test 18 | ``` 19 | 20 | ## Deploy 21 | 22 | *Requires [Vagrant](https://www.vagrantup.com/downloads.html) to deploy* 23 | 24 | Open [Vagrantfile]() and set Redis' password and port and your Digital Ocean token. 25 | 26 | Run: 27 | ``` 28 | vagrant up orbit-server 29 | vagrant ssh orbit-server 30 | screen -r 31 | ``` 32 | 33 | ## TODO 34 | - Metrics 35 | -------------------------------------------------------------------------------- /src/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const io = require('socket.io-client'); 4 | var socket = io('http://localhost:3333'); 5 | 6 | let connected = false; 7 | 8 | let subscriptions = {}; 9 | 10 | let channel = process.argv[2] ? process.argv[2] : 'default channel'; 11 | let prefix = process.argv[3] ? process.argv[3] : 'hello '; 12 | 13 | socket.on('connect', function (s) { 14 | console.log('connected') 15 | connected = true; 16 | socket.emit('subscribe', { channel: channel }); 17 | }); 18 | 19 | socket.on('message', function (event) { 20 | console.log('>>>', event) 21 | }); 22 | 23 | let count = 1; 24 | 25 | setInterval(() => { 26 | if(connected) { 27 | socket.send({ channel: channel, message: prefix + count }); 28 | count ++; 29 | } 30 | }, 1000); 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 haadcode 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/index.js.old: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | var async = require('asyncawait/async'); 6 | var await = require('asyncawait/await'); 7 | var ipfsDaemon = require('orbit-common/lib/ipfs-daemon'); 8 | var logger = require('orbit-common/lib//logger'); 9 | var utils = require('orbit-common/lib//utils'); 10 | var server = require('./server'); 11 | 12 | require('http').globalAgent.maxSockets = Infinity; 13 | 14 | const port = 3006; 15 | const serverConfig = { 16 | networkId: "anon-test", 17 | networkName: "Anonymous Networks TEST", 18 | salt: "thisisthenetworksalt", 19 | userDataPath: path.resolve(process.cwd(), "users/"), 20 | enableMetrics: false, 21 | metricsInterval: 60000 22 | } 23 | 24 | const startService = async (() => { 25 | return new Promise(async((resolve, reject) => { 26 | const ipfsd = await(ipfsDaemon()); 27 | server = server(ipfsd.daemon, ipfsd.nodeInfo, serverConfig); 28 | resolve(server.app); 29 | })); 30 | }); 31 | 32 | const main = async((callback) => { 33 | const app = await(startService()); 34 | app.listen(port, () => { 35 | logger.info('orbit-server listening at http://localhost:%s', port); 36 | if(callback) callback(); 37 | }); 38 | })(); 39 | 40 | module.exports = main; 41 | -------------------------------------------------------------------------------- /src/server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const IO = require('socket.io'); 4 | const redis = require("redis"); 5 | const adapter = require('socket.io-redis'); 6 | 7 | const Logger = require('logplease'); 8 | const logger = Logger.create('server', { color: Logger.Colors.Magenta, filename: 'server.log', appendFile: true }); 9 | 10 | const host = 'localhost' 11 | const port = process.env.REDIS_PORT ? process.env.REDIS_PORT : 6379; 12 | 13 | class OrbitServer { 14 | static start() { 15 | let io = IO(3333); 16 | let pub = redis.createClient({ host: host, port: port, auth_pass: process.env.REDIS_PASSWORD }); 17 | let sub = redis.createClient({ host: host, port: port, auth_pass: process.env.REDIS_PASSWORD }); 18 | let client = redis.createClient({ host: host, port: port, auth_pass: process.env.REDIS_PASSWORD }); 19 | 20 | io.adapter(adapter({ pubClient: pub, subClient: sub })); 21 | 22 | sub.on('message', (channel, data) => { 23 | io.sockets.in(channel).emit('message', channel, data); 24 | }); 25 | 26 | io.on('connection', function (socket) { 27 | logger.info("Client connected from " + JSON.stringify(socket.request.connection._peername)); 28 | 29 | socket.on('subscribe', function (event) { 30 | sub.subscribe(event.channel); 31 | socket.join(event.channel); 32 | logger.info("Client joined channel #" + event.channel); 33 | 34 | client.get(event.channel, (err, res) => { 35 | socket.emit('subscribed', event.channel, res); 36 | }); 37 | 38 | socket.on('message', function (a) { 39 | const e = JSON.parse(a); 40 | if(e.channel === event.channel) { 41 | pub.publish(e.channel, e.message); 42 | client.set(e.channel, e.message); 43 | } 44 | }); 45 | }); 46 | 47 | socket.on('unsubscribe', function (event) { 48 | socket.leave(event.channel); 49 | logger.info("Client left channel #" + event.channel); 50 | }); 51 | 52 | socket.on('disconnect', function () { 53 | }); 54 | }); 55 | 56 | logger.info("Started"); 57 | } 58 | }; 59 | 60 | module.exports = OrbitServer; 61 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | redis_port = "55555" 2 | redis_password = "this_should_be_a_very_long_password" 3 | digital_ocean_token = "insert_your_token_here" 4 | 5 | Vagrant.configure(2) do |config| 6 | config.vm.box = "digital_ocean" 7 | config.vm.box_url = "https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box" 8 | config.vm.synced_folder ".", "/vagrant", disabled: true 9 | 10 | config.vm.define "orbit-server" do |node| 11 | node.vm.provision "shell", inline: <<-SHELL 12 | sudo apt-get update 13 | sudo apt-get install -y python gcc make g++ git build-essential tcl8.5 14 | sudo apt-get install -y wget htop screen nano 15 | 16 | wget --quiet https://nodejs.org/dist/v4.4.5/node-v4.4.5-linux-x64.tar.gz 17 | tar -C /usr/local -zxf node-v4.4.5-linux-x64.tar.gz --strip 1 18 | 19 | wget --quiet http://download.redis.io/releases/redis-stable.tar.gz 20 | tar xzf redis-stable.tar.gz 21 | cd redis-stable 22 | make 23 | sudo make install 24 | 25 | screen -X -S redis quit 26 | echo 'bind 127.0.0.1' >> ./redis.conf 27 | echo 'port #{redis_port}' >> ./redis.conf 28 | echo 'requirepass #{redis_password}' >> ./redis.conf 29 | nohup screen -S redis -d -m redis-server ./redis.conf 30 | 31 | screen -X -S webrtc quit 32 | sudo npm install -g libp2p-webrtc-star 33 | nohup screen -S webrtc -d -m star-sig 34 | 35 | screen -X -S server quit 36 | sudo rm -rf /orbit-server 37 | sudo mkdir /orbit-server 38 | cd /orbit-server 39 | git clone https://github.com/haadcode/orbit-server.git 40 | cd orbit-server 41 | npm install --production 42 | export REDIS_PASSWORD=#{redis_password} 43 | export REDIS_PORT=#{redis_port} 44 | nohup screen -S server -d -m npm start 45 | 46 | SHELL 47 | 48 | node.vm.provider :digital_ocean do |provider, override| 49 | override.ssh.private_key_path = "~/.ssh/digital-ocean" 50 | override.vm.box = "digital_ocean" 51 | override.vm.box_url = "https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box" 52 | provider.token = digital_ocean_token 53 | provider.image = "ubuntu-14-04-x64" 54 | provider.region = "AMS3" 55 | provider.size = "512mb" 56 | end 57 | end 58 | 59 | end 60 | --------------------------------------------------------------------------------