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

feat: add protocol list to ipfs id #3250

Merged
merged 6 commits into from
Sep 2, 2020
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
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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should assert that there are protocols present, at a minimum I think /ipfs/id/1.0.0 should be supported

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a handful of protocols, I'd assert them all as they shouldn't change very frequently. There may be differences in Node.js vs browser, depending on modules included, but I think they are currently equivalent.

Copy link
Contributor Author

@tk26 tk26 Sep 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got ["/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"], adding those to the assertions. Thanks guys!


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
})
}
}