git ssb

16+

Dominic / patchbay



Tree: 27355b79781b9a149ac4078aa3661320e7fdf616

Files: 27355b79781b9a149ac4078aa3661320e7fdf616 / config.js

1809 bytesRaw
1const nest = require('depnest')
2const Config = require('ssb-config/inject')
3const ssbKeys = require('ssb-keys')
4const Path = require('path')
5const merge = require('lodash/merge')
6// settings not available in api yet, so we need to load it manually
7const settings = require('patch-settings').patchSettings
8
9const appName = process.env.ssb_appname || 'ssb'
10const opts = appName === 'ssb' ? null : null
11
12exports.gives = nest('config.sync.load')
13exports.create = (api) => {
14 var config
15 return nest('config.sync.load', () => {
16 if (config) return config
17
18 console.log('LOADING config')
19 config = Config(appName, opts)
20 config.keys = ssbKeys.loadOrCreateSync(Path.join(config.path, 'secret'))
21
22 config = merge(
23 config,
24 Connections(config),
25 Remote(config),
26 PubHopSettings(config)
27 )
28
29 return config
30 })
31}
32
33function Connections (config) {
34 const connections = (process.platform === 'win32')
35 ? undefined // this seems wrong?
36 : { incoming: { unix: [{ 'scope': 'local', 'transform': 'noauth', server: true }] } }
37
38 return connections ? { connections } : {}
39}
40
41function Remote (config) {
42 const pubkey = config.keys.id.slice(1).replace(`.${config.keys.curve}`, '')
43 const remote = (process.platform === 'win32')
44 ? undefined // `net:127.0.0.1:${config.port}~shs:${pubkey}` // currently broken
45 : `unix:${Path.join(config.path, 'socket')}:~noauth:${pubkey}`
46
47 return remote ? { remote } : {}
48}
49
50function PubHopSettings (config) {
51 const pubHopAll = 3
52 let pubHopConnections = settings.create().settings.sync.get('patchbay.pubHopConnections', pubHopAll)
53 if (pubHopConnections != pubHopAll) {
54 return {
55 friendPub: { hops: pubHopConnections },
56 gossip: {
57 friends: true,
58 global: false
59 }
60 }
61 } else
62 return {}
63}
64

Built with git-ssb-web