blind-peer 2.7.11 → 2.7.12
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 +19 -4
- package/index.js +8 -3
- package/package.json +1 -1
package/bin.js
CHANGED
|
@@ -9,6 +9,7 @@ const safetyCatch = require('safety-catch')
|
|
|
9
9
|
const byteSize = require('tiny-byte-size')
|
|
10
10
|
const pino = require('pino')
|
|
11
11
|
const b4a = require('b4a')
|
|
12
|
+
const hypCrypto = require('hypercore-crypto')
|
|
12
13
|
|
|
13
14
|
const BlindPeer = require('.')
|
|
14
15
|
|
|
@@ -48,9 +49,9 @@ const cmd = command('blind-peer',
|
|
|
48
49
|
logger.warn(`Error while flushing the db: ${e.stack}`)
|
|
49
50
|
})
|
|
50
51
|
|
|
51
|
-
blindPeer.on('add-core', record => {
|
|
52
|
+
blindPeer.on('add-core', (record, _, stream) => {
|
|
52
53
|
try {
|
|
53
|
-
logger.info(`add-core request received for record ${recordToStr(record)}`)
|
|
54
|
+
logger.info(`add-core request received from peer ${streamToStr(stream)} for record ${recordToStr(record)}`)
|
|
54
55
|
} catch (e) {
|
|
55
56
|
logger.info(`Invalid add-core request received: ${e.stack}`)
|
|
56
57
|
logger.info(record)
|
|
@@ -87,6 +88,13 @@ const cmd = command('blind-peer',
|
|
|
87
88
|
})
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
blindPeer.on('invalid-request', (core, err, req, from) => {
|
|
92
|
+
const address = `${from.stream?.rawStream?.remoteHost}:${from.stream?.rawStream?.remotePort}`
|
|
93
|
+
const remotePubKey = idEnc.normalize(from.stream.remotePublicKey)
|
|
94
|
+
const key = idEnc.normalize(core.key)
|
|
95
|
+
console.warn(`Received invalid request for core ${key} from peer ${remotePubKey} at ${address} (${err.stack})`)
|
|
96
|
+
})
|
|
97
|
+
|
|
90
98
|
logger.info(`Using storage '${storage}'`)
|
|
91
99
|
if (trustedPubKeys.length > 0) {
|
|
92
100
|
logger.info(`Trusted public keys:\n -${[...blindPeer.trustedPubKeys].map(idEnc.normalize).join('\n -')}`)
|
|
@@ -174,11 +182,18 @@ const cmd = command('blind-peer',
|
|
|
174
182
|
)
|
|
175
183
|
|
|
176
184
|
function recordToStr (record) {
|
|
177
|
-
|
|
185
|
+
const discKey = hypCrypto.discoveryKey(record.key)
|
|
186
|
+
return `DB Record for discovery key ${idEnc.normalize(discKey)} with priority: ${record.priority}. Announcing? ${record.announce}`
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function streamToStr (stream) {
|
|
190
|
+
const pubKey = idEnc.normalize(stream.remotePublicKey)
|
|
191
|
+
return `${pubKey}`
|
|
178
192
|
}
|
|
179
193
|
|
|
180
194
|
function coreToInfo (core) {
|
|
181
|
-
|
|
195
|
+
const discKey = hypCrypto.discoveryKey(core.key)
|
|
196
|
+
return `Discovery key ${idEnc.normalize(discKey)} (${core.contiguousLength} / ${core.length}, ${core.peers.length} peers)`
|
|
182
197
|
}
|
|
183
198
|
|
|
184
199
|
cmd.parse()
|
package/index.js
CHANGED
|
@@ -206,11 +206,15 @@ class BlindPeer extends ReadyResource {
|
|
|
206
206
|
|
|
207
207
|
async _open () {
|
|
208
208
|
await this.store.ready()
|
|
209
|
+
|
|
209
210
|
// legacy, we can remove once current ones are upgraded
|
|
210
211
|
const { secretKey } = await this.store.createKeyPair('blind-mirror-swarm')
|
|
211
212
|
this.db = new BlindPeerDB(this.rocks.session(), { swarming: secretKey.subarray(0, 32), encryption: null })
|
|
212
213
|
await this.db.ready()
|
|
213
214
|
|
|
215
|
+
// We don't need to track our own db, so we set this handler after the db core opened
|
|
216
|
+
this.store.watch(this._oncoreopen.bind(this))
|
|
217
|
+
|
|
214
218
|
if (this.swarm === null) {
|
|
215
219
|
const swarmOpts = { keyPair: this.db.swarmingKeyPair }
|
|
216
220
|
if (this._port) swarmOpts.port = typeof this._port === 'number' ? [this._port, this._port + 64] : this._port
|
|
@@ -224,8 +228,6 @@ class BlindPeer extends ReadyResource {
|
|
|
224
228
|
}
|
|
225
229
|
await Promise.all(announceProms)
|
|
226
230
|
|
|
227
|
-
this.store.watch(this._oncoreopen.bind(this))
|
|
228
|
-
|
|
229
231
|
this.flushInterval = setInterval(this.flush.bind(this), 10_000)
|
|
230
232
|
}
|
|
231
233
|
|
|
@@ -331,6 +333,9 @@ class BlindPeer extends ReadyResource {
|
|
|
331
333
|
this.activeReplication.delete(id)
|
|
332
334
|
}
|
|
333
335
|
})
|
|
336
|
+
session.on('invalid-request', (err, req, from) => {
|
|
337
|
+
this.emit('invalid-request', session, err, req, from)
|
|
338
|
+
})
|
|
334
339
|
}
|
|
335
340
|
|
|
336
341
|
async flush () { // not allowed to throw
|
|
@@ -437,7 +442,7 @@ class BlindPeer extends ReadyResource {
|
|
|
437
442
|
}
|
|
438
443
|
|
|
439
444
|
this.stats.coresAdded++
|
|
440
|
-
this.emit('add-core', record, true)
|
|
445
|
+
this.emit('add-core', record, true, stream)
|
|
441
446
|
|
|
442
447
|
await this._activateCore(stream, record)
|
|
443
448
|
|