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

Commit

Permalink
fix: peer ids are strings now (#3162)
Browse files Browse the repository at this point in the history
Cleans up last bits of libp2p's peerID -> string migration
  • Loading branch information
achingbrain authored Jul 9, 2020
1 parent f20cdf1 commit 281bfe6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
6 changes: 3 additions & 3 deletions packages/ipfs/src/cli/commands/swarm/addrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ module.exports = {
})

const output = res.map((peer) => {
const count = peer.multiaddrs.size
const peerAddrs = [`${peer.id.toB58String()} (${count})`]
const count = peer.addrs.length
const peerAddrs = [`${peer.id} (${count})`]

peer.multiaddrs.toArray().map((addr) => {
peer.addrs.map((addr) => {
let res
try {
res = addr.decapsulate('ipfs').toString()
Expand Down
9 changes: 5 additions & 4 deletions packages/ipfs/src/cli/commands/swarm/peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ module.exports = {
})

result.forEach((item) => {
let ma = multiaddr(item.addr.toString())
let ma = multiaddr(`${item.addr}`)

if (!mafmt.IPFS.matches(ma)) {
ma = ma.encapsulate('/ipfs/' + item.peer.toB58String())
ma = ma.encapsulate(`/ipfs/${item.peer}`)
}
const addr = ma.toString()
print(addr)

print(`${ma}`)
})
}
}
4 changes: 4 additions & 0 deletions packages/ipfs/src/cli/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const parser = yargs
type: 'boolean',
default: false
})
.options('api', {
desc: 'Remote API multiaddr to use',
type: 'string'
})
.epilog(utils.ipfsPathHelp)
.demandCommand(1, 'Please specify a command')
.showHelpOnFail(false)
Expand Down
26 changes: 10 additions & 16 deletions packages/ipfs/test/cli/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('swarm', () => {

it('peers online', async () => {
ipfs.swarm.peers.withArgs(defaultOptions).resolves([{
peer: { toB58String: () => 'Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z' },
peer: 'Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z',
addr: '/ip4/192.0.0.1/tcp/5001'
}, {
addr: '/ip4/192.0.0.2/tcp/5002/p2p/Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5a'
Expand All @@ -89,7 +89,7 @@ describe('swarm', () => {
...defaultOptions,
timeout: 1000
}).resolves([{
peer: { toB58String: () => 'Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z' },
peer: 'Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z',
addr: '/ip4/192.0.0.1/tcp/5001'
}, {
addr: '/ip4/192.0.0.2/tcp/5002/p2p/Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5a'
Expand All @@ -110,13 +110,10 @@ describe('swarm', () => {
const addr = `/ip4/192.0.0.2/tcp/5002/p2p/${peer}`

ipfs.swarm.addrs.withArgs(defaultOptions).resolves([{
id: { toB58String: () => peer },
multiaddrs: {
size: 1,
toArray: () => [
ma(addr)
]
}
id: peer,
addrs: [
ma(addr)
]
}])

const out = await cli('swarm addrs', { ipfs })
Expand All @@ -131,13 +128,10 @@ describe('swarm', () => {
...defaultOptions,
timeout: 1000
}).resolves([{
id: { toB58String: () => peer },
multiaddrs: {
size: 1,
toArray: () => [
ma(addr)
]
}
id: peer,
addrs: [
ma(addr)
]
}])

const out = await cli('swarm addrs --timeout=1s', { ipfs })
Expand Down

0 comments on commit 281bfe6

Please sign in to comment.