Files: 27355b79781b9a149ac4078aa3661320e7fdf616 / config.js
1809 bytesRaw
1 | const nest = require('depnest') |
2 | const Config = require('ssb-config/inject') |
3 | const ssbKeys = require('ssb-keys') |
4 | const Path = require('path') |
5 | const merge = require('lodash/merge') |
6 | // settings not available in api yet, so we need to load it manually |
7 | const settings = require('patch-settings').patchSettings |
8 | |
9 | const appName = process.env.ssb_appname || 'ssb' |
10 | const opts = appName === 'ssb' ? null : null |
11 | |
12 | exports.gives = nest('config.sync.load') |
13 | exports.create = (api) => { |
14 | var config |
15 | return nest('config.sync.load', () => { |
16 | if (config) return config |
17 | |
18 | console.log('LOADING config') |
19 | config = Config(appName, opts) |
20 | config.keys = ssbKeys.loadOrCreateSync(Path.join(config.path, 'secret')) |
21 | |
22 | config = merge( |
23 | config, |
24 | Connections(config), |
25 | Remote(config), |
26 | PubHopSettings(config) |
27 | ) |
28 | |
29 | return config |
30 | }) |
31 | } |
32 | |
33 | function Connections (config) { |
34 | const connections = (process.platform === 'win32') |
35 | ? undefined // this seems wrong? |
36 | : { incoming: { unix: [{ 'scope': 'local', 'transform': 'noauth', server: true }] } } |
37 | |
38 | return connections ? { connections } : {} |
39 | } |
40 | |
41 | function Remote (config) { |
42 | const pubkey = config.keys.id.slice(1).replace(`.${config.keys.curve}`, '') |
43 | const remote = (process.platform === 'win32') |
44 | ? undefined // `net:127.0.0.1:${config.port}~shs:${pubkey}` // currently broken |
45 | : `unix:${Path.join(config.path, 'socket')}:~noauth:${pubkey}` |
46 | |
47 | return remote ? { remote } : {} |
48 | } |
49 | |
50 | function PubHopSettings (config) { |
51 | const pubHopAll = 3 |
52 | let pubHopConnections = settings.create().settings.sync.get('patchbay.pubHopConnections', pubHopAll) |
53 | if (pubHopConnections != pubHopAll) { |
54 | return { |
55 | friendPub: { hops: pubHopConnections }, |
56 | gossip: { |
57 | friends: true, |
58 | global: false |
59 | } |
60 | } |
61 | } else |
62 | return {} |
63 | } |
64 |
Built with git-ssb-web