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

Commit

Permalink
fix: accept multiaddr param when opening connections (#336)
Browse files Browse the repository at this point in the history
This has been in libp2p for ages but was missed on the interface.
  • Loading branch information
achingbrain committed Jan 14, 2023
1 parent 12e3942 commit fef9c26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/interface-connection-manager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface ConnectionManager extends EventEmitter<ConnectionManagerEvents>
* const connection = await libp2p.connectionManager.openConnection(peerId)
* ```
*/
openConnection: (peer: PeerId, options?: AbortOptions) => Promise<Connection>
openConnection: (peer: PeerId | Multiaddr, options?: AbortOptions) => Promise<Connection>

/**
* Close our connections to a peer
Expand Down
7 changes: 6 additions & 1 deletion packages/interface-mocks/src/connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { connectionPair } from './connection.js'
import errCode from 'err-code'
import type { Registrar } from '@libp2p/interface-registrar'
import type { PubSub } from '@libp2p/interface-pubsub'
import { isMultiaddr, Multiaddr } from '@multiformats/multiaddr'

export interface MockNetworkComponents {
peerId: PeerId
Expand Down Expand Up @@ -75,11 +76,15 @@ class MockConnectionManager extends EventEmitter<ConnectionManagerEvents> implem
return this.connections
}

async openConnection (peerId: PeerId) {
async openConnection (peerId: PeerId | Multiaddr) {
if (this.components == null) {
throw errCode(new Error('Not initialized'), 'ERR_NOT_INITIALIZED')
}

if (isMultiaddr(peerId)) {
throw errCode(new Error('Dialing multiaddrs not supported'), 'ERR_NOT_SUPPORTED')
}

const existingConnections = this.getConnections(peerId)

if (existingConnections.length > 0) {
Expand Down

0 comments on commit fef9c26

Please sign in to comment.