autopass 3.1.0 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +17 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4,6 +4,7 @@ const Autobase = require('autobase')
|
|
|
4
4
|
const BlindPairing = require('blind-pairing')
|
|
5
5
|
const HyperDB = require('hyperdb')
|
|
6
6
|
const Hyperswarm = require('hyperswarm')
|
|
7
|
+
const Wakeup = require('protomux-wakeup')
|
|
7
8
|
const ReadyResource = require('ready-resource')
|
|
8
9
|
const z32 = require('z32')
|
|
9
10
|
const b4a = require('b4a')
|
|
@@ -18,6 +19,7 @@ class AutopassPairer extends ReadyResource {
|
|
|
18
19
|
this.store = store
|
|
19
20
|
this.invite = invite
|
|
20
21
|
this.swarm = null
|
|
22
|
+
this.wakeup = null
|
|
21
23
|
this.pairing = null
|
|
22
24
|
this.peering = null
|
|
23
25
|
this.candidate = null
|
|
@@ -38,9 +40,12 @@ class AutopassPairer extends ReadyResource {
|
|
|
38
40
|
relayThrough: this.relayThrough
|
|
39
41
|
})
|
|
40
42
|
|
|
43
|
+
this.wakeup = new Wakeup()
|
|
44
|
+
|
|
41
45
|
const store = this.store
|
|
42
46
|
this.swarm.on('connection', (connection, peerInfo) => {
|
|
43
47
|
store.replicate(connection)
|
|
48
|
+
this.wakeup.addStream(connection)
|
|
44
49
|
})
|
|
45
50
|
|
|
46
51
|
this.pairing = new BlindPairing(this.swarm)
|
|
@@ -56,6 +61,7 @@ class AutopassPairer extends ReadyResource {
|
|
|
56
61
|
this.pass = new Autopass(this.store, {
|
|
57
62
|
swarm: this.swarm,
|
|
58
63
|
key: result.key,
|
|
64
|
+
wakeup: this.wakeup,
|
|
59
65
|
encryptionKey: result.encryptionKey,
|
|
60
66
|
bootstrap: this.bootstrap
|
|
61
67
|
})
|
|
@@ -86,6 +92,10 @@ class AutopassPairer extends ReadyResource {
|
|
|
86
92
|
await this.candidate.close()
|
|
87
93
|
}
|
|
88
94
|
|
|
95
|
+
if (this.wakeup !== null) {
|
|
96
|
+
this.wakeup.destroy()
|
|
97
|
+
}
|
|
98
|
+
|
|
89
99
|
if (this.swarm !== null) {
|
|
90
100
|
await this.swarm.destroy()
|
|
91
101
|
}
|
|
@@ -160,9 +170,10 @@ class Autopass extends ReadyResource {
|
|
|
160
170
|
|
|
161
171
|
// Initialize autobase
|
|
162
172
|
_boot(opts = {}) {
|
|
163
|
-
const { encryptionKey, key } = opts
|
|
173
|
+
const { encryptionKey, key, wakeup } = opts
|
|
164
174
|
|
|
165
175
|
this.base = new Autobase(this.store, key, {
|
|
176
|
+
wakeup,
|
|
166
177
|
encrypt: true,
|
|
167
178
|
encryptionKey,
|
|
168
179
|
open(store) {
|
|
@@ -285,7 +296,7 @@ class Autopass extends ReadyResource {
|
|
|
285
296
|
bootstrap: this.bootstrap
|
|
286
297
|
})
|
|
287
298
|
this.swarm.on('connection', (connection, peerInfo) => {
|
|
288
|
-
this.
|
|
299
|
+
this.base.replicate(connection)
|
|
289
300
|
})
|
|
290
301
|
}
|
|
291
302
|
this.pairing = new BlindPairing(this.swarm)
|
|
@@ -311,12 +322,16 @@ class Autopass extends ReadyResource {
|
|
|
311
322
|
const mirrorList = await this.getMirror()
|
|
312
323
|
const mirrors = mirrorList.map((item) => item.key)
|
|
313
324
|
this.peering = new BlindPeering(this.swarm, this.store, {
|
|
325
|
+
wakeup: this.base.wakeupProtocol,
|
|
314
326
|
autobaseMirrors: mirrors
|
|
315
327
|
})
|
|
316
328
|
this.peering.addAutobaseBackground(this.base)
|
|
317
329
|
}
|
|
318
330
|
|
|
319
331
|
async add(key, value, file) {
|
|
332
|
+
if (file && file.byteLength > 6 * 1024 * 1024) {
|
|
333
|
+
throw new Error('File length should be less than 6 MB')
|
|
334
|
+
}
|
|
320
335
|
await this.base.append(encode('@autopass/put', { key, value, file }))
|
|
321
336
|
}
|
|
322
337
|
|