mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-15 00:31:36 +00:00
Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
66c8adb8bc | |||
d0c68f63fe | |||
6a1e6493cb | |||
89ed15e9d9 | |||
f3ee2f069b | |||
01f8ee1574 | |||
bb244ce392 | |||
ef04b79983 | |||
308cd9ab2c | |||
b8d2b3d651 | |||
c7eac39012 | |||
9d5f2a35ae | |||
7477c5c4a4 | |||
ba275558bb | |||
9b32d25de9 | |||
3c16dbe93e | |||
2dbcc4b126 | |||
27481e7edc | |||
aa199362c2 | |||
3694e02eaa | |||
b216471f44 | |||
10f4cb969d | |||
f3fd734a2a | |||
28d915ebb6 | |||
fb59bf2bf5 | |||
d0ae8b6267 | |||
4b01fbebf9 |
61
.travis.yml
61
.travis.yml
@ -1,32 +1,43 @@
|
|||||||
# Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
|
|
||||||
sudo: false
|
|
||||||
language: node_js
|
language: node_js
|
||||||
|
cache: npm
|
||||||
|
stages:
|
||||||
|
- check
|
||||||
|
- test
|
||||||
|
- cov
|
||||||
|
|
||||||
matrix:
|
node_js:
|
||||||
|
- '10'
|
||||||
|
|
||||||
|
os:
|
||||||
|
- linux
|
||||||
|
- osx
|
||||||
|
|
||||||
|
script: npx nyc -s npm run test:node -- --bail
|
||||||
|
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov
|
||||||
|
|
||||||
|
jobs:
|
||||||
include:
|
include:
|
||||||
- node_js: 6
|
- os: windows
|
||||||
env: CXX=g++-4.8
|
cache: false
|
||||||
- node_js: 8
|
|
||||||
env: CXX=g++-4.8
|
|
||||||
# - node_js: stable
|
|
||||||
# env: CXX=g++-4.8
|
|
||||||
|
|
||||||
script:
|
- stage: check
|
||||||
- npm run lint
|
script:
|
||||||
- npm run test
|
- npx aegir commitlint --travis
|
||||||
- npm run coverage
|
- npx aegir dep-check
|
||||||
|
- npm run lint
|
||||||
|
|
||||||
before_script:
|
- stage: test
|
||||||
- export DISPLAY=:99.0
|
name: chrome
|
||||||
- sh -e /etc/init.d/xvfb start
|
addons:
|
||||||
|
chrome: stable
|
||||||
|
script: npx aegir test -t browser -t webworker
|
||||||
|
|
||||||
after_success:
|
- stage: test
|
||||||
- npm run coverage-publish
|
name: firefox
|
||||||
|
addons:
|
||||||
|
firefox: latest
|
||||||
|
script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
email: false
|
||||||
|
|
||||||
addons:
|
|
||||||
firefox: 'latest'
|
|
||||||
apt:
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
packages:
|
|
||||||
- g++-4.8
|
|
||||||
|
50
CHANGELOG.md
50
CHANGELOG.md
@ -1,3 +1,53 @@
|
|||||||
|
<a name="0.7.6"></a>
|
||||||
|
## [0.7.6](https://github.com/libp2p/js-libp2p-identify/compare/v0.7.5...v0.7.6) (2019-03-20)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add protocol support to identify ([#51](https://github.com/libp2p/js-libp2p-identify/issues/51)) ([89ed15e](https://github.com/libp2p/js-libp2p-identify/commit/89ed15e))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a name="0.7.5"></a>
|
||||||
|
## [0.7.5](https://github.com/libp2p/js-libp2p-identify/compare/v0.7.4...v0.7.5) (2019-01-10)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* reduce bundle size ([b8d2b3d](https://github.com/libp2p/js-libp2p-identify/commit/b8d2b3d))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a name="0.7.4"></a>
|
||||||
|
## [0.7.4](https://github.com/libp2p/js-libp2p-identify/compare/v0.7.3...v0.7.4) (2019-01-04)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a name="0.7.3"></a>
|
||||||
|
## [0.7.3](https://github.com/libp2p/js-libp2p-identify/compare/v0.7.2...v0.7.3) (2018-11-26)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a name="0.7.2"></a>
|
||||||
|
## [0.7.2](https://github.com/libp2p/js-libp2p-identify/compare/v0.7.1...v0.7.2) (2018-07-23)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* add the ability to verify expected peer data ([aa19936](https://github.com/libp2p/js-libp2p-identify/commit/aa19936))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a name="0.7.1"></a>
|
||||||
|
## [0.7.1](https://github.com/libp2p/js-libp2p-identify/compare/v0.7.0...v0.7.1) (2018-04-30)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a name="0.7.0"></a>
|
||||||
|
# [0.7.0](https://github.com/libp2p/js-libp2p-identify/compare/v0.6.3...v0.7.0) (2018-04-05)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="0.6.3"></a>
|
<a name="0.6.3"></a>
|
||||||
## [0.6.3](https://github.com/libp2p/js-libp2p-identify/compare/v0.6.2...v0.6.3) (2018-01-28)
|
## [0.6.3](https://github.com/libp2p/js-libp2p-identify/compare/v0.6.2...v0.6.3) (2018-01-28)
|
||||||
|
|
||||||
|
21
README.md
21
README.md
@ -1,21 +1,24 @@
|
|||||||
# js-libp2p-identify
|
# js-libp2p-identify
|
||||||
|
|
||||||
[](http://ipn.io)
|
[](http://protocol.ai)
|
||||||
[](http://ipfs.io/)
|
[](http://libp2p.io/)
|
||||||
[](http://webchat.freenode.net/?channels=%23ipfs)
|
[](http://webchat.freenode.net/?channels=%23libp2p)
|
||||||
[](https://coveralls.io/github/libp2p/js-libp2p-identify?branch=master)
|
[](https://codecov.io/gh/libp2p/js-libp2p-identify)
|
||||||
[](https://travis-ci.org/libp2p/js-libp2p-identify)
|
[](https://travis-ci.com/libp2p/js-libp2p-identify)
|
||||||
[](https://circleci.com/gh/libp2p/js-libp2p-identify)
|
|
||||||
[](https://david-dm.org/libp2p/js-libp2p-identify)
|
[](https://david-dm.org/libp2p/js-libp2p-identify)
|
||||||
[](https://github.com/feross/standard)
|
[](https://github.com/feross/standard)
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
> libp2p Identify Protocol
|
> libp2p Identify Protocol
|
||||||
|
|
||||||
|
## Lead Maintainer
|
||||||
|
|
||||||
|
[Jacob Heun](https://github.com/jacobheun)
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
Identify is a STUN protocol, used by libp2p-swarmin order to broadcast and learn about the `ip:port` pairs a specific peer is available through and to know when a new stream muxer is established, so a conn can be reused.
|
Identify is a STUN protocol, used by libp2p-swarm in order to broadcast and learn about the `ip:port` pairs a specific peer is available through and to know when a new stream muxer is established, so a conn can be reused.
|
||||||
|
|
||||||
## How does it work
|
## How does it work
|
||||||
|
|
||||||
|
29
appveyor.yml
29
appveyor.yml
@ -1,29 +0,0 @@
|
|||||||
# Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
|
|
||||||
version: "{build}"
|
|
||||||
|
|
||||||
environment:
|
|
||||||
matrix:
|
|
||||||
- nodejs_version: "6"
|
|
||||||
- nodejs_version: "8"
|
|
||||||
|
|
||||||
matrix:
|
|
||||||
fast_finish: true
|
|
||||||
|
|
||||||
install:
|
|
||||||
# Install Node.js
|
|
||||||
- ps: Install-Product node $env:nodejs_version
|
|
||||||
|
|
||||||
# Upgrade npm
|
|
||||||
- npm install -g npm
|
|
||||||
|
|
||||||
# Output our current versions for debugging
|
|
||||||
- node --version
|
|
||||||
- npm --version
|
|
||||||
|
|
||||||
# Install our package dependencies
|
|
||||||
- npm install
|
|
||||||
|
|
||||||
test_script:
|
|
||||||
- npm run test:node
|
|
||||||
|
|
||||||
build: off
|
|
2
ci/Jenkinsfile
vendored
2
ci/Jenkinsfile
vendored
@ -1,2 +0,0 @@
|
|||||||
// Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
|
|
||||||
javascript()
|
|
15
circle.yml
15
circle.yml
@ -1,15 +0,0 @@
|
|||||||
# Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
|
|
||||||
machine:
|
|
||||||
node:
|
|
||||||
version: stable
|
|
||||||
|
|
||||||
dependencies:
|
|
||||||
pre:
|
|
||||||
- google-chrome --version
|
|
||||||
- curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
|
|
||||||
- sudo dpkg -i google-chrome.deb || true
|
|
||||||
- sudo apt-get update
|
|
||||||
- sudo apt-get install -f
|
|
||||||
- sudo apt-get install --only-upgrade lsb-base
|
|
||||||
- sudo dpkg -i google-chrome.deb
|
|
||||||
- google-chrome --version
|
|
31
package.json
31
package.json
@ -1,8 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "libp2p-identify",
|
"name": "libp2p-identify",
|
||||||
"version": "0.6.3",
|
"version": "0.7.6",
|
||||||
"description": "libp2p Identify Protocol",
|
"description": "libp2p Identify Protocol",
|
||||||
|
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist",
|
||||||
|
"src"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "aegir lint",
|
"lint": "aegir lint",
|
||||||
"build": "aegir build",
|
"build": "aegir build",
|
||||||
@ -14,7 +19,7 @@
|
|||||||
"release-major": "aegir release --type major",
|
"release-major": "aegir release --type major",
|
||||||
"coverage": "aegir coverage"
|
"coverage": "aegir coverage"
|
||||||
},
|
},
|
||||||
"pre-commit": [
|
"pre-push": [
|
||||||
"lint",
|
"lint",
|
||||||
"test"
|
"test"
|
||||||
],
|
],
|
||||||
@ -30,32 +35,36 @@
|
|||||||
"IPFS",
|
"IPFS",
|
||||||
"libp2p"
|
"libp2p"
|
||||||
],
|
],
|
||||||
"author": "David Dias <daviddias@ipfs.io>",
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/libp2p/js-libp2p-identify/issues"
|
"url": "https://github.com/libp2p/js-libp2p-identify/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/libp2p/js-libp2p-identify#readme",
|
"homepage": "https://github.com/libp2p/js-libp2p-identify#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"aegir": "^12.4.0",
|
"aegir": "^18.1.0",
|
||||||
"chai": "^4.1.2",
|
"chai": "^4.2.0",
|
||||||
"dirty-chai": "^2.0.1",
|
"dirty-chai": "^2.0.1",
|
||||||
"pre-commit": "^1.2.2",
|
|
||||||
"pull-pair": "^1.1.0"
|
"pull-pair": "^1.1.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"multiaddr": "^3.0.2",
|
"multiaddr": "^6.0.4",
|
||||||
"peer-id": "~0.10.5",
|
"peer-id": "~0.12.2",
|
||||||
"peer-info": "~0.11.6",
|
"peer-info": "~0.15.1",
|
||||||
"protons": "^1.0.1",
|
"protons": "^1.0.1",
|
||||||
"pull-length-prefixed": "^1.3.0",
|
"pull-length-prefixed": "^1.3.1",
|
||||||
"pull-stream": "^3.6.1"
|
"pull-stream": "^3.6.9"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"David Dias <daviddias.p@gmail.com>",
|
"David Dias <daviddias.p@gmail.com>",
|
||||||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
||||||
"Greenkeeper <support@greenkeeper.io>",
|
"Greenkeeper <support@greenkeeper.io>",
|
||||||
|
"Hugo Dias <hugomrdias@gmail.com>",
|
||||||
|
"Jacob Heun <jacobheun@gmail.com>",
|
||||||
|
"Jacob Heun <jake@andyet.net>",
|
||||||
|
"Maciej Krüger <mkg20001@gmail.com>",
|
||||||
"Richard Littauer <richard.littauer@gmail.com>",
|
"Richard Littauer <richard.littauer@gmail.com>",
|
||||||
|
"Vasco Santos <vasco.santos@moxy.studio>",
|
||||||
|
"Yusef Napora <yusef@protocol.ai>",
|
||||||
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>"
|
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,25 @@
|
|||||||
const PeerInfo = require('peer-info')
|
const PeerInfo = require('peer-info')
|
||||||
const PeerId = require('peer-id')
|
const PeerId = require('peer-id')
|
||||||
const multiaddr = require('multiaddr')
|
const multiaddr = require('multiaddr')
|
||||||
const pull = require('pull-stream')
|
const pull = require('pull-stream/pull')
|
||||||
|
const take = require('pull-stream/throughs/take')
|
||||||
|
const collect = require('pull-stream/sinks/collect')
|
||||||
const lp = require('pull-length-prefixed')
|
const lp = require('pull-length-prefixed')
|
||||||
|
|
||||||
const msg = require('./message')
|
const msg = require('./message')
|
||||||
|
|
||||||
module.exports = (conn, callback) => {
|
module.exports = (conn, expectedPeerInfo, callback) => {
|
||||||
|
if (typeof expectedPeerInfo === 'function') {
|
||||||
|
callback = expectedPeerInfo
|
||||||
|
expectedPeerInfo = null
|
||||||
|
console.warn('WARNING: no expected peer info was given, identify will not be able to verify peer integrity')
|
||||||
|
}
|
||||||
|
|
||||||
pull(
|
pull(
|
||||||
conn,
|
conn,
|
||||||
lp.decode(),
|
lp.decode(),
|
||||||
pull.take(1),
|
take(1),
|
||||||
pull.collect((err, data) => {
|
collect((err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
@ -30,11 +38,30 @@ module.exports = (conn, callback) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const peerInfo = new PeerInfo(id)
|
const peerInfo = new PeerInfo(id)
|
||||||
input.listenAddrs
|
if (expectedPeerInfo && expectedPeerInfo.id.toB58String() !== id.toB58String()) {
|
||||||
.map(multiaddr)
|
return callback(new Error('invalid peer'))
|
||||||
.forEach((ma) => peerInfo.multiaddrs.add(ma))
|
}
|
||||||
|
|
||||||
callback(null, peerInfo, getObservedAddrs(input))
|
try {
|
||||||
|
input.listenAddrs
|
||||||
|
.map(multiaddr)
|
||||||
|
.forEach((ma) => peerInfo.multiaddrs.add(ma))
|
||||||
|
} catch (err) {
|
||||||
|
return callback(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
let observedAddr
|
||||||
|
|
||||||
|
try {
|
||||||
|
observedAddr = getObservedAddrs(input)
|
||||||
|
} catch (err) {
|
||||||
|
return callback(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the protocols
|
||||||
|
peerInfo.protocols = new Set(input.protocols)
|
||||||
|
|
||||||
|
callback(null, peerInfo, observedAddr)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -47,7 +74,7 @@ function getObservedAddrs (input) {
|
|||||||
|
|
||||||
let addrs = input.observedAddr
|
let addrs = input.observedAddr
|
||||||
|
|
||||||
if (!Array.isArray(input.observedAddr)) {
|
if (!Array.isArray(addrs)) {
|
||||||
addrs = [addrs]
|
addrs = [addrs]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,3 +4,4 @@ exports = module.exports
|
|||||||
exports.multicodec = '/ipfs/id/1.0.0'
|
exports.multicodec = '/ipfs/id/1.0.0'
|
||||||
exports.listener = require('./listener')
|
exports.listener = require('./listener')
|
||||||
exports.dialer = require('./dialer')
|
exports.dialer = require('./dialer')
|
||||||
|
exports.message = require('./message')
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const pull = require('pull-stream')
|
const pull = require('pull-stream/pull')
|
||||||
|
const values = require('pull-stream/sources/values')
|
||||||
const lp = require('pull-length-prefixed')
|
const lp = require('pull-length-prefixed')
|
||||||
|
|
||||||
const msg = require('./message')
|
const msg = require('./message')
|
||||||
@ -21,11 +22,12 @@ module.exports = (conn, pInfoSelf) => {
|
|||||||
agentVersion: 'na',
|
agentVersion: 'na',
|
||||||
publicKey: publicKey,
|
publicKey: publicKey,
|
||||||
listenAddrs: pInfoSelf.multiaddrs.toArray().map((ma) => ma.buffer),
|
listenAddrs: pInfoSelf.multiaddrs.toArray().map((ma) => ma.buffer),
|
||||||
observedAddr: observedAddrs ? observedAddrs.buffer : Buffer.from('')
|
observedAddr: observedAddrs ? observedAddrs.buffer : Buffer.from(''),
|
||||||
|
protocols: Array.from(pInfoSelf.protocols)
|
||||||
})
|
})
|
||||||
|
|
||||||
pull(
|
pull(
|
||||||
pull.values([msgSend]),
|
values([msgSend]),
|
||||||
lp.encode(),
|
lp.encode(),
|
||||||
conn
|
conn
|
||||||
)
|
)
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
/* eslint-env mocha */
|
/* eslint-env mocha */
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const pull = require('pull-stream')
|
const pull = require('pull-stream/pull')
|
||||||
|
const values = require('pull-stream/sources/values')
|
||||||
const chai = require('chai')
|
const chai = require('chai')
|
||||||
const dirtyChai = require('dirty-chai')
|
const dirtyChai = require('dirty-chai')
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
@ -32,16 +33,20 @@ describe('identify.dialer', () => {
|
|||||||
it('works', (done) => {
|
it('works', (done) => {
|
||||||
const p = pair()
|
const p = pair()
|
||||||
original.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/5002'))
|
original.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/5002'))
|
||||||
|
original.protocols.add('/echo/1.0.0')
|
||||||
|
original.protocols.add('/ping/1.0.0')
|
||||||
|
|
||||||
const input = msg.encode({
|
const input = msg.encode({
|
||||||
protocolVersion: 'ipfs/0.1.0',
|
protocolVersion: 'ipfs/0.1.0',
|
||||||
agentVersion: 'na',
|
agentVersion: 'na',
|
||||||
publicKey: original.id.pubKey.bytes,
|
publicKey: original.id.pubKey.bytes,
|
||||||
listenAddrs: [multiaddr('/ip4/127.0.0.1/tcp/5002').buffer],
|
listenAddrs: [multiaddr('/ip4/127.0.0.1/tcp/5002').buffer],
|
||||||
observedAddr: multiaddr('/ip4/127.0.0.1/tcp/5001').buffer
|
observedAddr: multiaddr('/ip4/127.0.0.1/tcp/5001').buffer,
|
||||||
|
protocols: Array.from(original.protocols)
|
||||||
})
|
})
|
||||||
|
|
||||||
pull(
|
pull(
|
||||||
pull.values([input]),
|
values([input]),
|
||||||
lp.encode(),
|
lp.encode(),
|
||||||
p[0]
|
p[0]
|
||||||
)
|
)
|
||||||
@ -57,7 +62,123 @@ describe('identify.dialer', () => {
|
|||||||
expect(observedAddrs)
|
expect(observedAddrs)
|
||||||
.to.eql([multiaddr('/ip4/127.0.0.1/tcp/5001')])
|
.to.eql([multiaddr('/ip4/127.0.0.1/tcp/5001')])
|
||||||
|
|
||||||
|
expect(info.protocols).to.eql(original.protocols)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should handle missing protocols', (done) => {
|
||||||
|
const p = pair()
|
||||||
|
original.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/5002'))
|
||||||
|
|
||||||
|
const input = msg.encode({
|
||||||
|
protocolVersion: 'ipfs/0.1.0',
|
||||||
|
agentVersion: 'na',
|
||||||
|
publicKey: original.id.pubKey.bytes,
|
||||||
|
listenAddrs: [multiaddr('/ip4/127.0.0.1/tcp/5002').buffer],
|
||||||
|
observedAddr: multiaddr('/ip4/127.0.0.1/tcp/5001').buffer,
|
||||||
|
protocols: Array.from(original.protocols)
|
||||||
|
})
|
||||||
|
|
||||||
|
pull(
|
||||||
|
values([input]),
|
||||||
|
lp.encode(),
|
||||||
|
p[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
identify.dialer(p[1], (err, info, observedAddrs) => {
|
||||||
|
expect(err).to.not.exist()
|
||||||
|
expect(info.id.pubKey.bytes)
|
||||||
|
.to.eql(original.id.pubKey.bytes)
|
||||||
|
|
||||||
|
expect(info.multiaddrs.toArray())
|
||||||
|
.to.eql(original.multiaddrs.toArray())
|
||||||
|
|
||||||
|
expect(observedAddrs)
|
||||||
|
.to.eql([multiaddr('/ip4/127.0.0.1/tcp/5001')])
|
||||||
|
|
||||||
|
expect(Array.from(info.protocols)).to.eql([])
|
||||||
|
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not crash with invalid listen addresses', (done) => {
|
||||||
|
const p = pair()
|
||||||
|
original.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/5002'))
|
||||||
|
const input = msg.encode({
|
||||||
|
protocolVersion: 'ipfs/0.1.0',
|
||||||
|
agentVersion: 'na',
|
||||||
|
publicKey: original.id.pubKey.bytes,
|
||||||
|
listenAddrs: [Buffer.from('ffac010203')],
|
||||||
|
observedAddr: Buffer.from('ffac010203')
|
||||||
|
})
|
||||||
|
|
||||||
|
pull(
|
||||||
|
values([input]),
|
||||||
|
lp.encode(),
|
||||||
|
p[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
identify.dialer(p[1], (err, info, observedAddrs) => {
|
||||||
|
expect(err).to.exist()
|
||||||
|
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not crash with invalid observed address', (done) => {
|
||||||
|
const p = pair()
|
||||||
|
original.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/5002'))
|
||||||
|
const input = msg.encode({
|
||||||
|
protocolVersion: 'ipfs/0.1.0',
|
||||||
|
agentVersion: 'na',
|
||||||
|
publicKey: original.id.pubKey.bytes,
|
||||||
|
listenAddrs: [multiaddr('/ip4/127.0.0.1/tcp/5002').buffer],
|
||||||
|
observedAddr: Buffer.from('ffac010203')
|
||||||
|
})
|
||||||
|
|
||||||
|
pull(
|
||||||
|
values([input]),
|
||||||
|
lp.encode(),
|
||||||
|
p[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
identify.dialer(p[1], (err, info, observedAddrs) => {
|
||||||
|
expect(err).to.exist()
|
||||||
|
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return an error with mismatched peerInfo data', (done) => {
|
||||||
|
const p = pair()
|
||||||
|
original.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/5002'))
|
||||||
|
const input = msg.encode({
|
||||||
|
protocolVersion: 'ipfs/0.1.0',
|
||||||
|
agentVersion: 'na',
|
||||||
|
publicKey: original.id.pubKey.bytes,
|
||||||
|
listenAddrs: [multiaddr('/ip4/127.0.0.1/tcp/5002').buffer],
|
||||||
|
observedAddr: multiaddr('/ip4/127.0.0.1/tcp/5001').buffer
|
||||||
|
})
|
||||||
|
|
||||||
|
PeerInfo.create((err, info) => {
|
||||||
|
if (err) {
|
||||||
|
return done(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
pull(
|
||||||
|
values([input]),
|
||||||
|
lp.encode(),
|
||||||
|
p[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
identify.dialer(p[1], info, (err, peerInfo) => {
|
||||||
|
expect(err).to.exist()
|
||||||
|
expect(peerInfo).to.not.exist()
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
/* eslint-env mocha */
|
/* eslint-env mocha */
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const pull = require('pull-stream')
|
const pull = require('pull-stream/pull')
|
||||||
|
const collect = require('pull-stream/sinks/collect')
|
||||||
const chai = require('chai')
|
const chai = require('chai')
|
||||||
const dirtyChai = require('dirty-chai')
|
const dirtyChai = require('dirty-chai')
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
@ -25,6 +26,9 @@ describe('identify.listener', () => {
|
|||||||
return done(err)
|
return done(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_info.protocols.add('/echo/1.0.0')
|
||||||
|
_info.protocols.add('/chat/1.0.0')
|
||||||
|
|
||||||
info = _info
|
info = _info
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
@ -38,7 +42,7 @@ describe('identify.listener', () => {
|
|||||||
pull(
|
pull(
|
||||||
p[1],
|
p[1],
|
||||||
lp.decode(),
|
lp.decode(),
|
||||||
pull.collect((err, result) => {
|
collect((err, result) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
const input = msg.decode(result[0])
|
const input = msg.decode(result[0])
|
||||||
@ -50,7 +54,7 @@ describe('identify.listener', () => {
|
|||||||
publicKey: info.id.pubKey.bytes,
|
publicKey: info.id.pubKey.bytes,
|
||||||
listenAddrs: [multiaddr('/ip4/127.0.0.1/tcp/5002').buffer],
|
listenAddrs: [multiaddr('/ip4/127.0.0.1/tcp/5002').buffer],
|
||||||
observedAddr: multiaddr('/ip4/127.0.0.1/tcp/5001').buffer,
|
observedAddr: multiaddr('/ip4/127.0.0.1/tcp/5001').buffer,
|
||||||
protocols: []
|
protocols: ['/echo/1.0.0', '/chat/1.0.0']
|
||||||
})
|
})
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user