diff --git a/packages/interface-compliance-tests/src/connection/index.ts b/packages/interface-compliance-tests/src/connection/index.ts index 833ca30ba1..45c488abea 100644 --- a/packages/interface-compliance-tests/src/connection/index.ts +++ b/packages/interface-compliance-tests/src/connection/index.ts @@ -127,6 +127,7 @@ export default (test: TestSetup): void => { it.skip('should track inbound streams', async () => { // Add an remotely opened stream const stream = stubInterface() + // @ts-expect-error connection.addStream(stream) expect(stream).to.have.property('direction', 'inbound') }) diff --git a/packages/interface/src/connection/index.ts b/packages/interface/src/connection/index.ts index 6a2100f75d..2bed6736a1 100644 --- a/packages/interface/src/connection/index.ts +++ b/packages/interface/src/connection/index.ts @@ -258,16 +258,6 @@ export interface Connection { */ newStream: (protocols: string | string[], options?: NewStreamOptions) => Promise - /** - * Add a stream to this connection - */ - addStream: (stream: Stream) => void - - /** - * Remove a stream from this connection - */ - removeStream: (id: string) => void - /** * Gracefully close the connection. All queued data will be written to the * underlying transport. diff --git a/packages/libp2p/src/upgrader.ts b/packages/libp2p/src/upgrader.ts index f77dcf6319..0409c870f8 100644 --- a/packages/libp2p/src/upgrader.ts +++ b/packages/libp2p/src/upgrader.ts @@ -415,7 +415,7 @@ export class DefaultUpgrader implements Upgrader { protocols: [protocol] }) - connection.addStream(muxedStream) + connection.streams.push(muxedStream) this.components.metrics?.trackProtocolStream(muxedStream, connection) this._onStream({ connection, stream: muxedStream, protocol }) @@ -430,7 +430,7 @@ export class DefaultUpgrader implements Upgrader { }, // Run anytime a stream closes onStreamEnd: muxedStream => { - connection?.removeStream(muxedStream.id) + connection.streams.filter(stream => stream.id === muxedStream.id)[0]?.close() } }) diff --git a/packages/libp2p/test/connection/compliance.spec.ts b/packages/libp2p/test/connection/compliance.spec.ts index ca216acd5d..977f08d4b3 100644 --- a/packages/libp2p/test/connection/compliance.spec.ts +++ b/packages/libp2p/test/connection/compliance.spec.ts @@ -35,7 +35,7 @@ describe('connection compliance', () => { ...pair(), close: async () => { void stream.sink(async function * () {}()) - connection.removeStream(stream.id) + connection.streams.filter(s => s.id === stream.id)[0]?.close() openStreams = openStreams.filter(s => s.id !== id) }, closeRead: async () => {},