Compare commits

..

89 Commits

Author SHA1 Message Date
66c8adb8bc chore: release version v0.7.6
License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>
2019-03-20 18:49:02 +01:00
d0c68f63fe chore: update contributors 2019-03-20 18:49:01 +01:00
6a1e6493cb chore: add files to package.json
License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>
2019-03-20 18:47:56 +01:00
89ed15e9d9 feat: add protocol support to identify (#51) 2019-03-20 18:45:46 +01:00
f3ee2f069b chore: use travis ci (#50)
* chore: use travis ci
* chore: update badges
2019-02-21 15:56:39 +01:00
01f8ee1574 chore: update badges for consistency across libp2p org 2019-02-21 12:33:15 +01:00
bb244ce392 chore: release version v0.7.5
License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>
2019-01-10 14:43:08 +01:00
ef04b79983 chore: update contributors 2019-01-10 14:43:07 +01:00
308cd9ab2c chore: update deps 2019-01-10 14:41:29 +01:00
b8d2b3d651 fix: reduce bundle size 2019-01-10 14:41:29 +01:00
c7eac39012 chore: release version v0.7.4
License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>
2019-01-04 09:27:29 -07:00
9d5f2a35ae chore: update contributors 2019-01-04 09:27:29 -07:00
7477c5c4a4 chore: update dependencies 2019-01-04 09:24:19 -07:00
ba275558bb chore: release version v0.7.3
License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>
2018-11-26 14:38:08 +01:00
9b32d25de9 chore: update contributors 2018-11-26 14:38:07 +01:00
3c16dbe93e chore: upgrade dependencies 2018-11-26 14:26:27 +01:00
2dbcc4b126 chore: release version v0.7.2
License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>
2018-07-23 14:16:02 +02:00
27481e7edc chore: update contributors 2018-07-23 14:16:01 +02:00
aa199362c2 fix: add the ability to verify expected peer data
chore: remove non jenkins ci
chore: remove appveyor
chore: update deps
fix: linting
2018-07-23 14:14:57 +02:00
3694e02eaa chore: add lead maintainer (#45)
* chore: add lead maintainer

License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>

* Update package.json
2018-06-26 17:57:21 +02:00
b216471f44 chore: release version v0.7.1 2018-04-30 19:10:05 +01:00
10f4cb969d chore: update contributors 2018-04-30 19:10:05 +01:00
f3fd734a2a chore: update deps 2018-04-30 19:08:25 +01:00
28d915ebb6 Fix libp2p/js-libp2p#179 - Don't crash when receiving invalid data 2018-04-30 19:07:24 +01:00
fb59bf2bf5 chore: release version v0.7.0 2018-04-05 17:54:12 +01:00
d0ae8b6267 chore: update contributors 2018-04-05 17:54:12 +01:00
4b01fbebf9 chore: update deps 2018-04-05 17:52:05 +01:00
4f095a0543 chore: release version v0.6.3 2018-01-27 18:41:49 -08:00
aba09a4f30 chore: update contributors 2018-01-27 18:41:48 -08:00
90e88742b0 chore: update deps 2018-01-27 18:40:18 -08:00
fc492c6739 chore: release version v0.6.2 2018-01-07 15:09:08 +00:00
21d74401ed chore: update contributors 2018-01-07 15:09:08 +00:00
d5374f0167 chore: update gitignore 2018-01-07 15:08:45 +00:00
f73fe2502b chore: updating CI files (#43)
* Updating CI files

This commit updates all CI scripts to the latest version

* chore: update deps

* bump timeouts for key gen

* kick to make circle spin with trusty

* travis can be really slow
2018-01-07 15:07:51 +00:00
2d6c0ed3f7 chore: release version v0.6.1 2017-09-07 10:42:47 +01:00
ae0cd81ed9 chore: update contributors 2017-09-07 10:42:47 +01:00
4ac25c9f32 feat: replace protocol-buffers with protons (#42)
* feat: replace protocol-buffers with protons

Ref https://github.com/ipfs/js-ipfs/issues/991

* feat: upgrade to aegir@12
2017-09-07 10:39:56 +01:00
52fdf7b40c chore: release version v0.6.0 2017-09-03 12:17:39 +01:00
8ca5f60f42 chore: update contributors 2017-09-03 12:17:39 +01:00
b8f77ea5ed feat: p2p addrs situation (#41)
* chore: update gitignore

* chore: update CI

* chore: update deps
2017-09-03 12:16:32 +01:00
7e6f3f2e22 chore: release version v0.5.0 2017-07-22 13:53:29 -07:00
f9a35dd8a4 chore: update contributors 2017-07-22 13:53:29 -07:00
a2d2c953bc chore: update deps 2017-07-22 13:50:26 -07:00
e836bb7ff0 chore: update deps 2017-07-20 11:11:59 -07:00
f686a3a010 chore: release version v0.4.2 2017-07-08 21:24:29 +01:00
92946a59c3 chore: update contributors 2017-07-08 21:24:29 +01:00
65e8fd5f24 chore: update deps 2017-07-08 21:21:27 +01:00
f07b35f4d4 chore: release version v0.4.1 2017-04-06 15:26:16 -04:00
85f601f809 chore: update contributors 2017-04-06 15:26:15 -04:00
bb6d3dfc36 fix: if conn was closed, don't crash just because identify didn't get any data (#40) 2017-04-06 15:14:37 -04:00
4312acf49a chore: release version v0.4.0 2017-03-30 14:20:11 +01:00
45c0e957c3 chore: update contributors 2017-03-30 14:20:10 +01:00
7d4294b279 Feat/new peer info (#39)
* chore: update deps

* feat: peer-info rave
2017-03-30 14:17:25 +01:00
228c2b09de chore: release version v0.3.3 2017-03-21 15:17:06 +00:00
faa5433f8d chore: update contributors 2017-03-21 15:17:06 +00:00
de53a00e4d chore: update aegir 2017-03-21 15:16:31 +00:00
cf45341754 chore(package): update aegir to version 10.0.0 (#32)
https://greenkeeper.io/
2017-02-13 18:03:30 -08:00
8c75a1fe3c chore: release version v0.3.2 2017-02-09 10:03:06 -08:00
79f8ccb6fe chore: update contributors 2017-02-09 10:03:05 -08:00
4b1b8cdf49 missing dep 2017-02-09 10:00:48 -08:00
ac77cbfa16 chore(package): update aegir to version 9.3.1 (#31)
https://greenkeeper.io/
2017-01-19 13:41:15 +01:00
0764da9485 chore: release version v0.3.1 2017-01-11 12:04:16 +00:00
d94c205b94 chore: update contributors 2017-01-11 12:04:16 +00:00
02483376b4 chore: update deps 2017-01-11 12:03:59 +00:00
ee22cec1a6 chore(package): update peer-id to version 0.8.1 (#29)
https://greenkeeper.io/
2016-12-18 11:34:20 +00:00
78704d8f0a chore(package): update pre-commit to version 1.2.0 (#23)
https://greenkeeper.io/
2016-12-10 12:02:11 -08:00
533d36a161 chore(package): update aegir to version 9.2.1 (#24)
https://greenkeeper.io/
2016-12-10 12:01:25 -08:00
38171cd396 fix: remove deprecation notice from identify protobuf 2016-11-08 11:01:53 +00:00
cf48d49c59 Merge pull request #14 from libp2p/greenkeeper-aegir-9.1.1
aegir@9.1.1 breaks build ⚠️
2016-11-07 11:28:33 +01:00
945ac3b520 chore(package): update aegir to version 9.1.1
https://greenkeeper.io/
2016-11-04 21:37:06 +01:00
414a449ec1 Merge pull request #15 from libp2p/greenkeeper-protocol-buffers-3.1.8
protocol-buffers@3.1.8 breaks build ⚠️
2016-11-04 21:36:52 +01:00
2d527b6244 chore(package): update protocol-buffers to version 3.1.8
https://greenkeeper.io/
2016-11-04 20:27:58 +01:00
08a883c153 chore: release version v0.3.0 2016-11-03 09:14:13 +00:00
3224e9faa8 chore: update contributors 2016-11-03 09:14:12 +00:00
9bcc5055a2 Async Crypto Endeavour (#6) 2016-11-03 09:13:48 +00:00
c34f2a17df Merge pull request #7 from RichardLitt/master
Update README URLs based on HTTP redirects
2016-10-02 15:10:22 +01:00
ce0f6fd73f Update README URLs based on HTTP redirects 2016-09-30 14:44:24 -04:00
2b0477c5b3 chore: release version v0.2.0 2016-09-06 15:44:44 -04:00
79f4edf9e2 chore: update contributors 2016-09-06 15:44:43 -04:00
1af8355a88 Merge pull request #2 from libp2p/pull
[WIP] move to pull-streams
2016-09-06 15:39:15 -04:00
82bc0f2171 feat(readme): documentationa and cleanup of code 2016-09-06 14:52:26 -04:00
3b751c2247 feat(api): move to pull-streams 2016-09-06 14:52:14 -04:00
cf1a4c90e8 Merge pull request #5 from libp2p/greenkeeper-aegir-8.0.0
Update aegir to version 8.0.0 🚀
2016-09-06 14:51:30 -04:00
413f50fbbe chore(package): update aegir to version 8.0.0
https://greenkeeper.io/
2016-09-06 15:12:08 +02:00
1885c773c5 Merge pull request #1 from libp2p/greenkeeper-update-all
Update all dependencies 🌴
2016-08-04 20:47:35 +02:00
74748d91fa chore(package): update dependencies
https://greenkeeper.io/
2016-08-04 19:09:18 +02:00
4ccea11e6c chore: release version v0.1.3 2016-08-03 15:25:18 +01:00
cc8b68b659 chore: update contributors 2016-08-03 15:25:17 +01:00
db6808113c update deps 2016-08-03 15:20:51 +01:00
15 changed files with 697 additions and 199 deletions

View File

@ -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'
)
}
}
}
}

43
.gitignore vendored
View File

@ -1,34 +1,13 @@
package-lock.json
yarn.lock
docs
# Logs
logs
*.log
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
coverage
**/node_modules
**/*.log
test/setup/tmp-disposable-nodes-addrs.json
dist
lib
coverage
**/*.swp
examples/sub-module/**/bundle.js
examples/sub-module/**/*-minified.js
examples/sub-module/*-bundle.js

View File

@ -1,25 +1,43 @@
sudo: false
language: node_js
cache: npm
stages:
- check
- test
- cov
node_js:
- 4
- 5
- '10'
# Make sure we have new NPM.
before_install:
- npm install -g npm
os:
- linux
- osx
script:
- npm run lint
- npm test
- npm run coverage
script: npx nyc -s npm run test:node -- --bail
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov
addons:
firefox: 'latest'
jobs:
include:
- os: windows
cache: false
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- stage: check
script:
- npx aegir commitlint --travis
- npx aegir dep-check
- npm run lint
- stage: test
name: chrome
addons:
chrome: stable
script: npx aegir test -t browser -t webworker
- stage: test
name: firefox
addons:
firefox: latest
script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless
notifications:
email: false
after_success:
- npm run coverage-publish

161
CHANGELOG.md Normal file
View File

@ -0,0 +1,161 @@
<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>
## [0.6.3](https://github.com/libp2p/js-libp2p-identify/compare/v0.6.2...v0.6.3) (2018-01-28)
<a name="0.6.2"></a>
## [0.6.2](https://github.com/libp2p/js-libp2p-identify/compare/v0.6.1...v0.6.2) (2018-01-07)
<a name="0.6.1"></a>
## [0.6.1](https://github.com/libp2p/js-libp2p-identify/compare/v0.6.0...v0.6.1) (2017-09-07)
### Features
* replace protocol-buffers with protons ([#42](https://github.com/libp2p/js-libp2p-identify/issues/42)) ([4ac25c9](https://github.com/libp2p/js-libp2p-identify/commit/4ac25c9))
<a name="0.6.0"></a>
# [0.6.0](https://github.com/libp2p/js-libp2p-identify/compare/v0.5.0...v0.6.0) (2017-09-03)
### Features
* p2p addrs situation ([#41](https://github.com/libp2p/js-libp2p-identify/issues/41)) ([b8f77ea](https://github.com/libp2p/js-libp2p-identify/commit/b8f77ea))
<a name="0.5.0"></a>
# [0.5.0](https://github.com/libp2p/js-libp2p-identify/compare/v0.4.2...v0.5.0) (2017-07-22)
<a name="0.4.2"></a>
## [0.4.2](https://github.com/libp2p/js-libp2p-identify/compare/v0.4.1...v0.4.2) (2017-07-08)
<a name="0.4.1"></a>
## [0.4.1](https://github.com/libp2p/js-libp2p-identify/compare/v0.4.0...v0.4.1) (2017-04-06)
### Bug Fixes
* if conn was closed, don't crash just because identify didn't get any data ([#40](https://github.com/libp2p/js-libp2p-identify/issues/40)) ([bb6d3df](https://github.com/libp2p/js-libp2p-identify/commit/bb6d3df))
<a name="0.4.0"></a>
# [0.4.0](https://github.com/libp2p/js-libp2p-identify/compare/v0.3.3...v0.4.0) (2017-03-30)
<a name="0.3.3"></a>
## [0.3.3](https://github.com/libp2p/js-libp2p-identify/compare/v0.3.2...v0.3.3) (2017-03-21)
<a name="0.3.2"></a>
## [0.3.2](https://github.com/libp2p/js-libp2p-identify/compare/v0.3.1...v0.3.2) (2017-02-09)
<a name="0.3.1"></a>
## [0.3.1](https://github.com/libp2p/js-libp2p-identify/compare/v0.3.0...v0.3.1) (2017-01-11)
### Bug Fixes
* remove deprecation notice from identify protobuf ([38171cd](https://github.com/libp2p/js-libp2p-identify/commit/38171cd))
<a name="0.3.0"></a>
# [0.3.0](https://github.com/libp2p/js-libp2p-identify/compare/v0.2.0...v0.3.0) (2016-11-03)
<a name="0.2.0"></a>
# [0.2.0](https://github.com/libp2p/js-libp2p-identify/compare/v0.1.3...v0.2.0) (2016-09-06)
### Features
* **api:** move to pull-streams ([3b751c2](https://github.com/libp2p/js-libp2p-identify/commit/3b751c2))
* **readme:** documentationa and cleanup of code ([82bc0f2](https://github.com/libp2p/js-libp2p-identify/commit/82bc0f2))
<a name="0.1.3"></a>
## [0.1.3](https://github.com/libp2p/js-libp2p-identify/compare/v0.1.2...v0.1.3) (2016-08-03)
<a name="0.1.2"></a>
## [0.1.2](https://github.com/libp2p/js-libp2p-identify/compare/v0.1.1...v0.1.2) (2016-06-27)
<a name="0.1.1"></a>
## [0.1.1](https://github.com/libp2p/js-libp2p-identify/compare/v0.1.0...v0.1.1) (2016-06-27)
<a name="0.1.0"></a>
# 0.1.0 (2016-06-27)

View File

@ -1,4 +1,49 @@
libp2p-identify
===============
# js-libp2p-identify
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
[![](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-identify.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-identify)
[![](https://img.shields.io/travis/libp2p/js-libp2p-identify.svg?style=flat-square)](https://travis-ci.com/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%3D6.0.0-orange.svg?style=flat-square)
![](https://img.shields.io/badge/Node.js-%3E%3D10.0.0-orange.svg?style=flat-square)
> libp2p Identify Protocol
## Lead Maintainer
[Jacob Heun](https://github.com/jacobheun)
## Description
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
Best way to understand the current design is through this issue: https://github.com/libp2p/js-libp2p-swarm/issues/78
### This module uses `pull-streams`
We expose a streaming interface based on `pull-streams`, rather then on the Node.js core streams implementation (aka Node.js streams). `pull-streams` offers us a better mechanism for error handling and flow control guarantees. If you would like to know more about why we did this, see the discussion at this [issue](https://github.com/ipfs/js-ipfs/issues/362).
You can learn more about pull-streams at:
- [The history of Node.js streams, nodebp April 2014](https://www.youtube.com/watch?v=g5ewQEuXjsQ)
- [The history of streams, 2016](http://dominictarr.com/post/145135293917/history-of-streams)
- [pull-streams, the simple streaming primitive](http://dominictarr.com/post/149248845122/pull-streams-pull-streams-are-a-very-simple)
- [pull-streams documentation](https://pull-stream.github.io/)
#### Converting `pull-streams` to Node.js Streams
If you are a Node.js streams user, you can convert a pull-stream to a Node.js stream using the module [`pull-stream-to-stream`](https://github.com/pull-stream/pull-stream-to-stream), giving you an instance of a Node.js stream that is linked to the pull-stream. For example:
```js
const pullToStream = require('pull-stream-to-stream')
const nodeStreamInstance = pullToStream(pullStreamInstance)
// nodeStreamInstance is an instance of a Node.js Stream
```
To learn more about this utility, visit https://pull-stream.github.io/#pull-stream-to-stream.

View File

@ -1,13 +0,0 @@
machine:
node:
version: stable
dependencies:
pre:
- google-chrome --version
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
- sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
- sudo apt-get update
- sudo apt-get --only-upgrade install google-chrome-stable
- google-chrome --version

View File

@ -1,27 +1,31 @@
{
"name": "libp2p-identify",
"version": "0.1.2",
"version": "0.7.6",
"description": "libp2p Identify Protocol",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
"main": "src/index.js",
"files": [
"dist",
"src"
],
"scripts": {
"lint": "aegir-lint",
"build": "aegir-build",
"test": "aegir-test",
"test:node": "aegir-test test:node",
"test:browser": "aegir-test test:browser",
"release": "aegir-release",
"release-minor": "aegir-release --type minor",
"release-major": "aegir-release --type major",
"coverage": "aegir-coverage",
"coverage-publish": "aegir-coverage publish"
"lint": "aegir lint",
"build": "aegir build",
"test": "aegir test",
"test:node": "aegir test -t node",
"test:browser": "aegir test -t browser",
"release": "aegir release",
"release-minor": "aegir release --type minor",
"release-major": "aegir release --type major",
"coverage": "aegir coverage"
},
"pre-commit": [
"pre-push": [
"lint",
"test"
],
"engines": {
"node": "^4.3.0"
"node": ">=6.0.0",
"npm": ">=3.0.0"
},
"repository": {
"type": "git",
@ -31,25 +35,36 @@
"IPFS",
"libp2p"
],
"author": "David Dias <daviddias@ipfs.io>",
"license": "MIT",
"bugs": {
"url": "https://github.com/libp2p/js-libp2p-identify/issues"
},
"homepage": "https://github.com/libp2p/js-libp2p-identify#readme",
"devDependencies": {
"aegir": "^3.2.0",
"pre-commit": "^1.1.3",
"stream-pair": "^1.0.3"
"aegir": "^18.1.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"pull-pair": "^1.1.0"
},
"dependencies": {
"length-prefixed-stream": "^1.5.0",
"multiaddr": "^2.0.2",
"peer-id": "^0.7.0",
"peer-info": "^0.7.0",
"protocol-buffers": "^3.1.6"
"multiaddr": "^6.0.4",
"peer-id": "~0.12.2",
"peer-info": "~0.15.1",
"protons": "^1.0.1",
"pull-length-prefixed": "^1.3.1",
"pull-stream": "^3.6.9"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>"
"David Dias <daviddias.p@gmail.com>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"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>",
"Vasco Santos <vasco.santos@moxy.studio>",
"Yusef Napora <yusef@protocol.ai>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>"
]
}
}

86
src/dialer.js Normal file
View File

@ -0,0 +1,86 @@
'use strict'
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const multiaddr = require('multiaddr')
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 msg = require('./message')
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(
conn,
lp.decode(),
take(1),
collect((err, data) => {
if (err) {
return callback(err)
}
// connection got closed graciously
if (data.length === 0) {
return callback(new Error('conn was closed, did not receive data'))
}
const input = msg.decode(data[0])
PeerId.createFromPubKey(input.publicKey, (err, id) => {
if (err) {
return callback(err)
}
const peerInfo = new PeerInfo(id)
if (expectedPeerInfo && expectedPeerInfo.id.toB58String() !== id.toB58String()) {
return callback(new Error('invalid peer'))
}
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)
})
})
)
}
function getObservedAddrs (input) {
if (!hasObservedAddr(input)) {
return []
}
let addrs = input.observedAddr
if (!Array.isArray(addrs)) {
addrs = [addrs]
}
return addrs.map((oa) => multiaddr(oa))
}
function hasObservedAddr (input) {
return input.observedAddr && input.observedAddr.length > 0
}

View File

@ -1,89 +1,7 @@
/*
* Identify is one of the protocols swarms speaks 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
*/
'use strict'
const fs = require('fs')
const path = require('path')
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const multiaddr = require('multiaddr')
const bl = require('bl')
const lpstream = require('length-prefixed-stream')
const protobuf = require('protocol-buffers')
const schema = fs.readFileSync(path.join(__dirname, 'identify.proto'))
const idPb = protobuf(schema)
exports = module.exports
exports.multicodec = '/ipfs/id/1.0.0'
exports.exec = (conn, callback) => {
const decode = lpstream.decode()
conn
.pipe(decode)
.pipe(bl((err, data) => {
if (err) {
return callback(err)
}
const msg = idPb.Identify.decode(data)
let observedAddrs = []
if (hasObservedAddr(msg)) {
if (!Array.isArray(msg.observedAddr)) {
msg.observedAddr = [msg.observedAddr]
}
observedAddrs = msg.observedAddr.map((oa) => {
return multiaddr(oa)
})
}
const pId = PeerId.createFromPubKey(msg.publicKey)
const pInfo = new PeerInfo(pId)
msg.listenAddrs.forEach((ma) => {
pInfo.multiaddr.add(multiaddr(ma))
})
callback(null, pInfo, observedAddrs)
}))
conn.end()
}
exports.handler = (pInfoSelf) => {
return (conn) => {
// send what I see from the other + my Info
const encode = lpstream.encode()
encode.pipe(conn)
conn.getObservedAddrs((err, observedAddrs) => {
if (err) { return }
observedAddrs = observedAddrs[0]
let publicKey = new Buffer(0)
if (pInfoSelf.id.pubKey) {
publicKey = pInfoSelf.id.pubKey.bytes
}
const msgSend = idPb.Identify.encode({
protocolVersion: 'ipfs/0.1.0',
agentVersion: 'na',
publicKey: publicKey,
listenAddrs: pInfoSelf.multiaddrs.map((ma) => ma.buffer),
observedAddr: observedAddrs ? observedAddrs.buffer : new Buffer('')
})
encode.write(msgSend)
encode.end()
})
}
}
function hasObservedAddr (msg) {
return msg.observedAddr && msg.observedAddr.length > 0
}
exports.listener = require('./listener')
exports.dialer = require('./dialer')
exports.message = require('./message')

35
src/listener.js Normal file
View File

@ -0,0 +1,35 @@
'use strict'
const pull = require('pull-stream/pull')
const values = require('pull-stream/sources/values')
const lp = require('pull-length-prefixed')
const msg = require('./message')
module.exports = (conn, pInfoSelf) => {
// send what I see from the other + my Info
conn.getObservedAddrs((err, observedAddrs) => {
if (err) { return }
observedAddrs = observedAddrs[0]
let publicKey = Buffer.alloc(0)
if (pInfoSelf.id.pubKey) {
publicKey = pInfoSelf.id.pubKey.bytes
}
const msgSend = msg.encode({
protocolVersion: 'ipfs/0.1.0',
agentVersion: 'na',
publicKey: publicKey,
listenAddrs: pInfoSelf.multiaddrs.toArray().map((ma) => ma.buffer),
observedAddr: observedAddrs ? observedAddrs.buffer : Buffer.from(''),
protocols: Array.from(pInfoSelf.protocols)
})
pull(
values([msgSend]),
lp.encode(),
conn
)
})
}

View File

@ -1,5 +1,8 @@
message Identify {
'use strict'
const protons = require('protons')
const schema = `
message Identify {
// protocolVersion determines compatibility between peers
optional string protocolVersion = 5; // e.g. ipfs/1.0.0
@ -20,6 +23,8 @@ message Identify {
// determine whether its connection to the local peer goes through NAT.
optional bytes observedAddr = 4;
// (DEPRECATED) protocols are the services this node is running
// repeated string protocols = 3;
repeated string protocols = 3;
}
`
module.exports = protons(schema).Identify

15
test/basic.spec.js Normal file
View File

@ -0,0 +1,15 @@
/* eslint-env mocha */
'use strict'
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const identify = require('../src')
describe('basic', () => {
it('multicodec', () => {
expect(identify.multicodec).to.eql('/ipfs/id/1.0.0')
})
})

184
test/dialer.spec.js Normal file
View File

@ -0,0 +1,184 @@
/* eslint-env mocha */
'use strict'
const pull = require('pull-stream/pull')
const values = require('pull-stream/sources/values')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const pair = require('pull-pair/duplex')
const PeerInfo = require('peer-info')
const lp = require('pull-length-prefixed')
const multiaddr = require('multiaddr')
const msg = require('../src/message')
const identify = require('../src')
describe('identify.dialer', () => {
let original
beforeEach(function (done) {
this.timeout(20 * 1000)
PeerInfo.create((err, info) => {
if (err) {
return done(err)
}
original = info
done()
})
})
it('works', (done) => {
const p = pair()
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({
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(info.protocols).to.eql(original.protocols)
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()
})
})
})
})

View File

@ -1,4 +0,0 @@
/* eslint-env mocha */
'use strict'
describe('identify', () => {})

70
test/listener.spec.js Normal file
View File

@ -0,0 +1,70 @@
/* eslint-env mocha */
'use strict'
const pull = require('pull-stream/pull')
const collect = require('pull-stream/sinks/collect')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const pair = require('pull-pair/duplex')
const PeerInfo = require('peer-info')
const lp = require('pull-length-prefixed')
const multiaddr = require('multiaddr')
const msg = require('../src/message')
const identify = require('../src')
describe('identify.listener', () => {
let info
beforeEach(function (done) {
this.timeout(20 * 1000)
PeerInfo.create((err, _info) => {
if (err) {
return done(err)
}
_info.protocols.add('/echo/1.0.0')
_info.protocols.add('/chat/1.0.0')
info = _info
done()
})
})
it('works', (done) => {
const p = pair()
info.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/5002'))
pull(
p[1],
lp.decode(),
collect((err, result) => {
expect(err).to.not.exist()
const input = msg.decode(result[0])
expect(
input
).to.be.eql({
protocolVersion: 'ipfs/0.1.0',
agentVersion: 'na',
publicKey: info.id.pubKey.bytes,
listenAddrs: [multiaddr('/ip4/127.0.0.1/tcp/5002').buffer],
observedAddr: multiaddr('/ip4/127.0.0.1/tcp/5001').buffer,
protocols: ['/echo/1.0.0', '/chat/1.0.0']
})
done()
})
)
const conn = p[0]
conn.getObservedAddrs = (cb) => {
cb(null, [multiaddr('/ip4/127.0.0.1/tcp/5001')])
}
identify.listener(conn, info)
})
})