git ssb

16+

Dominic / patchbay



Tree: 6993e3bdaf03244699ce17ff18a4026c4724ea0b

Files: 6993e3bdaf03244699ce17ff18a4026c4724ea0b / config.js

2261 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 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
34function 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
49function 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
59function 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
75function 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