Skip to content

Commit

Permalink
fix: Remove Stream methods from Connection
Browse files Browse the repository at this point in the history
remove (add|remove)Stream from connection interface

Related: libp2p#1855

expect .addStream ts error

handle (add|remove)Stream usage
  • Loading branch information
tabcat committed Aug 5, 2023
1 parent 55e1230 commit 20c6680
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export default (test: TestSetup<Connection>): void => {
it.skip('should track inbound streams', async () => {
// Add an remotely opened stream
const stream = stubInterface<Stream>()
// @ts-expect-error
connection.addStream(stream)
expect(stream).to.have.property('direction', 'inbound')
})
Expand Down
10 changes: 0 additions & 10 deletions packages/interface/src/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,6 @@ export interface Connection {
*/
newStream: (protocols: string | string[], options?: NewStreamOptions) => Promise<Stream>

/**
* 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.
Expand Down
4 changes: 2 additions & 2 deletions packages/libp2p/src/upgrader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -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()
}
})

Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p/test/connection/compliance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {},
Expand Down

0 comments on commit 20c6680

Please sign in to comment.