Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

feat: add acceptIncomingConnection to ConnectionManager #295

Merged
merged 2 commits into from
Oct 4, 2022
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
10 changes: 9 additions & 1 deletion packages/interface-connection-manager/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AbortOptions } from '@libp2p/interfaces'
import type { EventEmitter } from '@libp2p/interfaces/events'
import type { Connection } from '@libp2p/interface-connection'
import type { Connection, MultiaddrConnection } from '@libp2p/interface-connection'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { Multiaddr } from '@multiformats/multiaddr'

Expand All @@ -24,6 +24,14 @@ export interface ConnectionManager extends EventEmitter<ConnectionManagerEvents>
* Close our connections to a peer
*/
closeConnections: (peer: PeerId) => Promise<void>

/**
* Invoked after an incoming connection is opened but before PeerIds are
* exchanged, this lets the ConnectionManager check we have sufficient
* resources to accept the connection in which case it will return true,
* otherwise it will return false.
*/
acceptIncomingConnection: (maConn: MultiaddrConnection) => Promise<boolean>
}

export interface Dialer {
Expand Down
4 changes: 4 additions & 0 deletions packages/interface-mocks/src/connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class MockConnectionManager extends EventEmitter<ConnectionManagerEvents> implem

await componentsB.getConnectionManager().closeConnections(this.components.getPeerId())
}

async acceptIncomingConnection (): Promise<boolean> {
return true
}
}

export function mockConnectionManager () {
Expand Down