mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-07-07 16:11:51 +00:00
Compare commits
1 Commits
v0.5.0
...
chore/skip
Author | SHA1 | Date | |
---|---|---|---|
82ed140b42 |
22
CHANGELOG.md
22
CHANGELOG.md
@ -1,25 +1,3 @@
|
||||
<a name="0.5.0"></a>
|
||||
# [0.5.0](https://github.com/libp2p/js-interfaces/compare/v0.4.1...v0.5.0) (2020-08-24)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* replace remaining Buffer usage with Uint8Array ([#62](https://github.com/libp2p/js-interfaces/issues/62)) ([4130e7f](https://github.com/libp2p/js-interfaces/commit/4130e7f))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* records now marshal as Uint8Array instead of Buffer
|
||||
|
||||
* fix: refactor remaining Buffer usage to Uint8Array
|
||||
|
||||
|
||||
|
||||
<a name="0.4.1"></a>
|
||||
## [0.4.1](https://github.com/libp2p/js-interfaces/compare/v0.4.0...v0.4.1) (2020-08-11)
|
||||
|
||||
|
||||
|
||||
<a name="0.4.0"></a>
|
||||
# [0.4.0](https://github.com/libp2p/js-interfaces/compare/v0.3.2...v0.4.0) (2020-08-10)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "libp2p-interfaces",
|
||||
"version": "0.5.0",
|
||||
"version": "0.4.0",
|
||||
"description": "Interfaces for JS Libp2p",
|
||||
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
||||
"main": "src/index.js",
|
||||
@ -35,6 +35,7 @@
|
||||
"dependencies": {
|
||||
"abort-controller": "^3.0.0",
|
||||
"abortable-iterator": "^3.0.0",
|
||||
"buffer": "^5.6.0",
|
||||
"chai": "^4.2.0",
|
||||
"chai-checkmark": "^1.0.1",
|
||||
"class-is": "^1.1.0",
|
||||
@ -45,15 +46,14 @@
|
||||
"it-goodbye": "^2.0.1",
|
||||
"it-pair": "^1.0.0",
|
||||
"it-pipe": "^1.1.0",
|
||||
"libp2p-tcp": "^0.15.0",
|
||||
"libp2p-tcp": "^0.14.5",
|
||||
"multiaddr": "^8.0.0",
|
||||
"p-defer": "^3.0.0",
|
||||
"p-limit": "^2.3.0",
|
||||
"p-wait-for": "^3.1.0",
|
||||
"peer-id": "^0.14.0",
|
||||
"sinon": "^9.0.2",
|
||||
"streaming-iterables": "^5.0.2",
|
||||
"uint8arrays": "^1.1.0"
|
||||
"streaming-iterables": "^5.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"aegir": "^25.0.0",
|
||||
|
@ -1,19 +1,17 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const { Buffer } = require('buffer')
|
||||
const duplexPair = require('it-pair/duplex')
|
||||
const pipe = require('it-pipe')
|
||||
const peers = require('../../utils/peers')
|
||||
const { UnexpectedPeerError } = require('../errors')
|
||||
const PeerId = require('peer-id')
|
||||
const { collect } = require('streaming-iterables')
|
||||
const chai = require('chai')
|
||||
const expect = chai.expect
|
||||
chai.use(require('dirty-chai'))
|
||||
|
||||
const duplexPair = require('it-pair/duplex')
|
||||
const pipe = require('it-pipe')
|
||||
const PeerId = require('peer-id')
|
||||
const { collect } = require('streaming-iterables')
|
||||
const uint8arrayFromString = require('uint8arrays/from-string')
|
||||
|
||||
const peers = require('../../utils/peers')
|
||||
const { UnexpectedPeerError } = require('../errors')
|
||||
|
||||
module.exports = (common) => {
|
||||
describe('interface-crypto', () => {
|
||||
let crypto
|
||||
@ -57,7 +55,7 @@ module.exports = (common) => {
|
||||
pipe(inboundResult.conn, inboundResult.conn)
|
||||
|
||||
// Send some data and collect the result
|
||||
const input = uint8arrayFromString('data to encrypt')
|
||||
const input = Buffer.from('data to encrypt')
|
||||
const result = await pipe(
|
||||
[input],
|
||||
outboundResult.conn,
|
||||
|
@ -33,19 +33,19 @@ Include this badge in your readme if you make a new module that uses interface-p
|
||||
Install `interface-discovery` as one of the dependencies of your project and as a test file. Then, using `mocha` (for JavaScript) or a test runner with compatible API, do:
|
||||
|
||||
```js
|
||||
const tests = require('libp2p-interfaces/src/peer-discovery/tests')
|
||||
const test = require('interface-discovery')
|
||||
|
||||
describe('your discovery', () => {
|
||||
// use all of the test suits
|
||||
tests({
|
||||
setup () {
|
||||
return YourDiscovery
|
||||
},
|
||||
teardown () {
|
||||
// Clean up any resources created by setup()
|
||||
}
|
||||
})
|
||||
})
|
||||
const common = {
|
||||
setup () {
|
||||
return YourDiscovery
|
||||
},
|
||||
teardown () {
|
||||
// Clean up any resources created by setup()
|
||||
}
|
||||
}
|
||||
|
||||
// use all of the test suits
|
||||
test(common)
|
||||
```
|
||||
|
||||
## API
|
||||
|
@ -7,7 +7,7 @@ The record represents the data that will be stored inside the **envelope** when
|
||||
|
||||
Taking into account that a record might be used in different contexts, an **envelope** signature made for a specific purpose **must not** be considered valid for a different purpose. Accordingly, each record has a short and descriptive string representing the record use case, known as **domain**. The data to be signed will be prepended with the domain string, in order to create a domain signature.
|
||||
|
||||
A record can also contain a Uint8Array codec (ideally registered as a [multicodec](https://github.com/multiformats/multicodec)). This codec will prefix the record data in the **envelope** , so that it can be deserialized deterministically.
|
||||
A record can also contain a Buffer codec (ideally registered as a [multicodec](https://github.com/multiformats/multicodec)). This codec will prefix the record data in the **envelope** , so that it can be deserialized deterministically.
|
||||
|
||||
## Usage
|
||||
|
||||
@ -30,11 +30,10 @@ describe('your record', () => {
|
||||
```js
|
||||
const multicodec = require('multicodec')
|
||||
const Record = require('libp2p-interfaces/src/record')
|
||||
const fromString = require('uint8arrays/from-string')
|
||||
// const Protobuf = require('./record.proto')
|
||||
|
||||
const ENVELOPE_DOMAIN_PEER_RECORD = 'libp2p-peer-record'
|
||||
const ENVELOPE_PAYLOAD_TYPE_PEER_RECORD = fromString('0301', 'hex')
|
||||
const ENVELOPE_PAYLOAD_TYPE_PEER_RECORD = Buffer.from('0301', 'hex')
|
||||
|
||||
class PeerRecord extends Record {
|
||||
constructor (peerId, multiaddrs, seqNumber) {
|
||||
|
@ -9,7 +9,7 @@ class Record {
|
||||
/**
|
||||
* @constructor
|
||||
* @param {String} domain signature domain
|
||||
* @param {Uint8Array} codec identifier of the type of record
|
||||
* @param {Buffer} codec identifier of the type of record
|
||||
*/
|
||||
constructor (domain, codec) {
|
||||
this.domain = domain
|
||||
|
@ -24,7 +24,7 @@ module.exports = (test) => {
|
||||
|
||||
it('is able to marshal', () => {
|
||||
const rawData = record.marshal()
|
||||
expect(rawData).to.be.an.instanceof(Uint8Array)
|
||||
expect(Buffer.isBuffer(rawData)).to.eql(true)
|
||||
})
|
||||
|
||||
it('is able to compare two records', () => {
|
||||
|
@ -2,6 +2,7 @@
|
||||
/* eslint max-nested-callbacks: ["error", 8] */
|
||||
'use strict'
|
||||
|
||||
const { Buffer } = require('buffer')
|
||||
const pair = require('it-pair/duplex')
|
||||
const pipe = require('it-pipe')
|
||||
const { consume } = require('streaming-iterables')
|
||||
@ -9,7 +10,6 @@ const Tcp = require('libp2p-tcp')
|
||||
const multiaddr = require('multiaddr')
|
||||
const abortable = require('abortable-iterator')
|
||||
const AbortController = require('abort-controller')
|
||||
const uint8arrayFromString = require('uint8arrays/from-string')
|
||||
|
||||
const mh = multiaddr('/ip4/127.0.0.1/tcp/0')
|
||||
|
||||
@ -18,7 +18,7 @@ function pause (ms) {
|
||||
}
|
||||
|
||||
function randomBuffer () {
|
||||
return uint8arrayFromString(Math.random().toString())
|
||||
return Buffer.from(Math.random().toString())
|
||||
}
|
||||
|
||||
const infiniteRandom = {
|
||||
|
@ -31,7 +31,8 @@ module.exports = (common) => {
|
||||
}
|
||||
}
|
||||
|
||||
describe('dial', () => {
|
||||
describe('dial', function () {
|
||||
this.timeout(20 * 1000)
|
||||
let addrs
|
||||
let transport
|
||||
let connector
|
||||
@ -129,7 +130,7 @@ module.exports = (common) => {
|
||||
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
|
||||
async function * delayedResponse (source) {
|
||||
for await (const val of source) {
|
||||
|
@ -2,6 +2,7 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const { Buffer } = require('buffer')
|
||||
const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
const expect = chai.expect
|
||||
@ -10,7 +11,6 @@ const sinon = require('sinon')
|
||||
|
||||
const pWaitFor = require('p-wait-for')
|
||||
const pipe = require('it-pipe')
|
||||
const uint8arrayFromString = require('uint8arrays/from-string')
|
||||
const { isValidTick } = require('./utils')
|
||||
|
||||
module.exports = (common) => {
|
||||
@ -31,7 +31,8 @@ module.exports = (common) => {
|
||||
}
|
||||
}
|
||||
|
||||
describe('listen', () => {
|
||||
describe('listen', function () {
|
||||
this.timeout(20 * 1000)
|
||||
let addrs
|
||||
let transport
|
||||
|
||||
@ -51,7 +52,7 @@ module.exports = (common) => {
|
||||
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 listenerConns = []
|
||||
|
||||
@ -76,7 +77,7 @@ module.exports = (common) => {
|
||||
// Wait for the data send and close to finish
|
||||
await Promise.all([
|
||||
pipe(
|
||||
[uint8arrayFromString('Some data that is never handled')],
|
||||
[Buffer.from('Some data that is never handled')],
|
||||
socket1
|
||||
),
|
||||
// Closer the listener (will take a couple of seconds to time out)
|
||||
@ -94,7 +95,7 @@ module.exports = (common) => {
|
||||
expect(upgradeSpy.callCount).to.equal(2)
|
||||
})
|
||||
|
||||
it('should not handle connection if upgradeInbound throws', async () => {
|
||||
it.skip('should not handle connection if upgradeInbound throws', async () => {
|
||||
sinon.stub(upgrader, 'upgradeInbound').throws()
|
||||
|
||||
const listener = transport.createListener(() => {
|
||||
|
Reference in New Issue
Block a user