@@ -2,7 +2,7 @@ import { FaultTolerance, InvalidParametersError, NotStartedError } from '@libp2p
2
2
import { trackedMap } from '@libp2p/utils/tracked-map'
3
3
import { IP4 , IP6 } from '@multiformats/multiaddr-matcher'
4
4
import { CustomProgressEvent } from 'progress-events'
5
- import { NoValidAddressesError , TransportUnavailableError } from './errors.js'
5
+ import { TransportUnavailableError , UnsupportedListenAddressError , UnsupportedListenAddressesError } from './errors.js'
6
6
import type { Libp2pEvents , ComponentLogger , Logger , Connection , TypedEventTarget , Metrics , Startable , Listener , Transport , Upgrader } from '@libp2p/interface'
7
7
import type { AddressManager , TransportManager , TransportManagerDialOptions } from '@libp2p/interface-internal'
8
8
import type { Multiaddr } from '@multiformats/multiaddr'
@@ -25,7 +25,7 @@ interface IPStats {
25
25
}
26
26
27
27
interface ListenStats {
28
- unsupportedAddresses : Set < string >
28
+ errors : Map < string , Error >
29
29
ipv4 : IPStats
30
30
ipv6 : IPStats
31
31
}
@@ -207,9 +207,7 @@ export class DefaultTransportManager implements TransportManager, Startable {
207
207
// track IPv4/IPv6 results - if we succeed on IPv4 but all IPv6 attempts
208
208
// fail then we are probably on a network without IPv6 support
209
209
const listenStats : ListenStats = {
210
- unsupportedAddresses : new Set (
211
- addrs . map ( ma => ma . toString ( ) )
212
- ) ,
210
+ errors : new Map ( ) ,
213
211
ipv4 : {
214
212
success : 0 ,
215
213
attempts : 0
@@ -220,6 +218,10 @@ export class DefaultTransportManager implements TransportManager, Startable {
220
218
}
221
219
}
222
220
221
+ addrs . forEach ( ma => {
222
+ listenStats . errors . set ( ma . toString ( ) , new UnsupportedListenAddressError ( ) )
223
+ } )
224
+
223
225
const tasks : Array < Promise < void > > = [ ]
224
226
225
227
for ( const [ key , transport ] of this . transports . entries ( ) ) {
@@ -269,7 +271,7 @@ export class DefaultTransportManager implements TransportManager, Startable {
269
271
tasks . push (
270
272
listener . listen ( addr )
271
273
. then ( ( ) => {
272
- listenStats . unsupportedAddresses . delete ( addr . toString ( ) )
274
+ listenStats . errors . delete ( addr . toString ( ) )
273
275
274
276
if ( IP4 . matches ( addr ) ) {
275
277
listenStats . ipv4 . success ++
@@ -280,6 +282,7 @@ export class DefaultTransportManager implements TransportManager, Startable {
280
282
}
281
283
} , ( err ) => {
282
284
this . log . error ( 'transport %s could not listen on address %a - %e' , key , addr , err )
285
+ listenStats . errors . set ( addr . toString ( ) , err )
283
286
throw err
284
287
} )
285
288
)
@@ -308,9 +311,13 @@ export class DefaultTransportManager implements TransportManager, Startable {
308
311
}
309
312
310
313
// if a configured address was not able to be listened on, throw an error
311
- throw new NoValidAddressesError ( `No configured transport could listen on these addresses, please remove them from your config: ${ [
312
- ...listenStats . unsupportedAddresses
313
- ] . join ( ', ' ) } `)
314
+ throw new UnsupportedListenAddressesError ( `Some configured addresses failed to be listened on, you may need to remove one or more listen addresses from your configuration or set \`transportManager.faultTolerance\` to NO_FATAL:\n${
315
+ [ ...listenStats . errors . entries ( ) ] . map ( ( [ addr , err ] ) => {
316
+ return `
317
+ ${ addr } : ${ `${ err . stack ?? err } ` . split ( '\n' ) . join ( '\n ' ) }
318
+ `
319
+ } ) . join ( '' )
320
+ } `)
314
321
}
315
322
316
323
private ipv6Unsupported ( listenStats : ListenStats ) : boolean {
0 commit comments