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