Compare commits

..

26 Commits

Author SHA1 Message Date
Vasco Santos
d163ffd224 chore: release version v0.31.4 2021-05-12 17:05:35 +02:00
Vasco Santos
b29d6c9304 chore: update contributors 2021-05-12 17:05:35 +02:00
zeim839
890dd05941 replaced libp2p with node (#942)
Co-authored-by: zeim839 <kassissahil@gmail.com>
2021-05-12 16:47:29 +02:00
zeim839
a79c6b50d7 fix: peerRouting.findPeer() trying to find self (#941)
* throw error if node attempts to find itself

Co-authored-by: Vasco Santos <vasco.santos@ua.pt>
2021-05-12 16:46:20 +02:00
Vasco Santos
d372a68692 chore: add github issue templates (#938) 2021-05-05 15:06:56 +02:00
Vasco Santos
4e3fc19623 chore: release version v0.31.3 2021-05-04 12:23:58 +02:00
Vasco Santos
2fa82b387c chore: update contributors 2021-05-04 12:23:57 +02:00
Alex Potsides
8fc6f8af81 chore: update ipfs-utils dep (#937) 2021-05-04 12:14:11 +02:00
Vasco Santos
924585b143 chore: release version v0.31.2 2021-04-30 15:45:45 +02:00
Vasco Santos
556f0203db chore: update contributors 2021-04-30 15:45:44 +02:00
Vasco Santos
b5a9eb2087 fix: moving averages record types (#935) 2021-04-30 15:42:34 +02:00
Vasco Santos
e5187d02ba chore: release version v0.31.1 2021-04-30 13:40:29 +02:00
Vasco Santos
150e4f97c1 chore: update contributors 2021-04-30 13:40:28 +02:00
Vasco Santos
302bb90058 fix: event emitter and interfaces types for discovery and routing (#934) 2021-04-30 13:20:12 +02:00
Vasco Santos
f860ffb3e7 chore: add migration guide to 0.31 (#912) 2021-04-30 09:30:41 +02:00
Vasco Santos
2572f3e034 chore: update libp2p dht and gossipsub to releases (#933) 2021-04-29 10:10:57 +02:00
Vasco Santos
d76356e56a chore: release version v0.31.0 2021-04-28 15:39:48 +02:00
Vasco Santos
e9543eb2e1 chore: update contributors 2021-04-28 15:39:48 +02:00
Vasco Santos
5282708263 chore: release version v0.31.0-rc.7 2021-04-27 17:18:12 +02:00
Vasco Santos
ed494f03ae chore: update contributors 2021-04-27 17:18:12 +02:00
Vasco Santos
ac370fc967 fix: address book guarantees no replicated entries are added (#927) 2021-04-27 17:14:48 +02:00
Vasco Santos
ef4393649f chore: remove chai deps (#929) 2021-04-27 17:13:34 +02:00
Vasco Santos
f23fd4b7c7 chore: update noise (#926) 2021-04-27 13:24:31 +02:00
Vasco Santos
5372f7af2f chore: release version v0.31.0-rc.6 2021-04-22 10:09:18 +02:00
Vasco Santos
97da0ba740 chore: update contributors 2021-04-22 10:09:18 +02:00
Vasco Santos
88b04156bf fix: keychain optional pw and use interfaces for validators and selectors instead (#924) 2021-04-22 09:53:55 +02:00
27 changed files with 348 additions and 88 deletions

5
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: libp2p Official Forum
url: https://discuss.libp2p.io
about: For general questions, support requests and discussions

55
.github/ISSUE_TEMPLATE/open_an_issue.md vendored Normal file
View File

@@ -0,0 +1,55 @@
---
name: Open an issue
about: For reporting bugs or errors in the JavaScript libp2p implementation
title: ''
labels: need/triage
assignees: ''
---
<!--
Thank you for reporting an issue.
This issue tracker is for bugs found within the JavaScript implementation of libp2p.
If you are asking a question about how to use libp2p, please ask on https://discuss.libp2p.io
Otherwise please fill in as much of the template below as possible.
-->
- **Version**:
<!--
Check package.json version
-->
- **Platform**:
<!--
Output of `uname -a` (UNIX), or version and 32 or 64-bit (Windows). If using in a Browser, please share the browser version as well
-->
- **Subsystem**:
<!--
If known, please specify affected core module name (e.g Dialer, Pubsub, Relay etc)
-->
#### Severity:
<!--
One of following:
Critical - System crash, application panic.
High - The main functionality of the application does not work, API breakage, repo format breakage, etc.
Medium - A non-essential functionality does not work, performance issues, etc.
Low - An optional functionality does not work.
Very Low - Translation or documentation mistake. Something that won't give anyone a bad day.
-->
#### Description:
<!--
- What you did
- What happened
- What you expected to happen
-->
#### Steps to reproduce the error:
<!--
If possible, please provide code that demonstrates the problem, keeping it as simple and free of external dependencies as you are able
-->

View File

@@ -25,7 +25,6 @@
- [ ] [js-ipfs](https://github.com/ipfs/js-ipfs)
- Documentation
- [ ] Ensure that README.md is up to date
- [ ] 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
- [ ] Create the release issue

View File

@@ -1,3 +1,56 @@
## [0.31.4](https://github.com/libp2p/js-libp2p/compare/v0.31.3...v0.31.4) (2021-05-12)
### Bug Fixes
* peerRouting.findPeer() trying to find self ([#941](https://github.com/libp2p/js-libp2p/issues/941)) ([a79c6b5](https://github.com/libp2p/js-libp2p/commit/a79c6b50d7fddbcdb1af53efae922cecad4c9a83))
## [0.31.3](https://github.com/libp2p/js-libp2p/compare/v0.31.2...v0.31.3) (2021-05-04)
## [0.31.2](https://github.com/libp2p/js-libp2p/compare/v0.31.1...v0.31.2) (2021-04-30)
### Bug Fixes
* moving averages record types ([#935](https://github.com/libp2p/js-libp2p/issues/935)) ([b5a9eb2](https://github.com/libp2p/js-libp2p/commit/b5a9eb208763efa027d0b4caae87c515b6f5869b))
## [0.31.1](https://github.com/libp2p/js-libp2p/compare/v0.31.0...v0.31.1) (2021-04-30)
### Bug Fixes
* event emitter and interfaces types for discovery and routing ([#934](https://github.com/libp2p/js-libp2p/issues/934)) ([302bb90](https://github.com/libp2p/js-libp2p/commit/302bb9005891aa06b70a5f354bfac6b2d5a3c3b8))
# [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)

View File

@@ -515,7 +515,7 @@ const node = await Libp2p.create({
}
})
await libp2p.loadKeychain()
await node.loadKeychain()
```
#### Configuring Dialing

View File

@@ -0,0 +1,123 @@
<!--Specify versions for migration below-->
# Migrating to libp2p@31
A migration guide for refactoring your application code from libp2p v0.30.x to v0.31.0.
## Table of Contents
- [Types](#types)
- [API](#api)
- [Module Updates](#module-updates)
## Types
Most of the type definitions in the libp2p configuration were `any` or were not included before this release. This might cause breaking changes on upstream projects relying on the previous provided types, as well as to libp2p modules implemented by the libp2p community.
## API
### Core API
`libp2p.dialProtocol` does not accept empty or null protocols returning a connection anymore and `dial` must be used instead.
```js
const connection = await libp2p.dialProtocol(peerId)
```
**After**
```js
const connection = await libp2p.dial(peerId)
```
### Connection Manager Options
We updated the connection manager options naming in `libp2p@0.29` but kept it backward compatible until now.
**Before**
```js
const node = await Libp2p.create({
connectionManager: {
minPeers: 0
}
})
```
**After**
```js
const node = await Libp2p.create({
connectionManager: {
minConnections: 0
}
})
```
You can see full details on how to configure the connection manager [here](https://github.com/libp2p/js-libp2p/blob/master/doc/CONFIGURATION.md#configuring-connection-manager).
### Dialer and Keychain components
Internal property names to create a libp2p `Dialer` and `Keychain` were updated to reflect the properties naming in the libp2p configuration. These are internal modules of libp2p core and should not impact most of the users, but as it is possible to use them separately here follow the changes:
***Before**
```js
const dialer = new Dialer({
transportManager,
peerStore,
concurrency,
perPeerLimit,
timeout,
resolvers,
addressSorter
})
const keychain = new Keychain(datastore, {
passPhrase
})
```
**After**
```js
this.dialer = new Dialer({
transportManager,
peerStore,
maxParallelDials,
maxDialsPerPeer,
dialTimeout,
resolvers,
addressSorter
})
const keychain = new Keychain(datastore, {
pass
})
```
## Module Updates
With this release you should update the following libp2p modules if you are relying on them:
<!--Specify module versions in JSON for migration below.
It's recommended to check package.json changes for this:
`git diff <release> <prev> -- package.json`
-->
```json
"libp2p-bootstrap": "^0.12.3",
"libp2p-crypto": "^0.19.4",
"libp2p-interfaces": "^0.10.0",
"libp2p-delegated-content-routing": "^0.10.0",
"libp2p-delegated-peer-routing": "^0.9.0",
"libp2p-floodsub": "^0.25.1",
"libp2p-gossipsub": "^0.9.0",
"libp2p-kad-dht": "^0.22.0",
"libp2p-mdns": "^0.16.0",
"libp2p-noise": "^3.0.0",
"libp2p-tcp": "^0.15.4",
"libp2p-webrtc-star": "^0.22.2",
"libp2p-websockets": "^0.15.6"
```
One of the main changes in this new release is the update to `multiaddr@9.0.0`. This should also be updated in upstream projects to avoid several multiaddr versions in the bundle and to avoid potential problems when libp2p interacts with provided outdated multiaddr instances.

View File

@@ -1,6 +1,6 @@
{
"name": "libp2p",
"version": "0.31.0-rc.5",
"version": "0.31.4",
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
"main": "src/index.js",
@@ -91,7 +91,7 @@
"events": "^3.3.0",
"hashlru": "^2.3.0",
"interface-datastore": "^4.0.0",
"ipfs-utils": "^6.0.0",
"ipfs-utils": "^7.0.0",
"it-all": "^1.0.4",
"it-buffer": "^0.1.2",
"it-drain": "^1.0.3",
@@ -103,12 +103,12 @@
"it-merge": "1.0.0",
"it-pipe": "^1.1.0",
"it-take": "1.0.0",
"libp2p-crypto": "^0.19.0",
"libp2p-interfaces": "^0.10.1",
"libp2p-crypto": "^0.19.4",
"libp2p-interfaces": "^0.10.4",
"libp2p-utils": "^0.3.1",
"mafmt": "^9.0.0",
"merge-options": "^3.0.4",
"moving-average": "^1.0.0",
"@vascosantos/moving-average": "^1.1.0",
"multiaddr": "^9.0.1",
"multicodec": "^3.0.1",
"multihashing-async": "^2.1.2",
@@ -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",
@@ -152,14 +150,14 @@
"libp2p-delegated-content-routing": "^0.10.0",
"libp2p-delegated-peer-routing": "^0.9.0",
"libp2p-floodsub": "^0.25.0",
"libp2p-gossipsub": "^0.8.0",
"libp2p-kad-dht": "^0.21.0",
"libp2p-gossipsub": "^0.9.0",
"libp2p-kad-dht": "^0.22.0",
"libp2p-mdns": "^0.16.0",
"libp2p-mplex": "^0.10.1",
"libp2p-noise": "^2.0.0",
"libp2p-tcp": "^0.15.1",
"libp2p-webrtc-star": "^0.22.0",
"libp2p-websockets": "^0.15.0",
"libp2p-noise": "^3.0.0",
"libp2p-tcp": "^0.15.4",
"libp2p-webrtc-star": "^0.22.2",
"libp2p-websockets": "^0.15.6",
"multihashes": "^4.0.2",
"nock": "^13.0.3",
"p-defer": "^3.0.0",
@@ -185,46 +183,46 @@
"Volker Mische <volker.mische@gmail.com>",
"Richard Littauer <richard.littauer@gmail.com>",
"a1300 <matthias-knopp@gmx.net>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
"Andrew Nesbitt <andrewnez@gmail.com>",
"Elven <mon.samuel@qq.com>",
"Giovanni T. Parra <fiatjaf@gmail.com>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
"Thomas Eizinger <thomas@eizinger.io>",
"Samlior <samlior@foxmail.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>",
"Smite Chow <xiaopengyou@live.com>",
"Soeren <nikorpoulsen@gmail.com>",
"Sönke Hahn <soenkehahn@gmail.com>",
"TJKoury <TJKoury@gmail.com>",
"Tiago Alves <alvesjtiago@gmail.com>",
"Yusef Napora <yusef@napora.org>",
"Zane Starr <zcstarr@gmail.com>",
"ebinks <elizabethjbinks@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>",
"Samlior <samlior@foxmail.com>",
"Thomas Eizinger <thomas@eizinger.io>",
"Didrik Nordström <didrik@betamos.se>",
"Fei Liu <liu.feiwood@gmail.com>",
"Felipe Martins <felipebrasil93@gmail.com>",
"Florian-Merle <florian.david.merle@gmail.com>",
"Francis Gulotta <wizard@roborooter.com>",
"Franck Royer <franck@royer.one>",
"Henrique Dias <hacdias@gmail.com>",
"Irakli Gozalishvili <rfobic@gmail.com>",
"Ethan Lam <elmemphis2000@gmail.com>",
"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>"
"Dmitriy Ryajov <dryajov@gmail.com>",
"Miguel Mota <miguelmota2@gmail.com>",
"Nuno Nogueira <nunofmn@gmail.com>",
"Diogo Silva <fsdiogo@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>",
"robertkiel <robert.kiel@validitylabs.org>",
"Tiago Alves <alvesjtiago@gmail.com>",
"Daijiro Wachi <daijiro.wachi@gmail.com>",
"Cindy Wu <ciindy.wu@gmail.com>",
"Yusef Napora <yusef@napora.org>",
"Zane Starr <zcstarr@gmail.com>",
"Chris Bratlien <chrisbratlien@gmail.com>",
"Bernd Strehl <bernd.strehl@gmail.com>",
"ebinks <elizabethjbinks@gmail.com>",
"Florian-Merle <florian.david.merle@gmail.com>",
"Francis Gulotta <wizard@roborooter.com>",
"Franck Royer <franck@royer.one>",
"Felipe Martins <felipebrasil93@gmail.com>",
"Aleksei <vozhdb@gmail.com>",
"Henrique Dias <hacdias@gmail.com>",
"isan_rivkin <isanrivkin@gmail.com>",
"Irakli Gozalishvili <rfobic@gmail.com>"
]
}

View File

@@ -1,6 +1,6 @@
'use strict'
const EventEmitter = require('events')
const { EventEmitter } = require('events')
const { Multiaddr } = require('multiaddr')
const PeerId = require('peer-id')

View File

@@ -11,7 +11,7 @@ const LatencyMonitor = require('./latency-monitor')
// @ts-ignore retimer does not have types
const retimer = require('retimer')
const EventEmitter = require('events')
const { EventEmitter } = require('events')
const PeerId = require('peer-id')

View File

@@ -5,7 +5,7 @@
* This code is based on `latency-monitor` (https://github.com/mlucool/latency-monitor) by `mlucool` (https://github.com/mlucool), available under Apache License 2.0 (https://github.com/mlucool/latency-monitor/blob/master/LICENSE)
*/
const EventEmitter = require('events')
const { EventEmitter } = require('events')
const VisibilityChangeEmitter = require('./visibility-change-emitter')
const debug = require('debug')('latency-monitor:LatencyMonitor')

View File

@@ -6,7 +6,7 @@
*/
'use strict'
const EventEmitter = require('events')
const { EventEmitter } = require('events')
const debug = require('debug')('latency-monitor:VisibilityChangeEmitter')

View File

@@ -16,7 +16,7 @@ const { pipe } = require('it-pipe')
* @typedef {import('peer-id')} PeerId
* @typedef {import('multiaddr').Multiaddr} Multiaddr
* @typedef {import('cids')} CID
* @typedef {import('libp2p-interfaces/src/content-routing/types')} ContentRoutingModule
* @typedef {import('libp2p-interfaces/src/content-routing/types').ContentRouting} ContentRoutingModule
*/
/**

View File

@@ -4,7 +4,7 @@ const debug = require('debug')
const log = Object.assign(debug('libp2p'), {
error: debug('libp2p:err')
})
const EventEmitter = require('events')
const { EventEmitter } = require('events')
const errCode = require('err-code')
const PeerId = require('peer-id')
@@ -40,9 +40,9 @@ const { updateSelfPeerRecord } = require('./record/utils')
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
* @typedef {import('libp2p-interfaces/src/transport/types').TransportFactory<any, any>} TransportFactory
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxerFactory} MuxerFactory
* @typedef {import('libp2p-interfaces/src/content-routing/types')} ContentRoutingModule
* @typedef {import('libp2p-interfaces/src/peer-discovery/types')} PeerDiscoveryModule
* @typedef {import('libp2p-interfaces/src/peer-routing/types')} PeerRoutingModule
* @typedef {import('libp2p-interfaces/src/content-routing/types').ContentRouting} ContentRoutingModule
* @typedef {import('libp2p-interfaces/src/peer-discovery/types').PeerDiscoveryFactory} PeerDiscoveryFactory
* @typedef {import('libp2p-interfaces/src/peer-routing/types').PeerRouting} PeerRoutingModule
* @typedef {import('libp2p-interfaces/src/crypto/types').Crypto} Crypto
* @typedef {import('libp2p-interfaces/src/pubsub')} Pubsub
* @typedef {import('libp2p-interfaces/src/pubsub').PubsubOptions} PubsubOptions
@@ -56,9 +56,6 @@ const { updateSelfPeerRecord } = require('./record/utils')
* @property {MuxedStream} stream
* @property {string} protocol
*
* @typedef {{ [key: string]: function (Uint8Array, Uint8Array[]): number }} DhtSelectors
* @typedef {{ [key: string]: { func: (key: Uint8Array, value: Uint8Array) => Promise<void> }}} DhtValidators
*
* @typedef {Object} RandomWalkOptions
* @property {boolean} [enabled = false]
* @property {number} [queriesPerPeriod = 1]
@@ -70,8 +67,8 @@ const { updateSelfPeerRecord } = require('./record/utils')
* @property {number} [kBucketSize = 20]
* @property {RandomWalkOptions} [randomWalk]
* @property {boolean} [clientMode]
* @property {DhtSelectors} [selectors]
* @property {DhtValidators} [validators]
* @property {import('libp2p-interfaces/src/types').DhtSelectors} [selectors]
* @property {import('libp2p-interfaces/src/types').DhtValidators} [validators]
*
* @typedef {Object} KeychainOptions
* @property {Datastore} [datastore]
@@ -103,7 +100,7 @@ const { updateSelfPeerRecord } = require('./record/utils')
* @property {TransportFactory[]} transport
* @property {MuxerFactory[]} streamMuxer
* @property {Crypto[]} connEncryption
* @property {PeerDiscoveryModule[]} [peerDiscovery]
* @property {PeerDiscoveryFactory[]} [peerDiscovery]
* @property {PeerRoutingModule[]} [peerRouting]
* @property {ContentRoutingModule[]} [contentRouting]
* @property {Object} [dht]
@@ -717,7 +714,7 @@ class Libp2p extends EventEmitter {
*/
async _setupPeerDiscovery () {
/**
* @param {PeerDiscoveryModule} DiscoveryService
* @param {PeerDiscoveryFactory} DiscoveryService
*/
const setupService = (DiscoveryService) => {
let config = {

View File

@@ -26,7 +26,7 @@ require('node-forge/lib/sha512')
* @property {number} keyLength
*
* @typedef {Object} KeychainOptions
* @property {string} pass
* @property {string} [pass]
* @property {DekOptions} [dek]
*/

View File

@@ -1,11 +1,15 @@
// @ts-nocheck
'use strict'
const EventEmitter = require('events')
const { EventEmitter } = require('events')
const { BigNumber: Big } = require('bignumber.js')
const MovingAverage = require('moving-average')
const MovingAverage = require('@vascosantos/moving-average')
const retimer = require('retimer')
/**
* @typedef {import('@vascosantos/moving-average').IMovingAverage} IMovingAverage
*/
class Stats extends EventEmitter {
/**
* A queue based manager for stat processing
@@ -29,7 +33,7 @@ class Stats extends EventEmitter {
this._frequencyLastTime = Date.now()
this._frequencyAccumulators = {}
/** @type {{ dataReceived: MovingAverage[], dataSent: MovingAverage[] }} */
/** @type {{ dataReceived: IMovingAverage[], dataSent: IMovingAverage[] }} */
this._movingAverages = {}
this._update = this._update.bind(this)

View File

@@ -25,7 +25,7 @@ const {
/**
* @typedef {import('peer-id')} PeerId
* @typedef {import('multiaddr').Multiaddr} Multiaddr
* @typedef {import('libp2p-interfaces/src/peer-routing/types')} PeerRoutingModule
* @typedef {import('libp2p-interfaces/src/peer-routing/types').PeerRouting} PeerRoutingModule
*/
/**
@@ -104,6 +104,10 @@ class PeerRouting {
throw errCode(new Error('No peer routers available'), 'NO_ROUTERS_AVAILABLE')
}
if (id.toB58String() === this._peerId.toB58String()) {
throw errCode(new Error('Should not try to find self'), 'ERR_FIND_SELF')
}
const output = await pipe(
merge(
...this._routers.map(router => [router.findPeer(id, options)])

View File

@@ -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

View File

@@ -2,7 +2,7 @@
const errcode = require('err-code')
const EventEmitter = require('events')
const { EventEmitter } = require('events')
const PeerId = require('peer-id')
const AddressBook = require('./address-book')

View File

@@ -137,7 +137,12 @@ class Upgrader {
* @returns {Promise<Connection>}
*/
async upgradeOutbound (maConn) {
const remotePeerId = PeerId.createFromB58String(maConn.remoteAddr.getPeerId())
const idStr = maConn.remoteAddr.getPeerId()
if (!idStr) {
throw errCode(new Error('outbound connection must have a peer id'), codes.ERR_INVALID_MULTIADDR)
}
const remotePeerId = PeerId.createFromB58String(idStr)
let encryptedConn
let remotePeer

View File

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

View File

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

View File

@@ -100,6 +100,12 @@ describe('peer-routing', () => {
return deferred.promise
})
it('should error when peer tries to find itself', async () => {
await expect(nodes[0].peerRouting.findPeer(nodes[0].peerId))
.to.eventually.be.rejected()
.and.to.have.property('code', 'ERR_FIND_SELF')
})
})
describe('via delegate router', () => {
@@ -187,6 +193,12 @@ describe('peer-routing', () => {
expect(mockApi.isDone()).to.equal(true)
})
it('should error when peer tries to find itself', async () => {
await expect(node.peerRouting.findPeer(node.peerId))
.to.eventually.be.rejected()
.and.to.have.property('code', 'ERR_FIND_SELF')
})
it('should error when a peer cannot be found', async () => {
const peerKey = 'key of a peer not on the network'
const mockApi = nock('http://0.0.0.0:60197')

View File

@@ -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', () => {

View File

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

View File

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

View File

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

View File

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