Compare commits

...

25 Commits

Author SHA1 Message Date
Vasco Santos
869d35d852 chore: release version v0.31.6 2021-05-27 10:48:26 +02:00
Vasco Santos
d6540bf01d chore: update contributors 2021-05-27 10:48:26 +02:00
zeim839
478963ad2d feat: keychain rotate passphrase (#944)
Co-authored-by: Vasco Santos <vasco.santos@ua.pt>
2021-05-27 10:30:19 +02:00
Vasco Santos
d22ad83890 chore: update libp2p interop (#940) 2021-05-21 10:22:11 +02:00
Vasco Santos
538f296b0a chore: release version v0.31.5 2021-05-12 19:17:23 +02:00
Vasco Santos
7bac2045cc chore: update contributors 2021-05-12 19:17:22 +02:00
Alex Potsides
818d2b2a98 fix: store remote agent and protocol version during identify (#943) 2021-05-12 19:11:17 +02:00
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
22 changed files with 488 additions and 57 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.6](https://github.com/libp2p/js-libp2p/compare/v0.31.5...v0.31.6) (2021-05-27)
### Features
* keychain rotate passphrase ([#944](https://github.com/libp2p/js-libp2p/issues/944)) ([478963a](https://github.com/libp2p/js-libp2p/commit/478963ad2d195444494c0acc54cb3847a29e117c))
## [0.31.5](https://github.com/libp2p/js-libp2p/compare/v0.31.4...v0.31.5) (2021-05-12)
### Bug Fixes
* store remote agent and protocol version during identify ([#943](https://github.com/libp2p/js-libp2p/issues/943)) ([818d2b2](https://github.com/libp2p/js-libp2p/commit/818d2b2a98736f4242694479089396f6070cdad5))
## [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)

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.7",
"version": "0.31.6",
"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.3",
"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",
@@ -139,7 +139,7 @@
"aegir": "^33.1.1",
"buffer": "^6.0.3",
"delay": "^5.0.0",
"interop-libp2p": "^0.3.0",
"interop-libp2p": "^0.4.0",
"into-stream": "^6.0.0",
"ipfs-http-client": "^49.0.4",
"it-concat": "^1.0.0",
@@ -150,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": "^3.0.0",
"libp2p-tcp": "^0.15.1",
"libp2p-webrtc-star": "^0.22.0",
"libp2p-websockets": "^0.15.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",
@@ -179,50 +179,50 @@
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Maciej Krüger <mkg20001@gmail.com>",
"Hugo Dias <mail@hugodias.me>",
"dirkmc <dirkmdev@gmail.com>",
"Volker Mische <volker.mische@gmail.com>",
"dirkmc <dirkmdev@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>",
"Samlior <samlior@foxmail.com>",
"Thomas Eizinger <thomas@eizinger.io>",
"Didrik Nordström <didrik@betamos.se>",
"Felipe Martins <felipebrasil93@gmail.com>",
"Fei Liu <liu.feiwood@gmail.com>",
"Joel Gustafson <joelg@mit.edu>",
"Julien Bouquillon <contact@revolunet.com>",
"Kevin Kwok <antimatter15@gmail.com>",
"Kevin Lacker <lacker@gmail.com>",
"Ethan Lam <elmemphis2000@gmail.com>",
"Miguel Mota <miguelmota2@gmail.com>",
"Nuno Nogueira <nunofmn@gmail.com>",
"Dmitriy Ryajov <dryajov@gmail.com>",
"Philipp Muens <raute1337@gmx.de>",
"RasmusErik Voel Jensen <github@solsort.com>",
"Diogo Silva <fsdiogo@gmail.com>",
"robertkiel <robert.kiel@validitylabs.org>",
"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>",
"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>",
"Fei Liu <liu.feiwood@gmail.com>",
"Felipe Martins <felipebrasil93@gmail.com>",
"Florian-Merle <florian.david.merle@gmail.com>",
"Chris Bratlien <chrisbratlien@gmail.com>",
"ebinks <elizabethjbinks@gmail.com>",
"Bernd Strehl <bernd.strehl@gmail.com>",
"Francis Gulotta <wizard@roborooter.com>",
"Franck Royer <franck@royer.one>",
"Florian-Merle <florian.david.merle@gmail.com>",
"isan_rivkin <isanrivkin@gmail.com>",
"Henrique Dias <hacdias@gmail.com>",
"Irakli Gozalishvili <rfobic@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>"
"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

@@ -189,6 +189,8 @@ class IdentifyService {
const envelope = await Envelope.openAndCertify(signedPeerRecord, PeerRecord.DOMAIN)
if (this.peerStore.addressBook.consumePeerRecord(envelope)) {
this.peerStore.protoBook.set(id, protocols)
this.peerStore.metadataBook.set(id, 'AgentVersion', uint8ArrayFromString(message.agentVersion))
this.peerStore.metadataBook.set(id, 'ProtocolVersion', uint8ArrayFromString(message.protocolVersion))
return
}
} catch (err) {
@@ -204,6 +206,7 @@ class IdentifyService {
this.peerStore.protoBook.set(id, protocols)
this.peerStore.metadataBook.set(id, 'AgentVersion', uint8ArrayFromString(message.agentVersion))
this.peerStore.metadataBook.set(id, 'ProtocolVersion', uint8ArrayFromString(message.protocolVersion))
// TODO: Add and score our observed addr
log('received observed address of %s', cleanObservedAddr)

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
@@ -100,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]
@@ -714,7 +714,7 @@ class Libp2p extends EventEmitter {
*/
async _setupPeerDiscovery () {
/**
* @param {PeerDiscoveryModule} DiscoveryService
* @param {PeerDiscoveryFactory} DiscoveryService
*/
const setupService = (DiscoveryService) => {
let config = {

View File

@@ -1,6 +1,9 @@
/* eslint max-nested-callbacks: ["error", 5] */
'use strict'
const debug = require('debug')
const log = Object.assign(debug('libp2p:keychain'), {
error: debug('libp2p:keychain:err')
})
const sanitize = require('sanitize-filename')
const mergeOptions = require('merge-options')
const crypto = require('libp2p-crypto')
@@ -503,6 +506,55 @@ class Keychain {
return throwDelayed(errcode(new Error(`Key '${name}' does not exist. ${err.message}`), 'ERR_KEY_NOT_FOUND'))
}
}
/**
* Rotate keychain password and re-encrypt all assosciated keys
*
* @param {string} oldPass - The old local keychain password
* @param {string} newPass - The new local keychain password
*/
async rotateKeychainPass (oldPass, newPass) {
if (typeof oldPass !== 'string') {
return throwDelayed(errcode(new Error(`Invalid old pass type '${typeof oldPass}'`), 'ERR_INVALID_OLD_PASS_TYPE'))
}
if (typeof newPass !== 'string') {
return throwDelayed(errcode(new Error(`Invalid new pass type '${typeof newPass}'`), 'ERR_INVALID_NEW_PASS_TYPE'))
}
if (newPass.length < 20) {
return throwDelayed(errcode(new Error(`Invalid pass length ${newPass.length}`), 'ERR_INVALID_PASS_LENGTH'))
}
log('recreating keychain')
const oldDek = privates.get(this).dek
this.opts.pass = newPass
const newDek = newPass
? crypto.pbkdf2(
newPass,
this.opts.dek.salt,
this.opts.dek.iterationCount,
this.opts.dek.keyLength,
this.opts.dek.hash)
: ''
privates.set(this, { dek: newDek })
const keys = await this.listKeys()
for (const key of keys) {
const res = await this.store.get(DsName(key.name))
const pem = uint8ArrayToString(res)
const privateKey = await crypto.keys.import(pem, oldDek)
const password = newDek.toString()
const keyAsPEM = await privateKey.export(password)
// Update stored key
const batch = this.store.batch()
const keyInfo = {
name: key.name,
id: key.id
}
batch.put(DsName(key.name), uint8ArrayFromString(keyAsPEM))
batch.put(DsInfoName(key.name), uint8ArrayFromString(JSON.stringify(keyInfo)))
await batch.commit()
}
log('keychain reconstructed')
}
}
module.exports = Keychain

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

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

@@ -430,6 +430,39 @@ describe('Identify', () => {
await connection.close()
})
it('should store remote agent and protocol versions in metadataBook after connecting', async () => {
libp2p = new Libp2p({
...baseOptions,
peerId
})
await libp2p.start()
sinon.spy(libp2p.identifyService, 'identify')
const peerStoreSpyConsumeRecord = sinon.spy(libp2p.peerStore.addressBook, 'consumePeerRecord')
const peerStoreSpyAdd = sinon.spy(libp2p.peerStore.addressBook, 'add')
const connection = await libp2p.dialer.connectToPeer(remoteAddr)
expect(connection).to.exist()
// Wait for peer store to be updated
// Dialer._createDialTarget (add), Identify (consume)
await pWaitFor(() => peerStoreSpyConsumeRecord.callCount === 1 && peerStoreSpyAdd.callCount === 1)
expect(libp2p.identifyService.identify.callCount).to.equal(1)
// The connection should have no open streams
await pWaitFor(() => connection.streams.length === 0)
await connection.close()
const remotePeer = PeerId.createFromB58String(remoteAddr.getPeerId())
const storedAgentVersion = libp2p.peerStore.metadataBook.getValue(remotePeer, 'AgentVersion')
const storedProtocolVersion = libp2p.peerStore.metadataBook.getValue(remotePeer, 'ProtocolVersion')
expect(storedAgentVersion).to.exist()
expect(storedProtocolVersion).to.exist()
})
it('should push protocol updates to an already connected peer', async () => {
libp2p = new Libp2p({
...baseOptions,

View File

@@ -9,9 +9,10 @@ const uint8ArrayToString = require('uint8arrays/to-string')
const peerUtils = require('../utils/creators/peer')
const { MemoryDatastore } = require('interface-datastore')
const { MemoryDatastore, Key } = require('interface-datastore')
const Keychain = require('../../src/keychain')
const PeerId = require('peer-id')
const crypto = require('libp2p-crypto')
describe('keychain', () => {
const passPhrase = 'this is not a secure phrase'
@@ -492,6 +493,88 @@ describe('keychain', () => {
expect(key).to.have.property('id', rsaKeyInfo.id)
})
})
describe('rotate keychain passphrase', () => {
let oldPass
let kc
let options
let ds
before(async () => {
ds = new MemoryDatastore()
oldPass = `hello-${Date.now()}-${Date.now()}`
options = {
pass: oldPass,
dek: {
salt: '3Nd/Ya4ENB3bcByNKptb4IR',
iterationCount: 10000,
keyLength: 64,
hash: 'sha2-512'
}
}
kc = new Keychain(ds, options)
await ds.open()
})
it('should validate newPass is a string', async () => {
try {
await kc.rotateKeychainPass(oldPass, 1234567890)
} catch (err) {
expect(err).to.exist()
}
})
it('should validate oldPass is a string', async () => {
try {
await kc.rotateKeychainPass(1234, 'newInsecurePassword1')
} catch (err) {
expect(err).to.exist()
}
})
it('should validate newPass is at least 20 characters', async () => {
try {
await kc.rotateKeychainPass(oldPass, 'not20Chars')
} catch (err) {
expect(err).to.exist()
}
})
it('can rotate keychain passphrase', async () => {
await kc.createKey('keyCreatedWithOldPassword', 'rsa', 2048)
await kc.rotateKeychainPass(oldPass, 'newInsecurePassphrase')
// Get Key PEM from datastore
const dsname = new Key('/pkcs8/' + 'keyCreatedWithOldPassword')
const res = await ds.get(dsname)
const pem = uint8ArrayToString(res)
const oldDek = options.pass
? crypto.pbkdf2(
options.pass,
options.dek.salt,
options.dek.iterationCount,
options.dek.keyLength,
options.dek.hash)
: ''
// eslint-disable-next-line no-constant-condition
const newDek = 'newInsecurePassphrase'
? crypto.pbkdf2(
'newInsecurePassphrase',
options.dek.salt,
options.dek.iterationCount,
options.dek.keyLength,
options.dek.hash)
: ''
// Dek with old password should not work:
await expect(kc.importKey('keyWhosePassChanged', pem, oldDek))
.to.eventually.be.rejected()
// Dek with new password should work:
await expect(kc.importKey('keyWhosePasswordChanged', pem, newDek))
.to.eventually.have.property('name', 'keyWhosePasswordChanged')
}).timeout(10000)
})
})
describe('libp2p.keychain', () => {

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