blind-peer 2.9.3 → 2.9.4
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/bin.js +3 -0
- package/index.js +24 -7
- package/package.json +1 -1
package/bin.js
CHANGED
|
@@ -131,6 +131,9 @@ const cmd = command(
|
|
|
131
131
|
blindPeer.on('announce-core', (core) => {
|
|
132
132
|
logger.info(`Started announcing core ${coreToInfo(core, true)}`)
|
|
133
133
|
})
|
|
134
|
+
blindPeer.on('announced-initial-cores', () => {
|
|
135
|
+
logger.info(`Announced all initial cores`)
|
|
136
|
+
})
|
|
134
137
|
blindPeer.on('core-downloaded', (core) => {
|
|
135
138
|
logger.info(`Announced core fully downloaded: ${coreToInfo(core, true)}`)
|
|
136
139
|
})
|
package/index.js
CHANGED
|
@@ -187,7 +187,16 @@ class WakeupHandler {
|
|
|
187
187
|
class BlindPeer extends ReadyResource {
|
|
188
188
|
constructor(
|
|
189
189
|
rocks,
|
|
190
|
-
{
|
|
190
|
+
{
|
|
191
|
+
swarm,
|
|
192
|
+
store,
|
|
193
|
+
wakeup,
|
|
194
|
+
maxBytes = 100_000_000_000,
|
|
195
|
+
enableGc = true,
|
|
196
|
+
trustedPubKeys,
|
|
197
|
+
port,
|
|
198
|
+
announcingInterval = 100
|
|
199
|
+
} = {}
|
|
191
200
|
) {
|
|
192
201
|
super()
|
|
193
202
|
|
|
@@ -195,6 +204,7 @@ class BlindPeer extends ReadyResource {
|
|
|
195
204
|
this.store = store || new Corestore(this.rocks, { active: false })
|
|
196
205
|
this.swarm = swarm || null
|
|
197
206
|
this._port = port || 0
|
|
207
|
+
this.announcingInterval = announcingInterval
|
|
198
208
|
this.trustedPubKeys = new Set()
|
|
199
209
|
for (const k of trustedPubKeys || []) this.addTrustedPubKey(k)
|
|
200
210
|
|
|
@@ -266,12 +276,7 @@ class BlindPeer extends ReadyResource {
|
|
|
266
276
|
}
|
|
267
277
|
this.swarm.on('connection', this._onconnection.bind(this))
|
|
268
278
|
|
|
269
|
-
|
|
270
|
-
for await (const record of this.db.createAnnouncingCoresStream()) {
|
|
271
|
-
announceProms.push(this._announceCore(record.key))
|
|
272
|
-
}
|
|
273
|
-
await Promise.all(announceProms)
|
|
274
|
-
|
|
279
|
+
this._announceCores().catch(safetyCatch) // announcing cores asynchronously
|
|
275
280
|
this.flushInterval = setInterval(this.flush.bind(this), 10_000)
|
|
276
281
|
}
|
|
277
282
|
|
|
@@ -442,6 +447,18 @@ class BlindPeer extends ReadyResource {
|
|
|
442
447
|
stream.on('close', () => core.close().catch(safetyCatch))
|
|
443
448
|
}
|
|
444
449
|
|
|
450
|
+
async _announceCores() {
|
|
451
|
+
for await (const record of this.db.createAnnouncingCoresStream()) {
|
|
452
|
+
if (this.closing) return
|
|
453
|
+
await this._announceCore(record.key)
|
|
454
|
+
if (this.closing) return
|
|
455
|
+
await new Promise((resolve) => setTimeout(resolve, this.announcingInterval))
|
|
456
|
+
if (this.closing) return
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
this.emit('announced-initial-cores')
|
|
460
|
+
}
|
|
461
|
+
|
|
445
462
|
async _announceCore(key) {
|
|
446
463
|
const coreId = IdEnc.normalize(key)
|
|
447
464
|
if (this.announcedCores.has(coreId)) return
|