@@ -18,7 +18,12 @@ import {
1818} from '../../errors/reqresp.error.js' ;
1919import { SnappyTransform } from '../encoding.js' ;
2020import type { PeerScoring } from '../peer-manager/peer_scoring.js' ;
21- import type { P2PReqRespConfig } from './config.js' ;
21+ import {
22+ DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS ,
23+ DEFAULT_OVERALL_REQUEST_TIMEOUT_MS ,
24+ DEFAULT_REQRESP_DIAL_TIMEOUT_MS ,
25+ type P2PReqRespConfig ,
26+ } from './config.js' ;
2227import { BatchConnectionSampler } from './connection-sampler/batch_connection_sampler.js' ;
2328import { ConnectionSampler , RandomSampler } from './connection-sampler/connection_sampler.js' ;
2429import {
@@ -57,8 +62,9 @@ import { ReqRespStatus, ReqRespStatusError, parseStatusChunk, prettyPrintReqResp
5762 * see: https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/p2p-interface.md#the-reqresp-domain
5863 */
5964export class ReqResp implements ReqRespInterface {
60- private overallRequestTimeoutMs : number ;
61- private individualRequestTimeoutMs : number ;
65+ private overallRequestTimeoutMs : number = DEFAULT_OVERALL_REQUEST_TIMEOUT_MS ;
66+ private individualRequestTimeoutMs : number = DEFAULT_INDIVIDUAL_REQUEST_TIMEOUT_MS ;
67+ private dialTimeoutMs : number = DEFAULT_REQRESP_DIAL_TIMEOUT_MS ;
6268
6369 // Warning, if the `start` function is not called as the parent class constructor, then the default sub protocol handlers will be used ( not good )
6470 private subProtocolHandlers : ReqRespSubProtocolHandlers = DEFAULT_SUB_PROTOCOL_HANDLERS ;
@@ -79,8 +85,7 @@ export class ReqResp implements ReqRespInterface {
7985 rateLimits : Partial < ReqRespSubProtocolRateLimits > = { } ,
8086 telemetryClient : TelemetryClient = getTelemetryClient ( ) ,
8187 ) {
82- this . overallRequestTimeoutMs = config . overallRequestTimeoutMs ;
83- this . individualRequestTimeoutMs = config . individualRequestTimeoutMs ;
88+ this . updateConfig ( config ) ;
8489
8590 this . rateLimiter = new RequestResponseRateLimiter ( peerScoring , rateLimits ) ;
8691
@@ -96,6 +101,20 @@ export class ReqResp implements ReqRespInterface {
96101 this . metrics = new ReqRespMetrics ( telemetryClient ) ;
97102 }
98103
104+ public updateConfig ( config : Partial < P2PReqRespConfig > ) : void {
105+ if ( typeof config . overallRequestTimeoutMs === 'number' ) {
106+ this . overallRequestTimeoutMs = config . overallRequestTimeoutMs ;
107+ }
108+
109+ if ( typeof config . individualRequestTimeoutMs === 'number' ) {
110+ this . individualRequestTimeoutMs = config . individualRequestTimeoutMs ;
111+ }
112+
113+ if ( typeof config . dialTimeoutMs === 'number' ) {
114+ this . dialTimeoutMs = config . dialTimeoutMs ;
115+ }
116+ }
117+
99118 get tracer ( ) {
100119 return this . metrics . tracer ;
101120 }
@@ -372,7 +391,7 @@ export class ReqResp implements ReqRespInterface {
372391 peerId : PeerId ,
373392 subProtocol : ReqRespSubProtocol ,
374393 payload : Buffer ,
375- dialTimeout : number = 500 ,
394+ dialTimeout : number = this . dialTimeoutMs ,
376395 ) : Promise < ReqRespResponse > {
377396 let stream : Stream | undefined ;
378397 try {
0 commit comments