@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.
@@ -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>): void {
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