diff --git a/.aegir.js b/.aegir.js deleted file mode 100644 index e3151ab..0000000 --- a/.aegir.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict' - -const path = require('path') - -module.exports = { - webpack: { - resolve: { - alias: { - 'node-forge': path.resolve( - path.dirname(require.resolve('libp2p-crypto')), - '../vendor/forge.bundle.js' - ) - } - } - } -} diff --git a/.gitignore b/.gitignore index d5c8745..cd638b1 100644 --- a/.gitignore +++ b/.gitignore @@ -31,4 +31,3 @@ node_modules coverage dist -lib \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index ab2ce22..4fe6550 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,15 @@ - sudo: false language: node_js -node_js: - - 4 - - 5 +matrix: + include: + - node_js: 4 + env: CXX=g++-4.8 + - node_js: 6 + env: + - SAUCE=true + - CXX=g++-4.8 + - node_js: stable + env: CXX=g++-4.8 # Make sure we have new NPM. before_install: @@ -14,12 +20,17 @@ script: - npm test - npm run coverage -addons: - firefox: 'latest' - before_script: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start after_success: - - npm run coverage-publish \ No newline at end of file + - npm run coverage-publish + +addons: + firefox: 'latest' + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 \ No newline at end of file diff --git a/README.md b/README.md index c70cee3..ed487b8 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,10 @@ [![Travis CI](https://travis-ci.org/libp2p/js-libp2p-identify.svg?branch=master)](https://travis-ci.org/libp2p/js-libp2p-identify) [![Circle CI](https://circleci.com/gh/libp2p/js-libp2p-identify.svg?style=svg)](https://circleci.com/gh/libp2p/js-libp2p-identify) [![Dependency Status](https://david-dm.org/libp2p/js-libp2p-identify.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-identify) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) +![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square) +![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square) + +[![Sauce Test Status](https://saucelabs.com/browser-matrix/libp2p-js-identify.svg)](https://saucelabs.com/u/libp2p-js-identify) > libp2p Identify Protocol diff --git a/package.json b/package.json index 3619a77..365b0eb 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,7 @@ "name": "libp2p-identify", "version": "0.2.0", "description": "libp2p Identify Protocol", - "main": "lib/index.js", - "jsnext:main": "src/index.js", + "main": "src/index.js", "scripts": { "lint": "aegir-lint", "build": "aegir-build", @@ -21,7 +20,7 @@ "test" ], "engines": { - "node": "^4.3.0" + "node": ">=4.0.0" }, "repository": { "type": "git", @@ -38,22 +37,22 @@ }, "homepage": "https://github.com/libp2p/js-libp2p-identify#readme", "devDependencies": { - "aegir": "^8.0.0", + "aegir": "^9.0.1", "chai": "^3.5.0", "pre-commit": "^1.1.3", "pull-pair": "^1.1.0" }, "dependencies": { - "multiaddr": "^2.0.2", - "peer-id": "^0.7.0", - "peer-info": "^0.7.0", + "multiaddr": "^2.0.3", + "peer-id": "^0.8.0", + "peer-info": "^0.8.0", "protocol-buffers": "^3.1.6", - "pull-length-prefixed": "^1.0.0", - "pull-stream": "^3.4.3" + "pull-length-prefixed": "^1.2.0", + "pull-stream": "^3.5.0" }, "contributors": [ "David Dias ", "dignifiedquire ", "greenkeeperio-bot " ] -} \ No newline at end of file +} diff --git a/src/dialer.js b/src/dialer.js index 69e99a3..836ae63 100644 --- a/src/dialer.js +++ b/src/dialer.js @@ -19,13 +19,18 @@ module.exports = (conn, callback) => { const input = msg.decode(data[0]) - const id = PeerId.createFromPubKey(input.publicKey) - const info = new PeerInfo(id) - input.listenAddrs - .map(multiaddr) - .forEach((ma) => info.multiaddr.add(ma)) - - callback(null, info, getObservedAddrs(input)) + PeerId.createFromPubKey(input.publicKey, (err, id) => { + if (err) { + return callback(err) + } + + const info = new PeerInfo(id) + input.listenAddrs + .map(multiaddr) + .forEach((ma) => info.multiaddr.add(ma)) + + callback(null, info, getObservedAddrs(input)) + }) }) ) } diff --git a/src/message/identify.proto b/src/message.js similarity index 89% rename from src/message/identify.proto rename to src/message.js index e4845aa..8905e7a 100644 --- a/src/message/identify.proto +++ b/src/message.js @@ -1,5 +1,8 @@ -message Identify { +'use strict' +const protobuf = require('protocol-buffers') +const schema = new Buffer(` +message Identify { // protocolVersion determines compatibility between peers optional string protocolVersion = 5; // e.g. ipfs/1.0.0 @@ -23,3 +26,6 @@ message Identify { // (DEPRECATED) protocols are the services this node is running // repeated string protocols = 3; } +`) + +module.exports = protobuf(schema).Identify diff --git a/src/message/index.js b/src/message/index.js deleted file mode 100644 index 8a8b2e4..0000000 --- a/src/message/index.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict' - -const fs = require('fs') -const path = require('path') -const protobuf = require('protocol-buffers') -const schema = fs.readFileSync(path.join(__dirname, 'identify.proto')) - -module.exports = protobuf(schema).Identify diff --git a/test/dialer.spec.js b/test/dialer.spec.js index c0dae7f..1224406 100644 --- a/test/dialer.spec.js +++ b/test/dialer.spec.js @@ -12,9 +12,20 @@ const msg = require('../src/message') const identify = require('../src') describe('identify.dialer', () => { + let original + beforeEach((done) => { + PeerInfo.create((err, info) => { + if (err) { + return done(err) + } + + original = info + done() + }) + }) + it('works', (done) => { const p = pair() - const original = new PeerInfo() original.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/5002')) const input = msg.encode({ protocolVersion: 'ipfs/0.1.0', diff --git a/test/listener.spec.js b/test/listener.spec.js index fb25a31..b590933 100644 --- a/test/listener.spec.js +++ b/test/listener.spec.js @@ -12,9 +12,20 @@ const msg = require('../src/message') const identify = require('../src') describe('identify.listener', () => { + let info + beforeEach((done) => { + PeerInfo.create((err, _info) => { + if (err) { + return done(err) + } + + info = _info + done() + }) + }) + it('works', (done) => { const p = pair() - const info = new PeerInfo() info.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/5002')) pull( p[1],