├── .gitignore ├── LICENSE ├── README.md ├── dist ├── bundle.js └── index.html ├── index.js ├── package.json ├── screenshot.png └── webpack.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | *sublime* 2 | *.log 3 | dist/bundle.js.map 4 | node_modules/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Haad 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # proto2 - orbit-db visualization 2 | 3 | This prototype visualizes how orbit-db's data flow works. 4 | 5 | ## Demo 6 | Live demo: http://celebdil.benet.ai:8080/ipfs/Qmezm7g8mBpWyuPk6D84CNcfLKJwU6mpXuEN5GJZNkX3XK/ 7 | 8 | ![Screenshot](https://raw.githubusercontent.com/haadcode/proto2/master/screenshot.png) 9 | 10 | ## Run 11 | Open `dist/index.html` in your browser. 12 | 13 | ## Build 14 | ``` 15 | npm run build 16 | ``` 17 | 18 | This will compile `index.js` to `dist/bundle.js`. 19 | -------------------------------------------------------------------------------- /dist/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | Foreground: 11 | Key-Value: 12 | 13 |
14 | 15 | Background: 16 | Speed: 17 | 18 |
19 |
20 | 21 | 22 | OrbitDB 23 | KeyValueStore 24 | KeyValueStore 25 | Store 26 | Store 27 | 28 | .put(  ) 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | .addOperation() 41 | { "op": "PUT", "key": "foreground", "value": "#6428b6", "meta": { "ts": 1465293000893 }} 42 | 43 | .sync(                          ) 44 | QmQoJtbDW2QySdzqUBnmsjK5hm6bjUWHMU14ADGdrz82uM 45 | 46 | .merge(                          ) 47 | QmQoJtbDW2QySdzqUBnmsjK5hm6bjUWHMU14ADGdrz82uM 48 | 49 | 50 | 530 | 531 | 532 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const IpfsApi = require('exports?Ipfs!ipfs/dist/index.js'); 4 | const Promise = require('bluebird'); 5 | const Logger = require('logplease'); 6 | const logger = Logger.create("orbit-db example", { color: Logger.Colors.Green, showTimestamp: false, showLevel: false }); 7 | const OrbitDB = require('orbit-db'); 8 | 9 | const host = '178.62.241.75' 10 | const port = 3333; 11 | const username = 'Peer'; 12 | const channel = 'upgradetheinternet'; 13 | const key = 'greeting'; 14 | const value = 'Hello world'; 15 | 16 | const ipfsDaemon = (IPFS, repo, signalServerAddress) => { 17 | repo = repo || '/tmp/orbit'; 18 | console.log("Signalling server: " + signalServerAddress); 19 | signalServerAddress = signalServerAddress || '178.62.241.75'; 20 | console.log("IPFS Path: " + repo); 21 | const ipfs = new IPFS(repo); 22 | return new Promise((resolve, reject) => { 23 | ipfs.init({}, (err) => { 24 | if (err) { 25 | if (err.message === 'repo already exists') { 26 | console.log(repo, err.message) 27 | return resolve(); 28 | } 29 | return reject(err); 30 | } 31 | resolve(); 32 | }) 33 | }) 34 | .then(() => { 35 | return new Promise((resolve, reject) => { 36 | ipfs.goOnline(() => { 37 | resolve(ipfs); 38 | }); 39 | }); 40 | }) 41 | .then((id) => { 42 | return new Promise((resolve, reject) => { 43 | ipfs.config.show((err, config) => { 44 | if (err) return reject(err); 45 | resolve(config); 46 | }); 47 | }); 48 | }) 49 | .then(() => { 50 | return new Promise((resolve, reject) => { 51 | ipfs.id((err, id) => { 52 | if (err) return reject(err); 53 | resolve(id); 54 | }); 55 | }); 56 | }) 57 | .then((id) => new Promise((resolve, reject) => { 58 | ipfs.config.show((err, config) => { 59 | if (err) return reject(err); 60 | const signallingServer = `/libp2p-webrtc-star/ip4/${signalServerAddress}/tcp/9090/ws`; // localhost 61 | config.Addresses.Swarm = [`${signallingServer}/ipfs/${id.ID}`]; 62 | ipfs.config.replace(config, (err) => { 63 | if (err) return reject(err); 64 | resolve(); 65 | }); 66 | }); 67 | })) 68 | .then(() => { 69 | return new Promise((resolve, reject) => { 70 | ipfs.goOffline(resolve); 71 | }); 72 | }) 73 | .then(() => { 74 | return new Promise((resolve, reject) => { 75 | ipfs.goOnline(() => { 76 | resolve(ipfs); 77 | }); 78 | }); 79 | }) 80 | .then(() => { 81 | return new Promise((resolve, reject) => { 82 | ipfs.id((err, id) => { 83 | if (err) return reject(err); 84 | resolve(id); 85 | }); 86 | }); 87 | }) 88 | .then((id) => { 89 | return new Promise((resolve, reject) => { 90 | ipfs.config.show((err, config) => { 91 | if (err) return reject(err); 92 | resolve(config); 93 | }); 94 | }); 95 | }) 96 | .then(() => { 97 | console.log("IPFS", ipfs) 98 | return ipfs; 99 | }) 100 | } 101 | 102 | let ipfs, orbit; 103 | const peers = ['/tmp/proto2-1', '/tmp/proto2-2']; 104 | Promise.map(peers, (peer, index) => { 105 | return ipfsDaemon(IpfsApi, peer) 106 | .then((ipfs) => OrbitDB.connect(null, username + ((index+1) % 2 !== 0 ? 'A' : 'B'), '', ipfs)) 107 | }, { concurrency: 1 }) 108 | .then((res) => { 109 | Promise.map(res, (orbit, index) => { 110 | return orbit.kvstore(channel, { maxHistory: 5 }) 111 | .then((db) => window.onOrbitDBReady(res[index], db)) 112 | }, { concurrency : 1 }); 113 | }); 114 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "proto2", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "./node_modules/.bin/webpack --config webpack.config.js" 8 | }, 9 | "author": "Haad", 10 | "license": "MIT", 11 | "devDependencies": { 12 | "babel-core": "^6.9.0", 13 | "babel-loader": "^6.2.4", 14 | "babel-plugin-transform-runtime": "^6.9.0", 15 | "babel-preset-es2015": "^6.9.0", 16 | "exports-loader": "^0.6.3", 17 | "idb-plus-blob-store": "^1.1.2", 18 | "json-loader": "^0.5.4", 19 | "libp2p-ipfs": "^0.7.0", 20 | "stream-http": "^2.2.1", 21 | "webpack": "^2.1.0-beta.7" 22 | }, 23 | "dependencies": { 24 | "ipfs": "^0.11.1", 25 | "logplease": "^1.2.7", 26 | "orbit-db": "^0.9.7" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haadcode/proto2/5645e779a02f0ea6db1c924f20d2185e1f4aa2b3/screenshot.png -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const webpack = require('webpack'); 4 | const path = require('path'); 5 | 6 | module.exports = { 7 | entry: './index.js', 8 | output: { 9 | filename: './dist/bundle.js' 10 | }, 11 | cache: false, 12 | debug: true, 13 | devtool: 'sourcemap', 14 | node: { 15 | console: false, 16 | process: 'mock', 17 | Buffer: 'buffer' 18 | }, 19 | stats: { 20 | colors: true, 21 | reasons: true 22 | }, 23 | resolveLoader: { 24 | root: path.join(__dirname, 'node_modules') 25 | }, 26 | resolve: { 27 | // extensions: ['', '.js', '.jsx'], 28 | modulesDirectories: [ 29 | 'node_modules', 30 | path.join(__dirname, 'node_modules') 31 | ], 32 | alias: { 33 | "libp2p-ipfs": "libp2p-ipfs-browser", 34 | 'node_modules': path.join(__dirname + '/node_modules'), 35 | 'app': __dirname + '/src/app/', 36 | 'styles': __dirname + '/src/styles', 37 | 'mixins': __dirname + '/src/mixins', 38 | 'components': __dirname + '/src/components/', 39 | 'stores': __dirname + '/src/stores/', 40 | 'actions': __dirname + '/src/actions/', 41 | 'utils': __dirname + '/src/utils/' 42 | } 43 | }, 44 | module: { 45 | loaders: [{ 46 | test: /\.(js|jsx)$/, 47 | exclude: /node_modules/, 48 | loader: 'babel' 49 | }, { 50 | test: /\.js$/, 51 | include: /node_modules\/(hoek|qs|wreck|boom|ipfs-.+)/, 52 | loader: 'babel' 53 | }, { 54 | test: /\.scss/, 55 | loader: 'style-loader!css-loader!sass-loader?outputStyle=expanded' 56 | }, { 57 | test: /\.css$/, 58 | loader: 'style-loader!css-loader' 59 | }, { 60 | test: /\.(png|jpg|woff|woff2)$/, 61 | loader: 'url-loader?limit=8192' 62 | }, { 63 | test: /\.json$/, 64 | loader: 'json' 65 | }] 66 | }, 67 | plugins: [ 68 | new webpack.HotModuleReplacementPlugin() 69 | ], 70 | externals: { 71 | net: '{}', 72 | tls: '{}', 73 | fs: '{}', 74 | 'require-dir': '{}', 75 | mkdirp: '{}' 76 | } 77 | }; 78 | --------------------------------------------------------------------------------