Skip to content

Commit

Permalink
fix: remove stream add/remove methods from connection interface (#1912)
Browse files Browse the repository at this point in the history
Co-authored-by: Chad Nehemiah <chad.nehemiah94@gmail.com>
  • Loading branch information
tabcat and maschad authored Aug 7, 2023
1 parent b7e6089 commit e26848b
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 50 deletions.
1 change: 0 additions & 1 deletion packages/interface-compliance-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@
"p-wait-for": "^5.0.2",
"protons-runtime": "^5.0.0",
"sinon": "^15.1.2",
"ts-sinon": "^2.0.2",
"uint8arraylist": "^2.4.3",
"uint8arrays": "^4.0.4"
},
Expand Down
10 changes: 1 addition & 9 deletions packages/interface-compliance-tests/src/connection/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { expect } from 'aegir/chai'
import sinon from 'sinon'
import { stubInterface } from 'ts-sinon'
import type { TestSetup } from '../index.js'
import type { Connection, Stream } from '@libp2p/interface/connection'
import type { Connection } from '@libp2p/interface/connection'

export default (test: TestSetup<Connection>): void => {
describe('connection', () => {
Expand Down Expand Up @@ -124,13 +123,6 @@ export default (test: TestSetup<Connection>): void => {
expect(stream).to.have.property('direction', 'outbound')
})

it.skip('should track inbound streams', async () => {
// Add an remotely opened stream
const stream = stubInterface<Stream>()
connection.addStream(stream)
expect(stream).to.have.property('direction', 'inbound')
})

it('should support a proxy on the timeline', async () => {
sinon.spy(proxyHandler, 'set')
expect(connection.timeline.close).to.not.exist()
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 e26848b

Please sign in to comment.