git ssb

16+

Dominic / patchbay



Tree: 63eee5c010c2dc3e0a2b270dd65bb7ea5783f2fd

Files: 63eee5c010c2dc3e0a2b270dd65bb7ea5783f2fd / config.js

2425 bytesRaw
1const nest = require('depnest')
2const Config = require('ssb-config/inject')
3const Path = require('path')
4const merge = require('lodash/merge')
5// settings not available in api yet, so we need to load it manually
6const settings = require('patch-settings').patchSettings
7
8exports.gives = nest('config.sync.load')
9exports.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 // HACK (mix): patch-settings currently uses localStorage as persistence
25 // this means trying to load config outside context of electron crashes app ):
26 config = pubHopSettings(config)
27 config = torOnly(config)
28 } catch (e) {
29 console.log('TODO: decouple patchbay config from localStorage')
30 }
31
32 return config
33 })
34}
35
36function addSockets (config) {
37 if (process.platform === 'win32') return config
38
39 const pubkey = config.keys.id.slice(1).replace(`.${config.keys.curve}`, '')
40 return merge(
41 config,
42 {
43 connections: {
44 incoming: { unix: [{ scope: 'device', transform: 'noauth', server: true }] }
45 },
46 remote: `unix:${Path.join(config.path, 'socket')}:~noauth:${pubkey}` // overwrites
47 }
48 )
49}
50
51function fixLocalhost (config) {
52 if (process.platform !== 'win32') return config
53
54 // without this host defaults to :: which doesn't work on windows 10?
55 config.connections.incoming.net[0].host = '127.0.0.1'
56 config.connections.incoming.ws[0].host = '127.0.0.1'
57 config.host = '127.0.0.1'
58 return config
59}
60
61function pubHopSettings (config) {
62 const pubHopAll = 3
63 let pubHopConnections = settings.create().settings.sync.get('patchbay.pubHopConnections', pubHopAll)
64 if (pubHopConnections === pubHopAll) return config
65
66 return merge(
67 config,
68 {
69 friendPub: { hops: pubHopConnections },
70 gossip: {
71 friends: true,
72 global: false
73 }
74 })
75}
76
77function torOnly (config) {
78 if (settings.create().settings.sync.get('patchbay.torOnly', false)) {
79 config = merge(config, {
80 connections: {
81 outgoing: {
82 'onion': [{ 'transform': 'shs' }]
83 }
84 }
85 })
86
87 delete config.connections.outgoing.net
88 return config
89 } else { return config }
90}
91

Built with git-ssb-web