mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-24 13:01:58 +00:00
Compare commits
31 Commits
fix/addres
...
v0.31.0
Author | SHA1 | Date | |
---|---|---|---|
|
d76356e56a | ||
|
e9543eb2e1 | ||
|
5282708263 | ||
|
ed494f03ae | ||
|
ac370fc967 | ||
|
ef4393649f | ||
|
f23fd4b7c7 | ||
|
5372f7af2f | ||
|
97da0ba740 | ||
|
88b04156bf | ||
|
64f3af897b | ||
|
54e502afcb | ||
|
086b0ec0df | ||
|
cc1f4af879 | ||
|
6456a0fff8 | ||
|
44463b9145 | ||
|
7eb2cea570 | ||
|
c381be3510 | ||
|
975e77991e | ||
|
b043bca607 | ||
|
06e8f3dd42 | ||
|
3f7dde3e13 | ||
|
6f4e7ceeac | ||
|
2af692fb4d | ||
|
906315ce73 | ||
|
49f04cbe70 | ||
|
3d0a79eff3 | ||
|
55ee332907 | ||
|
ffe122d47e | ||
|
21c9aeecb1 | ||
|
a93cca9178 |
76
CHANGELOG.md
76
CHANGELOG.md
@@ -1,3 +1,79 @@
|
||||
# [0.31.0](https://github.com/libp2p/js-libp2p/compare/v0.31.0-rc.7...v0.31.0) (2021-04-28)
|
||||
|
||||
|
||||
|
||||
# [0.31.0-rc.7](https://github.com/libp2p/js-libp2p/compare/v0.31.0-rc.6...v0.31.0-rc.7) (2021-04-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* address book guarantees no replicated entries are added ([#927](https://github.com/libp2p/js-libp2p/issues/927)) ([ac370fc](https://github.com/libp2p/js-libp2p/commit/ac370fc9679b51da8cee3791b6dd268d0695d136))
|
||||
|
||||
|
||||
|
||||
# [0.31.0-rc.6](https://github.com/libp2p/js-libp2p/compare/v0.31.0-rc.5...v0.31.0-rc.6) (2021-04-22)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* keychain optional pw and use interfaces for validators and selectors instead ([#924](https://github.com/libp2p/js-libp2p/issues/924)) ([88b0415](https://github.com/libp2p/js-libp2p/commit/88b04156bf614650c2b14d49b12e969c5eecf04d))
|
||||
|
||||
|
||||
|
||||
# [0.31.0-rc.5](https://github.com/libp2p/js-libp2p/compare/v0.31.0-rc.4...v0.31.0-rc.5) (2021-04-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* address book should not emit peer event if no addresses are known ([b4fb9b7](https://github.com/libp2p/js-libp2p/commit/b4fb9b7bf266ba03c4462c0a41b1c2691e4e88d4))
|
||||
* demand pubsub subclass instead of pubsub instance ([#922](https://github.com/libp2p/js-libp2p/issues/922)) ([086b0ec](https://github.com/libp2p/js-libp2p/commit/086b0ec0df2fac93845d0a0a6b2e2464e869afcd))
|
||||
* dht configuration selectors and validators ([#919](https://github.com/libp2p/js-libp2p/issues/919)) ([cc1f4af](https://github.com/libp2p/js-libp2p/commit/cc1f4af879a58e94538591851d0085ff98cd2641))
|
||||
|
||||
|
||||
|
||||
# [0.31.0-rc.4](https://github.com/libp2p/js-libp2p/compare/v0.31.0-rc.3...v0.31.0-rc.4) (2021-04-20)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add clientMode dht arg and upgrade interface-datastore ([#918](https://github.com/libp2p/js-libp2p/issues/918)) ([975e779](https://github.com/libp2p/js-libp2p/commit/975e77991e67dd9bff790b83df7bd6fa5ddcfc67))
|
||||
* do not add abort signals to useless addresses ([#913](https://github.com/libp2p/js-libp2p/issues/913)) ([06e8f3d](https://github.com/libp2p/js-libp2p/commit/06e8f3dd42432e4b37ab7904b02abde7d1cadda3))
|
||||
* specify pbjs root ([#917](https://github.com/libp2p/js-libp2p/issues/917)) ([b043bca](https://github.com/libp2p/js-libp2p/commit/b043bca607565cf534771e6cf975288a8ff3030b))
|
||||
|
||||
|
||||
|
||||
# [0.31.0-rc.3](https://github.com/libp2p/js-libp2p/compare/v0.31.0-rc.2...v0.31.0-rc.3) (2021-04-19)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* remove inline arg types from function definitions ([#916](https://github.com/libp2p/js-libp2p/issues/916)) ([2af692f](https://github.com/libp2p/js-libp2p/commit/2af692fb4de572168524ae684608fc6526de4ef7))
|
||||
|
||||
|
||||
|
||||
# [0.31.0-rc.2](https://github.com/libp2p/js-libp2p/compare/v0.31.0-rc.1...v0.31.0-rc.2) (2021-04-16)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* metrics stats and moving averages types ([#915](https://github.com/libp2p/js-libp2p/issues/915)) ([3d0a79e](https://github.com/libp2p/js-libp2p/commit/3d0a79eff3bc34a5bdc8ffa31e9b09345a02ad9d))
|
||||
|
||||
|
||||
|
||||
# [0.31.0-rc.1](https://github.com/libp2p/js-libp2p/compare/v0.31.0-rc.0...v0.31.0-rc.1) (2021-04-16)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* dial protocol should throw if no protocol is provided ([#914](https://github.com/libp2p/js-libp2p/issues/914)) ([21c9aee](https://github.com/libp2p/js-libp2p/commit/21c9aeecb13440238aa6b0fb5a6731d2f87d4938))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* dialProtocol does not return connection when no protocols are provided
|
||||
|
||||
|
||||
|
||||
# [0.31.0-rc.0](https://github.com/libp2p/js-libp2p/compare/v0.30.12...v0.31.0-rc.0) (2021-04-15)
|
||||
|
||||
|
||||
|
@@ -25,7 +25,6 @@
|
||||
- [ ] [js-ipfs](https://github.com/ipfs/js-ipfs)
|
||||
- Documentation
|
||||
- [ ] Ensure that README.md is up to date
|
||||
- [ ] Ensure that all the examples run
|
||||
- [ ] Ensure [libp2p/js-libp2p-examples](https://github.com/libp2p/js-libp2p-examples) is updated
|
||||
- [ ] Ensure that [libp2p/docs](https://github.com/libp2p/docs) is updated
|
||||
- Communication
|
||||
|
@@ -4,9 +4,13 @@ This example leverages the [Parcel.js bundler](https://parceljs.org/) to compile
|
||||
|
||||
## Setup
|
||||
|
||||
In order to run the example, first install the dependencies from same directory as this README:
|
||||
In order to run the example:
|
||||
|
||||
- Install dependencey at the root of the js-libp2p repository (if not already done),
|
||||
- then, install the dependencies from same directory as this README:
|
||||
|
||||
```
|
||||
npm install
|
||||
cd ./examples/libp2p-in-the-browser
|
||||
npm install
|
||||
```
|
||||
|
67
package.json
67
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "libp2p",
|
||||
"version": "0.31.0-rc.0",
|
||||
"version": "0.31.0",
|
||||
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
|
||||
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
||||
"main": "src/index.js",
|
||||
@@ -21,13 +21,13 @@
|
||||
"lint": "aegir lint",
|
||||
"build": "aegir build",
|
||||
"build:proto": "npm run build:proto:circuit && npm run build:proto:identify && npm run build:proto:plaintext && npm run build:proto:address-book && npm run build:proto:proto-book && npm run build:proto:peer-record && npm run build:proto:envelope",
|
||||
"build:proto:circuit": "pbjs -t static-module -w commonjs --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/circuit/protocol/index.js ./src/circuit/protocol/index.proto",
|
||||
"build:proto:identify": "pbjs -t static-module -w commonjs --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/identify/message.js ./src/identify/message.proto",
|
||||
"build:proto:plaintext": "pbjs -t static-module -w commonjs --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/insecure/proto.js ./src/insecure/proto.proto",
|
||||
"build:proto:address-book": "pbjs -t static-module -w commonjs --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/peer-store/persistent/pb/address-book.js ./src/peer-store/persistent/pb/address-book.proto",
|
||||
"build:proto:proto-book": "pbjs -t static-module -w commonjs --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/peer-store/persistent/pb/proto-book.js ./src/peer-store/persistent/pb/proto-book.proto",
|
||||
"build:proto:peer-record": "pbjs -t static-module -w commonjs --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/record/peer-record/peer-record.js ./src/record/peer-record/peer-record.proto",
|
||||
"build:proto:envelope": "pbjs -t static-module -w commonjs --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/record/envelope/envelope.js ./src/record/envelope/envelope.proto",
|
||||
"build:proto:circuit": "pbjs -t static-module -w commonjs -r libp2p-circuit --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/circuit/protocol/index.js ./src/circuit/protocol/index.proto",
|
||||
"build:proto:identify": "pbjs -t static-module -w commonjs -r libp2p-identify --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/identify/message.js ./src/identify/message.proto",
|
||||
"build:proto:plaintext": "pbjs -t static-module -w commonjs -r libp2p-plaintext --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/insecure/proto.js ./src/insecure/proto.proto",
|
||||
"build:proto:address-book": "pbjs -t static-module -w commonjs -r libp2p-address-book --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/peer-store/persistent/pb/address-book.js ./src/peer-store/persistent/pb/address-book.proto",
|
||||
"build:proto:proto-book": "pbjs -t static-module -w commonjs -r libp2p-proto-book --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/peer-store/persistent/pb/proto-book.js ./src/peer-store/persistent/pb/proto-book.proto",
|
||||
"build:proto:peer-record": "pbjs -t static-module -w commonjs -r libp2p-peer-record --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/record/peer-record/peer-record.js ./src/record/peer-record/peer-record.proto",
|
||||
"build:proto:envelope": "pbjs -t static-module -w commonjs -r libp2p-envelope --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/record/envelope/envelope.js ./src/record/envelope/envelope.proto",
|
||||
"build:proto-types": "npm run build:proto-types:circuit && npm run build:proto-types:identify && npm run build:proto-types:plaintext && npm run build:proto-types:address-book && npm run build:proto-types:proto-book && npm run build:proto-types:peer-record && npm run build:proto-types:envelope",
|
||||
"build:proto-types:circuit": "pbts -o src/circuit/protocol/index.d.ts src/circuit/protocol/index.js",
|
||||
"build:proto-types:identify": "pbts -o src/identify/message.d.ts src/identify/message.js",
|
||||
@@ -90,7 +90,7 @@
|
||||
"es6-promisify": "^6.1.1",
|
||||
"events": "^3.3.0",
|
||||
"hashlru": "^2.3.0",
|
||||
"interface-datastore": "^3.0.3",
|
||||
"interface-datastore": "^4.0.0",
|
||||
"ipfs-utils": "^6.0.0",
|
||||
"it-all": "^1.0.4",
|
||||
"it-buffer": "^0.1.2",
|
||||
@@ -104,7 +104,7 @@
|
||||
"it-pipe": "^1.1.0",
|
||||
"it-take": "1.0.0",
|
||||
"libp2p-crypto": "^0.19.0",
|
||||
"libp2p-interfaces": "^0.10.0",
|
||||
"libp2p-interfaces": "^0.10.3",
|
||||
"libp2p-utils": "^0.3.1",
|
||||
"mafmt": "^9.0.0",
|
||||
"merge-options": "^3.0.4",
|
||||
@@ -136,10 +136,8 @@
|
||||
"@types/node-forge": "^0.9.7",
|
||||
"@types/varint": "^6.0.0",
|
||||
"abortable-iterator": "^3.0.0",
|
||||
"aegir": "^33.0.0",
|
||||
"aegir": "^33.1.1",
|
||||
"buffer": "^6.0.3",
|
||||
"chai-bytes": "^0.1.2",
|
||||
"chai-string": "^1.5.0",
|
||||
"delay": "^5.0.0",
|
||||
"interop-libp2p": "^0.3.0",
|
||||
"into-stream": "^6.0.0",
|
||||
@@ -156,7 +154,7 @@
|
||||
"libp2p-kad-dht": "^0.21.0",
|
||||
"libp2p-mdns": "^0.16.0",
|
||||
"libp2p-mplex": "^0.10.1",
|
||||
"libp2p-noise": "^2.0.0",
|
||||
"libp2p-noise": "^3.0.0",
|
||||
"libp2p-tcp": "^0.15.1",
|
||||
"libp2p-webrtc-star": "^0.22.0",
|
||||
"libp2p-websockets": "^0.15.0",
|
||||
@@ -172,58 +170,59 @@
|
||||
},
|
||||
"contributors": [
|
||||
"David Dias <daviddias.p@gmail.com>",
|
||||
"Jacob Heun <jacobheun@gmail.com>",
|
||||
"Vasco Santos <vasco.santos@moxy.studio>",
|
||||
"Alan Shaw <alan@tableflip.io>",
|
||||
"Jacob Heun <jacobheun@gmail.com>",
|
||||
"Alex Potsides <alex@achingbrain.net>",
|
||||
"Alan Shaw <alan@tableflip.io>",
|
||||
"Cayman <caymannava@gmail.com>",
|
||||
"Pedro Teixeira <i@pgte.me>",
|
||||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
||||
"Maciej Krüger <mkg20001@gmail.com>",
|
||||
"Hugo Dias <mail@hugodias.me>",
|
||||
"Volker Mische <volker.mische@gmail.com>",
|
||||
"dirkmc <dirkmdev@gmail.com>",
|
||||
"Volker Mische <volker.mische@gmail.com>",
|
||||
"Richard Littauer <richard.littauer@gmail.com>",
|
||||
"a1300 <matthias-knopp@gmx.net>",
|
||||
"Elven <mon.samuel@qq.com>",
|
||||
"Andrew Nesbitt <andrewnez@gmail.com>",
|
||||
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
|
||||
"Giovanni T. Parra <fiatjaf@gmail.com>",
|
||||
"Ryan Bell <ryan@piing.net>",
|
||||
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
|
||||
"Thomas Eizinger <thomas@eizinger.io>",
|
||||
"Samlior <samlior@foxmail.com>",
|
||||
"Didrik Nordström <didrik@betamos.se>",
|
||||
"Julien Bouquillon <contact@revolunet.com>",
|
||||
"Kevin Kwok <antimatter15@gmail.com>",
|
||||
"Kevin Lacker <lacker@gmail.com>",
|
||||
"Miguel Mota <miguelmota2@gmail.com>",
|
||||
"Ryan Bell <ryan@piing.net>",
|
||||
"Andrew Nesbitt <andrewnez@gmail.com>",
|
||||
"Didrik Nordström <didrik.nordstrom@gmail.com>",
|
||||
"Nuno Nogueira <nunofmn@gmail.com>",
|
||||
"Philipp Muens <raute1337@gmx.de>",
|
||||
"RasmusErik Voel Jensen <github@solsort.com>",
|
||||
"Smite Chow <xiaopengyou@live.com>",
|
||||
"Soeren <nikorpoulsen@gmail.com>",
|
||||
"Sönke Hahn <soenkehahn@gmail.com>",
|
||||
"TJKoury <TJKoury@gmail.com>",
|
||||
"Tiago Alves <alvesjtiago@gmail.com>",
|
||||
"Daijiro Wachi <daijiro.wachi@gmail.com>",
|
||||
"Cindy Wu <ciindy.wu@gmail.com>",
|
||||
"Chris Bratlien <chrisbratlien@gmail.com>",
|
||||
"Yusef Napora <yusef@napora.org>",
|
||||
"Zane Starr <zcstarr@gmail.com>",
|
||||
"Bernd Strehl <bernd.strehl@gmail.com>",
|
||||
"ebinks <elizabethjbinks@gmail.com>",
|
||||
"Ethan Lam <elmemphis2000@gmail.com>",
|
||||
"isan_rivkin <isanrivkin@gmail.com>",
|
||||
"robertkiel <robert.kiel@validitylabs.org>",
|
||||
"RasmusErik Voel Jensen <github@solsort.com>",
|
||||
"Aleksei <vozhdb@gmail.com>",
|
||||
"Bernd Strehl <bernd.strehl@gmail.com>",
|
||||
"Chris Bratlien <chrisbratlien@gmail.com>",
|
||||
"Cindy Wu <ciindy.wu@gmail.com>",
|
||||
"Daijiro Wachi <daijiro.wachi@gmail.com>",
|
||||
"Diogo Silva <fsdiogo@gmail.com>",
|
||||
"Dmitriy Ryajov <dryajov@gmail.com>",
|
||||
"Ethan Lam <elmemphis2000@gmail.com>",
|
||||
"Fei Liu <liu.feiwood@gmail.com>",
|
||||
"Felipe Martins <felipebrasil93@gmail.com>",
|
||||
"Florian-Merle <florian.david.merle@gmail.com>",
|
||||
"Francis Gulotta <wizard@roborooter.com>",
|
||||
"Dmitriy Ryajov <dryajov@gmail.com>",
|
||||
"Franck Royer <franck@royer.one>",
|
||||
"Henrique Dias <hacdias@gmail.com>",
|
||||
"Irakli Gozalishvili <rfobic@gmail.com>",
|
||||
"Diogo Silva <fsdiogo@gmail.com>",
|
||||
"Joel Gustafson <joelg@mit.edu>"
|
||||
"Joel Gustafson <joelg@mit.edu>",
|
||||
"Julien Bouquillon <contact@revolunet.com>",
|
||||
"Kevin Kwok <antimatter15@gmail.com>",
|
||||
"Kevin Lacker <lacker@gmail.com>",
|
||||
"Miguel Mota <miguelmota2@gmail.com>"
|
||||
]
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ var $protobuf = require("protobufjs/minimal");
|
||||
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
|
||||
|
||||
// Exported root namespace
|
||||
var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});
|
||||
var $root = $protobuf.roots["libp2p-circuit"] || ($protobuf.roots["libp2p-circuit"] = {});
|
||||
|
||||
$root.CircuitRelay = (function() {
|
||||
|
||||
|
@@ -110,7 +110,7 @@ class Dialer {
|
||||
const dialTarget = await this._createDialTarget(peer)
|
||||
|
||||
if (!dialTarget.addrs.length) {
|
||||
throw errCode(new Error('The dial request has no addresses'), codes.ERR_NO_VALID_ADDRESSES)
|
||||
throw errCode(new Error('The dial request has no valid addresses'), codes.ERR_NO_VALID_ADDRESSES)
|
||||
}
|
||||
const pendingDial = this._pendingDials.get(dialTarget.id) || this._createPendingDial(dialTarget, options)
|
||||
|
||||
@@ -134,6 +134,7 @@ class Dialer {
|
||||
* Creates a DialTarget. The DialTarget is used to create and track
|
||||
* the DialRequest to a given peer.
|
||||
* If a multiaddr is received it should be the first address attempted.
|
||||
* Multiaddrs not supported by the available transports will be filtered out.
|
||||
*
|
||||
* @private
|
||||
* @param {PeerId|Multiaddr|string} peer - A PeerId or Multiaddr
|
||||
@@ -162,9 +163,12 @@ class Dialer {
|
||||
resolvedAddrs.forEach(ra => addrs.push(ra))
|
||||
}
|
||||
|
||||
// Multiaddrs not supported by the available transports will be filtered out.
|
||||
const supportedAddrs = addrs.filter(a => this.transportManager.transportForMultiaddr(a))
|
||||
|
||||
return {
|
||||
id: id.toB58String(),
|
||||
addrs
|
||||
addrs: supportedAddrs
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -11,6 +11,7 @@ exports.codes = {
|
||||
PUBSUB_NOT_STARTED: 'ERR_PUBSUB_NOT_STARTED',
|
||||
DHT_NOT_STARTED: 'ERR_DHT_NOT_STARTED',
|
||||
CONN_ENCRYPTION_REQUIRED: 'ERR_CONN_ENCRYPTION_REQUIRED',
|
||||
ERR_INVALID_PROTOCOLS_FOR_STREAM: 'ERR_INVALID_PROTOCOLS_FOR_STREAM',
|
||||
ERR_CONNECTION_ENDED: 'ERR_CONNECTION_ENDED',
|
||||
ERR_CONNECTION_FAILED: 'ERR_CONNECTION_FAILED',
|
||||
ERR_NODE_NOT_STARTED: 'ERR_NODE_NOT_STARTED',
|
||||
|
@@ -7,7 +7,7 @@ var $protobuf = require("protobufjs/minimal");
|
||||
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
|
||||
|
||||
// Exported root namespace
|
||||
var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});
|
||||
var $root = $protobuf.roots["libp2p-identify"] || ($protobuf.roots["libp2p-identify"] = {});
|
||||
|
||||
$root.Identify = (function() {
|
||||
|
||||
|
20
src/index.js
20
src/index.js
@@ -66,6 +66,9 @@ const { updateSelfPeerRecord } = require('./record/utils')
|
||||
* @property {boolean} [enabled = false]
|
||||
* @property {number} [kBucketSize = 20]
|
||||
* @property {RandomWalkOptions} [randomWalk]
|
||||
* @property {boolean} [clientMode]
|
||||
* @property {import('libp2p-interfaces/src/types').DhtSelectors} [selectors]
|
||||
* @property {import('libp2p-interfaces/src/types').DhtValidators} [validators]
|
||||
*
|
||||
* @typedef {Object} KeychainOptions
|
||||
* @property {Datastore} [datastore]
|
||||
@@ -101,7 +104,7 @@ const { updateSelfPeerRecord } = require('./record/utils')
|
||||
* @property {PeerRoutingModule[]} [peerRouting]
|
||||
* @property {ContentRoutingModule[]} [contentRouting]
|
||||
* @property {Object} [dht]
|
||||
* @property {Pubsub} [pubsub]
|
||||
* @property {{new(...args: any[]): Pubsub}} [pubsub]
|
||||
* @property {Protector} [connProtector]
|
||||
*
|
||||
* @typedef {Object} Libp2pOptions
|
||||
@@ -462,26 +465,23 @@ class Libp2p extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Dials to the provided peer and handshakes with the given protocol.
|
||||
* Dials to the provided peer and tries to handshake with the given protocols in order.
|
||||
* If successful, the known metadata of the peer will be added to the nodes `peerStore`,
|
||||
* and the `Connection` will be returned
|
||||
* and the `MuxedStream` will be returned together with the successful negotiated protocol.
|
||||
*
|
||||
* @async
|
||||
* @param {PeerId|Multiaddr|string} peer - The peer to dial
|
||||
* @param {string[]|string} protocols
|
||||
* @param {object} [options]
|
||||
* @param {AbortSignal} [options.signal]
|
||||
* @returns {Promise<Connection|{ stream: MuxedStream; protocol: string; }>}
|
||||
*/
|
||||
async dialProtocol (peer, protocols, options) {
|
||||
const connection = await this._dial(peer, options)
|
||||
|
||||
// If a protocol was provided, create a new stream
|
||||
if (protocols && protocols.length) {
|
||||
return connection.newStream(protocols)
|
||||
if (!protocols || !protocols.length) {
|
||||
throw errCode(new Error('no protocols were provided to open a stream'), codes.ERR_INVALID_PROTOCOLS_FOR_STREAM)
|
||||
}
|
||||
|
||||
return connection
|
||||
const connection = await this._dial(peer, options)
|
||||
return connection.newStream(protocols)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -7,7 +7,7 @@ var $protobuf = require("protobufjs/minimal");
|
||||
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
|
||||
|
||||
// Exported root namespace
|
||||
var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});
|
||||
var $root = $protobuf.roots["libp2p-plaintext"] || ($protobuf.roots["libp2p-plaintext"] = {});
|
||||
|
||||
$root.Exchange = (function() {
|
||||
|
||||
|
@@ -26,7 +26,7 @@ require('node-forge/lib/sha512')
|
||||
* @property {number} keyLength
|
||||
*
|
||||
* @typedef {Object} KeychainOptions
|
||||
* @property {string} pass
|
||||
* @property {string} [pass]
|
||||
* @property {DekOptions} [dek]
|
||||
*/
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
'use strict'
|
||||
|
||||
const EventEmitter = require('events')
|
||||
const Big = require('bignumber.js')
|
||||
const { BigNumber: Big } = require('bignumber.js')
|
||||
const MovingAverage = require('moving-average')
|
||||
const retimer = require('retimer')
|
||||
|
||||
@@ -19,11 +19,17 @@ class Stats extends EventEmitter {
|
||||
|
||||
this._options = options
|
||||
this._queue = []
|
||||
this._stats = {}
|
||||
|
||||
/** @type {{ dataReceived: Big, dataSent: Big }} */
|
||||
this._stats = {
|
||||
dataReceived: Big(0),
|
||||
dataSent: Big(0)
|
||||
}
|
||||
|
||||
this._frequencyLastTime = Date.now()
|
||||
this._frequencyAccumulators = {}
|
||||
|
||||
/** @type {{ dataReceived: MovingAverage[], dataSent: MovingAverage[] }} */
|
||||
this._movingAverages = {}
|
||||
|
||||
this._update = this._update.bind(this)
|
||||
|
@@ -307,10 +307,13 @@ class AddressBook extends Book {
|
||||
throw errcode(new Error(`multiaddr ${addr} must be an instance of multiaddr`), ERR_INVALID_PARAMETERS)
|
||||
}
|
||||
|
||||
addresses.push({
|
||||
multiaddr: addr,
|
||||
isCertified
|
||||
})
|
||||
// Guarantee no replicates
|
||||
if (!addresses.find((a) => a.multiaddr.equals(addr))) {
|
||||
addresses.push({
|
||||
multiaddr: addr,
|
||||
isCertified
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return addresses
|
||||
|
@@ -7,7 +7,7 @@ var $protobuf = require("protobufjs/minimal");
|
||||
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
|
||||
|
||||
// Exported root namespace
|
||||
var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});
|
||||
var $root = $protobuf.roots["libp2p-address-book"] || ($protobuf.roots["libp2p-address-book"] = {});
|
||||
|
||||
$root.Addresses = (function() {
|
||||
|
||||
|
@@ -7,7 +7,7 @@ var $protobuf = require("protobufjs/minimal");
|
||||
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
|
||||
|
||||
// Exported root namespace
|
||||
var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});
|
||||
var $root = $protobuf.roots["libp2p-proto-book"] || ($protobuf.roots["libp2p-proto-book"] = {});
|
||||
|
||||
$root.Protocols = (function() {
|
||||
|
||||
|
@@ -7,12 +7,13 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {import("libp2p-interfaces/src/pubsub")} PubsubRouter
|
||||
* @param {{new(...args: any[]): PubsubRouter}} PubsubRouter
|
||||
* @param {import('.')} libp2p
|
||||
* @param {{ enabled: boolean; } & import(".").PubsubLocalOptions & import("libp2p-interfaces/src/pubsub").PubsubOptions} options
|
||||
*/
|
||||
function pubsubAdapter (PubsubRouter, libp2p, options) {
|
||||
// @ts-ignore Pubsub constructor type not defined
|
||||
/** @type {PubsubRouter & { _subscribeAdapter: PubsubRouter['subscribe'], _unsubscribeAdapter: PubsubRouter['unsubscribe'] }} */
|
||||
// @ts-ignore we set the extra _subscribeAdapter and _unsubscribeAdapter properties afterwards
|
||||
const pubsub = new PubsubRouter(libp2p, options)
|
||||
pubsub._subscribeAdapter = pubsub.subscribe
|
||||
pubsub._unsubscribeAdapter = pubsub.unsubscribe
|
||||
|
@@ -7,7 +7,7 @@ var $protobuf = require("protobufjs/minimal");
|
||||
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
|
||||
|
||||
// Exported root namespace
|
||||
var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});
|
||||
var $root = $protobuf.roots["libp2p-envelope"] || ($protobuf.roots["libp2p-envelope"] = {});
|
||||
|
||||
$root.Envelope = (function() {
|
||||
|
||||
|
@@ -7,7 +7,7 @@ var $protobuf = require("protobufjs/minimal");
|
||||
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
|
||||
|
||||
// Exported root namespace
|
||||
var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});
|
||||
var $root = $protobuf.roots["libp2p-peer-record"] || ($protobuf.roots["libp2p-peer-record"] = {});
|
||||
|
||||
$root.PeerRecord = (function() {
|
||||
|
||||
|
@@ -222,6 +222,7 @@ class Upgrader {
|
||||
}) {
|
||||
/** @type {import("libp2p-interfaces/src/stream-muxer/types").Muxer} */
|
||||
let muxer
|
||||
/** @type {import("libp2p-interfaces/src/connection/connection").CreatedMuxedStream | undefined} */
|
||||
let newStream
|
||||
/** @type {Connection} */
|
||||
let connection // eslint-disable-line prefer-const
|
||||
@@ -249,7 +250,7 @@ class Upgrader {
|
||||
}
|
||||
})
|
||||
|
||||
newStream = async (/** @type {string | string[]} */ protocols) => {
|
||||
newStream = async (protocols) => {
|
||||
log('%s: starting new stream on %s', direction, protocols)
|
||||
const muxedStream = muxer.newStream()
|
||||
const mss = new Multistream.Dialer(muxedStream)
|
||||
@@ -309,8 +310,8 @@ class Upgrader {
|
||||
},
|
||||
newStream: newStream || errConnectionNotMultiplexed,
|
||||
getStreams: () => muxer ? muxer.streams : errConnectionNotMultiplexed(),
|
||||
close: async (/** @type {Error | undefined} */ err) => {
|
||||
await maConn.close(err)
|
||||
close: async () => {
|
||||
await maConn.close()
|
||||
// Ensure remaining streams are aborted
|
||||
if (muxer) {
|
||||
muxer.streams.map(stream => stream.abort())
|
||||
|
@@ -45,7 +45,7 @@ describe('Listening', () => {
|
||||
expect(addrs.length).to.be.at.least(2)
|
||||
for (const addr of addrs) {
|
||||
const opts = addr.toOptions()
|
||||
expect(opts.family).to.equal('ipv4')
|
||||
expect(opts.family).to.equal(4)
|
||||
expect(opts.transport).to.equal('tcp')
|
||||
expect(opts.host).to.match(/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/)
|
||||
expect(opts.port).to.be.gt(0)
|
||||
|
@@ -98,8 +98,8 @@ describe('Dialing (direct, TCP)', () => {
|
||||
const dialer = new Dialer({ transportManager: localTM, peerStore })
|
||||
|
||||
await expect(dialer.connectToPeer(unsupportedAddr))
|
||||
.to.eventually.be.rejectedWith(AggregateError)
|
||||
.and.to.have.nested.property('._errors[0].code', ErrorCodes.ERR_TRANSPORT_UNAVAILABLE)
|
||||
.to.eventually.be.rejectedWith(Error)
|
||||
.and.to.have.nested.property('.code', ErrorCodes.ERR_NO_VALID_ADDRESSES)
|
||||
})
|
||||
|
||||
it('should fail to connect if peer has no known addresses', async () => {
|
||||
@@ -139,8 +139,28 @@ describe('Dialing (direct, TCP)', () => {
|
||||
const peerId = await PeerId.createFromJSON(Peers[0])
|
||||
|
||||
await expect(dialer.connectToPeer(peerId))
|
||||
.to.eventually.be.rejectedWith(AggregateError)
|
||||
.and.to.have.nested.property('._errors[0].code', ErrorCodes.ERR_TRANSPORT_UNAVAILABLE)
|
||||
.to.eventually.be.rejectedWith(Error)
|
||||
.and.to.have.nested.property('.code', ErrorCodes.ERR_NO_VALID_ADDRESSES)
|
||||
})
|
||||
|
||||
it('should only try to connect to addresses supported by the transports configured', async () => {
|
||||
const remoteAddrs = remoteTM.getAddrs()
|
||||
const dialer = new Dialer({
|
||||
transportManager: localTM,
|
||||
peerStore: {
|
||||
addressBook: {
|
||||
add: () => { },
|
||||
getMultiaddrsForPeer: () => [...remoteAddrs, unsupportedAddr]
|
||||
}
|
||||
}
|
||||
})
|
||||
const peerId = await PeerId.createFromJSON(Peers[0])
|
||||
|
||||
sinon.spy(localTM, 'dial')
|
||||
const connection = await dialer.connectToPeer(peerId)
|
||||
expect(localTM.dial.callCount).to.equal(remoteAddrs.length)
|
||||
expect(connection).to.exist()
|
||||
await connection.close()
|
||||
})
|
||||
|
||||
it('should abort dials on queue task timeout', async () => {
|
||||
@@ -352,6 +372,25 @@ describe('Dialing (direct, TCP)', () => {
|
||||
await pWaitFor(() => remoteConn.streams.length === 0)
|
||||
})
|
||||
|
||||
it('should throw when using dialProtocol with no protocols', async () => {
|
||||
libp2p = new Libp2p({
|
||||
peerId,
|
||||
modules: {
|
||||
transport: [Transport],
|
||||
streamMuxer: [Muxer],
|
||||
connEncryption: [Crypto]
|
||||
}
|
||||
})
|
||||
|
||||
await expect(libp2p.dialProtocol(remotePeerId))
|
||||
.to.eventually.be.rejectedWith(Error)
|
||||
.and.to.have.property('code', ErrorCodes.ERR_INVALID_PROTOCOLS_FOR_STREAM)
|
||||
|
||||
await expect(libp2p.dialProtocol(remotePeerId, []))
|
||||
.to.eventually.be.rejectedWith(Error)
|
||||
.and.to.have.property('code', ErrorCodes.ERR_INVALID_PROTOCOLS_FOR_STREAM)
|
||||
})
|
||||
|
||||
it('should be able to use hangup to close connections', async () => {
|
||||
libp2p = new Libp2p({
|
||||
peerId,
|
||||
|
@@ -2,8 +2,7 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const { chai, expect } = require('aegir/utils/chai')
|
||||
chai.use(require('chai-string'))
|
||||
const { expect } = require('aegir/utils/chai')
|
||||
const uint8ArrayFromString = require('uint8arrays/from-string')
|
||||
const uint8ArrayToString = require('uint8arrays/to-string')
|
||||
const { MemoryDatastore } = require('interface-datastore')
|
||||
|
@@ -2,9 +2,8 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const { chai, expect } = require('aegir/utils/chai')
|
||||
const { expect } = require('aegir/utils/chai')
|
||||
const fail = expect.fail
|
||||
chai.use(require('chai-string'))
|
||||
const uint8ArrayFromString = require('uint8arrays/from-string')
|
||||
const uint8ArrayToString = require('uint8arrays/to-string')
|
||||
|
||||
|
@@ -287,6 +287,14 @@ describe('addressBook', () => {
|
||||
|
||||
await defer.promise
|
||||
})
|
||||
|
||||
it('does not add replicated content', () => {
|
||||
// set 1
|
||||
ab.set(peerId, [addr1, addr1])
|
||||
|
||||
const addresses = ab.get(peerId)
|
||||
expect(addresses).to.have.lengthOf(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('addressBook.get', () => {
|
||||
|
@@ -1,8 +1,7 @@
|
||||
'use strict'
|
||||
/* eslint-env mocha */
|
||||
|
||||
const { chai, expect } = require('aegir/utils/chai')
|
||||
chai.use(require('chai-bytes'))
|
||||
const { expect } = require('aegir/utils/chai')
|
||||
const sinon = require('sinon')
|
||||
|
||||
const PeerStore = require('../../src/peer-store')
|
||||
|
@@ -1,8 +1,7 @@
|
||||
'use strict'
|
||||
/* eslint-env mocha */
|
||||
|
||||
const { chai, expect } = require('aegir/utils/chai')
|
||||
chai.use(require('chai-bytes'))
|
||||
const { expect } = require('aegir/utils/chai')
|
||||
const uint8ArrayFromString = require('uint8arrays/from-string')
|
||||
|
||||
const pDefer = require('p-defer')
|
||||
|
@@ -1,8 +1,7 @@
|
||||
'use strict'
|
||||
/* eslint-env mocha */
|
||||
|
||||
const { chai, expect } = require('aegir/utils/chai')
|
||||
chai.use(require('chai-bytes'))
|
||||
const { expect } = require('aegir/utils/chai')
|
||||
const sinon = require('sinon')
|
||||
|
||||
const baseOptions = require('../utils/base-options')
|
||||
|
@@ -1,8 +1,7 @@
|
||||
'use strict'
|
||||
/* eslint-env mocha */
|
||||
|
||||
const { chai, expect } = require('aegir/utils/chai')
|
||||
chai.use(require('chai-bytes'))
|
||||
const { expect } = require('aegir/utils/chai')
|
||||
const uint8arrayFromString = require('uint8arrays/from-string')
|
||||
const uint8arrayEquals = require('uint8arrays/equals')
|
||||
const Envelope = require('../../src/record/envelope')
|
||||
|
@@ -9,10 +9,11 @@
|
||||
"libp2p-delegated-content-routing": "^0.9.0",
|
||||
"libp2p-delegated-peer-routing": "^0.8.2",
|
||||
"libp2p-gossipsub": "^0.8.0",
|
||||
"libp2p-interfaces": "^0.8.4",
|
||||
"libp2p-interfaces": "^0.10.1",
|
||||
"libp2p-kad-dht": "^0.21.0",
|
||||
"libp2p-mplex": "^0.10.2",
|
||||
"libp2p-noise": "^2.0.5",
|
||||
"libp2p-record": "^0.10.2",
|
||||
"libp2p-tcp": "^0.15.3",
|
||||
"libp2p-websockets": "^0.15.3",
|
||||
"peer-id": "^0.14.3"
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import Libp2p = require('libp2p')
|
||||
import Libp2pRecord = require('libp2p-record')
|
||||
|
||||
const TCP = require('libp2p-tcp')
|
||||
const WEBSOCKETS = require('libp2p-websockets')
|
||||
@@ -22,6 +23,7 @@ const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
|
||||
const DelegatedContentRouter = require('libp2p-delegated-content-routing')
|
||||
const PeerId = require('peer-id')
|
||||
|
||||
|
||||
// Known peers addresses
|
||||
const bootstrapMultiaddrs = [
|
||||
'/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb',
|
||||
@@ -125,6 +127,13 @@ async function main() {
|
||||
enabled: true, // Allows to disable discovery (enabled by default)
|
||||
interval: 300e3,
|
||||
timeout: 10e3
|
||||
},
|
||||
clientMode: true,
|
||||
validators: {
|
||||
pk: Libp2pRecord.validator.validators.pk
|
||||
},
|
||||
selectors: {
|
||||
pk: Libp2pRecord.selection.selectors.pk
|
||||
}
|
||||
},
|
||||
nat: {
|
||||
|
Reference in New Issue
Block a user