blind-peer 3.9.0 → 3.10.0
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 +76 -3
- package/package.json +7 -5
package/index.js
CHANGED
|
@@ -24,6 +24,8 @@ const {
|
|
|
24
24
|
RouterResolvePeersRequest,
|
|
25
25
|
RouterResolvePeersResponse
|
|
26
26
|
} = require('blind-peer-encodings')
|
|
27
|
+
const blindPush = require('blind-push')
|
|
28
|
+
const { ForwardPushRequest } = require('blind-push/encodings')
|
|
27
29
|
|
|
28
30
|
const BlindPeerDB = require('./lib/db.js')
|
|
29
31
|
const TopKWindow = require('./lib/top-k.js')
|
|
@@ -218,6 +220,8 @@ class BlindPeer extends ReadyResource {
|
|
|
218
220
|
routerPoolOpts,
|
|
219
221
|
ipBanListKeys = [],
|
|
220
222
|
banTimeout = 16_000,
|
|
223
|
+
pushGatewayKeys,
|
|
224
|
+
pushGatewayPoolOpts,
|
|
221
225
|
port,
|
|
222
226
|
bootstrap = null,
|
|
223
227
|
announcingInterval = 100,
|
|
@@ -257,10 +261,13 @@ class BlindPeer extends ReadyResource {
|
|
|
257
261
|
this.announcedCores = new Map()
|
|
258
262
|
this.replicationLagThreshold = replicationLagThreshold
|
|
259
263
|
|
|
264
|
+
this.rpcClient = null
|
|
260
265
|
this.routerKey = routerKey || null
|
|
261
266
|
this.routerPoolOpts = routerPoolOpts || {}
|
|
262
267
|
this.routerPool = null
|
|
263
268
|
this.adminRouter = adminRouter
|
|
269
|
+
this.pushGatewayKeys = pushGatewayKeys || []
|
|
270
|
+
this.pushGatewayPoolOpts = pushGatewayPoolOpts || {}
|
|
264
271
|
|
|
265
272
|
this.stats = {
|
|
266
273
|
bytesGcd: 0,
|
|
@@ -268,6 +275,9 @@ class BlindPeer extends ReadyResource {
|
|
|
268
275
|
activations: 0,
|
|
269
276
|
wakeups: 0,
|
|
270
277
|
addCoresRx: 0,
|
|
278
|
+
notificationsRx: 0,
|
|
279
|
+
notificationsSent: 0,
|
|
280
|
+
notificationErrors: 0,
|
|
271
281
|
muxerPaired: 0,
|
|
272
282
|
muxerErrors: 0
|
|
273
283
|
}
|
|
@@ -365,9 +375,20 @@ class BlindPeer extends ReadyResource {
|
|
|
365
375
|
})
|
|
366
376
|
)
|
|
367
377
|
|
|
378
|
+
this.rpcClient = new ProtomuxRpcClient(this.swarm.dht)
|
|
368
379
|
if (this.routerKey) {
|
|
369
|
-
|
|
370
|
-
|
|
380
|
+
this.routerPool = new ProtomuxRpcClientPool(
|
|
381
|
+
[this.routerKey],
|
|
382
|
+
this.rpcClient,
|
|
383
|
+
this.routerPoolOpts
|
|
384
|
+
)
|
|
385
|
+
}
|
|
386
|
+
if (this.pushGatewayKeys.length) {
|
|
387
|
+
this.gatewayPool = new ProtomuxRpcClientPool(
|
|
388
|
+
this.pushGatewayKeys,
|
|
389
|
+
this.rpcClient,
|
|
390
|
+
this.pushGatewayPoolOpts
|
|
391
|
+
)
|
|
371
392
|
}
|
|
372
393
|
|
|
373
394
|
await this.topKByPeer.ready()
|
|
@@ -537,6 +558,15 @@ class BlindPeer extends ReadyResource {
|
|
|
537
558
|
self.emit('muxer-error', e, conn)
|
|
538
559
|
throw e
|
|
539
560
|
}
|
|
561
|
+
},
|
|
562
|
+
async onnotification(request) {
|
|
563
|
+
try {
|
|
564
|
+
await self._onnotification(conn, request)
|
|
565
|
+
} catch (e) {
|
|
566
|
+
self.stats.notificationErrors++
|
|
567
|
+
self.emit('notification-error', e, conn)
|
|
568
|
+
throw e
|
|
569
|
+
}
|
|
540
570
|
}
|
|
541
571
|
})
|
|
542
572
|
})
|
|
@@ -878,11 +908,46 @@ class BlindPeer extends ReadyResource {
|
|
|
878
908
|
return true
|
|
879
909
|
}
|
|
880
910
|
|
|
911
|
+
async _onnotification(stream, request) {
|
|
912
|
+
this.stats.notificationsRx++
|
|
913
|
+
|
|
914
|
+
if (!this.gatewayPool) {
|
|
915
|
+
return null
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
const core = this.store.get({ key: request.block.key })
|
|
919
|
+
|
|
920
|
+
await core.ready()
|
|
921
|
+
|
|
922
|
+
const payload = await blindPush.createNotification(core, {
|
|
923
|
+
roomKey: request.destination.key,
|
|
924
|
+
roomDiscoveryKey: request.destination.discoveryKey,
|
|
925
|
+
index: request.block.index,
|
|
926
|
+
version: request.version,
|
|
927
|
+
extra: request.extra
|
|
928
|
+
})
|
|
929
|
+
|
|
930
|
+
await this.gatewayPool.makeRequest(
|
|
931
|
+
'forward-push',
|
|
932
|
+
{ payload, appId: request.appId },
|
|
933
|
+
{
|
|
934
|
+
requestEncoding: ForwardPushRequest,
|
|
935
|
+
responseEncoding: c.none
|
|
936
|
+
}
|
|
937
|
+
)
|
|
938
|
+
|
|
939
|
+
this.stats.notificationsSent++
|
|
940
|
+
this.emit('notification-sent', request, payload, stream)
|
|
941
|
+
}
|
|
942
|
+
|
|
881
943
|
async _close() {
|
|
882
944
|
if (this.routerPool) {
|
|
883
945
|
await this.routerPool.destroy()
|
|
884
|
-
await this.routerPool.statelessRpc.close()
|
|
885
946
|
}
|
|
947
|
+
if (this.gatewayPool) {
|
|
948
|
+
await this.gatewayPool.destroy()
|
|
949
|
+
}
|
|
950
|
+
await this.rpcClient.close()
|
|
886
951
|
if (this.adminRouter) await this.adminRouter.close()
|
|
887
952
|
clearInterval(this.flushInterval)
|
|
888
953
|
await this.topKByPeer.close()
|
|
@@ -1074,6 +1139,14 @@ class BlindPeer extends ReadyResource {
|
|
|
1074
1139
|
this.set(self.store.active ? 1 : 0)
|
|
1075
1140
|
}
|
|
1076
1141
|
})
|
|
1142
|
+
|
|
1143
|
+
new promClient.Gauge({
|
|
1144
|
+
name: 'blind_peer_push_notifications_active',
|
|
1145
|
+
help: 'Whether push notifications can be forwarded (1) or not (0)',
|
|
1146
|
+
collect() {
|
|
1147
|
+
this.set(self.gatewayPool ? 1 : 0)
|
|
1148
|
+
}
|
|
1149
|
+
})
|
|
1077
1150
|
}
|
|
1078
1151
|
}
|
|
1079
1152
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "blind-peer",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"description": "Blind peers help keep hypercores available",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"autobase": "^7.0.18",
|
|
8
8
|
"b4a": "^1.6.7",
|
|
9
9
|
"blind-peer-encodings": "^3.3.0",
|
|
10
|
-
"blind-peer-muxer": "^1.
|
|
10
|
+
"blind-peer-muxer": "^1.3.0",
|
|
11
|
+
"blind-push": "^0.2.5",
|
|
11
12
|
"compact-encoding": "^3.0.0",
|
|
12
13
|
"corestore": "^7.4.4",
|
|
13
14
|
"hypercore": "^11.26.0",
|
|
@@ -19,8 +20,8 @@
|
|
|
19
20
|
"hyperswarm": "^4.13.1",
|
|
20
21
|
"ip-ban-list": "^0.3.0",
|
|
21
22
|
"protomux-rpc": "^1.7.1",
|
|
22
|
-
"protomux-rpc-client": "^2.
|
|
23
|
-
"protomux-rpc-client-pool": "^2.
|
|
23
|
+
"protomux-rpc-client": "^2.3.0",
|
|
24
|
+
"protomux-rpc-client-pool": "^2.2.0",
|
|
24
25
|
"protomux-wakeup": "^2.9.0",
|
|
25
26
|
"ready-resource": "^1.1.2",
|
|
26
27
|
"repl-swarm": "^2.3.0",
|
|
@@ -34,7 +35,8 @@
|
|
|
34
35
|
"bare-process": "^4.2.2",
|
|
35
36
|
"bare-prom-client": "^15.1.3",
|
|
36
37
|
"blind-peer-router": "^0.2.2",
|
|
37
|
-
"blind-peering": "^2.1
|
|
38
|
+
"blind-peering": "^2.2.1",
|
|
39
|
+
"blind-push-gateway": "^0.1.1",
|
|
38
40
|
"brittle": "^3.7.0",
|
|
39
41
|
"debounceify": "^1.1.0",
|
|
40
42
|
"graceful-goodbye": "^1.3.3",
|