@libp2p/webtransport 3.0.11 → 3.1.0-972b10a9

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,10 +1,15 @@
1
1
  import { type Transport } from '@libp2p/interface/transport';
2
+ import type { CounterGroup, Metrics } from '@libp2p/interface/metrics';
2
3
  import type { PeerId } from '@libp2p/interface/peer-id';
3
4
  export interface WebTransportInit {
4
5
  maxInboundStreams?: number;
5
6
  }
6
7
  export interface WebTransportComponents {
7
8
  peerId: PeerId;
9
+ metrics?: Metrics;
10
+ }
11
+ export interface WebTransportMetrics {
12
+ dialerEvents: CounterGroup;
8
13
  }
9
14
  export declare function webTransport(init?: WebTransportInit): (components: WebTransportComponents) => Transport;
10
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAuE,MAAM,6BAA6B,CAAA;AAQjI,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAWvD,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAA;CACf;AA+RD,wBAAgB,YAAY,CAAE,IAAI,GAAE,gBAAqB,GAAG,CAAC,UAAU,EAAE,sBAAsB,KAAK,SAAS,CAE5G"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAuE,MAAM,6BAA6B,CAAA;AASjI,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAWvD,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,YAAY,CAAA;CAC3B;AA+SD,wBAAgB,YAAY,CAAE,IAAI,GAAE,gBAAqB,GAAG,CAAC,UAAU,EAAE,sBAAsB,KAAK,SAAS,CAE5G"}
package/dist/src/index.js CHANGED
@@ -2,6 +2,7 @@ import { noise } from '@chainsafe/libp2p-noise';
2
2
  import { symbol } from '@libp2p/interface/transport';
3
3
  import { logger } from '@libp2p/logger';
4
4
  import {} from '@multiformats/multiaddr';
5
+ import { WebTransport as WebTransportMatcher } from '@multiformats/multiaddr-matcher';
5
6
  import { webtransportBiDiStreamToStream } from './stream.js';
6
7
  import { inertDuplex } from './utils/inert-duplex.js';
7
8
  import { isSubset } from './utils/is-subset.js';
