@@ -10,10 +10,7 @@ import { multiaddr, protocols } from '@multiformats/multiaddr'
10
10
import { anySignal } from 'any-signal'
11
11
import { pbStream } from 'it-protobuf-stream'
12
12
import * 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'
17
14
import { Message } from './pb/index.js'
18
15
import type { AutoNATComponents , AutoNATServiceInit } from './index.js'
19
16
import type { Logger , Connection , PeerId , Startable , AbortOptions } from '@libp2p/interface'
@@ -89,6 +86,7 @@ export class AutoNATService implements Startable {
89
86
private readonly timeout : number
90
87
private readonly maxInboundStreams : number
91
88
private readonly maxOutboundStreams : number
89
+ private readonly maxMessageSize : number
92
90
private started : boolean
93
91
private readonly log : Logger
94
92
private topologyId ?: string
@@ -106,6 +104,7 @@ export class AutoNATService implements Startable {
106
104
this . maxInboundStreams = init . maxInboundStreams ?? MAX_INBOUND_STREAMS
107
105
this . maxOutboundStreams = init . maxOutboundStreams ?? MAX_OUTBOUND_STREAMS
108
106
this . connectionThreshold = init . connectionThreshold ?? DEFAULT_CONNECTION_THRESHOLD
107
+ this . maxMessageSize = init . maxMessageSize ?? MAX_MESSAGE_SIZE
109
108
this . dialResults = new Map ( )
110
109
this . findPeers = repeatingTask ( this . findRandomPeers . bind ( this ) , 60_000 )
111
110
this . addressFilter = createScalableCuckooFilter ( 1024 )
@@ -229,7 +228,9 @@ export class AutoNATService implements Startable {
229
228
const signal = AbortSignal . timeout ( this . timeout )
230
229
setMaxListeners ( Infinity , signal )
231
230
232
- const messages = pbStream ( data . stream ) . pb ( Message )
231
+ const messages = pbStream ( data . stream , {
232
+ maxDataLength : this . maxMessageSize
233
+ } ) . pb ( Message )
233
234
234
235
try {
235
236
const request = await messages . read ( {
0 commit comments