Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

feat: prepare for swarm.peers changes in 0.4.5 #94

Merged
merged 3 commits into from
Nov 17, 2016
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
15 changes: 13 additions & 2 deletions API/swarm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,20 @@ ipfs.swarm.disconnect(addr, function (err) {})

##### `Go` **WIP**

##### `JavaScript` - ipfs.swarm.peers([callback])
##### `JavaScript` - ipfs.swarm.peers([opts] [, callback])

`callback` must follow `function (err, peerInfos) {}` signature, where `err` is an error if the operation was not successful. `peerInfos` will be an array of [PeerInfo]().
If `opts.verbose` is set to `true` additional information, such as `latency` is provided.

`callback` must follow `function (err, peerInfos) {}` signature, where `err` is an error if the operation was not successful. `peerInfos` will be an array of the form

- `addr: Multiaddr`
- `peer: [PeerInfo]()`
- `latency: String` Only if `verbose: true` was passed

Starting with `go-ipfs 0.4.5` these additional properties are provided

- `muxer: String` - The type of stream muxer the peer is usng
- `streams: []String` - Only if `verbose: true`, a list of currently open streams

If no `callback` is passed, a promise is returned.

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"detect-node": "^2.0.3",
"ipfs-block": "^0.5.0",
"ipld-dag-pb": "^0.8.0",
"multiaddr": "^2.0.3",
"multihashes": "^0.2.2",
"readable-stream": "2.1.5"
},
Expand All @@ -49,4 +50,4 @@
"Victor Bjelkholm <victorbjelkholm@gmail.com>",
"nginnever <ginneversource@gmail.com>"
]
}
}
53 changes: 47 additions & 6 deletions src/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

const expect = require('chai').expect
const series = require('async/series')
const multiaddr = require('multiaddr')

module.exports = (common) => {
describe('.swarm', () => {
Expand Down Expand Up @@ -42,21 +43,61 @@ module.exports = (common) => {
common.teardown(done)
})

let ipfsBId

describe('callback API', () => {
it('.connect', (done) => {
ipfsB.id((err, id) => {
expect(err).to.not.exist

ipfsBId = id
const ipfsBAddr = id.addresses[0]
ipfsA.swarm.connect(ipfsBAddr, done)
})
})

it('.peers', (done) => {
ipfsA.swarm.peers((err, multiaddrs) => {
expect(err).to.not.exist
expect(multiaddrs).to.have.length.above(0)
done()
describe('.peers', () => {
beforeEach((done) => {
const ipfsBAddr = ipfsBId.addresses[0]
ipfsA.swarm.connect(ipfsBAddr, done)
})

it('default', (done) => {
ipfsB.swarm.peers((err, peers) => {
expect(err).to.not.exist
expect(peers).to.have.length.above(0)

const peer = peers[0]

expect(peer).to.have.a.property('addr')
expect(multiaddr.isMultiaddr(peer.addr)).to.be.true
expect(peer).to.have.a.property('peer')
expect(peer).to.not.have.a.property('latency')

// only available in 0.4.5
// expect(peer).to.have.a.property('muxer')
// expect(peer).to.not.have.a.property('streams')

done()
})
})

it('verbose', (done) => {
ipfsA.swarm.peers({verbose: true}, (err, peers) => {
expect(err).to.not.exist
expect(peers).to.have.length.above(0)

const peer = peers[0]
expect(peer).to.have.a.property('addr')
expect(multiaddr.isMultiaddr(peer.addr)).to.be.true
expect(peer).to.have.a.property('peer')
expect(peer).to.have.a.property('latency')

// Only available in 0.4.5
// expect(peer).to.have.a.property('muxer')
// expect(peer).to.have.a.property('streams')

done()
})
})
})

Expand Down