Skip to content

Commit

Permalink
fix: query for circuit relays after start (#2309)
Browse files Browse the repository at this point in the history
This should be done in the `afterStart` method otherwise the DHT
query manager may not have been started yet.
  • Loading branch information
achingbrain authored Dec 18, 2023
1 parent 984f13e commit dc56856
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ export class RelayDiscovery extends TypedEventEmitter<RelayDiscoveryEvents> impl
}
})

this.started = true
}

afterStart (): void {
void this.discover()
.catch(err => {
this.log.error('error listening on relays', err)
this.log.error('error discovering relays', err)
})

this.started = true
}

stop (): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ export class ReservationStore extends TypedEventEmitter<ReservationStoreEvents>
return this.started
}

async start (): Promise<void> {
start (): void {
this.started = true
}

async stop (): Promise<void> {
stop (): void {
this.reserveQueue.clear()
this.reservations.forEach(({ timeout }) => {
clearTimeout(timeout)
Expand Down
11 changes: 8 additions & 3 deletions packages/transport-circuit-relay-v2/src/transport/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ export class CircuitRelayTransport implements Transport {
}

async start (): Promise<void> {
await this.reservationStore.start()
await this.discovery?.start()
this.reservationStore.start()

await this.registrar.handle(RELAY_V2_STOP_CODEC, (data) => {
void this.onStop(data).catch(err => {
Expand All @@ -117,12 +116,18 @@ export class CircuitRelayTransport implements Transport {
runOnTransientConnection: true
})

await this.discovery?.start()

this.started = true
}

afterStart (): void {
this.discovery?.afterStart()
}

async stop (): Promise<void> {
this.discovery?.stop()
await this.reservationStore.stop()
this.reservationStore.stop()
await this.registrar.unhandle(RELAY_V2_STOP_CODEC)

this.started = false
Expand Down

0 comments on commit dc56856

Please sign in to comment.