Skip to content

Commit c396f8c

Browse files
authored
fix: remove metrics from component (#17)
Since muxers are factories there's no point tracking stream metrics for each instance as they trample over each other, so remove the use of tracked maps in this module. This was added to mplex by mistake and copied here, but it's since been removed from mplex so this change brings yamux in line.
1 parent 7f25aab commit c396f8c

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,8 @@
171171
},
172172
"dependencies": {
173173
"@libp2p/interface-connection": "^3.0.1",
174-
"@libp2p/interface-metrics": "^3.0.0",
175174
"@libp2p/interface-stream-muxer": "^3.0.0",
176175
"@libp2p/logger": "^2.0.1",
177-
"@libp2p/tracked-map": "^2.0.2",
178176
"abortable-iterator": "^4.0.2",
179177
"any-signal": "^3.0.1",
180178
"err-code": "^3.0.1",

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer'
22
import { Yamux } from './muxer.js'
3-
import type { YamuxMuxerInit, YamuxComponents } from './muxer.js'
3+
import type { YamuxMuxerInit } from './muxer.js'
44
export { GoAwayCode } from './frame.js'
55

6-
export function yamux (init: YamuxMuxerInit = {}): (components?: YamuxComponents) => StreamMuxerFactory {
7-
return (components: YamuxComponents = {}) => new Yamux(components, init)
6+
export function yamux (init: YamuxMuxerInit = {}): () => StreamMuxerFactory {
7+
return () => new Yamux(init)
88
}

src/muxer.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/i
33
import { abortableSource } from 'abortable-iterator'
44
import { pipe } from 'it-pipe'
55
import type { Sink, Source } from 'it-stream-types'
6-
import { trackedMap } from '@libp2p/tracked-map'
76
import { pushable, Pushable } from 'it-pushable'
87
import errcode from 'err-code'
98
import anySignal from 'any-signal'
@@ -15,29 +14,22 @@ import { Config, defaultConfig, verifyConfig } from './config.js'
1514
import { Decoder } from './decode.js'
1615
import type { Logger } from '@libp2p/logger'
1716
import type { Uint8ArrayList } from 'uint8arraylist'
18-
import type { Metrics } from '@libp2p/interface-metrics'
1917

2018
const YAMUX_PROTOCOL_ID = '/yamux/1.0.0'
2119

2220
export interface YamuxMuxerInit extends StreamMuxerInit, Partial<Config> {
2321
}
2422

25-
export interface YamuxComponents {
26-
metrics?: Metrics
27-
}
28-
2923
export class Yamux implements StreamMuxerFactory {
3024
protocol = YAMUX_PROTOCOL_ID
31-
private readonly components: YamuxComponents
3225
private readonly _init: YamuxMuxerInit
3326

34-
constructor (components: YamuxComponents, init: YamuxMuxerInit = {}) {
35-
this.components = components
27+
constructor (init: YamuxMuxerInit = {}) {
3628
this._init = init
3729
}
3830

3931
createStreamMuxer (init?: YamuxMuxerInit): YamuxMuxer {
40-
return new YamuxMuxer(this.components, {
32+
return new YamuxMuxer({
4133
...this._init,
4234
...init
4335
})
@@ -82,7 +74,7 @@ export class YamuxMuxer implements StreamMuxer {
8274
private readonly onIncomingStream?: (stream: Stream) => void
8375
private readonly onStreamEnd?: (stream: Stream) => void
8476

85-
constructor (components: YamuxComponents, init: YamuxMuxerInit) {
77+
constructor (init: YamuxMuxerInit) {
8678
this._init = init
8779
this.client = init.direction === 'outbound'
8880
this.config = { ...defaultConfig, ...init }
@@ -94,7 +86,7 @@ export class YamuxMuxer implements StreamMuxer {
9486
this.onIncomingStream = init.onIncomingStream
9587
this.onStreamEnd = init.onStreamEnd
9688

97-
this._streams = trackedMap({ metrics: components.metrics, component: 'yamux', metric: 'streams' })
89+
this._streams = new Map()
9890

9991
this.source = pushable({
10092
onEnd: (err?: Error): void => {

test/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class TestYamux extends Yamux {
3333
}
3434

3535
export function testYamuxMuxer (name: string, client: boolean, conf: YamuxMuxerInit = {}) {
36-
return new YamuxMuxer({}, {
36+
return new YamuxMuxer({
3737
...testConf,
3838
...conf,
3939
direction: client ? 'outbound' : 'inbound',

0 commit comments

Comments
 (0)