@libp2p/floodsub 11.0.25-4bb8fbe8d → 11.0.25-89335e39f
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/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/decodeRpc.d.ts +22 -0
- package/dist/src/decodeRpc.d.ts.map +1 -0
- package/dist/src/decodeRpc.js +15 -0
- package/dist/src/decodeRpc.js.map +1 -0
- package/dist/src/floodsub.d.ts +1 -0
- package/dist/src/floodsub.d.ts.map +1 -1
- package/dist/src/floodsub.js +17 -7
- package/dist/src/floodsub.js.map +1 -1
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/message/rpc.d.ts +1 -187
- package/dist/src/message/rpc.d.ts.map +1 -1
- package/dist/src/message/rpc.js +0 -650
- package/dist/src/message/rpc.js.map +1 -1
- package/dist/src/peer-streams.d.ts +2 -1
- package/dist/src/peer-streams.d.ts.map +1 -1
- package/dist/src/peer-streams.js +7 -2
- package/dist/src/peer-streams.js.map +1 -1
- package/package.json +8 -8
- package/src/decodeRpc.ts +33 -0
- package/src/floodsub.ts +19 -7
- package/src/index.ts +8 -0
- package/src/message/rpc.proto +3 -32
- package/src/message/rpc.ts +1 -934
- package/src/peer-streams.ts +8 -2
package/src/peer-streams.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { pbStream } from '@libp2p/utils'
|
|
2
2
|
import { TypedEventEmitter } from 'main-event'
|
|
3
3
|
import { RPC } from './message/rpc.ts'
|
|
4
|
+
import type { RPCDecodeLimits } from './decodeRpc.ts'
|
|
4
5
|
import type { PubSubRPC } from './floodsub.ts'
|
|
5
6
|
import type { PeerStreamsEvents } from './index.ts'
|
|
6
7
|
import type { Stream, PeerId } from '@libp2p/interface'
|
|
@@ -38,7 +39,7 @@ export class PeerStreams extends TypedEventEmitter<PeerStreamsEvents> {
|
|
|
38
39
|
this.shutDownController = new AbortController()
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
attachInboundStream (stream: Stream, streamOpts?: Partial<ProtobufStreamOpts
|
|
42
|
+
attachInboundStream (stream: Stream, streamOpts?: Partial<ProtobufStreamOpts>, decodeRpcLimits?: RPCDecodeLimits): void {
|
|
42
43
|
this.inboundPb = pbStream(stream, streamOpts).pb(RPC)
|
|
43
44
|
|
|
44
45
|
Promise.resolve().then(async () => {
|
|
@@ -48,7 +49,8 @@ export class PeerStreams extends TypedEventEmitter<PeerStreamsEvents> {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
const message = await this.inboundPb.read({
|
|
51
|
-
signal: this.shutDownController.signal
|
|
52
|
+
signal: this.shutDownController.signal,
|
|
53
|
+
limits: decodeRpcLimits
|
|
52
54
|
})
|
|
53
55
|
|
|
54
56
|
this.safeDispatchEvent('message', {
|
|
@@ -57,7 +59,11 @@ export class PeerStreams extends TypedEventEmitter<PeerStreamsEvents> {
|
|
|
57
59
|
}
|
|
58
60
|
})
|
|
59
61
|
.catch(err => {
|
|
62
|
+
// the inbound stream errored (e.g. a frame exceeded the decode limits):
|
|
63
|
+
// reset it and close the peer so floodsub removes it instead of leaving
|
|
64
|
+
// a half-open peer with a dead inbound stream
|
|
60
65
|
this.inboundPb?.unwrap().unwrap().abort(err)
|
|
66
|
+
this.close()
|
|
61
67
|
})
|
|
62
68
|
}
|
|
63
69
|
|