forked from arj03/ssb-browser-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
72 lines (62 loc) · 1.48 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var SecretStack = require('secret-stack')
var caps = require('ssb-caps')
var ssbKeys = require('ssb-keys')
var path = require('path')
exports.init = function(dir) {
var keys = ssbKeys.loadOrCreateSync(path.join(dir, 'secret'))
var r = SecretStack({
caps: { shs: Buffer.from(caps.shs, 'base64') },
keys,
connections: {
incoming: {
tunnel: [{ transform: 'shs' }]
},
outgoing: {
net: [{ transform: 'shs' }],
onion: [{ transform: 'shs' }],
ws: [{ transform: 'shs' }, { transform: 'noauth' }],
tunnel: [{ transform: 'shs' }]
}
},
path: dir,
timers: {
inactivity: 30e3
},
tunnel: {
logging: true
}
})
.use(require('./ssb-db'))
.use(require('./ssb-get-thread'))
.use(require('./simple-ooo'))
.use(require('ssb-onion'))
.use(require('ssb-no-auth'))
.use(require('ssb-ws'))
.use(require('ssb-ebt'))
.use(require('ssb-tunnel'))
.use(require('./tunnel-chat'))
.use(require("./simple-blobs"))
()
var timer
r.on('rpc:connect', function (rpc, isClient) {
console.log("connected to:", rpc.id)
function ping() {
rpc.tunnel.ping(function (err, _ts) {
if (err) return console.error(err)
clearTimeout(timer)
timer = setTimeout(ping, 10e3)
})
}
ping()
})
r.on('replicate:finish', function () {
console.log("finished ebt replicate")
})
r.gossip = {
connect: function(addr, cb) {
// hack for ssb-tunnel
r.connect(SSB.remoteAddress, cb)
}
}
return r
}