Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
feat: replace protocol-buffers with protons (#5)
Browse files Browse the repository at this point in the history
* feat: replace protocol-buffers with protons

Ref ipfs/js-ipfs#991

* feat: upgrade to aegir@12

* chore: fix coverage command
  • Loading branch information
dignifiedquire authored and daviddias committed Sep 7, 2017
1 parent 71bfe60 commit 8774a4f
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 39 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ test/test-data/go-ipfs-repo/LOG.old

# while testing npm5
package-lock.json
yarn.lock

docs
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ matrix:
script:
- npm run lint
- npm run test
- npm run coverage
- make test
- npm run coverage -- --upload

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

after_success:
- npm run coverage-publish

addons:
firefox: 'latest'
apt:
Expand Down
33 changes: 15 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
"description": "libp2p record implementation",
"main": "src/index.js",
"scripts": {
"test": "aegir-test",
"lint": "aegir-lint",
"test:node": "aegir-test node",
"test:browser": "aegir-test browser",
"build": "aegir-build",
"docs": "aegir-docs",
"release": "aegir-release --docs",
"release-minor": "aegir-release --type minor --docs",
"release-major": "aegir-release --type major --docs",
"coverage": "aegir-coverage",
"coverage-publish": "aegir-coverage publish"
"test": "aegir test",
"lint": "aegir lint",
"test:node": "aegir test -t node",
"test:browser": "aegir test -t browser -t webworker",
"build": "aegir build",
"docs": "aegir docs",
"release": "aegir release",
"release-minor": "aegir release --type minor",
"release-major": "aegir release --type major",
"coverage": "aegir coverage"
},
"repository": {
"type": "git",
Expand All @@ -38,12 +37,11 @@
},
"homepage": "https://github.com/libp2p/js-libp2p-record",
"devDependencies": {
"aegir": "^11.0.2",
"aegir": "^12.0.6",
"chai": "^4.1.2",
"dirty-chai": "^2.0.1",
"libp2p-crypto": "~0.10.0",
"pre-commit": "^1.2.2",
"safe-buffer": "^5.1.1"
"libp2p-crypto": "~0.10.2",
"pre-commit": "^1.2.2"
},
"dependencies": {
"async": "^2.5.0",
Expand All @@ -52,11 +50,10 @@
"multihashes": "~0.4.9",
"multihashing-async": "~0.4.6",
"peer-id": "~0.10.0",
"protocol-buffers": "^3.2.1",
"safe-buffer": "^5.1.1"
"protons": "^1.0.0"
},
"contributors": [
"David Dias <[email protected]>",
"Friedel Ziegelmayer <[email protected]>"
]
}
}
5 changes: 2 additions & 3 deletions src/record.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict'

const protobuf = require('protocol-buffers')
const Buffer = require('safe-buffer').Buffer
const protons = require('protons')
const assert = require('assert')
const PeerId = require('peer-id')

const pb = protobuf(require('./record.proto')).Record
const pb = protons(require('./record.proto')).Record
const utils = require('./utils')

class Record {
Expand Down
2 changes: 1 addition & 1 deletion src/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const bestRecord = (selectors, k, records) => {
throw new Error('No records given')
}

const parts = bsplit(k, new Buffer('/'))
const parts = bsplit(k, Buffer.from('/'))

if (parts.length < 3) {
throw new Error('Record key does not have a selector function')
Expand Down
4 changes: 2 additions & 2 deletions src/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const bsplit = require('buffer-split')
*/
const verifyRecord = (validators, record, callback) => {
const key = record.key
const parts = bsplit(key, new Buffer('/'))
const parts = bsplit(key, Buffer.from('/'))

if (parts.length < 3) {
// No validator available
Expand All @@ -37,7 +37,7 @@ const verifyRecord = (validators, record, callback) => {
* @returns {boolean}
*/
const isSigned = (validators, key) => {
const parts = bsplit(key, new Buffer('/'))
const parts = bsplit(key, Buffer.from('/'))

if (parts.length < 3) {
// No validator available
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/go-key-records.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

module.exports = {
publicKey: new Buffer(
publicKey: Buffer.from(
'CAASXjBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDjXAQQMal4SB2tSnX6NJIPmC69/BT8A8jc7/gDUZNkEhdhYHvc7k7S4vntV/c92nJGxNdop9fKJyevuNMuXhhHAgMBAAE=',
'base64'
)
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/go-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
// ioutil.WriteFile("js-libp2p-record/test/fixtures/record.bin", enc, 0644)
// ioutil.WriteFile("js-libp2p-record/test/fixtures/record-signed.bin", enc2, 0644)
module.exports = {
serialized: new Buffer(
serialized: Buffer.from(
'0a0568656c6c6f1205776f726c641a2212201bd5175b1d4123ee29665348c60ea5cf5ac62e2e05215b97a7b9a9b0cf71d116',
'hex'
),
serializedSigned: new Buffer(
serializedSigned: Buffer.from(
'0a0568656c6c6f1205776f726c641a2212201bd5175b1d4123ee29665348c60ea5cf5ac62e2e05215b97a7b9a9b0cf71d116228001500fe7505698b8a873ccde6f1d36a2be662d57807490d9a9959540f2645a454bf615215092e10123f6ffc4ed694711bfbb1d5ccb62f3da83cf4528ee577a96b6cf0272eef9a920bd56459993690060353b72c22b8c03ad2a33894522dac338905b201179a85cb5e2fc68ed58be96cf89beec6dc0913887dddc10f202a2a1b117',
'hex'
)
Expand Down
12 changes: 6 additions & 6 deletions test/selection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ var expect = require('chai').expect
const libp2pRecord = require('../src')
const selection = libp2pRecord.selection

const records = [new Buffer(0), new Buffer('hello')]
const records = [Buffer.alloc(0), Buffer.from('hello')]

describe('selection', () => {
describe('bestRecord', () => {
it('throws on missing selector in the record key', () => {
expect(
() => selection.bestRecord({}, new Buffer('/'), records)
() => selection.bestRecord({}, Buffer.from('/'), records)
).to.throw(
/Record key does not have a selector function/
)
})

it('throws on unknown key prefix', () => {
expect(
() => selection.bestRecord({world () {}}, new Buffer('/hello/'), records)
() => selection.bestRecord({world () {}}, Buffer.from('/hello/'), records)
).to.throw(
/Unrecognized key prefix: hello/
)
Expand All @@ -30,15 +30,15 @@ describe('selection', () => {
it('returns the index from the matching selector', () => {
const selectors = {
hello (k, recs) {
expect(k).to.be.eql(new Buffer('/hello/world'))
expect(k).to.be.eql(Buffer.from('/hello/world'))
expect(recs).to.be.eql(records)

return 1
}
}

expect(
selection.bestRecord(selectors, new Buffer('/hello/world'), records)
selection.bestRecord(selectors, Buffer.from('/hello/world'), records)
).to.equal(
1
)
Expand All @@ -48,7 +48,7 @@ describe('selection', () => {
describe('selectors', () => {
it('public key', () => {
expect(
selection.selectors.pk(new Buffer('/hello/world'), records)
selection.selectors.pk(Buffer.from('/hello/world'), records)
).to.equal(
0
)
Expand Down
1 change: 0 additions & 1 deletion test/validator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const waterfall = require('async/waterfall')
const each = require('async/each')
const crypto = require('libp2p-crypto')
const PeerId = require('peer-id')
const Buffer = require('safe-buffer').Buffer

const libp2pRecord = require('../src')
const validator = libp2pRecord.validator
Expand Down

0 comments on commit 8774a4f

Please sign in to comment.