@libp2p/circuit-relay-v2 2.1.3-e99e8f448 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,10 @@
1
- import { KEEP_ALIVE, TypedEventEmitter, setMaxListeners } from '@libp2p/interface';
1
+ import { TypedEventEmitter, setMaxListeners } from '@libp2p/interface';
2
2
  import { PeerMap } from '@libp2p/peer-collections';
3
3
  import { createBloomFilter } from '@libp2p/utils/filters';
4
4
  import { PeerQueue } from '@libp2p/utils/peer-queue';
5
5
  import { multiaddr } from '@multiformats/multiaddr';
6
6
  import { pbStream } from 'it-protobuf-stream';
7
- import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
8
- import { DEFAULT_MAX_RESERVATION_QUEUE_LENGTH, DEFAULT_RESERVATION_COMPLETION_TIMEOUT, DEFAULT_RESERVATION_CONCURRENCY, RELAY_TAG, RELAY_V2_HOP_CODEC } from '../constants.js';
7
+ import { DEFAULT_MAX_RESERVATION_QUEUE_LENGTH, DEFAULT_RESERVATION_COMPLETION_TIMEOUT, DEFAULT_RESERVATION_CONCURRENCY, KEEP_ALIVE_TAG, RELAY_TAG, RELAY_V2_HOP_CODEC } from '../constants.js';
9
8
  import { HopMessage, Status } from '../pb/index.js';
10
9
  import { getExpirationMilliseconds } from '../utils.js';
11
10
  // allow refreshing a relay reservation if it will expire in the next 10 minutes
@@ -48,11 +47,19 @@ export class ReservationStore extends TypedEventEmitter {
48
47
  metricName: 'libp2p_relay_reservation_queue',
49
48
  metrics: components.metrics
50
49
  });
