mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-03-31 19:11:27 +00:00
refactor: async
This commit is contained in:
parent
360dcfba12
commit
e690d28e0d
40
.gitignore
vendored
40
.gitignore
vendored
@ -1,38 +1,8 @@
|
|||||||
dist
|
**/node_modules/
|
||||||
# Logs
|
**/*.log
|
||||||
logs
|
package-lock.json
|
||||||
*.log
|
|
||||||
npm-debug.log*
|
|
||||||
|
|
||||||
# Runtime data
|
|
||||||
pids
|
|
||||||
*.pid
|
|
||||||
*.seed
|
|
||||||
|
|
||||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
||||||
lib-cov
|
|
||||||
|
|
||||||
# Coverage directory used by tools like istanbul
|
# Coverage directory used by tools like istanbul
|
||||||
coverage
|
coverage
|
||||||
|
docs
|
||||||
# nyc test coverage
|
dist
|
||||||
.nyc_output
|
|
||||||
|
|
||||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
|
||||||
.grunt
|
|
||||||
|
|
||||||
# node-waf configuration
|
|
||||||
.lock-wscript
|
|
||||||
|
|
||||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
|
||||||
build/Release
|
|
||||||
|
|
||||||
# Dependency directories
|
|
||||||
node_modules
|
|
||||||
jspm_packages
|
|
||||||
|
|
||||||
# Optional npm cache directory
|
|
||||||
.npm
|
|
||||||
|
|
||||||
# Optional REPL history
|
|
||||||
.node_repl_history
|
|
||||||
|
10
.travis.yml
Normal file
10
.travis.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
language: node_js
|
||||||
|
cache: npm
|
||||||
|
stages:
|
||||||
|
- check
|
||||||
|
|
||||||
|
node_js:
|
||||||
|
- '10'
|
||||||
|
|
||||||
|
script:
|
||||||
|
- npm run lint
|
33
README.md
33
README.md
@ -21,7 +21,7 @@ The API is presented with both Node.js and Go primitives, however, there is not
|
|||||||
## Modules that implement the interface
|
## Modules that implement the interface
|
||||||
|
|
||||||
- [JavaScript libp2p-mdns](https://github.com/libp2p/js-libp2p-mdns)
|
- [JavaScript libp2p-mdns](https://github.com/libp2p/js-libp2p-mdns)
|
||||||
- [JavaScript libp2p-railing](https://github.com/libp2p/js-libp2p-railing)
|
- [JavaScript libp2p-bootstrap](https://github.com/libp2p/js-libp2p-bootstrap)
|
||||||
- [JavaScript libp2p-kad-dht](https://github.com/libp2p/js-libp2p-kad-dht)
|
- [JavaScript libp2p-kad-dht](https://github.com/libp2p/js-libp2p-kad-dht)
|
||||||
- [JavaScript libp2p-webrtc-star](https://github.com/libp2p/js-libp2p-webrtc-star)
|
- [JavaScript libp2p-webrtc-star](https://github.com/libp2p/js-libp2p-webrtc-star)
|
||||||
- [JavaScript libp2p-websocket-star](https://github.com/libp2p/js-libp2p-websocket-star)
|
- [JavaScript libp2p-websocket-star](https://github.com/libp2p/js-libp2p-websocket-star)
|
||||||
@ -44,11 +44,11 @@ Install `interface-peer-discovery` as one of the dependencies of your project an
|
|||||||
const test = require('interface-peer-discovery')
|
const test = require('interface-peer-discovery')
|
||||||
|
|
||||||
const common = {
|
const common = {
|
||||||
setup (cb) {
|
setup () {
|
||||||
cb(null, yourMuxer)
|
return YourDiscovery
|
||||||
},
|
},
|
||||||
teardown (cb) {
|
teardown () {
|
||||||
cb()
|
// Clean up any resources created by setup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,25 +56,28 @@ const common = {
|
|||||||
test(common)
|
test(common)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Go
|
|
||||||
|
|
||||||
> WIP - go-libp2p does not have a test suite available for Peer Discovery yet.
|
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
A valid (read: that follows this abstraction) Peer Discovery module must implement the following API:
|
A valid (read: that follows this abstraction) Peer Discovery module must implement the following API:
|
||||||
|
|
||||||
### `start` the service
|
### `start` the service
|
||||||
|
|
||||||
- `JavaScript` discovery.start(callback)
|
- `await discovery.start()`
|
||||||
- `Go` NA
|
|
||||||
|
Start the discovery service.
|
||||||
|
|
||||||
|
It returns a `Promise`
|
||||||
|
|
||||||
### `stop` the service
|
### `stop` the service
|
||||||
|
|
||||||
- `JavaScript` discovery.stop(callback)
|
- `await discovery.stop()`
|
||||||
- `Go` NA
|
|
||||||
|
Stop the discovery service.
|
||||||
|
|
||||||
|
It returns a `Promise`
|
||||||
|
|
||||||
### discoverying peers
|
### discoverying peers
|
||||||
|
|
||||||
- `JavaScript` discovery.on('peer', function (peerInfo) {})
|
- `discovery.on('peer', (peerInfo) => {})`
|
||||||
- `Go` NA
|
|
||||||
|
Everytime a peer is discovered by a discovery service, it emmits a `peer` event with the discover peer's [PeerInfo](https://github.com/libp2p/js-peer-info).
|
||||||
|
35
package.json
35
package.json
@ -5,22 +5,29 @@
|
|||||||
"leadMaintainer": "Vasco Santos <vasco.santos@moxy.studio>",
|
"leadMaintainer": "Vasco Santos <vasco.santos@moxy.studio>",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "aegir-lint",
|
"lint": "aegir lint",
|
||||||
"build": "aegir-build",
|
"test": "aegir test",
|
||||||
"test": "exit 0",
|
"build": "aegir build",
|
||||||
"release": "aegir-release",
|
"release": "aegir release --no-test",
|
||||||
"release-minor": "aegir-release --type minor",
|
"release-minor": "aegir release --type minor --no-test",
|
||||||
"release-major": "aegir-release --type major"
|
"release-major": "aegir release --type major --no-test",
|
||||||
|
"coverage": "exit(0)",
|
||||||
|
"coverage-publish": "exit(0)"
|
||||||
},
|
},
|
||||||
"pre-commit": [
|
"pre-push": [
|
||||||
"lint",
|
"lint"
|
||||||
"test"
|
|
||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/libp2p/interface-peer-discovery.git"
|
"url": "https://github.com/libp2p/interface-peer-discovery.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
"libp2p",
|
||||||
|
"network",
|
||||||
|
"p2p",
|
||||||
|
"peer",
|
||||||
|
"discovery",
|
||||||
|
"peer-to-peer",
|
||||||
"IPFS"
|
"IPFS"
|
||||||
],
|
],
|
||||||
"author": "David Dias <daviddias@ipfs.io>",
|
"author": "David Dias <daviddias@ipfs.io>",
|
||||||
@ -31,13 +38,15 @@
|
|||||||
"homepage": "https://github.com/libp2p/interface-peer-discovery",
|
"homepage": "https://github.com/libp2p/interface-peer-discovery",
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"aegir": "^18.2.2"
|
"aegir": "^20.3.1",
|
||||||
|
"chai": "^4.2.0",
|
||||||
|
"dirty-chai": "^2.0.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=4.0.0",
|
"node": ">=10.0.0",
|
||||||
"npm": ">=3.0.0"
|
"npm": ">=6.0.0"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"David Dias <daviddias.p@gmail.com>"
|
"David Dias <daviddias.p@gmail.com>"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
32
src/index.js
Normal file
32
src/index.js
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* eslint-env mocha */
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
module.exports = (common) => {
|
||||||
|
describe('interface-peer-discovery', () => {
|
||||||
|
let discovery
|
||||||
|
|
||||||
|
before(() => {
|
||||||
|
discovery = common.setup()
|
||||||
|
})
|
||||||
|
|
||||||
|
after(() => common.teardown && common.teardown())
|
||||||
|
|
||||||
|
it('can start the service', async () => {
|
||||||
|
await discovery.start()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can start and stop the service', async () => {
|
||||||
|
await discovery.start()
|
||||||
|
await discovery.stop()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should not fail to stop the service if it was not started', async () => {
|
||||||
|
await discovery.stop()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should not fail to start the service if it is already started', async () => {
|
||||||
|
await discovery.start()
|
||||||
|
await discovery.start()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user