@@ -10,11 +11,20 @@ const log = logger('libp2p:webtransport');
10
11
  class WebTransportTransport {
11
12
  components;
12
13
  config;
14
+ metrics;
13
15
  constructor(components, init = {}) {
14
16
  this.components = components;
15
17
  this.config = {
16
18
  maxInboundStreams: init.maxInboundStreams ?? 1000
17
19
  };
20
+ if (components.metrics != null) {
21
+ this.metrics = {
22
+ dialerEvents: components.metrics.registerCounterGroup('libp2p_webtransport_dialer_events_total', {
23
+ label: 'event',
24
+ help: 'Total count of WebTransport dialer events by type'
25
+ })
26
+ };
27
+ }
18
28
  }
19
29
  [Symbol.toStringTag] = '@libp2p/webtransport';
20
30
  [symbol] = true;
@@ -36,75 +46,74 @@ class WebTransportTransport {
36
46
  let abortListener;
37
47
  let maConn;
38
48
  let cleanUpWTSession = () => { };
49
+ let closed = false;
50
+ let ready = false;
51
+ let authenticated = false;
39
52
  try {
40
- let closed = false;
53
+ this.metrics?.dialerEvents.increment({ pending: true });
41
54
  const wt = new WebTransport(`${url}/.well-known/libp2p-webtransport?type=noise`, {
42
55
  serverCertificateHashes: certhashes.map(certhash => ({
43
56
  algorithm: 'sha-256',
44
57
  value: certhash.digest
45
58
  }))
46
59
  });
47
- cleanUpWTSession = (closeInfo) => {
60
+ cleanUpWTSession = (metric) => {
61
+ if (closed) {
62
+ // already closed session
63
+ return;
64
+ }
48
65
  try {
49
- if (maConn != null) {
50
- if (maConn.timeline.close != null) {
51
- // already closed session
52
- return;
53
- }
54
- // This is how we specify the connection is closed and shouldn't be used.
55
- maConn.timeline.close = Date.now();
56
- }
57
- if (closed) {
58
- // already closed session
59
- return;
60
- }
61
- wt.close(closeInfo);
66
+ this.metrics?.dialerEvents.increment({ [metric]: true });
67
+ wt.close();
62
68
  }
63
69
  catch (err) {
64
70
  log.error('error closing wt session', err);
65
71
  }
66
72
  finally {
73
+ // This is how we specify the connection is closed and shouldn't be used.
74
+ if (maConn != null) {
75
+ maConn.timeline.close = Date.now();
76
+ }
67
77
  closed = true;
68
78
  }
69
79
  };
70
- // this promise resolves/throws when the session is closed or failed to init
71
- wt.closed
72
- .then(async () => {
73
- await maConn?.close();
74
- })
75
- .catch((err) => {
76
- log.error('error on remote wt session close', err);
77
- maConn?.abort(err);
78
- })
79
- .finally(() => {
80
- // if we never got as far as creating the maConn, just clean up the session
81
- if (maConn == null) {
82
- cleanUpWTSession();
83
- }
84
- });
85
80
  // if the dial is aborted before we are ready, close the WebTransport session
86
81
  abortListener = () => {
87
- if (abortListener != null) {
88
- options.signal?.removeEventListener('abort', abortListener);
82
+ if (ready) {
83
+ cleanUpWTSession('noise_timeout');
84
+ }
85
+ else {
86
+ cleanUpWTSession('ready_timeout');
89
87
  }
90
- cleanUpWTSession();
91
88
  };
92
- options.signal?.addEventListener('abort', abortListener);
93
- await wt.ready;
89
+ options.signal?.addEventListener('abort', abortListener, {
90
+ once: true
91
+ });
92
+ await Promise.race([
93
+ wt.closed,
94
+ wt.ready
95
+ ]);
96
+ ready = true;
97
+ this.metrics?.dialerEvents.increment({ ready: true });
98
+ // this promise resolves/throws when the session is closed
99
+ wt.closed.catch((err) => {
100
+ log.error('error on remote wt session close', err);
101
+ })
102
+ .finally(() => {
103
+ cleanUpWTSession('remote_close');
104
+ });
94
105
  if (!await this.authenticateWebTransport(wt, localPeer, remotePeer, certhashes)) {
95
106
  throw new Error('Failed to authenticate webtransport');
96
107
  }
108
+ this.metrics?.dialerEvents.increment({ open: true });
97
109
  maConn = {
98
- close: async (options) => {
110
+ close: async () => {
99
111
  log('Closing webtransport');
100
- cleanUpWTSession();
112
+ cleanUpWTSession('close');
101
113
  },
102
114
  abort: (err) => {
103
115
  log('aborting webtransport due to passed err', err);
104
- cleanUpWTSession({
105
- closeCode: 0,
106
- reason: err.message
107
- });
116
+ cleanUpWTSession('abort');
108
117
  },
109
118
  remoteAddr: ma,
110
119
  timeline: {
@@ -113,15 +122,20 @@ class WebTransportTransport {
113
122
  // This connection is never used directly since webtransport supports native streams.
114
123
  ...inertDuplex()
115
124
  };
116
- options?.signal?.throwIfAborted();
117
- return await options.upgrader.upgradeOutbound(maConn, { skipEncryption: true, muxerFactory: this.webtransportMuxer(wt, cleanUpWTSession), skipProtection: true });
125
+ authenticated = true;
126
+ return await options.upgrader.upgradeOutbound(maConn, { skipEncryption: true, muxerFactory: this.webtransportMuxer(wt), skipProtection: true });
118
127
  }
119
128
  catch (err) {
120
129
  log.error('caught wt session err', err);
121
- cleanUpWTSession({
122
- closeCode: 0,
123
- reason: err.message
124
- });
130
+ if (authenticated) {
131
+ cleanUpWTSession('upgrade_error');
132
+ }
133
+ else if (ready) {
134
+ cleanUpWTSession('noise_error');
135
+ }
136
+ else {
137
+ cleanUpWTSession('ready_error');
138
+ }
125
139
  throw err;
126
140
  }
127
141
  finally {
@@ -168,7 +182,7 @@ class WebTransportTransport {
168
182
  }
169
183
  return true;
170
184
  }
171
- webtransportMuxer(wt, cleanUpWTSession) {
185
+ webtransportMuxer(wt) {
172
186
  let streamIDCounter = 0;
173
187
  const config = this.config;
174
188
  return {
@@ -220,14 +234,13 @@ class WebTransportTransport {
220
234
  */
221
235
  close: async (options) => {
222
236
  log('Closing webtransport muxer');
223
- cleanUpWTSession();
237
+ await Promise.all(activeStreams.map(async (s) => s.close(options)));
224
238
  },
225
239
  abort: (err) => {
226
240
  log('Aborting webtransport muxer with err:', err);
227
- cleanUpWTSession({
228
- closeCode: 0,
229
- reason: err.message
230
- });
241
+ for (const stream of activeStreams) {
242
+ stream.abort(err);
243
+ }
231
244
  },
232
245
  // This stream muxer is webtransport native. Therefore it doesn't plug in with any other duplex.
233
246
  ...inertDuplex()
@@ -243,7 +256,7 @@ class WebTransportTransport {
243
256
  * Takes a list of `Multiaddr`s and returns only valid webtransport addresses.
244
257
  */
245
258
  filter(multiaddrs) {
246
- return multiaddrs.filter(ma => ma.protoNames().includes('webtransport'));
259
+ return multiaddrs.filter(WebTransportMatcher.exactMatch);
247
260
  }
248
261
  }
249
262
  export function webTransport(init = {}) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC/C,OAAO,EAAkB,MAAM,EAA+D,MAAM,6BAA6B,CAAA;AACjI,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAqC,MAAM,yBAAyB,CAAA;AAC3E,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAW3D,MAAM,GAAG,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAA;AAUzC,MAAM,qBAAqB;IACR,UAAU,CAAwB;IAClC,MAAM,CAA4B;IAEnD,YAAa,UAAkC,EAAE,OAAyB,EAAE;QAC1E,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;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,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAC/C,CAAA;oBACH,CAAC;oBACD,KAAK,EAAE,CAAC,GAAU,EAAE,EAAE;wBACpB,GAAG,CAAC,uCAAuC,EAAE,GAAG,CAAC,CAAA;wBAEjD,KAAK,MAAM,MAAM,IAAI,aAAa,EAAE;4BAClC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;yBAClB;oBACH,CAAC;oBACD,gGAAgG;oBAChG,GAAG,WAAW,EAAE;iBACjB,CAAA;gBAED,OAAO,KAAK,CAAA;YACd,CAAC;SACF,CAAA;IACH,CAAC;IAED,cAAc,CAAE,OAA8B;QAC5C,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAA;IAClF,CAAC;IAED;;OAEG;IACH,MAAM,CAAE,UAAuB;QAC7B,OAAO,UAAU,CAAC,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAA;IAC1D,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAAE,OAAyB,EAAE;IACvD,OAAO,CAAC,UAAkC,EAAE,EAAE,CAAC,IAAI,qBAAqB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AAC5F,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/webtransport",
3
- "version": "3.0.11",
3
+ "version": "3.1.0-972b10a9",
4
4
  "description": "JavaScript implementation of the WebTransport module that libp2p uses and that implements the interface-transport spec",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/transport-webtransport#readme",
@@ -61,9 +61,9 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "@chainsafe/libp2p-noise": "^13.0.0",
64
- "@libp2p/interface": "^0.1.2",
65
- "@libp2p/logger": "^3.0.2",
66
- "@libp2p/peer-id": "^3.0.2",
64
+ "@libp2p/interface": "0.1.2-972b10a9",
65
+ "@libp2p/logger": "3.0.2-972b10a9",
66
+ "@libp2p/peer-id": "3.0.2-972b10a9",
67
67
  "@multiformats/multiaddr": "^12.1.5",
68
68
  "@multiformats/multiaddr-matcher": "^1.0.1",
69
69
  "it-stream-types": "^2.0.1",
@@ -72,8 +72,9 @@
72
72
  "uint8arrays": "^4.0.6"
73
73
  },
74
74
  "devDependencies": {
75
+ "@libp2p/peer-id-factory": "3.0.4-972b10a9",
75
76
  "aegir": "^40.0.8",
76
- "libp2p": "^0.46.11",
77
+ "libp2p": "0.46.11-972b10a9",
77
78
  "p-defer": "^4.0.0"
78
79
  },
79
80
  "browser": {
package/src/index.ts CHANGED
@@ -2,18 +2,20 @@ import { noise } from '@chainsafe/libp2p-noise'
2
2
  import { type Transport, symbol, type CreateListenerOptions, type DialOptions, type Listener } from '@libp2p/interface/transport'
3
3
  import { logger } from '@libp2p/logger'
4
4
  import { type Multiaddr, type AbortOptions } from '@multiformats/multiaddr'
5
+ import { WebTransport as WebTransportMatcher } from '@multiformats/multiaddr-matcher'
5
6
  import { webtransportBiDiStreamToStream } from './stream.js'
6
7
  import { inertDuplex } from './utils/inert-duplex.js'
7
8
  import { isSubset } from './utils/is-subset.js'
8
9
  import { parseMultiaddr } from './utils/parse-multiaddr.js'
9
10
  import type { Connection, MultiaddrConnection, Stream } from '@libp2p/interface/connection'
11
+ import type { CounterGroup, Metrics } from '@libp2p/interface/metrics'
10
12
  import type { PeerId } from '@libp2p/interface/peer-id'
11
13
  import type { StreamMuxerFactory, StreamMuxerInit, StreamMuxer } from '@libp2p/interface/stream-muxer'
12
14
  import type { Source } from 'it-stream-types'
13
15
  import type { MultihashDigest } from 'multiformats/hashes/interface'
14
16
 
15
17
  interface WebTransportSessionCleanup {
16
- (closeInfo?: WebTransportCloseInfo): void
18
+ (metric: string): void
17
19
  }
18
20
 
19
21
  const log = logger('libp2p:webtransport')
@@ -24,17 +26,32 @@ export interface WebTransportInit {
24
26
 
25
27
  export interface WebTransportComponents {
26
28
  peerId: PeerId
29
+ metrics?: Metrics
30
+ }
31
+
32
+ export interface WebTransportMetrics {
33
+ dialerEvents: CounterGroup
27
34
  }
28
35
 
29
36
  class WebTransportTransport implements Transport {
30
37
  private readonly components: WebTransportComponents
31
38
  private readonly config: Required<WebTransportInit>
39
+ private readonly metrics?: WebTransportMetrics
32
40
 
33
41
  constructor (components: WebTransportComponents, init: WebTransportInit = {}) {
34
42
  this.components = components
35
43
  this.config = {
36
44
  maxInboundStreams: init.maxInboundStreams ?? 1000
37
45
  }
46
+
47
+ if (components.metrics != null) {
48
+ this.metrics = {
49
+ dialerEvents: components.metrics.registerCounterGroup('libp2p_webtransport_dialer_events_total', {
50
+ label: 'event',
51
+ help: 'Total count of WebTransport dialer events by type'
52
+ })
53
+ }
54
+ }
38
55
  }
39
56
 
40
57
  readonly [Symbol.toStringTag] = '@libp2p/webtransport'
@@ -65,10 +82,15 @@ class WebTransportTransport implements Transport {
65
82
  let abortListener: (() => void) | undefined
66
83
  let maConn: MultiaddrConnection | undefined
67
84
 
68
- let cleanUpWTSession: (closeInfo?: WebTransportCloseInfo) => void = () => {}
85
+ let cleanUpWTSession: WebTransportSessionCleanup = () => {}
86
+
87
+ let closed = false
88
+ let ready = false
89
+ let authenticated = false
69
90
 
70
91
  try {
71
- let closed = false
92
+ this.metrics?.dialerEvents.increment({ pending: true })
93
+
72
94
  const wt = new WebTransport(`${url}/.well-known/libp2p-webtransport?type=noise`, {
73
95
  serverCertificateHashes: certhashes.map(certhash => ({
74
96
  algorithm: 'sha-256',
@@ -76,74 +98,69 @@ class WebTransportTransport implements Transport {
76
98
  }))
77
99
  })
78
100
 
79
- cleanUpWTSession = (closeInfo?: WebTransportCloseInfo) => {
101
+ cleanUpWTSession = (metric: string) => {
102
+ if (closed) {
103
+ // already closed session
104
+ return
105
+ }
106
+
80
107
  try {
108
+ this.metrics?.dialerEvents.increment({ [metric]: true })
109
+ wt.close()
110
+ } catch (err) {
111
+ log.error('error closing wt session', err)
112
+ } finally {
113
+ // This is how we specify the connection is closed and shouldn't be used.
81
114
  if (maConn != null) {
82
- if (maConn.timeline.close != null) {
83
- // already closed session
84
- return
85
- }
86
-
87
- // This is how we specify the connection is closed and shouldn't be used.
88
115
  maConn.timeline.close = Date.now()
89
116
  }
90
117
 
91
- if (closed) {
92
- // already closed session
93
- return
94
- }
95
-
96
- wt.close(closeInfo)
97
- } catch (err) {
98
- log.error('error closing wt session', err)
99
- } finally {
100
118
  closed = true
101
119
  }
102
120
  }
103
121
 
104
- // this promise resolves/throws when the session is closed or failed to init
105
- wt.closed
106
- .then(async () => {
107
- await maConn?.close()
108
- })
109
- .catch((err: Error) => {
110
- log.error('error on remote wt session close', err)
111
- maConn?.abort(err)
112
- })
113
- .finally(() => {
114
- // if we never got as far as creating the maConn, just clean up the session
115
- if (maConn == null) {
116
- cleanUpWTSession()
117
- }
118
- })
119
-
120
122
  // if the dial is aborted before we are ready, close the WebTransport session
121
123
  abortListener = () => {
122
- if (abortListener != null) {
123
- options.signal?.removeEventListener('abort', abortListener)
124
+ if (ready) {
125
+ cleanUpWTSession('noise_timeout')
126
+ } else {
127
+ cleanUpWTSession('ready_timeout')
124
128
  }
125
-
126
- cleanUpWTSession()
127
129
  }
128
- options.signal?.addEventListener('abort', abortListener)
130
+ options.signal?.addEventListener('abort', abortListener, {
131
+ once: true
132
+ })
129
133
 
130
- await wt.ready
134
+ await Promise.race([
135
+ wt.closed,
136
+ wt.ready
137
+ ])
138
+
139
+ ready = true
140
+ this.metrics?.dialerEvents.increment({ ready: true })
141
+
142
+ // this promise resolves/throws when the session is closed
143
+ wt.closed.catch((err: Error) => {
144
+ log.error('error on remote wt session close', err)
145
+ })
146
+ .finally(() => {
147
+ cleanUpWTSession('remote_close')
148
+ })
131
149
 
132
150
  if (!await this.authenticateWebTransport(wt, localPeer, remotePeer, certhashes)) {
133
151
  throw new Error('Failed to authenticate webtransport')
134
152
  }
135
153
 
154
+ this.metrics?.dialerEvents.increment({ open: true })
155
+
136
156
  maConn = {
137
- close: async (options?: AbortOptions) => {
157
+ close: async () => {
138
158
  log('Closing webtransport')
139
- cleanUpWTSession()
159
+ cleanUpWTSession('close')
140
160
  },
141
161
  abort: (err: Error) => {
142
162
  log('aborting webtransport due to passed err', err)
143
- cleanUpWTSession({
144
- closeCode: 0,
145
- reason: err.message
146
- })
163
+ cleanUpWTSession('abort')
147
164
  },
148
165
  remoteAddr: ma,
149
166
  timeline: {
@@ -153,16 +170,19 @@ class WebTransportTransport implements Transport {
153
170
  ...inertDuplex()
154
171
  }
155
172
 
156
- options?.signal?.throwIfAborted()
173
+ authenticated = true
157
174
 
158
- return await options.upgrader.upgradeOutbound(maConn, { skipEncryption: true, muxerFactory: this.webtransportMuxer(wt, cleanUpWTSession), skipProtection: true })
175
+ return await options.upgrader.upgradeOutbound(maConn, { skipEncryption: true, muxerFactory: this.webtransportMuxer(wt), skipProtection: true })
159
176
  } catch (err: any) {
160
177
  log.error('caught wt session err', err)
161
178
 
162
- cleanUpWTSession({
163
- closeCode: 0,
164
- reason: err.message
165
- })
179
+ if (authenticated) {
180
+ cleanUpWTSession('upgrade_error')
181
+ } else if (ready) {
182
+ cleanUpWTSession('noise_error')
183
+ } else {
184
+ cleanUpWTSession('ready_error')
185
+ }
166
186
 
167
187
  throw err
168
188
  } finally {
@@ -220,7 +240,7 @@ class WebTransportTransport implements Transport {
220
240
  return true
221
241
  }
222
242
 
223
- webtransportMuxer (wt: WebTransport, cleanUpWTSession: WebTransportSessionCleanup): StreamMuxerFactory {
243
+ webtransportMuxer (wt: WebTransport): StreamMuxerFactory {
224
244
  let streamIDCounter = 0
225
245
  const config = this.config
226
246
  return {
@@ -281,14 +301,17 @@ class WebTransportTransport implements Transport {
281
301
  */
282
302
  close: async (options?: AbortOptions) => {
283
303
  log('Closing webtransport muxer')
284
- cleanUpWTSession()
304
+
305
+ await Promise.all(
306
+ activeStreams.map(async s => s.close(options))
307
+ )
285
308
  },
286
309
  abort: (err: Error) => {
287
310
  log('Aborting webtransport muxer with err:', err)
288
- cleanUpWTSession({
289
- closeCode: 0,
290
- reason: err.message
291
- })
311
+
312
+ for (const stream of activeStreams) {
313
+ stream.abort(err)
314
+ }
292
315
  },
293
316
  // This stream muxer is webtransport native. Therefore it doesn't plug in with any other duplex.
294
317
  ...inertDuplex()
@@ -307,7 +330,7 @@ class WebTransportTransport implements Transport {
307
330
  * Takes a list of `Multiaddr`s and returns only valid webtransport addresses.
308
331
  */
309
332
  filter (multiaddrs: Multiaddr[]): Multiaddr[] {
310
- return multiaddrs.filter(ma => ma.protoNames().includes('webtransport'))
333
+ return multiaddrs.filter(WebTransportMatcher.exactMatch)
311
334
  }
312
335
  }
313
336
 
@@ -1,8 +0,0 @@
1
- {
2
- "WebTransportComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportComponents.html",
3
- ".:WebTransportComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportComponents.html",
4
- "WebTransportInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportInit.html",
5
- ".:WebTransportInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webtransport.WebTransportInit.html",
6
- "webTransport": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webtransport.webTransport.html",
7
- ".:webTransport": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webtransport.webTransport.html"
8
- }