From 1479ca3258c329d3fffb2be56f95b466c349c22d Mon Sep 17 00:00:00 2001 From: tabcat Date: Sun, 30 Jul 2023 21:19:14 -0500 Subject: [PATCH] fix: Remove Stream methods from Connection remove (add|remove)Stream from connection interface Related: #1855 comment out .addStream test usage handle (add|remove)Stream usage --- .../interface-compliance-tests/src/connection/index.ts | 2 +- packages/interface/src/connection/index.ts | 10 ---------- packages/libp2p/src/upgrader.ts | 4 ++-- packages/libp2p/test/connection/compliance.spec.ts | 2 +- 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/packages/interface-compliance-tests/src/connection/index.ts b/packages/interface-compliance-tests/src/connection/index.ts index 833ca30ba1..604030182d 100644 --- a/packages/interface-compliance-tests/src/connection/index.ts +++ b/packages/interface-compliance-tests/src/connection/index.ts @@ -127,7 +127,7 @@ export default (test: TestSetup): void => { it.skip('should track inbound streams', async () => { // Add an remotely opened stream const stream = stubInterface() - connection.addStream(stream) + // 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 () => {},