Files: 3bd137609d70f9a0d68010c74ec5af5af8d59863 / config.js
1770 bytesRaw
1 | const nest = require('depnest') |
2 | const Config = require('ssb-config/inject') |
3 | const Path = require('path') |
4 | const merge = require('lodash/merge') |
5 | // settings not available in api yet, so we need to load it manually |
6 | const settings = require('patch-settings').patchSettings |
7 | |
8 | exports.gives = nest('config.sync.load') |
9 | exports.create = (api) => { |
10 | var config |
11 | return nest('config.sync.load', () => { |
12 | if (config) return config |
13 | |
14 | console.log('LOADING config') |
15 | config = Config(process.env.ssb_appname || 'ssb') |
16 | |
17 | config = addSockets(config) |
18 | config = fixLocalhost(config) |
19 | config = PubHopSettings(config) |
20 | |
21 | return config |
22 | }) |
23 | } |
24 | |
25 | function addSockets (config) { |
26 | if (process.platform === 'win32') return config |
27 | |
28 | const pubkey = config.keys.id.slice(1).replace(`.${config.keys.curve}`, '') |
29 | return merge( |
30 | config, |
31 | { |
32 | connections: { |
33 | incoming: { unix: [{ scope: 'local', transform: 'noauth', server: true }] } |
34 | }, |
35 | remote: `unix:${Path.join(config.path, 'socket')}:~noauth:${pubkey}` // overwrites |
36 | } |
37 | ) |
38 | } |
39 | |
40 | function fixLocalhost (config) { |
41 | if (process.platform !== 'win32') return config |
42 | |
43 | // without this host defaults to :: which doesn't work on windows 10? |
44 | config.connections.incoming.net[0].host = '127.0.0.1' |
45 | config.connections.incoming.ws[0].host = '127.0.0.1' |
46 | config.host = '127.0.0.1' |
47 | return config |
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 merge( |
55 | config, |
56 | { |
57 | friendPub: { hops: pubHopConnections }, |
58 | gossip: { |
59 | friends: true, |
60 | global: false |
61 | } |
62 | }) |
63 | } else |
64 | return config |
65 | } |
66 |
Built with git-ssb-web