mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-07-10 19:21:40 +00:00
Compare commits
10 Commits
v0.2.6
...
chore/skip
Author | SHA1 | Date | |
---|---|---|---|
28eeaf6977 | |||
170c2fd46e | |||
12f11c88e2 | |||
e5f4bdac44 | |||
dba3b9932f | |||
c56dd3e3fa | |||
de64a49007 | |||
3cfd9714bd | |||
78e015cef3 | |||
bd5a8b9337 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -13,3 +13,4 @@ docs
|
|||||||
node_modules
|
node_modules
|
||||||
# Lock files
|
# Lock files
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
yarn.lock
|
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,3 +1,13 @@
|
|||||||
|
<a name="0.2.7"></a>
|
||||||
|
## [0.2.7](https://github.com/libp2p/js-interfaces/compare/v0.2.6...v0.2.7) (2020-03-20)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* add buffer ([#39](https://github.com/libp2p/js-interfaces/issues/39)) ([78e015c](https://github.com/libp2p/js-interfaces/commit/78e015c))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="0.2.6"></a>
|
<a name="0.2.6"></a>
|
||||||
## [0.2.6](https://github.com/libp2p/js-interfaces/compare/v0.2.5...v0.2.6) (2020-02-17)
|
## [0.2.6](https://github.com/libp2p/js-interfaces/compare/v0.2.5...v0.2.6) (2020-02-17)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "libp2p-interfaces",
|
"name": "libp2p-interfaces",
|
||||||
"version": "0.2.6",
|
"version": "0.2.7",
|
||||||
"description": "Interfaces for JS Libp2p",
|
"description": "Interfaces for JS Libp2p",
|
||||||
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
@ -35,9 +35,11 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"abort-controller": "^3.0.0",
|
"abort-controller": "^3.0.0",
|
||||||
"abortable-iterator": "^3.0.0",
|
"abortable-iterator": "^3.0.0",
|
||||||
|
"buffer": "^5.5.0",
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
"chai-checkmark": "^1.0.1",
|
"chai-checkmark": "^1.0.1",
|
||||||
"class-is": "^1.1.0",
|
"class-is": "^1.1.0",
|
||||||
|
"delay": "^4.3.0",
|
||||||
"detect-node": "^2.0.4",
|
"detect-node": "^2.0.4",
|
||||||
"dirty-chai": "^2.0.1",
|
"dirty-chai": "^2.0.1",
|
||||||
"err-code": "^2.0.0",
|
"err-code": "^2.0.0",
|
||||||
@ -46,11 +48,12 @@
|
|||||||
"it-pipe": "^1.0.1",
|
"it-pipe": "^1.0.1",
|
||||||
"libp2p-tcp": "^0.14.1",
|
"libp2p-tcp": "^0.14.1",
|
||||||
"multiaddr": "^7.1.0",
|
"multiaddr": "^7.1.0",
|
||||||
|
"p-defer": "^3.0.0",
|
||||||
"p-limit": "^2.2.2",
|
"p-limit": "^2.2.2",
|
||||||
"p-wait-for": "^3.1.0",
|
"p-wait-for": "^3.1.0",
|
||||||
"peer-id": "^0.13.3",
|
"peer-id": "^0.13.3",
|
||||||
"peer-info": "^0.17.0",
|
"peer-info": "^0.17.0",
|
||||||
"sinon": "^8.1.1",
|
"sinon": "^9.0.0",
|
||||||
"streaming-iterables": "^4.1.0"
|
"streaming-iterables": "^4.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* eslint-env mocha */
|
/* eslint-env mocha */
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const { Buffer } = require('buffer')
|
||||||
const duplexPair = require('it-pair/duplex')
|
const duplexPair = require('it-pair/duplex')
|
||||||
const pipe = require('it-pipe')
|
const pipe = require('it-pipe')
|
||||||
const peers = require('../../utils/peers')
|
const peers = require('../../utils/peers')
|
||||||
|
@ -16,6 +16,7 @@ The API is presented with both Node.js and Go primitives, however, there is not
|
|||||||
- [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)
|
||||||
|
- [TypeScript discv5](https://github.com/chainsafe/discv5)
|
||||||
|
|
||||||
Send a PR to add a new one if you happen to find or write one.
|
Send a PR to add a new one if you happen to find or write one.
|
||||||
|
|
||||||
@ -69,6 +70,9 @@ It returns a `Promise`
|
|||||||
|
|
||||||
### discoverying peers
|
### discoverying peers
|
||||||
|
|
||||||
- `discovery.on('peer', (peerInfo) => {})`
|
- `discovery.on('peer', (peerData) => {})`
|
||||||
|
|
||||||
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).
|
Every time a peer is discovered by a discovery service, it emits a `peer` event with the discovered peer's information, which must contain the following properties:
|
||||||
|
|
||||||
|
- `<`[`PeerId`](https://github.com/libp2p/js-peer-id)`>` `peerData.id`
|
||||||
|
- `<Array<`[`Multiaddr`](https://github.com/multiformats/js-multiaddr)`>>` `peerData.multiaddrs`
|
||||||
|
@ -1,17 +1,31 @@
|
|||||||
/* eslint-env mocha */
|
/* eslint-env mocha */
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const chai = require('chai')
|
||||||
|
const expect = chai.expect
|
||||||
|
chai.use(require('dirty-chai'))
|
||||||
|
|
||||||
|
const multiaddr = require('multiaddr')
|
||||||
|
const PeerId = require('peer-id')
|
||||||
|
|
||||||
|
const delay = require('delay')
|
||||||
|
const pDefer = require('p-defer')
|
||||||
|
|
||||||
module.exports = (common) => {
|
module.exports = (common) => {
|
||||||
describe('interface-peer-discovery', () => {
|
describe('interface-peer-discovery', () => {
|
||||||
let discovery
|
let discovery
|
||||||
|
|
||||||
before(async () => {
|
beforeEach(async () => {
|
||||||
discovery = await common.setup()
|
discovery = await common.setup()
|
||||||
})
|
})
|
||||||
|
|
||||||
after(() => common.teardown && common.teardown())
|
afterEach('ensure discovery was stopped', async () => {
|
||||||
|
await discovery.stop()
|
||||||
|
|
||||||
afterEach('ensure discovery was stopped', () => discovery.stop())
|
discovery.removeAllListeners()
|
||||||
|
|
||||||
|
common.teardown && common.teardown()
|
||||||
|
})
|
||||||
|
|
||||||
it('can start the service', async () => {
|
it('can start the service', async () => {
|
||||||
await discovery.start()
|
await discovery.start()
|
||||||
@ -30,5 +44,49 @@ module.exports = (common) => {
|
|||||||
await discovery.start()
|
await discovery.start()
|
||||||
await discovery.start()
|
await discovery.start()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should emit a peer event after start', async () => {
|
||||||
|
const defer = pDefer()
|
||||||
|
await discovery.start()
|
||||||
|
|
||||||
|
discovery.once('peer', ({ id, multiaddrs }) => {
|
||||||
|
expect(id).to.exist()
|
||||||
|
expect(PeerId.isPeerId(id)).to.eql(true)
|
||||||
|
expect(multiaddrs).to.exist()
|
||||||
|
|
||||||
|
multiaddrs.forEach((m) => expect(multiaddr.isMultiaddr(m)).to.eql(true))
|
||||||
|
|
||||||
|
defer.resolve()
|
||||||
|
})
|
||||||
|
|
||||||
|
await defer.promise
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should not receive a peer event before start', async () => {
|
||||||
|
discovery.once('peer', () => {
|
||||||
|
throw new Error('should not receive a peer event before start')
|
||||||
|
})
|
||||||
|
|
||||||
|
await delay(2000)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should not receive a peer event after stop', async () => {
|
||||||
|
const deferStart = pDefer()
|
||||||
|
|
||||||
|
await discovery.start()
|
||||||
|
|
||||||
|
discovery.once('peer', () => {
|
||||||
|
deferStart.resolve()
|
||||||
|
})
|
||||||
|
|
||||||
|
await deferStart.promise
|
||||||
|
await discovery.stop()
|
||||||
|
|
||||||
|
discovery.once('peer', () => {
|
||||||
|
throw new Error('should not receive a peer event after stop')
|
||||||
|
})
|
||||||
|
|
||||||
|
await delay(2000)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
/* eslint max-nested-callbacks: ["error", 8] */
|
/* eslint max-nested-callbacks: ["error", 8] */
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const { Buffer } = require('buffer')
|
||||||
const pair = require('it-pair/duplex')
|
const pair = require('it-pair/duplex')
|
||||||
const pipe = require('it-pipe')
|
const pipe = require('it-pipe')
|
||||||
const { consume } = require('streaming-iterables')
|
const { consume } = require('streaming-iterables')
|
||||||
|
@ -31,7 +31,8 @@ module.exports = (common) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('dial', () => {
|
describe('dial', function () {
|
||||||
|
this.timeout(20 * 1000)
|
||||||
let addrs
|
let addrs
|
||||||
let transport
|
let transport
|
||||||
let connector
|
let connector
|
||||||
@ -129,7 +130,7 @@ module.exports = (common) => {
|
|||||||
expect.fail('Did not throw error with code ' + AbortError.code)
|
expect.fail('Did not throw error with code ' + AbortError.code)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('abort while reading throws AbortError', async () => {
|
it.skip('abort while reading throws AbortError', async () => {
|
||||||
// Add a delay to the response from the server
|
// Add a delay to the response from the server
|
||||||
async function * delayedResponse (source) {
|
async function * delayedResponse (source) {
|
||||||
for await (const val of source) {
|
for await (const val of source) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
/* eslint-env mocha */
|
/* eslint-env mocha */
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const { Buffer } = require('buffer')
|
||||||
const chai = require('chai')
|
const chai = require('chai')
|
||||||
const dirtyChai = require('dirty-chai')
|
const dirtyChai = require('dirty-chai')
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
@ -30,7 +31,8 @@ module.exports = (common) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('listen', () => {
|
describe('listen', function () {
|
||||||
|
this.timeout(20 * 1000)
|
||||||
let addrs
|
let addrs
|
||||||
let transport
|
let transport
|
||||||
|
|
||||||
@ -50,7 +52,7 @@ module.exports = (common) => {
|
|||||||
await listener.close()
|
await listener.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('close listener with connections, through timeout', async () => {
|
it.skip('close listener with connections, through timeout', async () => {
|
||||||
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound')
|
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound')
|
||||||
const listenerConns = []
|
const listenerConns = []
|
||||||
|
|
||||||
|
@ -5,13 +5,20 @@ const tests = require('../../src/peer-discovery/tests')
|
|||||||
const MockDiscovery = require('./mock-discovery')
|
const MockDiscovery = require('./mock-discovery')
|
||||||
|
|
||||||
describe('compliance tests', () => {
|
describe('compliance tests', () => {
|
||||||
|
let intervalId
|
||||||
|
|
||||||
tests({
|
tests({
|
||||||
async setup () {
|
setup () {
|
||||||
await new Promise(resolve => setTimeout(resolve, 10))
|
const mockDiscovery = new MockDiscovery({
|
||||||
return new MockDiscovery()
|
discoveryDelay: 1
|
||||||
|
})
|
||||||
|
|
||||||
|
intervalId = setInterval(mockDiscovery._discoverPeer, 1000)
|
||||||
|
|
||||||
|
return mockDiscovery
|
||||||
},
|
},
|
||||||
async teardown () {
|
teardown () {
|
||||||
await new Promise(resolve => setTimeout(resolve, 10))
|
clearInterval(intervalId)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
const { EventEmitter } = require('events')
|
const { EventEmitter } = require('events')
|
||||||
|
|
||||||
|
const multiaddr = require('multiaddr')
|
||||||
const PeerId = require('peer-id')
|
const PeerId = require('peer-id')
|
||||||
const PeerInfo = require('peer-info')
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emits 'peer' events on discovery.
|
* Emits 'peer' events on discovery.
|
||||||
@ -37,10 +37,12 @@ class MockDiscovery extends EventEmitter {
|
|||||||
if (!this._isRunning) return
|
if (!this._isRunning) return
|
||||||
|
|
||||||
const peerId = await PeerId.create({ bits: 512 })
|
const peerId = await PeerId.create({ bits: 512 })
|
||||||
const peerInfo = new PeerInfo(peerId)
|
|
||||||
|
|
||||||
this._timer = setTimeout(() => {
|
this._timer = setTimeout(() => {
|
||||||
this.emit('peer', peerInfo)
|
this.emit('peer', {
|
||||||
|
id: peerId,
|
||||||
|
multiaddrs: [multiaddr('/ip4/127.0.0.1/tcp/8000')]
|
||||||
|
})
|
||||||
}, this.options.discoveryDelay || 1000)
|
}, this.options.discoveryDelay || 1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user