Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: loosen input type for swarm.connect and swarm.disconnect (#3673)
Browse files Browse the repository at this point in the history
Accept peer ids as strings or multiaddrs as Multiaddrs.

Fixes #3638
  • Loading branch information
achingbrain authored May 6, 2021
1 parent 5eb32a7 commit 46618c7
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/ipfs-core-types/src/bitswap/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface API<OptionExtension = {}> {
* // [ CID('QmHash') ]
* ```
*/
wantlistForPeer: (peerId: CID | string, options?: AbortOptions & OptionExtension) => Promise<CID[]>
wantlistForPeer: (peerId: string, options?: AbortOptions & OptionExtension) => Promise<CID[]>

/**
* Removes one or more CIDs from the wantlist
Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs-core-types/src/dht/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface API<OptionExtension = {}> {
* // '/ip4/147.75.94.115/tcp/4001'
* ```
*/
findPeer: (peerId: CID | string, options?: AbortOptions & OptionExtension) => Promise<PeerResult>
findPeer: (peerId: string, options?: AbortOptions & OptionExtension) => Promise<PeerResult>

/**
* Find peers in the DHT that can provide a specific value, given a CID.
Expand Down Expand Up @@ -59,7 +59,7 @@ export interface API<OptionExtension = {}> {
/**
* Find the closest peers to a given `PeerId`, by querying the DHT.
*/
query: (peerId: CID | string, options?: AbortOptions & OptionExtension) => AsyncIterable<PeerResult>
query: (peerId: string, options?: AbortOptions & OptionExtension) => AsyncIterable<PeerResult>
}

export interface PeerResult {
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core-types/src/root.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export interface API<OptionExtension = {}> {
* }
* ```
*/
ping: (peerId: CID | string, options?: PingOptions & OptionExtension) => AsyncIterable<PingResult>
ping: (peerId: string, options?: PingOptions & OptionExtension) => AsyncIterable<PingResult>

/**
* Resolve the value of names to IPFS
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core-types/src/stats/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface API<OptionExtension = {}> {
}

export interface BWOptions extends AbortOptions {
peer?: CID | string
peer?: string
proto?: string
poll?: boolean
interval?: number
Expand Down
10 changes: 5 additions & 5 deletions packages/ipfs-core-types/src/swarm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import type CID from 'cids'
import type { Multiaddr } from 'multiaddr'

export interface API<OptionExtension = {}> {
/**
/**
* List of known addresses of each peer connected
*/
addrs: (options?: AbortOptions & OptionExtension) => Promise<AddrsResult[]>

/**
* Open a connection to a given address
* Open a connection to a given address or peer id
*/
connect: (addr: Multiaddr, options?: AbortOptions & OptionExtension) => Promise<void>
connect: (addr: Multiaddr | string, options?: AbortOptions & OptionExtension) => Promise<void>

/**
* Close a connection to a given address
* Close a connection to a given address or peer id
*/
disconnect: (addr: Multiaddr, options?: AbortOptions & OptionExtension) => Promise<void>
disconnect: (addr: Multiaddr | string, options?: AbortOptions & OptionExtension) => Promise<void>

/**
* Local addresses this node is listening on
Expand Down
3 changes: 1 addition & 2 deletions packages/ipfs-http-client/src/dht/find-peer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const CID = require('cids')
const { Multiaddr } = require('multiaddr')
const configure = require('../lib/configure')
const toUrlSearchParams = require('../lib/to-url-search-params')
Expand All @@ -20,7 +19,7 @@ module.exports = configure(api => {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams({
arg: `${peerId instanceof Uint8Array ? new CID(peerId) : peerId}`,
arg: peerId,
...options
}),
headers: options.headers
Expand Down

0 comments on commit 46618c7

Please sign in to comment.