diff --git a/packages/transport-circuit-relay-v2/src/transport/transport.ts b/packages/transport-circuit-relay-v2/src/transport/transport.ts index cc1978276b..e4cfdca724 100644 --- a/packages/transport-circuit-relay-v2/src/transport/transport.ts +++ b/packages/transport-circuit-relay-v2/src/transport/transport.ts @@ -233,7 +233,7 @@ export class CircuitRelayTransport implements Transport { this.log('new outbound transient connection %a', maConn.remoteAddr) return await this.upgrader.upgradeOutbound(maConn, { - transient: true + transient: status.limit !== undefined }) } catch (err: any) { this.log.error(`Circuit relay dial to destination ${destinationPeer.toString()} via relay ${connection.remotePeer.toString()} failed`, err) @@ -348,7 +348,7 @@ export class CircuitRelayTransport implements Transport { this.log('new inbound transient connection %a', maConn.remoteAddr) await this.upgrader.upgradeInbound(maConn, { - transient: true + transient: request.limit !== undefined }) this.log('%s connection %a upgraded', 'inbound', maConn.remoteAddr) } diff --git a/packages/transport-circuit-relay-v2/test/stop.spec.ts b/packages/transport-circuit-relay-v2/test/stop.spec.ts index 57a9926754..a068202a34 100644 --- a/packages/transport-circuit-relay-v2/test/stop.spec.ts +++ b/packages/transport-circuit-relay-v2/test/stop.spec.ts @@ -194,4 +194,32 @@ describe('circuit-relay stop protocol', function () { 'did not dial relay we did not have a reservation on' ) }) + + it('Should not be a transient connection if the relay has no limit', async () => { + const remotePeer = await createEd25519PeerId() + const remoteAddr = multiaddr(`/ip4/127.0.0.1/tcp/4001/p2p/${remotePeer}`) + + transport.reservationStore.hasReservation = Sinon.stub().returns(false) + const connection = stubInterface({ + remotePeer, + remoteAddr + }) + + components.transportManager.listen.returns(Promise.resolve()) + + void transport.onStop({ + connection, + stream: remoteStream + }) + + await pbstr.write({ + type: StopMessage.Type.CONNECT, + peer: { + id: sourcePeer.toBytes(), + addrs: [] + } + }) + + expect(connection.transient).to.be.false() + }) })