Files: 4a873ea55bb2878927cf328e9044264bfdba5430 / config.js
2130 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 | config = torOnly(config) |
21 | |
22 | return config |
23 | }) |
24 | } |
25 | |
26 | function addSockets (config) { |
27 | if (process.platform === 'win32') return config |
28 | |
29 | const pubkey = config.keys.id.slice(1).replace(`.${config.keys.curve}`, '') |
30 | return merge( |
31 | config, |
32 | { |
33 | connections: { |
34 | incoming: { unix: [{ scope: 'local', transform: 'noauth', server: true }] } |
35 | }, |
36 | remote: `unix:${Path.join(config.path, 'socket')}:~noauth:${pubkey}` // overwrites |
37 | } |
38 | ) |
39 | } |
40 | |
41 | function fixLocalhost (config) { |
42 | if (process.platform !== 'win32') return config |
43 | |
44 | // without this host defaults to :: which doesn't work on windows 10? |
45 | config.connections.incoming.net[0].host = '127.0.0.1' |
46 | config.connections.incoming.ws[0].host = '127.0.0.1' |
47 | config.host = '127.0.0.1' |
48 | return config |
49 | } |
50 | |
51 | function pubHopSettings (config) { |
52 | const pubHopAll = 3 |
53 | let pubHopConnections = settings.create().settings.sync.get('patchbay.pubHopConnections', pubHopAll) |
54 | if (pubHopConnections != pubHopAll) { |
55 | return merge( |
56 | config, |
57 | { |
58 | friendPub: { hops: pubHopConnections }, |
59 | gossip: { |
60 | friends: true, |
61 | global: false |
62 | } |
63 | }) |
64 | } else |
65 | return config |
66 | } |
67 | |
68 | function torOnly (config) { |
69 | if (settings.create().settings.sync.get('patchbay.torOnly', false)) { |
70 | config = merge(config, { |
71 | connections: { |
72 | outgoing: { |
73 | "onion": [{ "transform": "shs" }] |
74 | } |
75 | } |
76 | }) |
77 | |
78 | delete config.connections.outgoing.net |
79 | return config |
80 | } else |
81 | return config |
82 | } |
83 |
Built with git-ssb-web