Compare commits

..

27 Commits

Author SHA1 Message Date
Jacob Heun
32e7a83c39 chore: release version v0.29.0-rc.0 2020-08-25 16:59:42 +02:00
Jacob Heun
83856611de chore: update contributors 2020-08-25 16:59:41 +02:00
Vasco Santos
69c31374ab docs: migration 0.28 to 0.29 (#736)
* docs: migration 0.28 to 0.29

* chore: finish pubsub migration

* chore: add uintarray migration and modules

* chore: apply suggestions from code review

Co-authored-by: Jacob Heun <jacobheun@gmail.com>

* chore: add uint8array module reference

* chore: rename files

Co-authored-by: Jacob Heun <jacobheun@gmail.com>
2020-08-25 16:49:07 +02:00
Vasco Santos
e14ce40b09 feat: gossipsub 1.1 (#733)
* feat: gossipsub 1.1

BREAKING CHANGE: pubsub implementation is now directly exposed and its API was updated according to the new pubsub interface in js-libp2p-interfaces repo

* chore: use gossipsub branch with src added

* fix: add pubsub handlers adapter

* chore: fix deps

* chore: update pubsub docs and examples

* chore: apply suggestions from code review

Co-authored-by: Jacob Heun <jacobheun@gmail.com>

* chore: use new floodsub

* chore: change validator doc set

Co-authored-by: Jacob Heun <jacobheun@gmail.com>

* chore: add new gossipsub src

Co-authored-by: Jacob Heun <jacobheun@gmail.com>
2020-08-25 16:48:04 +02:00
Alex Potsides
507f8c441c fix: replace node buffers with uint8arrays (#730)
* fix: replace node buffers with uint8arrays

Upgrades all deps and replaces all use of node Buffers with Uint8Arrays

BREAKING CHANGES:

- All deps used by this module now use Uint8Arrays in place of node Buffers

* chore: browser fixes

* chore: remove .only

* chore: stringify uint8array before parsing

* chore: update interop suite

* chore: remove ts from build command

* chore: update deps

* fix: update records to use uint8array

* chore: fix lint

* chore: update deps

Co-authored-by: Jacob Heun <jacobheun@gmail.com>
2020-08-24 12:58:02 +02:00
Vasco Santos
02b6248aa3 chore: apply suggestions from code review
Co-authored-by: Jacob Heun <jacobheun@gmail.com>
2020-08-12 17:08:27 +02:00
Vasco Santos
7681a19cd9 chore: add notice for addressBook.set 2020-08-12 17:08:27 +02:00
Vasco Santos
c7e93a5764 chore: apply suggestions from code review
Co-authored-by: Jacob Heun <jacobheun@gmail.com>
2020-08-12 17:08:27 +02:00
Vasco Santos
26e4481bcb chore: apply suggestions from code review 2020-08-12 17:08:26 +02:00
Vasco Santos
e1b8edcfa3 fix: do not return self on peerstore.peers 2020-08-12 17:08:26 +02:00
Vasco Santos
5bce4cbbc6 chore: increase bundle size 2020-08-12 17:08:26 +02:00
Vasco Santos
109abda1fe chore: rename isEqual to equals in tests 2020-08-12 17:08:26 +02:00
Vasco Santos
cbd2b52e0e chore: add certified peer records to persisted peer store 2020-08-12 17:08:26 +02:00
Vasco Santos
e0ed258c54 feat: cerified addressbook 2020-08-12 17:08:01 +02:00
Vasco Santos
40e4e94f20 chore: apply suggestions from code review
Co-authored-by: Jacob Heun <jacobheun@gmail.com>
2020-08-12 17:08:00 +02:00
Vasco Santos
a798c65286 fix: revert new identify protocol versions 2020-08-12 17:08:00 +02:00
Vasco Santos
4dfa8094d8 chore: address review 2020-08-12 17:05:17 +02:00
Vasco Santos
83922a7fad feat: create self peer record in identify 2020-08-12 17:05:17 +02:00
Vasco Santos
f8354577a2 feat: exchange signed peer records in identify 2020-08-12 17:05:17 +02:00
Vasco Santos
ce8b77106e chore: apply suggestions from code review
Co-authored-by: Jacob Heun <jacobheun@gmail.com>
2020-08-12 17:03:41 +02:00
Vasco Santos
53340af863 chore: address review 2020-08-12 17:01:48 +02:00
Vasco Santos
97b5d2ade4 fix: signature compliant with spec 2020-08-12 17:01:47 +02:00
Vasco Santos
1e6ada5db9 chore: refactor and better docs 2020-08-12 17:01:47 +02:00
Vasco Santos
e29d4a6d6c chore: apply suggestions from code review
Co-authored-by: Jacob Heun <jacobheun@gmail.com>
2020-08-12 17:01:47 +02:00
Vasco Santos
f95edf1c20 feat: signed peer records record manager 2020-08-12 17:01:47 +02:00
Jacob Heun
c27228878e chore: update travis to use node lts and stable
BREAKING CHANGE: this drops testing support in node 10.
2020-08-12 17:01:47 +02:00
Vasco Santos
ad7f02e62a revert: reapply "fix: throw if no conn encryption module provided (#665)"
This reapplies commit b621fbdfdc.
2020-08-12 17:01:47 +02:00
10 changed files with 18 additions and 135 deletions

View File

@@ -1,95 +1,3 @@
<a name="0.29.0"></a>
# [0.29.0](https://github.com/libp2p/js-libp2p/compare/v0.28.10...v0.29.0) (2020-08-27)
### Bug Fixes
* do not return self on peerstore.peers ([15613cc](https://github.com/libp2p/js-libp2p/commit/15613cc))
* peer record interop with go ([#739](https://github.com/libp2p/js-libp2p/issues/739)) ([93dda74](https://github.com/libp2p/js-libp2p/commit/93dda74))
* replace node buffers with uint8arrays ([#730](https://github.com/libp2p/js-libp2p/issues/730)) ([1e86971](https://github.com/libp2p/js-libp2p/commit/1e86971))
* revert new identify protocol versions ([3158366](https://github.com/libp2p/js-libp2p/commit/3158366))
* signature compliant with spec ([4ab125e](https://github.com/libp2p/js-libp2p/commit/4ab125e))
### Chores
* update travis to use node lts and stable ([098f3d1](https://github.com/libp2p/js-libp2p/commit/098f3d1))
### Features
* cerified addressbook ([8f2e690](https://github.com/libp2p/js-libp2p/commit/8f2e690))
* create self peer record in identify ([8a97dde](https://github.com/libp2p/js-libp2p/commit/8a97dde))
* exchange signed peer records in identify ([e50f0ee](https://github.com/libp2p/js-libp2p/commit/e50f0ee))
* gossipsub 1.1 ([#733](https://github.com/libp2p/js-libp2p/issues/733)) ([55c9bfa](https://github.com/libp2p/js-libp2p/commit/55c9bfa))
* signed peer records record manager ([3e5d450](https://github.com/libp2p/js-libp2p/commit/3e5d450))
### Reverts
* reapply "fix: throw if no conn encryption module provided ([#665](https://github.com/libp2p/js-libp2p/issues/665))" ([689f90a](https://github.com/libp2p/js-libp2p/commit/689f90a))
### BREAKING CHANGES
* pubsub implementation is now directly exposed and its API was updated according to the new pubsub interface in js-libp2p-interfaces repo
* chore: use gossipsub branch with src added
* fix: add pubsub handlers adapter
* chore: fix deps
* chore: update pubsub docs and examples
* chore: apply suggestions from code review
Co-authored-by: Jacob Heun <jacobheun@gmail.com>
* chore: use new floodsub
* chore: change validator doc set
Co-authored-by: Jacob Heun <jacobheun@gmail.com>
* chore: add new gossipsub src
Co-authored-by: Jacob Heun <jacobheun@gmail.com>
* - All deps used by this module now use Uint8Arrays in place of node Buffers
* chore: browser fixes
* chore: remove .only
* chore: stringify uint8array before parsing
* chore: update interop suite
* chore: remove ts from build command
* chore: update deps
* fix: update records to use uint8array
* chore: fix lint
* chore: update deps
Co-authored-by: Jacob Heun <jacobheun@gmail.com>
* this drops testing support in node 10.
<a name="0.29.0-rc.1"></a>
# [0.29.0-rc.1](https://github.com/libp2p/js-libp2p/compare/v0.29.0-rc.0...v0.29.0-rc.1) (2020-08-27)
### Bug Fixes
* peer record interop with go ([#739](https://github.com/libp2p/js-libp2p/issues/739)) ([c4c7ef9](https://github.com/libp2p/js-libp2p/commit/c4c7ef9))
<a name="0.29.0-rc.0"></a>
# [0.29.0-rc.0](https://github.com/libp2p/js-libp2p/compare/v0.28.10...v0.29.0-rc.0) (2020-08-25)

View File

@@ -1220,7 +1220,7 @@ Get the stored information of a given peer, namely its [`PeerId`][peer-id], know
| Type | Description |
|------|-------------|
| `{ id: PeerId, addresses: Array<Address>, metadata: Map<string, Buffer>}, protocols: Array<string> }` | Peer information of the provided peer |
| `{ id: PeerId, addresses: Array<Address>, protocols: Array<string> }` | Peer information of the provided peer |
#### Example
@@ -1247,13 +1247,13 @@ Get all the stored information of every peer.
| Type | Description |
|------|-------------|
| `Map<string, { id: PeerId, addresses: Array<Address>, metadata: Map<string, Buffer>}, protocols: Array<string> }>` | Peer data of every peer known |
| `Map<string, { id: PeerId, addresses: Array<Address>, protocols: Array<string> }>` | Peer data of every peer known |
#### Example
```js
for (let [peerIdString, peer] of peerStore.peers.entries()) {
// peer { id, addresses, metadata, protocols }
// peer { id, addresses, protocols }
}
```

View File

@@ -277,6 +277,6 @@ With this release you should update the following libp2p modules if you are rely
"libp2p-noise": "^2.0.0",
"libp2p-secio": "^0.13.1",
"libp2p-tcp": "^0.15.1",
"libp2p-webrtc-star": "^0.20.0",
"libp2p-webrtc-star": "^0.19.0",
"libp2p-websockets": "^0.14.0",
```

View File

@@ -1,6 +1,6 @@
{
"name": "libp2p",
"version": "0.29.0",
"version": "0.29.0-rc.0",
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
"main": "src/index.js",
@@ -65,7 +65,7 @@
"merge-options": "^2.0.0",
"moving-average": "^1.0.0",
"multiaddr": "^8.0.0",
"multicodec": "^2.0.0",
"multicodec": "^1.0.2",
"multistream-select": "^1.0.0",
"mutable-proxy": "^1.0.0",
"node-forge": "^0.9.1",
@@ -92,7 +92,7 @@
"cids": "^1.0.0",
"delay": "^4.3.0",
"dirty-chai": "^2.0.1",
"interop-libp2p": "^0.3.0",
"interop-libp2p": "libp2p/interop#chore/gossipsub-1.1",
"ipfs-http-client": "^46.0.0",
"it-concat": "^1.0.0",
"it-pair": "^1.0.0",
@@ -102,14 +102,14 @@
"libp2p-delegated-content-routing": "^0.6.0",
"libp2p-delegated-peer-routing": "^0.6.0",
"libp2p-floodsub": "^0.23.0",
"libp2p-gossipsub": "^0.6.0",
"libp2p-gossipsub": "ChainSafe/js-libp2p-gossipsub#chore/use-libp2p-interfaces0.5.1-with-src",
"libp2p-kad-dht": "^0.20.0",
"libp2p-mdns": "^0.15.0",
"libp2p-mplex": "^0.10.0",
"libp2p-noise": "^2.0.0",
"libp2p-secio": "^0.13.1",
"libp2p-tcp": "^0.15.1",
"libp2p-webrtc-star": "^0.20.0",
"libp2p-webrtc-star": "^0.19.0",
"libp2p-websockets": "^0.14.0",
"multihashes": "^3.0.1",
"nock": "^13.0.3",

View File

@@ -32,7 +32,6 @@ class PeerStore extends EventEmitter {
* @property {PeerId} id peer's peer-id instance.
* @property {Array<Address>} addresses peer's addresses containing its multiaddrs and metadata.
* @property {Array<string>} protocols peer's supported protocols.
* @property {Map<string, Buffer>} metadata peer's metadata map.
*/
/**

View File

@@ -140,7 +140,7 @@ Envelope.createFromProtobuf = async (data) => {
*/
Envelope.seal = async (record, peerId) => {
const domain = record.domain
const payloadType = record.codec
const payloadType = uint8arraysFromString(record.codec)
const payload = record.marshal()
const signData = formatSignaturePayload(domain, payloadType, payload)

View File

@@ -3,9 +3,9 @@
const multicodec = require('multicodec')
// The domain string used for peer records contained in a Envelope.
module.exports.ENVELOPE_DOMAIN_PEER_RECORD = multicodec.getName(multicodec.LIBP2P_PEER_RECORD)
module.exports.ENVELOPE_DOMAIN_PEER_RECORD = 'libp2p-peer-record'
// The type hint used to identify peer records in a Envelope.
// Defined in https://github.com/multiformats/multicodec/blob/master/table.csv
// with name "libp2p-peer-record"
module.exports.ENVELOPE_PAYLOAD_TYPE_PEER_RECORD = Uint8Array.from([3, 1])
module.exports.ENVELOPE_PAYLOAD_TYPE_PEER_RECORD = multicodec.print[multicodec.LIBP2P_PEER_RECORD]

View File

@@ -311,11 +311,7 @@ describe('Pubsub subsystem operates correctly', () => {
expect(handlerSpy.args.map(([message]) => uint8ArrayToString(message.data))).to.include.members(['message1', 'message2'])
// Disconnect the first connection (this acts as a delayed reconnect)
const libp2pConnUpdateSpy = sinon.spy(libp2p.connectionManager.connections, 'set')
const remoteLibp2pConnUpdateSpy = sinon.spy(remoteLibp2p.connectionManager.connections, 'set')
await originalConnection.close()
await pWaitFor(() => libp2pConnUpdateSpy.callCount === 1 && remoteLibp2pConnUpdateSpy.callCount === 1)
// Verify messages go both ways after the disconnect
handlerSpy.resetHistory()

View File

@@ -7,8 +7,6 @@ chai.use(require('chai-bytes'))
chai.use(require('chai-as-promised'))
const { expect } = chai
const uint8arrayFromString = require('uint8arrays/from-string')
const uint8arrayEquals = require('uint8arrays/equals')
const Envelope = require('../../src/record/envelope')
const Record = require('libp2p-interfaces/src/record')
const { codes: ErrorCodes } = require('../../src/errors')
@@ -16,7 +14,7 @@ const { codes: ErrorCodes } = require('../../src/errors')
const peerUtils = require('../utils/creators/peer')
const domain = 'libp2p-testing'
const codec = uint8arrayFromString('/libp2p/testdata')
const codec = '/libp2p/testdata'
class TestRecord extends Record {
constructor (data) {
@@ -25,16 +23,16 @@ class TestRecord extends Record {
}
marshal () {
return uint8arrayFromString(this.data)
return Buffer.from(this.data)
}
equals (other) {
return uint8arrayEquals(this.data, other.data)
return Buffer.compare(this.data, other.data)
}
}
describe('Envelope', () => {
const payloadType = codec
const payloadType = Buffer.from(codec)
let peerId
let testRecord
@@ -45,7 +43,7 @@ describe('Envelope', () => {
it('creates an envelope with a random key', () => {
const payload = testRecord.marshal()
const signature = uint8arrayFromString(Math.random().toString(36).substring(7))
const signature = Buffer.from(Math.random().toString(36).substring(7))
const envelope = new Envelope({
peerId,
@@ -65,7 +63,7 @@ describe('Envelope', () => {
const envelope = await Envelope.seal(testRecord, peerId)
expect(envelope).to.exist()
expect(envelope.peerId.equals(peerId)).to.eql(true)
expect(envelope.payloadType).to.eql(payloadType)
expect(envelope.payloadType).to.equalBytes(payloadType)
expect(envelope.payload).to.exist()
expect(envelope.signature).to.exist()
})

View File

@@ -7,7 +7,6 @@ const { expect } = chai
const tests = require('libp2p-interfaces/src/record/tests')
const multiaddr = require('multiaddr')
const PeerId = require('peer-id')
const Envelope = require('../../src/record/envelope')
const PeerRecord = require('../../src/record/peer-record')
@@ -33,23 +32,6 @@ describe('PeerRecord', () => {
[peerId] = await peerUtils.createPeerId()
})
it('de/serializes the same as a go record', async () => {
const privKey = Uint8Array.from([8, 1, 18, 64, 133, 251, 231, 43, 96, 100, 40, 144, 4, 165, 49, 249, 103, 137, 141, 245, 49, 158, 224, 41, 146, 253, 216, 64, 33, 250, 80, 82, 67, 75, 246, 238, 17, 187, 163, 237, 23, 33, 148, 140, 239, 180, 229, 11, 10, 11, 181, 202, 216, 166, 181, 45, 199, 177, 164, 15, 79, 102, 82, 16, 92, 145, 226, 196])
const rawEnvelope = Uint8Array.from([10, 36, 8, 1, 18, 32, 17, 187, 163, 237, 23, 33, 148, 140, 239, 180, 229, 11, 10, 11, 181, 202, 216, 166, 181, 45, 199, 177, 164, 15, 79, 102, 82, 16, 92, 145, 226, 196, 18, 2, 3, 1, 26, 170, 1, 10, 38, 0, 36, 8, 1, 18, 32, 17, 187, 163, 237, 23, 33, 148, 140, 239, 180, 229, 11, 10, 11, 181, 202, 216, 166, 181, 45, 199, 177, 164, 15, 79, 102, 82, 16, 92, 145, 226, 196, 16, 216, 184, 224, 191, 147, 145, 182, 151, 22, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 0, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 1, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 2, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 3, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 4, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 5, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 6, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 7, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 8, 26, 10, 10, 8, 4, 1, 2, 3, 4, 6, 0, 9, 42, 64, 177, 151, 247, 107, 159, 40, 138, 242, 180, 103, 254, 102, 111, 119, 68, 118, 40, 112, 73, 180, 36, 183, 57, 117, 200, 134, 14, 251, 2, 55, 45, 2, 106, 121, 149, 132, 84, 26, 215, 47, 38, 84, 52, 100, 133, 188, 163, 236, 227, 100, 98, 183, 209, 177, 57, 28, 141, 39, 109, 196, 171, 139, 202, 11])
const peerId = await PeerId.createFromPrivKey(privKey)
const env = await Envelope.openAndCertify(rawEnvelope, PeerRecord.DOMAIN)
expect(peerId.equals(env.peerId))
const record = PeerRecord.createFromProtobuf(env.payload)
// The payload isn't going to match because of how the protobuf encodes uint64 values
// They are marshalled correctly on both sides, but will be off by 1 value
// Signatures will still be validated
const jsEnv = await Envelope.seal(record, peerId)
expect(env.payloadType).to.eql(jsEnv.payloadType)
})
it('creates a peer record with peerId', () => {
const peerRecord = new PeerRecord({ peerId })