Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set transient connection based on relay node limits #2556

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
28 changes: 28 additions & 0 deletions packages/transport-circuit-relay-v2/test/stop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection>({
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()
})
})
Loading