This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
Merged
swarm API #35
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
Swarm API | ||
========= | ||
|
||
#### `addrs` | ||
|
||
> List of known addresses of each peer connected. | ||
|
||
##### `Go` **WIP** | ||
|
||
##### `JavaScript` - ipfs.swarm.addrs([callback]) | ||
|
||
`callback` must follow `function (err, addrs) {}` signature, where `err` is an error if the operation was not successful. `addrs` will be an array of multiaddrs. | ||
|
||
If no `callback` is passed, a promise is returned. | ||
|
||
Example: | ||
|
||
```JavaScript | ||
ipfs.swarm.addrs(function (err, addrs) {}) | ||
``` | ||
|
||
#### `connect` | ||
|
||
> Open a connection to a given address. | ||
|
||
##### `Go` **WIP** | ||
|
||
##### `JavaScript` - ipfs.swarm.connect(addr, [callback]) | ||
|
||
Where `addr` is of type [multiaddr](https://github.com/multiformats/js-multiaddr) | ||
|
||
`callback` must follow `function (err, res) {}` signature, where `err` is an error if the operation was not successful. | ||
|
||
If no `callback` is passed, a promise is returned. | ||
|
||
Example: | ||
|
||
```JavaScript | ||
ipfs.swarm.connect(addr, function (err) { | ||
// if no err is present, connection is now open | ||
}) | ||
``` | ||
|
||
#### `disconnect` | ||
|
||
> Close a connection on a given address. | ||
|
||
##### `Go` **WIP** | ||
|
||
##### `JavaScript` - ipfs.swarm.disconnect(addr, [callback]) | ||
|
||
Where `addr` is of type [multiaddr](https://github.com/multiformats/js-multiaddr) | ||
|
||
`callback` must follow `function (err) {}` signature, where `err` is an error if the operation was not successful. | ||
|
||
If no `callback` is passed, a promise is returned. | ||
|
||
Example: | ||
|
||
```JavaScript | ||
ipfs.swarm.disconnect(addr, function (err) {}) | ||
``` | ||
|
||
#### `peers` | ||
|
||
> List out the peers that we have connections with. | ||
|
||
##### `Go` **WIP** | ||
|
||
##### `JavaScript` - ipfs.swarm.peers([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 no `callback` is passed, a promise is returned. | ||
|
||
Example: | ||
|
||
```JavaScript | ||
ipfs.swarm.peers(function (err, peerInfos) {}) | ||
``` | ||
|
||
------------------------------ | ||
|
||
> NOT IMPLEMENTED YET | ||
|
||
#### `filters` | ||
|
||
> Display current multiaddr filters. Filters are a way to set up rules for the network connections established. | ||
|
||
##### `Go` **WIP** | ||
|
||
##### `JavaScript` - ipfs.swarm.filters([callback]) | ||
|
||
`callback` must follow `function (err, filters) {}` signature, where `err` is an error if the operation was not successful. `filters` is an array of multiaddrs that represent the filters being applied. | ||
|
||
If no `callback` is passed, a promise is returned. | ||
|
||
Example: | ||
|
||
```JavaScript | ||
ipfs.swarm.filters(function (err, filters) {}) | ||
``` | ||
|
||
#### `filters.add` | ||
|
||
> Add another filter. | ||
|
||
##### `Go` **WIP** | ||
|
||
##### `JavaScript` - ipfs.swarm.filters.add(filter, [callback]) | ||
|
||
Where `filter` is of type [multiaddr]() | ||
|
||
`callback` must follow `function (err) {}` signature, where `err` is an error if the operation was not successful. | ||
|
||
If no `callback` is passed, a promise is returned. | ||
|
||
Example: | ||
|
||
```JavaScript | ||
ipfs.swarm.filters.add(filter, function (err) {}) | ||
``` | ||
|
||
#### `filters.rm` | ||
|
||
> Remove a filter | ||
|
||
##### `Go` **WIP** | ||
|
||
##### `JavaScript` - ipfs.swarm.filters.rm(filter, [callback]) | ||
|
||
Where `filter` is of type [multiaddr]() | ||
|
||
`callback` must follow `function (err, res) {}` signature, where `err` is an error if the operation was not successful. `res` will be an array of: | ||
|
||
If no `callback` is passed, a promise is returned. | ||
|
||
Example: | ||
|
||
```JavaScript | ||
ipfs.swarm.filters.rm(filter, function (err) {}) | ||
``` | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* eslint-env mocha */ | ||
/* eslint max-nested-callbacks: ["error", 8] */ | ||
|
||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const series = require('run-series') | ||
|
||
module.exports = (common) => { | ||
describe('.swarm', () => { | ||
let ipfsA | ||
let ipfsB | ||
|
||
before(function (done) { | ||
// CI takes longer to instantiate the daemon, | ||
// so we need to increase the timeout for the | ||
// before step | ||
this.timeout(20 * 1000) | ||
|
||
common.setup((err, factory) => { | ||
expect(err).to.not.exist | ||
series([ | ||
(cb) => { | ||
factory.spawnNode((err, node) => { | ||
expect(err).to.not.exist | ||
ipfsA = node | ||
cb() | ||
}) | ||
}, | ||
(cb) => { | ||
factory.spawnNode((err, node) => { | ||
expect(err).to.not.exist | ||
ipfsB = node | ||
cb() | ||
}) | ||
} | ||
], done) | ||
}) | ||
}) | ||
|
||
after((done) => { | ||
common.teardown(done) | ||
}) | ||
|
||
describe('callback API', () => { | ||
it('.connect', (done) => { | ||
ipfsB.id((err, id) => { | ||
expect(err).to.not.exist | ||
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() | ||
}) | ||
}) | ||
|
||
it('.addrs', (done) => { | ||
ipfsA.swarm.addrs((err, multiaddrs) => { | ||
expect(err).to.not.exist | ||
expect(multiaddrs).to.have.length.above(0) | ||
done() | ||
}) | ||
}) | ||
|
||
it('.localAddrs', (done) => { | ||
ipfsA.swarm.localAddrs((err, multiaddrs) => { | ||
expect(err).to.not.exist | ||
expect(multiaddrs).to.have.length.above(0) | ||
done() | ||
}) | ||
}) | ||
|
||
it('.disconnect', (done) => { | ||
ipfsB.id((err, id) => { | ||
expect(err).to.not.exist | ||
const ipfsBAddr = id.addresses[0] | ||
ipfsA.swarm.disconnect(ipfsBAddr, done) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('promise API', () => { | ||
it('.connect', () => { | ||
return ipfsB.id() | ||
.then((id) => { | ||
const ipfsBAddr = id.addresses[0] | ||
return ipfsA.swarm.connect(ipfsBAddr) | ||
}) | ||
}) | ||
|
||
it('.peers', () => { | ||
return ipfsA.swarm.peers().then((multiaddrs) => { | ||
expect(multiaddrs).to.have.length.above(0) | ||
}) | ||
}) | ||
|
||
it('.addrs', () => { | ||
return ipfsA.swarm.addrs().then((multiaddrs) => { | ||
expect(multiaddrs).to.have.length.above(0) | ||
}) | ||
}) | ||
|
||
it('.localAddrs', () => { | ||
return ipfsA.swarm.localAddrs().then((multiaddrs) => { | ||
expect(multiaddrs).to.have.length.above(0) | ||
}) | ||
}) | ||
|
||
it('.disconnect', () => { | ||
return ipfsB.id() | ||
.then((id) => { | ||
const ipfsBAddr = id.addresses[0] | ||
return ipfsA.swarm.disconnect(ipfsBAddr) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have a little bit more explanation of what
filters
actually do