Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove stream add/remove methods from connection interface #1912

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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