51
- // When a peer disconnects, if we had a reservation on that peer
52
- // remove the reservation and multiaddr and maybe trigger search
53
- // for new relays
54
- this.events.addEventListener('peer:disconnect', (evt) => {
55
- this.#removeRelay(evt.detail);
50
+ // reservations are only valid while we are still connected to the relay.
51
+ // if we had a reservation opened via that connection, remove it and maybe
52
+ // trigger a search for new relays
53
+ this.events.addEventListener('connection:close', (evt) => {
54
+ const reservation = [...this.reservations.values()]
55
+ .find(reservation => reservation.connection === evt.detail.id);
56
+ if (reservation == null) {
57
+ return;
58
+ }
59
+ this.#removeReservation(evt.detail.remotePeer, reservation)
60
+ .catch(err => {
61
+ this.log('could not remove relay %p - %e', evt.detail, err);
62
+ });
56
63
  });
57
64
  }
58
65
  isStarted() {
@@ -62,10 +69,32 @@ export class ReservationStore extends TypedEventEmitter {
62
69
  this.started = true;
63
70
  }
64
71
  afterStart() {
65
- if (this.reservations.size < this.maxDiscoveredRelays) {
66
- this.log('not enough relays %d/%d', this.reservations.size, this.maxDiscoveredRelays);
67
- this.safeDispatchEvent('relay:not-enough-relays', {});
68
- }
72
+ // remove old relay tags
73
+ void Promise.resolve()
74
+ .then(async () => {
75
+ const relayPeers = await this.peerStore.all({
76
+ filters: [(peer) => {
77
+ return peer.tags.has(RELAY_TAG);
78
+ }]
79
+ });
80
+ this.log('removing tag from %d old relays', relayPeers.length);
81
+ // remove old relay tag and redial
82
+ await Promise.all(relayPeers.map(async (peer) => {
83
+ await this.peerStore.merge(peer.id, {
84
+ tags: {
85
+ [RELAY_TAG]: undefined,
86
+ [KEEP_ALIVE_TAG]: undefined
87
+ }
88
+ });
89
+ }));
90
+ if (this.reservations.size < this.maxDiscoveredRelays) {
91
+ this.log('not enough relays %d/%d', this.reservations.size, this.maxDiscoveredRelays);
92
+ this.safeDispatchEvent('relay:not-enough-relays', {});
93
+ }
94
+ })
95
+ .catch(err => {
96
+ this.log.error(err);
97
+ });
69
98
  }
70
99
  stop() {
71
100
  this.reserveQueue.clear();
@@ -83,34 +112,34 @@ export class ReservationStore extends TypedEventEmitter {
83
112
  */
84
113
  async addRelay(peerId, type) {
85
114
  if (this.peerId.equals(peerId)) {
86
- this.log('not trying to use self as relay');
115
+ this.log.trace('not trying to use self as relay');
87
116
  return;
88
117
  }
89
118
  if (this.reserveQueue.size > this.maxReservationQueueLength) {
90
- this.log('not adding potential relay peer %p as the queue is full', peerId);
119
+ this.log.trace('not adding potential relay peer %p as the queue is full', peerId);
91
120
  return;
92
121
  }
93
122
  if (this.reserveQueue.has(peerId)) {
94
- this.log('potential relay peer %p is already in the reservation queue', peerId);
123
+ this.log.trace('potential relay peer %p is already in the reservation queue', peerId);
95
124
  return;
96
125
  }
97
126
  if (this.relayFilter.has(peerId.toMultihash().bytes)) {
98
- this.log('potential relay peer %p has failed previously, not trying again', peerId);
127
+ this.log.trace('potential relay peer %p has failed previously, not trying again', peerId);
99
128
  return;
100
129
  }
101
- this.log('try to reserve relay slot with %p', peerId);
130
+ this.log.trace('try to reserve relay slot with %p', peerId);
102
131
  await this.reserveQueue.add(async () => {
103
132
  const start = Date.now();
104
133
  try {
105
134
  // allow refresh of an existing reservation if it is about to expire
106
135
  const existingReservation = this.reservations.get(peerId);
107
136
  if (existingReservation != null) {
108
- if (getExpirationMilliseconds(existingReservation.reservation.expire) > REFRESH_WINDOW) {
109
- this.log('already have reservation on relay peer %p and it expires in more than 10 minutes', peerId);
137
+ if (this.connectionManager.getConnections(peerId).map(conn => conn.id).includes(existingReservation.connection) && getExpirationMilliseconds(existingReservation.reservation.expire) > REFRESH_WINDOW) {
138
+ this.log('already have relay reservation with %p but we are still connected and it does not expire soon', peerId);
110
139
  return;
111
140
  }
112
- clearTimeout(existingReservation.timeout);
113
- this.reservations.delete(peerId);
141
+ this.log('already have relay reservation with %p but the original connection is no longer open', peerId);
142
+ await this.#removeReservation(peerId, existingReservation);
114
143
  }
115
144
  if (type === 'discovered' && [...this.reservations.values()].reduce((acc, curr) => {
116
145
  if (curr.type === 'discovered') {
@@ -118,7 +147,7 @@ export class ReservationStore extends TypedEventEmitter {
118
147
  }
119
148
  return acc;
120
149
  }, 0) >= this.maxDiscoveredRelays) {
121
- this.log('already have enough discovered relays');
150
+ this.log.trace('already have enough discovered relays');
122
151
  return;
123
152
  }
124
153
  const signal = AbortSignal.timeout(this.reservationCompletionTimeout);
@@ -147,7 +176,8 @@ export class ReservationStore extends TypedEventEmitter {
147
176
  this.reservations.set(peerId, {
148
177
  timeout,
149
178
  reservation,
150
- type
179
+ type,
180
+ connection: connection.id
151
181
  });
152
182
  // ensure we don't close the connection to the relay
153
183
  await this.peerStore.merge(peerId, {
@@ -156,7 +186,7 @@ export class ReservationStore extends TypedEventEmitter {
156
186
  value: 1,
157
187
  ttl: expiration
158
188
  },
159
- [KEEP_ALIVE]: {
189
+ [KEEP_ALIVE_TAG]: {
160
190
  value: 1,
161
191
  ttl: expiration
162
192
  }
@@ -193,6 +223,11 @@ export class ReservationStore extends TypedEventEmitter {
193
223
  reservationCount() {
194
224
  return this.reservations.size;
195
225
  }
226
+ async cancelReservations() {
227
+ await Promise.all([...this.reservations.entries()].map(async ([peerId, reservation]) => {
228
+ await this.#removeReservation(peerId, reservation);
229
+ }));
230
+ }
196
231
  async #createReservation(connection, options) {
197
232
  options.signal?.throwIfAborted();
198
233
  this.log('requesting reservation from %p', connection.remotePeer);
@@ -213,21 +248,22 @@ export class ReservationStore extends TypedEventEmitter {
213
248
  await stream.close(options);
214
249
  }
215
250
  }
216
- if (response.status === Status.OK && (response.reservation != null)) {
251
+ if (response.status === Status.OK && response.reservation != null) {
217
252
  // check that the returned relay has the relay address - this can be
218
253
  // omitted when requesting a reservation from a go-libp2p relay we
219
254
  // already have a reservation on
220
- let hasRelayAddress = false;
221
- const relayAddressBytes = connection.remoteAddr.bytes;
255
+ const addresses = new Set();
256
+ addresses.add(connection.remoteAddr.toString());
222
257
  for (const buf of response.reservation.addrs) {
223
- if (uint8ArrayEquals(relayAddressBytes, buf)) {
224
- hasRelayAddress = true;
225
- break;
258
+ let ma = multiaddr(buf);
259
+ if (ma.getPeerId() == null) {
260
+ ma = ma.encapsulate(`/p2p/${connection.remotePeer}`);
226
261
  }
262
+ // TODO: workaround for https://github.com/libp2p/go-libp2p/issues/3003
263
+ ma = multiaddr(ma.toString().replace(`/p2p/${connection.remotePeer}/p2p/${connection.remotePeer}`, `/p2p/${connection.remotePeer}`));
264
+ addresses.add(ma.toString());
227
265
  }
228
- if (!hasRelayAddress) {
229
- response.reservation.addrs.push(relayAddressBytes);
230
- }
266
+ response.reservation.addrs = [...addresses].map(str => multiaddr(str).bytes);
231
267
  return response.reservation;
232
268
  }
233
269
  const errMsg = `reservation failed with status ${response.status ?? 'undefined'}`;
@@ -237,14 +273,17 @@ export class ReservationStore extends TypedEventEmitter {
237
273
  /**
238
274
  * Remove listen relay
239
275
  */
240
- #removeRelay(peerId) {
241
- const existingReservation = this.reservations.get(peerId);
242
- if (existingReservation == null) {
243
- return;
244
- }
245
- this.log('connection to relay %p closed, removing reservation from local store', peerId);
246
- clearTimeout(existingReservation.timeout);
276
+ async #removeReservation(peerId, reservation) {
277
+ this.log('removing relay reservation with %p from local store', peerId);
278
+ clearTimeout(reservation.timeout);
247
279
  this.reservations.delete(peerId);
280
+ // untag the relay
281
+ await this.peerStore.merge(peerId, {
282
+ tags: {
283
+ [RELAY_TAG]: undefined,
284
+ [KEEP_ALIVE_TAG]: undefined
285
+ }
286
+ });
248
287
  this.safeDispatchEvent('relay:removed', { detail: peerId });
249
288
  if (this.reservations.size < this.maxDiscoveredRelays) {
250
289
  this.log('not enough relays %d/%d', this.reservations.size, this.maxDiscoveredRelays);
@@ -1 +1 @@
1
- {"version":3,"file":"reservation-store.js","sourceRoot":"","sources":["../../../src/transport/reservation-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAClF,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D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2
+ "codec": "https://libp2p.github.io/js-libp2p/functions/_libp2p_circuit_relay_v2.Limit.codec.html",
3
+ "decode": "https://libp2p.github.io/js-libp2p/functions/_libp2p_circuit_relay_v2.Limit.decode.html",
4
+ "encode": "https://libp2p.github.io/js-libp2p/functions/_libp2p_circuit_relay_v2.Limit.encode.html",
5
+ "CircuitRelayServerComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.CircuitRelayServerComponents.html",
6
+ "CircuitRelayServerInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.CircuitRelayServerInit.html",
7
+ "CircuitRelayService": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.CircuitRelayService.html",
8
+ ".:CircuitRelayService": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.CircuitRelayService.html",
9
+ "CircuitRelayServiceEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.CircuitRelayServiceEvents.html",
10
+ ".:CircuitRelayServiceEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.CircuitRelayServiceEvents.html",
11
+ "CircuitRelayTransportComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.CircuitRelayTransportComponents.html",
12
+ "CircuitRelayTransportInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.CircuitRelayTransportInit.html",
13
+ "Limit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.Limit-1.html",
14
+ "RelayDiscoveryComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.RelayDiscoveryComponents.html",
15
+ "RelayReservation": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.RelayReservation.html",
16
+ ".:RelayReservation": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.RelayReservation.html",
17
+ "ServerReservationStoreInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.ServerReservationStoreInit.html",
18
+ "TransportReservationStoreInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_circuit_relay_v2.TransportReservationStoreInit.html",
19
+ "RELAY_V2_HOP_CODEC": "https://libp2p.github.io/js-libp2p/variables/_libp2p_circuit_relay_v2.RELAY_V2_HOP_CODEC.html",
20
+ "RELAY_V2_STOP_CODEC": "https://libp2p.github.io/js-libp2p/variables/_libp2p_circuit_relay_v2.RELAY_V2_STOP_CODEC.html",
21
+ "circuitRelayServer": "https://libp2p.github.io/js-libp2p/functions/_libp2p_circuit_relay_v2.circuitRelayServer.html",
22
+ "circuitRelayTransport": "https://libp2p.github.io/js-libp2p/functions/_libp2p_circuit_relay_v2.circuitRelayTransport.html"
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/circuit-relay-v2",
3
- "version": "2.1.3-e99e8f448",
3
+ "version": "2.1.4",
4
4
  "description": "Implementation of Circuit Relay v2",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-circuit-relay-v2#readme",
@@ -52,19 +52,18 @@
52
52
  "doc-check": "aegir doc-check"
53
53
  },
54
54
  "dependencies": {
55
- "@libp2p/interface": "2.1.2-e99e8f448",
56
- "@libp2p/interface-internal": "2.0.7-e99e8f448",
57
- "@libp2p/peer-collections": "6.0.7-e99e8f448",
58
- "@libp2p/peer-id": "5.0.4-e99e8f448",
59
- "@libp2p/peer-record": "8.0.7-e99e8f448",
60
- "@libp2p/utils": "6.1.0-e99e8f448",
55
+ "@libp2p/interface": "^2.1.3",
56
+ "@libp2p/interface-internal": "^2.0.8",
57
+ "@libp2p/peer-collections": "^6.0.8",
58
+ "@libp2p/peer-id": "^5.0.5",
59
+ "@libp2p/peer-record": "^8.0.8",
60
+ "@libp2p/utils": "^6.1.1",
61
61
  "@multiformats/mafmt": "^12.1.6",
62
62
  "@multiformats/multiaddr": "^12.2.3",
63
63
  "any-signal": "^4.1.1",
64
64
  "it-protobuf-stream": "^1.1.3",
65
65
  "it-stream-types": "^2.0.1",
66
66
  "multiformats": "^13.1.0",
67
- "p-defer": "^4.0.1",
68
67
  "progress-events": "^1.0.0",
69
68
  "protons-runtime": "^5.4.0",
70
69
  "race-signal": "^1.0.2",
@@ -72,9 +71,9 @@
72
71
  "uint8arrays": "^5.1.0"
73
72
  },
74
73
  "devDependencies": {
75
- "@libp2p/crypto": "5.0.4-e99e8f448",
76
- "@libp2p/interface-compliance-tests": "6.1.5-e99e8f448",
77
- "@libp2p/logger": "5.1.0-e99e8f448",
74
+ "@libp2p/crypto": "^5.0.5",
75
+ "@libp2p/interface-compliance-tests": "^6.1.6",
76
+ "@libp2p/logger": "^5.1.1",
78
77
  "aegir": "^44.0.1",
79
78
  "delay": "^6.0.0",
80
79
  "it-drain": "^3.0.7",
package/src/constants.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { KEEP_ALIVE } from '@libp2p/interface'
2
+
1
3
  const second = 1000
2
4
  const minute = 60 * second
3
5
 
@@ -27,9 +29,9 @@ export const DEFAULT_MAX_RESERVATION_TTL = 2 * 60 * minute
27
29
  export const DEFAULT_RESERVATION_CONCURRENCY = 1
28
30
 
29
31
  /**
30
- * How long to wait for a reservation attempt to finsih
32
+ * How long to wait for a reservation attempt to finish
31
33
  */
32
- export const DEFAULT_RESERVATION_COMPLETION_TIMEOUT = 1000
34
+ export const DEFAULT_RESERVATION_COMPLETION_TIMEOUT = 2000
33
35
 
34
36
  /**
35
37
  * How long to let the reservation attempt queue to grow
@@ -40,6 +42,9 @@ export const RELAY_SOURCE_TAG = 'circuit-relay-source'
40
42
 
41
43
  export const RELAY_TAG = 'circuit-relay-relay'
42
44
 
45
+ export const KEEP_ALIVE_TAG = `${KEEP_ALIVE}-circuit-relay`
46
+ export const KEEP_ALIVE_SOURCE_TAG = `${KEEP_ALIVE}-circuit-relay-source`
47
+
43
48
  // circuit v2 connection limits
44
49
  // https://github.com/libp2p/go-libp2p/blob/master/p2p/protocol/circuitv2/relay/resources.go#L61-L66
45
50
 
package/src/index.ts CHANGED
@@ -64,10 +64,10 @@ export interface CircuitRelayService extends TypedEventEmitter<CircuitRelayServi
64
64
 
65
65
  export { circuitRelayServer } from './server/index.js'
66
66
  export type { CircuitRelayServerInit, CircuitRelayServerComponents } from './server/index.js'
67
- export type { ReservationStoreInit } from './server/reservation-store.js'
67
+ export type { ReservationStoreInit as ServerReservationStoreInit } from './server/reservation-store.js'
68
68
  export { circuitRelayTransport } from './transport/index.js'
69
69
  export type { RelayDiscoveryComponents } from './transport/discovery.js'
70
- export type { RelayStoreInit } from './transport/reservation-store.js'
70
+ export type { ReservationStoreInit as TransportReservationStoreInit } from './transport/reservation-store.js'
71
71
  export type { CircuitRelayTransportInit, CircuitRelayTransportComponents } from './transport/index.js'
72
72
 
73
73
  export {
@@ -4,10 +4,10 @@ import { RecordEnvelope } from '@libp2p/peer-record'
4
4
  import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'
5
5
  import { pbStream, type ProtobufStream } from 'it-protobuf-stream'
6
6
  import * as Digest from 'multiformats/hashes/digest'
7
- import pDefer from 'p-defer'
8
7
  import {
9
8
  CIRCUIT_PROTO_CODE,
10
9
  DEFAULT_HOP_TIMEOUT,
10
+ KEEP_ALIVE_SOURCE_TAG,
11
11
  MAX_CONNECTIONS,
12
12
  RELAY_SOURCE_TAG,
13
13
  RELAY_V2_HOP_CODEC,
@@ -18,7 +18,7 @@ import { createLimitedRelay } from '../utils.js'
18
18
  import { ReservationStore, type ReservationStoreInit } from './reservation-store.js'
19
19
  import { ReservationVoucherRecord } from './reservation-voucher.js'
20
20
  import type { CircuitRelayService, RelayReservation } from '../index.js'
21
- import type { ComponentLogger, Logger, Connection, Stream, ConnectionGater, PeerId, PeerStore, Startable, PrivateKey, Metrics } from '@libp2p/interface'
21
+ import type { ComponentLogger, Logger, Connection, Stream, ConnectionGater, PeerId, PeerStore, Startable, PrivateKey, Metrics, AbortOptions } from '@libp2p/interface'
22
22
  import type { AddressManager, ConnectionManager, IncomingStreamData, Registrar } from '@libp2p/interface-internal'
23
23
  import type { PeerMap } from '@libp2p/peer-collections'
24
24
 
@@ -175,17 +175,13 @@ class CircuitRelayServer extends TypedEventEmitter<RelayServerEvents> implements
175
175
  async onHop ({ connection, stream }: IncomingStreamData): Promise<void> {
176
176
  this.log('received circuit v2 hop protocol stream from %p', connection.remotePeer)
177
177
 
178
- const hopTimeoutPromise = pDefer<HopMessage>()
179
- const timeout = setTimeout(() => {
180
- hopTimeoutPromise.reject('timed out')
181
- }, this.hopTimeout)
178
+ const options = {
179
+ signal: AbortSignal.timeout(this.hopTimeout)
180
+ }
182
181
  const pbstr = pbStream(stream)
183
182
 
184
183
  try {
185
- const request: HopMessage = await Promise.race([
186
- pbstr.pb(HopMessage).read(),
187
- hopTimeoutPromise.promise
188
- ])
184
+ const request: HopMessage = await pbstr.pb(HopMessage).read(options)
189
185
 
190
186
  if (request?.type == null) {
191
187
  throw new Error('request was invalid, could not read from stream')
@@ -193,31 +189,26 @@ class CircuitRelayServer extends TypedEventEmitter<RelayServerEvents> implements
193
189
 
194
190
  this.log('received', request.type)
195
191
 
196
- await Promise.race([
197
- this.handleHopProtocol({
198
- connection,
199
- stream: pbstr,
200
- request
201
- }),
202
- hopTimeoutPromise.promise
203
- ])
192
+ await this.handleHopProtocol({
193
+ connection,
194
+ stream: pbstr,
195
+ request
196
+ }, options)
204
197
  } catch (err: any) {
205
198
  this.log.error('error while handling hop', err)
206
199
  await pbstr.pb(HopMessage).write({
207
200
  type: HopMessage.Type.STATUS,
208
201
  status: Status.MALFORMED_MESSAGE
209
- })
202
+ }, options)
210
203
  stream.abort(err)
211
- } finally {
212
- clearTimeout(timeout)
213
204
  }
214
205
  }
215
206
 
216
- async handleHopProtocol ({ stream, request, connection }: HopProtocolOptions): Promise<void> {
207
+ async handleHopProtocol ({ stream, request, connection }: HopProtocolOptions, options: AbortOptions): Promise<void> {
217
208
  this.log('received hop message')
218
209
  switch (request.type) {
219
- case HopMessage.Type.RESERVE: await this.handleReserve({ stream, request, connection }); break
220
- case HopMessage.Type.CONNECT: await this.handleConnect({ stream, request, connection }); break
210
+ case HopMessage.Type.RESERVE: await this.handleReserve({ stream, request, connection }, options); break
211
+ case HopMessage.Type.CONNECT: await this.handleConnect({ stream, request, connection }, options); break
221
212
  default: {
222
213
  this.log.error('invalid hop request type %s via peer %p', request.type, connection.remotePeer)
223
214
  await stream.pb(HopMessage).write({ type: HopMessage.Type.STATUS, status: Status.UNEXPECTED_MESSAGE })
@@ -225,37 +216,38 @@ class CircuitRelayServer extends TypedEventEmitter<RelayServerEvents> implements
225
216
  }
226
217
  }
227
218
 
228
- async handleReserve ({ stream, request, connection }: HopProtocolOptions): Promise<void> {
219
+ async handleReserve ({ stream, connection }: HopProtocolOptions, options: AbortOptions): Promise<void> {
229
220
  const hopstr = stream.pb(HopMessage)
230
221
  this.log('hop reserve request from %p', connection.remotePeer)
231
222
 
232
223
  if (isRelayAddr(connection.remoteAddr)) {
233
224
  this.log.error('relay reservation over circuit connection denied for peer: %p', connection.remotePeer)
234
- await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.PERMISSION_DENIED })
225
+ await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.PERMISSION_DENIED }, options)
235
226
  return
236
227
  }
237
228
 
238
229
  if ((await this.connectionGater.denyInboundRelayReservation?.(connection.remotePeer)) === true) {
239
230
  this.log.error('reservation for %p denied by connection gater', connection.remotePeer)
240
- await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.PERMISSION_DENIED })
231
+ await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.PERMISSION_DENIED }, options)
241
232
  return
242
233
  }
243
234
 
244
235
  const result = this.reservationStore.reserve(connection.remotePeer, connection.remoteAddr)
245
236
 
246
- if (result.status !== Status.OK) {
247
- await hopstr.write({ type: HopMessage.Type.STATUS, status: result.status })
248
- return
249
- }
250
-
251
237
  try {
238
+ if (result.status !== Status.OK) {
239
+ await hopstr.write({ type: HopMessage.Type.STATUS, status: result.status }, options)
240
+ return
241
+ }
242
+
252
243
  // tag relay target peer
253
244
  // result.expire is non-null if `ReservationStore.reserve` returns with status == OK
254
245
  if (result.expire != null) {
255
246
  const ttl = (result.expire * 1000) - Date.now()
256
247
  await this.peerStore.merge(connection.remotePeer, {
257
248
  tags: {
258
- [RELAY_SOURCE_TAG]: { value: 1, ttl }
249
+ [RELAY_SOURCE_TAG]: { value: 1, ttl },
250
+ [KEEP_ALIVE_SOURCE_TAG]: { value: 1, ttl }
259
251
  }
260
252
  })
261
253
  }
@@ -265,11 +257,22 @@ class CircuitRelayServer extends TypedEventEmitter<RelayServerEvents> implements
265
257
  status: Status.OK,
266
258
  reservation: await this.makeReservation(connection.remotePeer, BigInt(result.expire ?? 0)),
267
259
  limit: this.reservationStore.get(connection.remotePeer)?.limit
268
- })
260
+ }, options)
269
261
  this.log('sent confirmation response to %s', connection.remotePeer)
270
262
  } catch (err) {
271
- this.log.error('failed to send confirmation response to %p', connection.remotePeer, err)
263
+ this.log.error('failed to send confirmation response to %p - %e', connection.remotePeer, err)
272
264
  this.reservationStore.removeReservation(connection.remotePeer)
265
+
266
+ try {
267
+ await this.peerStore.merge(connection.remotePeer, {
268
+ tags: {
269
+ [RELAY_SOURCE_TAG]: undefined,
270
+ [KEEP_ALIVE_SOURCE_TAG]: undefined
271
+ }
272
+ })
273
+ } catch (err) {
274
+ this.log.error('failed to untag relay source peer %p - %e', connection.remotePeer, err)
275
+ }
273
276
  }
274
277
  }
275
278
 
@@ -300,12 +303,12 @@ class CircuitRelayServer extends TypedEventEmitter<RelayServerEvents> implements
300
303
  }
301
304
  }
302
305
 
303
- async handleConnect ({ stream, request, connection }: HopProtocolOptions): Promise<void> {
306
+ async handleConnect ({ stream, request, connection }: HopProtocolOptions, options: AbortOptions): Promise<void> {
304
307
  const hopstr = stream.pb(HopMessage)
305
308
 
306
309
  if (isRelayAddr(connection.remoteAddr)) {
307
310
  this.log.error('relay reservation over circuit connection denied for peer: %p', connection.remotePeer)
308
- await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.PERMISSION_DENIED })
311
+ await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.PERMISSION_DENIED }, options)
309
312
  return
310
313
  }
311
314
 
@@ -323,19 +326,19 @@ class CircuitRelayServer extends TypedEventEmitter<RelayServerEvents> implements
323
326
  dstPeer = peerIdFromMultihash(Digest.decode(request.peer.id))
324
327
  } catch (err) {
325
328
  this.log.error('invalid hop connect request via peer %p %s', connection.remotePeer, err)
326
- await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.MALFORMED_MESSAGE })
329
+ await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.MALFORMED_MESSAGE }, options)
327
330
  return
328
331
  }
329
332
 
330
333
  if (!this.reservationStore.hasReservation(dstPeer)) {
331
334
  this.log.error('hop connect denied for destination peer %p not having a reservation for %p with status %s', dstPeer, connection.remotePeer, Status.NO_RESERVATION)
332
- await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.NO_RESERVATION })
335
+ await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.NO_RESERVATION }, options)
333
336
  return
334
337
  }
335
338
 
336
339
  if ((await this.connectionGater.denyOutboundRelayedConnection?.(connection.remotePeer, dstPeer)) === true) {
337
340
  this.log.error('hop connect for %p to %p denied by connection gater', connection.remotePeer, dstPeer)
338
- await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.PERMISSION_DENIED })
341
+ await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.PERMISSION_DENIED }, options)
339
342
  return
340
343
  }
341
344
 
@@ -343,7 +346,7 @@ class CircuitRelayServer extends TypedEventEmitter<RelayServerEvents> implements
343
346
 
344
347
  if (connections.length === 0) {
345
348
  this.log('hop connect denied for destination peer %p not having a connection for %p as there is no destination connection', dstPeer, connection.remotePeer)
346
- await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.NO_RESERVATION })
349
+ await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.NO_RESERVATION }, options)
347
350
  return
348
351
  }
349
352
 
@@ -360,11 +363,11 @@ class CircuitRelayServer extends TypedEventEmitter<RelayServerEvents> implements
360
363
  },
361
364
  limit
362
365
  }
363
- })
366
+ }, options)
364
367
 
365
368
  if (destinationStream == null) {
366
369
  this.log.error('failed to open stream to destination peer %p', destinationConnection?.remotePeer)
367
- await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.CONNECTION_FAILED })
370
+ await hopstr.write({ type: HopMessage.Type.STATUS, status: Status.CONNECTION_FAILED }, options)
368
371
  return
369
372
  }
370
373
 
@@ -372,7 +375,7 @@ class CircuitRelayServer extends TypedEventEmitter<RelayServerEvents> implements
372
375
  type: HopMessage.Type.STATUS,
373
376
  status: Status.OK,
374
377
  limit
375
- })
378
+ }, options)
376
379
  const sourceStream = stream.unwrap()
377
380
 
378
381
  this.log('connection from %p to %p established - merging streams', connection.remotePeer, dstPeer)
@@ -385,29 +388,27 @@ class CircuitRelayServer extends TypedEventEmitter<RelayServerEvents> implements
385
388
  /**
386
389
  * Send a STOP request to the target peer that the dialing peer wants to contact
387
390
  */
388
- async stopHop ({
389
- connection,
390
- request
391
- }: StopOptions): Promise<Stream | undefined> {
391
+ async stopHop ({ connection, request }: StopOptions, options: AbortOptions): Promise<Stream | undefined> {
392
392
  this.log('starting circuit relay v2 stop request to %s', connection.remotePeer)
393
393
  const stream = await connection.newStream([RELAY_V2_STOP_CODEC], {
394
394
  maxOutboundStreams: this.maxOutboundStopStreams,
395
- runOnLimitedConnection: true
395
+ runOnLimitedConnection: true,
396
+ ...options
396
397
  })
397
398
  const pbstr = pbStream(stream)
398
399
  const stopstr = pbstr.pb(StopMessage)
399
- await stopstr.write(request)
400
+ await stopstr.write(request, options)
400
401
  let response
401
402
 
402
403
  try {
403
- response = await stopstr.read()
404
+ response = await stopstr.read(options)
404
405
  } catch (err) {
405
406
  this.log.error('error parsing stop message response from %p', connection.remotePeer)
406
407
  }
407
408
 
408
409
  if (response == null) {
409
410
  this.log.error('could not read response from %p', connection.remotePeer)
410
- await stream.close()
411
+ await stream.close(options)
411
412
  return
412
413
  }
413
414
 
@@ -417,7 +418,7 @@ class CircuitRelayServer extends TypedEventEmitter<RelayServerEvents> implements
417
418
  }
418
419
 
419
420
  this.log('stop request failed with code %d', response.status)
420
- await stream.close()
421
+ await stream.close(options)
421
422
  }
422
423
 
423
424
  get reservations (): PeerMap<RelayReservation> {