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