git ssb

16+

Dominic / patchbay



Tree: 890a328ec16a614760b6633754e1dc90ec3ce40e

Files: 890a328ec16a614760b6633754e1dc90ec3ce40e / config.js

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

Built with git-ssb-web