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

remove (add|remove)Stream use from interface-compliance-tests

remove (add|remove)Stream from libp2p connection methods

remove (add|remove)Stream from libp2p upgrader methods
  • Loading branch information
tabcat committed Aug 7, 2023
1 parent b7e6089 commit c9f0ab4
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default (test: TestSetup<Connection>): void => {
it.skip('should track inbound streams', async () => {
// Add an remotely opened stream
const stream = stubInterface<Stream>()
connection.addStream(stream)
// connection.addStream(stream)
expect(stream).to.have.property('direction', 'inbound')
})

Expand Down
12 changes: 2 additions & 10 deletions packages/interface-compliance-tests/src/mocks/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ class MockConnection implements Connection {
return stream
}

addStream (stream: Stream): void {
this.streams.push(stream)
}

removeStream (id: string): void {
this.streams = this.streams.filter(stream => stream.id !== id)
}

async close (options?: AbortOptions): Promise<void> {
this.status = 'closing'
await Promise.all(
Expand Down Expand Up @@ -147,7 +139,7 @@ export function mockConnection (maConn: MultiaddrConnection, opts: MockConnectio
muxedStream.sink = stream.sink
muxedStream.source = stream.source

connection.addStream(muxedStream)
connection.streams.push(muxedStream)
const { handler } = registrar.getHandler(protocol)

handler({ connection, stream: muxedStream })
Expand All @@ -159,7 +151,7 @@ export function mockConnection (maConn: MultiaddrConnection, opts: MockConnectio
}
},
onStreamEnd: (muxedStream) => {
connection.removeStream(muxedStream.id)
connection.streams = connection.streams.filter(stream => stream.id !== muxedStream.id)
}
})

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
14 changes: 0 additions & 14 deletions packages/libp2p/src/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,6 @@ export class ConnectionImpl implements Connection {
return stream
}

/**
* Add a stream when it is opened to the registry
*/
addStream (stream: Stream): void {
stream.direction = 'inbound'
}

/**
* Remove stream registry after it is closed
*/
removeStream (id: string): void {

}

/**
* Close the connection
*/
Expand Down
5 changes: 0 additions & 5 deletions packages/libp2p/src/upgrader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ export class DefaultUpgrader implements Upgrader {
protocols: [protocol]
})

connection.addStream(muxedStream)
this.components.metrics?.trackProtocolStream(muxedStream, connection)

this._onStream({ connection, stream: muxedStream, protocol })
Expand All @@ -427,10 +426,6 @@ export class DefaultUpgrader implements Upgrader {
await muxedStream.close()
}
})
},
// Run anytime a stream closes
onStreamEnd: muxedStream => {
connection?.removeStream(muxedStream.id)
}
})

Expand Down
1 change: 0 additions & 1 deletion packages/libp2p/test/connection/compliance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe('connection compliance', () => {
...pair(),
close: async () => {
void stream.sink(async function * () {}())
connection.removeStream(stream.id)
openStreams = openStreams.filter(s => s.id !== id)
},
closeRead: async () => {},
Expand Down

0 comments on commit c9f0ab4

Please sign in to comment.