1- import { CodeError , TypedEventEmitter , setMaxListeners } from '@libp2p/interface'
1+ import { InvalidParametersError , NotStartedError , TimeoutError , TypedEventEmitter , UnsupportedProtocolError , setMaxListeners } from '@libp2p/interface'
22import { PeerQueue , type PeerQueueJobOptions } from '@libp2p/utils/peer-queue'
33import drain from 'it-drain'
44import * as lp from 'it-length-prefixed'
@@ -41,7 +41,7 @@ export interface NetworkInit {
4141 messageReceiveTimeout ?: number
4242 messageSendConcurrency ?: number
4343 protocols ?: string [ ]
44- runOnTransientConnections ?: boolean
44+ runOnLimitedConnections ?: boolean
4545 maxOutgoingMessageSize ?: number
4646 maxIncomingMessageSize ?: number
4747}
@@ -80,7 +80,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
8080 private registrarIds : string [ ]
8181 private readonly metrics : { blocksSent ?: Counter , dataSent ?: Counter }
8282 private readonly sendQueue : PeerQueue < void , SendMessageJobOptions >
83- private readonly runOnTransientConnections : boolean
83+ private readonly runOnLimitedConnections : boolean
8484 private readonly maxOutgoingMessageSize : number
8585 private readonly maxIncomingMessageSize : number
8686
@@ -99,7 +99,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
9999 this . maxInboundStreams = init . maxInboundStreams ?? DEFAULT_MAX_INBOUND_STREAMS
100100 this . maxOutboundStreams = init . maxOutboundStreams ?? DEFAULT_MAX_OUTBOUND_STREAMS
101101 this . messageReceiveTimeout = init . messageReceiveTimeout ?? DEFAULT_MESSAGE_RECEIVE_TIMEOUT
102- this . runOnTransientConnections = init . runOnTransientConnections ?? DEFAULT_RUN_ON_TRANSIENT_CONNECTIONS
102+ this . runOnLimitedConnections = init . runOnLimitedConnections ?? DEFAULT_RUN_ON_TRANSIENT_CONNECTIONS
103103 this . maxIncomingMessageSize = init . maxIncomingMessageSize ?? DEFAULT_MAX_OUTGOING_MESSAGE_SIZE
104104 this . maxOutgoingMessageSize = init . maxOutgoingMessageSize ?? init . maxIncomingMessageSize ?? DEFAULT_MAX_INCOMING_MESSAGE_SIZE
105105 this . metrics = {
@@ -127,7 +127,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
127127 await this . libp2p . handle ( this . protocols , this . _onStream , {
128128 maxInboundStreams : this . maxInboundStreams ,
129129 maxOutboundStreams : this . maxOutboundStreams ,
130- runOnTransientConnection : this . runOnTransientConnections
130+ runOnLimitedConnection : this . runOnLimitedConnections
131131 } )
132132
133133 // register protocol with topology
@@ -188,7 +188,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
188188 this . log ( 'incoming new bitswap %s stream from %p' , stream . protocol , connection . remotePeer )
189189 const abortListener = ( ) : void => {
190190 if ( stream . status === 'open' ) {
191- stream . abort ( new CodeError ( `Incoming Bitswap stream timed out after ${ this . messageReceiveTimeout } ms` , 'ERR_TIMEOUT' ) )
191+ stream . abort ( new TimeoutError ( `Incoming Bitswap stream timed out after ${ this . messageReceiveTimeout } ms` ) )
192192 } else {
193193 this . log ( 'stream aborted with status %s' , stream . status )
194194 }
@@ -247,7 +247,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
247247 for await ( const provider of this . routing . findProviders ( cid , options ) ) {
248248 // make sure we can dial the provider
249249 const dialable = await this . libp2p . isDialable ( provider . multiaddrs , {
250- runOnTransientConnection : this . runOnTransientConnections
250+ runOnLimitedConnection : this . runOnLimitedConnections
251251 } )
252252
253253 if ( ! dialable ) {
@@ -300,7 +300,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
300300 const message = options ?. message
301301
302302 if ( message == null ) {
303- throw new CodeError ( 'No message to send' , 'ERR_NO_MESSAGE ')
303+ throw new InvalidParametersError ( 'No message to send' )
304304 }
305305
306306 this . log ( 'sendMessage to %p' , peerId )
@@ -337,7 +337,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
337337 */
338338 async connectTo ( peer : PeerId , options ?: AbortOptions & ProgressOptions < BitswapNetworkProgressEvents > ) : Promise < Connection > { // eslint-disable-line require-await
339339 if ( ! this . running ) {
340- throw new CodeError ( 'Network isn\'t running' , 'ERR_NOT_STARTED ')
340+ throw new NotStartedError ( 'Network isn\'t running' )
341341 }
342342
343343 options ?. onProgress ?.( new CustomProgressEvent < PeerId > ( 'bitswap:network:dial' , peer ) )
@@ -359,7 +359,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
359359 return true
360360 }
361361
362- throw new CodeError ( `${ peer } did not support ${ BITSWAP_120 } ` , 'ERR_BITSWAP_UNSUPPORTED_BY_PEER' )
362+ throw new UnsupportedProtocolError ( `${ peer } did not support ${ BITSWAP_120 } ` )
363363 }
364364 } )
365365 ] )
0 commit comments