mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-07-07 22:01:38 +00:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
aacb0e27d0 | |||
c00f94dfaf | |||
5967834a2f | |||
32ee3e18e2 | |||
557f6cab66 | |||
d98bb23fea | |||
6cf3723019 | |||
01e240420d | |||
ff0313721c |
30
CHANGELOG.md
30
CHANGELOG.md
@ -1,3 +1,33 @@
|
|||||||
|
<a name="0.2.2"></a>
|
||||||
|
## [0.2.2](https://github.com/libp2p/js-interfaces/compare/v0.2.1...v0.2.2) (2020-01-17)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **connection:** dont require remoteAddr on creation ([#20](https://github.com/libp2p/js-interfaces/issues/20)) ([5967834](https://github.com/libp2p/js-interfaces/commit/5967834))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a name="0.2.1"></a>
|
||||||
|
## [0.2.1](https://github.com/libp2p/js-interfaces/compare/v0.2.0...v0.2.1) (2019-12-28)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add crypto transmission error ([#17](https://github.com/libp2p/js-interfaces/issues/17)) ([d98bb23](https://github.com/libp2p/js-interfaces/commit/d98bb23))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a name="0.2.0"></a>
|
||||||
|
# [0.2.0](https://github.com/libp2p/js-interfaces/compare/v0.1.7...v0.2.0) (2019-12-20)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* transport should not handle connection if upgradeInbound throws ([#16](https://github.com/libp2p/js-interfaces/issues/16)) ([ff03137](https://github.com/libp2p/js-interfaces/commit/ff03137))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="0.1.7"></a>
|
<a name="0.1.7"></a>
|
||||||
## [0.1.7](https://github.com/libp2p/js-interfaces/compare/v0.1.6...v0.1.7) (2019-12-15)
|
## [0.1.7](https://github.com/libp2p/js-interfaces/compare/v0.1.6...v0.1.7) (2019-12-15)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "libp2p-interfaces",
|
"name": "libp2p-interfaces",
|
||||||
"version": "0.1.7",
|
"version": "0.2.2",
|
||||||
"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",
|
||||||
@ -46,6 +46,7 @@
|
|||||||
"libp2p-tcp": "^0.14.1",
|
"libp2p-tcp": "^0.14.1",
|
||||||
"multiaddr": "^7.1.0",
|
"multiaddr": "^7.1.0",
|
||||||
"p-limit": "^2.2.1",
|
"p-limit": "^2.2.1",
|
||||||
|
"p-wait-for": "^3.1.0",
|
||||||
"peer-id": "^0.13.3",
|
"peer-id": "^0.13.3",
|
||||||
"sinon": "^7.5.0",
|
"sinon": "^7.5.0",
|
||||||
"streaming-iterables": "^4.1.0"
|
"streaming-iterables": "^4.1.0"
|
||||||
@ -65,6 +66,7 @@
|
|||||||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
||||||
"Greg Zuro <gregzuro@users.noreply.github.com>",
|
"Greg Zuro <gregzuro@users.noreply.github.com>",
|
||||||
"Jacob Heun <jacobheun@gmail.com>",
|
"Jacob Heun <jacobheun@gmail.com>",
|
||||||
|
"Jacob Heun <jacobheun@Jacobs-MacBook-Pro.local>",
|
||||||
"James Ray <16969914+jamesray1@users.noreply.github.com>",
|
"James Ray <16969914+jamesray1@users.noreply.github.com>",
|
||||||
"Jeffrey Hulten <jhulten@gmail.com>",
|
"Jeffrey Hulten <jhulten@gmail.com>",
|
||||||
"João Santos <joaosantos15@users.noreply.github.com>",
|
"João Santos <joaosantos15@users.noreply.github.com>",
|
||||||
|
@ -110,7 +110,7 @@ const conn = new Connection({
|
|||||||
Creates a new Connection instance.
|
Creates a new Connection instance.
|
||||||
|
|
||||||
`localAddr` is the optional [multiaddr](https://github.com/multiformats/multiaddr) address used by the local peer to reach the remote.
|
`localAddr` is the optional [multiaddr](https://github.com/multiformats/multiaddr) address used by the local peer to reach the remote.
|
||||||
`remoteAddr` is the [multiaddr](https://github.com/multiformats/multiaddr) address used to communicate with the remote peer.
|
`remoteAddr` is the optional [multiaddr](https://github.com/multiformats/multiaddr) address used to communicate with the remote peer.
|
||||||
`localPeer` is the [PeerId](https://github.com/libp2p/js-peer-id) of the local peer.
|
`localPeer` is the [PeerId](https://github.com/libp2p/js-peer-id) of the local peer.
|
||||||
`remotePeer` is the [PeerId](https://github.com/libp2p/js-peer-id) of the remote peer.
|
`remotePeer` is the [PeerId](https://github.com/libp2p/js-peer-id) of the remote peer.
|
||||||
`newStream` is the `function` responsible for getting a new muxed+multistream-selected stream.
|
`newStream` is the `function` responsible for getting a new muxed+multistream-selected stream.
|
||||||
|
@ -18,7 +18,7 @@ class Connection {
|
|||||||
* Creates an instance of Connection.
|
* Creates an instance of Connection.
|
||||||
* @param {object} properties properties of the connection.
|
* @param {object} properties properties of the connection.
|
||||||
* @param {multiaddr} [properties.localAddr] local multiaddr of the connection if known.
|
* @param {multiaddr} [properties.localAddr] local multiaddr of the connection if known.
|
||||||
* @param {multiaddr} properties.remoteAddr remote multiaddr of the connection.
|
* @param {multiaddr} [properties.remoteAddr] remote multiaddr of the connection.
|
||||||
* @param {PeerId} properties.localPeer local peer-id.
|
* @param {PeerId} properties.localPeer local peer-id.
|
||||||
* @param {PeerId} properties.remotePeer remote peer-id.
|
* @param {PeerId} properties.remotePeer remote peer-id.
|
||||||
* @param {function} properties.newStream new stream muxer function.
|
* @param {function} properties.newStream new stream muxer function.
|
||||||
@ -34,7 +34,6 @@ class Connection {
|
|||||||
*/
|
*/
|
||||||
constructor ({ localAddr, remoteAddr, localPeer, remotePeer, newStream, close, getStreams, stat }) {
|
constructor ({ localAddr, remoteAddr, localPeer, remotePeer, newStream, close, getStreams, stat }) {
|
||||||
localAddr && assert(multiaddr.isMultiaddr(localAddr), 'localAddr must be an instance of multiaddr')
|
localAddr && assert(multiaddr.isMultiaddr(localAddr), 'localAddr must be an instance of multiaddr')
|
||||||
assert(multiaddr.isMultiaddr(remoteAddr), 'remoteAddr must be an instance of multiaddr')
|
|
||||||
assert(PeerId.isPeerId(localPeer), 'localPeer must be an instance of peer-id')
|
assert(PeerId.isPeerId(localPeer), 'localPeer must be an instance of peer-id')
|
||||||
assert(PeerId.isPeerId(remotePeer), 'remotePeer must be an instance of peer-id')
|
assert(PeerId.isPeerId(remotePeer), 'remotePeer must be an instance of peer-id')
|
||||||
assert(typeof newStream === 'function', 'new stream must be a function')
|
assert(typeof newStream === 'function', 'new stream must be a function')
|
||||||
|
@ -85,6 +85,7 @@ Common crypto errors come with the interface, and can be imported directly. All
|
|||||||
```js
|
```js
|
||||||
const {
|
const {
|
||||||
InvalidCryptoExchangeError,
|
InvalidCryptoExchangeError,
|
||||||
|
InvalidCryptoTransmissionError,
|
||||||
UnexpectedPeerError
|
UnexpectedPeerError
|
||||||
} = require('libp2p-interfaces/src/crypto/errors')
|
} = require('libp2p-interfaces/src/crypto/errors')
|
||||||
|
|
||||||
@ -95,4 +96,5 @@ console.log(error.code === UnexpectedPeerError.code) // true
|
|||||||
### Error Types
|
### Error Types
|
||||||
|
|
||||||
- `InvalidCryptoExchangeError` - Should be thrown when a peer provides data that is insufficient to finish the crypto exchange.
|
- `InvalidCryptoExchangeError` - Should be thrown when a peer provides data that is insufficient to finish the crypto exchange.
|
||||||
|
- `InvalidCryptoTransmissionError` - Should be thrown when an error occurs during encryption/decryption.
|
||||||
- `UnexpectedPeerError` - Should be thrown when the expected peer id does not match the peer id determined via the crypto exchange.
|
- `UnexpectedPeerError` - Should be thrown when the expected peer id does not match the peer id determined via the crypto exchange.
|
||||||
|
@ -22,7 +22,19 @@ class InvalidCryptoExchangeError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class InvalidCryptoTransmissionError extends Error {
|
||||||
|
constructor (message = 'Invalid crypto transmission') {
|
||||||
|
super(message)
|
||||||
|
this.code = InvalidCryptoTransmissionError.code
|
||||||
|
}
|
||||||
|
|
||||||
|
static get code () {
|
||||||
|
return 'ERR_INVALID_CRYPTO_TRANSMISSION'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
UnexpectedPeerError,
|
UnexpectedPeerError,
|
||||||
InvalidCryptoExchangeError
|
InvalidCryptoExchangeError,
|
||||||
|
InvalidCryptoTransmissionError
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ const expect = chai.expect
|
|||||||
chai.use(dirtyChai)
|
chai.use(dirtyChai)
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
|
|
||||||
|
const pWaitFor = require('p-wait-for')
|
||||||
const pipe = require('it-pipe')
|
const pipe = require('it-pipe')
|
||||||
const { isValidTick } = require('./utils')
|
const { isValidTick } = require('./utils')
|
||||||
|
|
||||||
@ -92,6 +93,23 @@ module.exports = (common) => {
|
|||||||
expect(upgradeSpy.callCount).to.equal(2)
|
expect(upgradeSpy.callCount).to.equal(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should not handle connection if upgradeInbound throws', async () => {
|
||||||
|
sinon.stub(upgrader, 'upgradeInbound').throws()
|
||||||
|
|
||||||
|
const listener = transport.createListener(() => {
|
||||||
|
throw new Error('should not handle the connection if upgradeInbound throws')
|
||||||
|
})
|
||||||
|
|
||||||
|
// Listen
|
||||||
|
await listener.listen(addrs[0])
|
||||||
|
|
||||||
|
// Create a connection to the listener
|
||||||
|
const socket = await transport.dial(addrs[0])
|
||||||
|
|
||||||
|
await pWaitFor(() => typeof socket.timeline.close === 'number')
|
||||||
|
await listener.close()
|
||||||
|
})
|
||||||
|
|
||||||
describe('events', () => {
|
describe('events', () => {
|
||||||
it('connection', (done) => {
|
it('connection', (done) => {
|
||||||
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound')
|
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound')
|
||||||
|
48
test/connection/index.spec.js
Normal file
48
test/connection/index.spec.js
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/* eslint-env mocha */
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const { Connection } = require('../../src/connection')
|
||||||
|
const peers = require('../../src/utils/peers')
|
||||||
|
const PeerId = require('peer-id')
|
||||||
|
const pair = require('it-pair')
|
||||||
|
|
||||||
|
describe('connection tests', () => {
|
||||||
|
it('should not require local or remote addrs', async () => {
|
||||||
|
const [localPeer, remotePeer] = await Promise.all([
|
||||||
|
PeerId.createFromJSON(peers[0]),
|
||||||
|
PeerId.createFromJSON(peers[1])
|
||||||
|
])
|
||||||
|
const openStreams = []
|
||||||
|
let streamId = 0
|
||||||
|
|
||||||
|
return new Connection({
|
||||||
|
localPeer,
|
||||||
|
remotePeer,
|
||||||
|
stat: {
|
||||||
|
timeline: {
|
||||||
|
open: Date.now() - 10,
|
||||||
|
upgraded: Date.now()
|
||||||
|
},
|
||||||
|
direction: 'outbound',
|
||||||
|
encryption: '/secio/1.0.0',
|
||||||
|
multiplexer: '/mplex/6.7.0'
|
||||||
|
},
|
||||||
|
newStream: (protocols) => {
|
||||||
|
const id = streamId++
|
||||||
|
const stream = pair()
|
||||||
|
|
||||||
|
stream.close = () => stream.sink([])
|
||||||
|
stream.id = id
|
||||||
|
|
||||||
|
openStreams.push(stream)
|
||||||
|
|
||||||
|
return {
|
||||||
|
stream,
|
||||||
|
protocol: protocols[0]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
close: () => {},
|
||||||
|
getStreams: () => openStreams
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
Reference in New Issue
Block a user