fix: transport manager fault tolerance should include tolerance to transport listen fail (#893)

This commit is contained in:
Vasco Santos 2021-02-25 15:23:07 +01:00 committed by GitHub
parent 4ee3e1973b
commit 3f314d5e90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -196,7 +196,7 @@ class TransportManager {
// listening on remote addresses as they may be offline. We could then potentially
// just wait for any (`p-any`) listener to succeed on each transport before returning
const isListening = results.find(r => r.isFulfilled === true)
if (!isListening) {
if (!isListening && this.faultTolerance !== FAULT_TOLERANCE.NO_FATAL) {
throw errCode(new Error(`Transport (${key}) could not listen on any available address`), codes.ERR_NO_VALID_ADDRESSES)
}
}

View File

@ -209,7 +209,7 @@ describe('libp2p.transportManager (dial only)', () => {
throw new Error('it should fail to start if multiaddr fails to listen')
})
it('does not fail to start if multiaddr fails to listen when supporting dial only mode', async () => {
it('does not fail to start if provided listen multiaddr are not compatible to configured transports (when supporting dial only mode)', async () => {
libp2p = new Libp2p({
peerId,
addresses: {
@ -226,4 +226,22 @@ describe('libp2p.transportManager (dial only)', () => {
await libp2p.start()
})
it('does not fail to start if provided listen multiaddr fail to listen on configured transports (when supporting dial only mode)', async () => {
libp2p = new Libp2p({
peerId,
addresses: {
listen: [multiaddr('/ip4/127.0.0.1/tcp/12345/p2p/QmWDn2LY8nannvSWJzruUYoLZ4vV83vfCBwd8DipvdgQc3/p2p-circuit')]
},
transportManager: {
faultTolerance: FaultTolerance.NO_FATAL
},
modules: {
transport: [Transport],
connEncryption: [Crypto]
}
})
await libp2p.start()
})
})