@@ -10,10 +10,7 @@ import { multiaddr, protocols } from '@multiformats/multiaddr'
1010import { anySignal } from 'any-signal'
1111import { pbStream } from 'it-protobuf-stream'
1212import * as Digest from 'multiformats/hashes/digest'
13- import {
14- DEFAULT_CONNECTION_THRESHOLD ,
15- MAX_INBOUND_STREAMS , MAX_OUTBOUND_STREAMS , PROTOCOL_NAME , PROTOCOL_PREFIX , PROTOCOL_VERSION , TIMEOUT
16- } from './constants.js'
13+ import { DEFAULT_CONNECTION_THRESHOLD , MAX_INBOUND_STREAMS , MAX_MESSAGE_SIZE , MAX_OUTBOUND_STREAMS , PROTOCOL_NAME , PROTOCOL_PREFIX , PROTOCOL_VERSION , TIMEOUT } from './constants.js'
1714import { Message } from './pb/index.js'
1815import type { AutoNATComponents , AutoNATServiceInit } from './index.js'
1916import type { Logger , Connection , PeerId , Startable , AbortOptions } from '@libp2p/interface'
@@ -89,6 +86,7 @@ export class AutoNATService implements Startable {
8986 private readonly timeout : number
9087 private readonly maxInboundStreams : number
9188 private readonly maxOutboundStreams : number
89+ private readonly maxMessageSize : number
9290 private started : boolean
9391 private readonly log : Logger
9492 private topologyId ?: string
@@ -106,6 +104,7 @@ export class AutoNATService implements Startable {
106104 this . maxInboundStreams = init . maxInboundStreams ?? MAX_INBOUND_STREAMS
107105 this . maxOutboundStreams = init . maxOutboundStreams ?? MAX_OUTBOUND_STREAMS
108106 this . connectionThreshold = init . connectionThreshold ?? DEFAULT_CONNECTION_THRESHOLD
107+ this . maxMessageSize = init . maxMessageSize ?? MAX_MESSAGE_SIZE
109108 this . dialResults = new Map ( )
110109 this . findPeers = repeatingTask ( this . findRandomPeers . bind ( this ) , 60_000 )
111110 this . addressFilter = createScalableCuckooFilter ( 1024 )
@@ -229,7 +228,9 @@ export class AutoNATService implements Startable {
229228 const signal = AbortSignal . timeout ( this . timeout )
230229 setMaxListeners ( Infinity , signal )
231230
232- const messages = pbStream ( data . stream ) . pb ( Message )
231+ const messages = pbStream ( data . stream , {
232+ maxDataLength : this . maxMessageSize
233+ } ) . pb ( Message )
233234
234235 try {
235236 const request = await messages . read ( {
0 commit comments