Files: 9fdc650f04f0bea7982659a5d5de3ce799b8ad6a / server-process.js
1606 bytesRaw
1 | var serveBlobs = require('./lib/serve-blobs') |
2 | var fs = require('fs') |
3 | var Path = require('path') |
4 | var electron = require('electron') |
5 | |
6 | var createSbot = require('scuttlebot') |
7 | .use(require('scuttlebot/plugins/master')) |
8 | .use(require('./lib/persistent-gossip')) // override |
9 | .use(require('scuttlebot/plugins/friends')) |
10 | .use(require('scuttlebot/plugins/replicate')) |
11 | .use(require('ssb-blobs')) |
12 | .use(require('scuttlebot/plugins/invite')) |
13 | .use(require('scuttlebot/plugins/block')) |
14 | .use(require('scuttlebot/plugins/local')) |
15 | .use(require('scuttlebot/plugins/logging')) |
16 | .use(require('scuttlebot/plugins/private')) |
17 | .use(require('ssb-links')) |
18 | .use(require('ssb-query')) |
19 | |
20 | module.exports = function (ssbConfig) { |
21 | var context = { |
22 | sbot: createSbot(ssbConfig), |
23 | config: ssbConfig |
24 | } |
25 | ssbConfig.manifest = context.sbot.getManifest() |
26 | serveBlobs(context) |
27 | fs.writeFileSync(Path.join(ssbConfig.path, 'manifest.json'), JSON.stringify(ssbConfig.manifest)) |
28 | connectToFriendlyPubs(context.sbot) |
29 | electron.ipcRenderer.send('server-started', ssbConfig) |
30 | } |
31 | |
32 | function connectToFriendlyPubs (sbot) { |
33 | sbot.gossip.peers((err, peers) => { |
34 | if (err) return console.log(err) |
35 | sbot.friends.all((err, friends) => { |
36 | if (err) return console.log(err) |
37 | console.log('Attempting to connect to friendly pubs...') |
38 | peers.filter((p) => p.state !== 'connected' && isFriends(friends, sbot.id, p.key)).forEach((peer) => { |
39 | sbot.gossip.connect(peer, () => {}) |
40 | }) |
41 | }) |
42 | }) |
43 | } |
44 | |
45 | function isFriends (friends, a, b) { |
46 | return friends[a] && friends[b] && friends[a][b] && friends[b][a] |
47 | } |
48 |
Built with git-ssb-web