git ssb

16+

Dominic / patchbay



Tree: 03ce3474ce130d4761d364412f79db838997ddb9

Files: 03ce3474ce130d4761d364412f79db838997ddb9 / config.js

2139 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 config = pubHopSettings(config)
22 config = torOnly(config)
23
24 return config
25 })
26}
27
28function 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
43function 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
53function 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
69function 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