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

Commit

Permalink
feat: add protocol list to ipfs id (#3250)
Browse files Browse the repository at this point in the history
Adds `.protocols` property to the output of `ipfs.id` which contains all libp2p protocols supported by the current node.

Closes #3219
  • Loading branch information
tk26 authored Sep 2, 2020
1 parent 63d4d35 commit 1b6cf60
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/core-api/MISCELLANEOUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ The Peer identity has the following properties:
- `addresses: Multiaddr[]` - A list of multiaddrs this node is listening on
- `agentVersion: String` - The agent version
- `protocolVersion: String` - The supported protocol version
- `protocols: String[]` - The supported protocols

### Example

Expand Down
19 changes: 19 additions & 0 deletions packages/interface-ipfs-core/src/miscellaneous/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,24 @@ module.exports = (common, options) => {
expect(Multiaddr.isMultiaddr(ma)).to.be.true()
}
})

it('should have protocols property', async () => {
const res = await ipfs.id()

expect(res).to.have.a.property('protocols').that.is.an('array')

expect(res.protocols).to.have.members([
'/floodsub/1.0.0',
'/ipfs/bitswap/1.0.0',
'/ipfs/bitswap/1.1.0',
'/ipfs/bitswap/1.2.0',
'/ipfs/id/1.0.0',
'/ipfs/id/push/1.0.0',
'/ipfs/ping/1.0.0',
'/libp2p/circuit/relay/0.1.0',
'/meshsub/1.0.0',
'/meshsub/1.1.0'
])
})
})
}
4 changes: 4 additions & 0 deletions packages/ipfs-http-client/test/interface.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ describe('interface-ipfs-core tests', () => {
{
name: 'should include the interface-ipfs-core version',
reason: 'TODO not implemented in go-ipfs yet'
},
{
name: 'should have protocols property',
reason: 'TODO not implemented in go-ipfs yet'
}
]
})
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs/src/cli/commands/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
format: {
alias: 'f',
type: 'string',
describe: 'Print Node ID info in the given format. Allowed tokens: <id> <aver> <pver> <pubkey> <addrs>'
describe: 'Print Node ID info in the given format. Allowed tokens: <id> <aver> <pver> <pubkey> <addrs> <protocols>'
},
timeout: {
type: 'string',
Expand All @@ -31,6 +31,7 @@ module.exports = {
.replace('<pver>', id.protocolVersion)
.replace('<pubkey>', id.publicKey)
.replace('<addrs>', (id.addresses || []).map(addr => addr.toString()).join('\n'))
.replace('<protocols>', (id.protocols || []).map(protocol => protocol.toString()).join('\n'))
)

return
Expand Down
5 changes: 4 additions & 1 deletion packages/ipfs/src/core/components/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ module.exports = ({ peerId, libp2p }) => {
return withTimeoutOption(async function id () { // eslint-disable-line require-await
const id = peerId.toB58String()
let addresses = []
let protocols = []

if (libp2p) {
// only available while the node is running
addresses = libp2p.transportManager.getAddrs()
protocols = Array.from(libp2p.upgrader.protocols.keys())
}

return {
Expand All @@ -33,7 +35,8 @@ module.exports = ({ peerId, libp2p }) => {
.sort()
.map(ma => multiaddr(ma)),
agentVersion: `js-ipfs/${pkgversion}`,
protocolVersion: '9000'
protocolVersion: '9000',
protocols: protocols.sort()
}
})
}
3 changes: 2 additions & 1 deletion packages/ipfs/src/http/api/resources/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ module.exports = {
PublicKey: id.publicKey,
Addresses: id.addresses,
AgentVersion: id.agentVersion,
ProtocolVersion: id.protocolVersion
ProtocolVersion: id.protocolVersion,
Protocols: id.protocols
})
}
}

0 comments on commit 1b6cf60

Please sign in to comment.