git ssb

16+

Dominic / patchbay



Tree: 271995b29180d065f2acc8b818aa0c1205347eff

Files: 271995b29180d065f2acc8b818aa0c1205347eff / app / html / settings / tor-only.js

2035 bytesRaw
1const nest = require('depnest')
2const { h, Value, resolve, watch, computed } = require('mutant')
3const { cloneDeep, set, get, isEmpty } = require('lodash')
4
5exports.gives = nest({
6 'app.html.settings': true
7})
8
9exports.needs = nest({
10 'app.html.settings': 'map',
11 'config.sync.get': 'first',
12 'config.sync.getCustom': 'first',
13 'config.sync.setCustom': 'first'
14})
15
16exports.create = function (api) {
17 return nest({
18 'app.html.settings': torOnly
19 })
20
21 function torOnly () {
22 const torOnly = Value(isTorOnly(api.config.sync.get()))
23 torOnly.initial = torOnly()
24
25 watch(torOnly, (torOnly) => {
26 updateConfig(torOnly)
27 })
28
29 return {
30 group: 'gossip',
31 title: 'Tor only connections',
32 body: h('TorOnly', [
33 h('p', [
34 'Preserve your ip privacy by only connecting to other nodes using tor',
35 h('input', {
36 type: 'checkbox',
37 checked: torOnly,
38 'ev-change': () => torOnly.set(!resolve(torOnly))
39 })
40 ]),
41 computed(torOnly, (_torOnly) => {
42 if (_torOnly === torOnly.initial) return
43 return h('div.alert', [
44 h('i.fa.fa-warning'),
45 ' please restart patchbay for this to take effect'
46 ])
47 })
48 ])
49 }
50 }
51
52 function updateConfig (torOnly) {
53 var next = cloneDeep(api.config.sync.getCustom())
54
55 if (torOnly) {
56 set(next, 'connections.outgoing.onion', [{ 'transform': 'shs' }])
57 set(next, 'connections.outgoing.net', [])
58 } else if (get(next, 'connections.outgoing.onion')) {
59 delete next.connections.outgoing.onion
60 delete next.connections.outgoing.net
61 if (isEmpty(next.connections.outgoing)) delete next.connections.outgoing
62 if (isEmpty(next.connections)) delete next.connections
63 }
64
65 api.config.sync.setCustom(next)
66 }
67}
68
69function isTorOnly (config) {
70 const onionOut = get(config, 'connections.outgoing.onion[0]')
71 const netOut = get(config, 'connections.outgoing.net[0]')
72
73 return onionOut && !netOut
74}
75

Built with git-ssb-web