From 5414953010b18ce9b24b3c7bcf75501c8678a922 Mon Sep 17 00:00:00 2001 From: Chad Nehemiah Date: Tue, 17 Jan 2023 00:10:05 -0500 Subject: [PATCH 1/6] docs: update connection manager docs (#1555) --- doc/CONNECTION_MANAGER.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/CONNECTION_MANAGER.md b/doc/CONNECTION_MANAGER.md index 4b1af662e5..a22a14fcb1 100644 --- a/doc/CONNECTION_MANAGER.md +++ b/doc/CONNECTION_MANAGER.md @@ -1,3 +1,3 @@ # Connection Manager -The documentation here has moved to https://libp2p.github.io/js-libp2p/interfaces/index.ConnectionManagerConfig.html - please update your bookmarks! +The documentation here has moved to https://libp2p.github.io/js-libp2p-interfaces/modules/_libp2p_interface_connection_manager.html - please update your bookmarks! From 79005f31c020262e01e13bd2fa75782cf307b0c6 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Tue, 17 Jan 2023 10:10:25 +0000 Subject: [PATCH 2/6] chore: update dependanbot config (#1558) Update config so it works with our semantic release config --- .github/dependabot.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 290ad02837..0bc3b42de8 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,3 +6,6 @@ updates: interval: daily time: "10:00" open-pull-requests-limit: 10 + commit-message: + prefix: "deps" + prefix-development: "deps(dev)" From b6fde9358833b70021ecf62e8b929ec8dd338dc8 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Tue, 17 Jan 2023 10:10:36 +0000 Subject: [PATCH 3/6] chore: remove unused rimraf dep (#1559) This isn't used any more so remove it --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index e1bc116d88..75159c5676 100644 --- a/package.json +++ b/package.json @@ -200,7 +200,6 @@ "p-times": "^4.0.0", "p-wait-for": "^5.0.0", "protons": "^6.0.0", - "rimraf": "^3.0.2", "sinon": "^15.0.1", "sinon-ts": "^1.0.0" }, From 0831cd960d423545ee60b457d66a6a996888804b Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Tue, 17 Jan 2023 10:11:02 +0000 Subject: [PATCH 4/6] fix: allow reading PeerId from keychain (#1552) libp2p has a secure keychain where all items are stored in the datastore in an encrypted format, including the PeerId of the current node. If no PeerId is passed into the factory function, a new PeerId is created for the current node. Instead, if the factory function is passed a DataStore, it should try to read the PeerId from the DataStore and only create a new PeerId if reading the `self` key fails. --- src/libp2p.ts | 25 +++++++ test/core/peer-id.spec.ts | 145 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 test/core/peer-id.spec.ts diff --git a/src/libp2p.ts b/src/libp2p.ts index a35316a293..00cdb23647 100644 --- a/src/libp2p.ts +++ b/src/libp2p.ts @@ -49,6 +49,7 @@ import { DummyPubSub } from './pubsub/dummy-pubsub.js' import { PeerSet } from '@libp2p/peer-collections' import { DefaultDialer } from './connection-manager/dialer/index.js' import { peerIdFromString } from '@libp2p/peer-id' +import type { Datastore } from 'interface-datastore' const log = logger('libp2p') @@ -510,6 +511,30 @@ export class Libp2pNode extends EventEmitter implements Libp2p { */ export async function createLibp2pNode (options: Libp2pOptions): Promise { if (options.peerId == null) { + const datastore = options.datastore as Datastore | undefined + + if (datastore != null) { + try { + // try load the peer id from the keychain + // @ts-expect-error missing the peer id property + const keyChain = new KeyChain({ + datastore + }, { + ...KeyChain.generateOptions(), + ...(options.keychain ?? {}) + }) + + options.peerId = await keyChain.exportPeerId('self') + } catch (err: any) { + if (err.code !== 'ERR_NOT_FOUND') { + throw err + } + } + } + } + + if (options.peerId == null) { + // no peer id in the keychain, create a new peer id options.peerId = await createEd25519PeerId() } diff --git a/test/core/peer-id.spec.ts b/test/core/peer-id.spec.ts new file mode 100644 index 0000000000..0219d9ffc8 --- /dev/null +++ b/test/core/peer-id.spec.ts @@ -0,0 +1,145 @@ +/* eslint-env mocha */ + +import { expect } from 'aegir/chai' +import { webSockets } from '@libp2p/websockets' +import { plaintext } from '../../src/insecure/index.js' +import { createLibp2p, Libp2p } from '../../src/index.js' +import { MemoryDatastore } from 'datastore-core' + +describe('peer-id', () => { + let libp2p: Libp2p + + afterEach(async () => { + if (libp2p != null) { + await libp2p.stop() + } + }) + + it('should create a PeerId if none is passed', async () => { + libp2p = await createLibp2p({ + transports: [ + webSockets() + ], + connectionEncryption: [ + plaintext() + ] + }) + + expect(libp2p.peerId).to.be.ok() + }) + + it('should retrieve the PeerId from the datastore', async () => { + const datastore = new MemoryDatastore() + + libp2p = await createLibp2p({ + datastore, + transports: [ + webSockets() + ], + connectionEncryption: [ + plaintext() + ] + }) + + // this PeerId was created by default + const peerId = libp2p.peerId + + await libp2p.stop() + + // create a new node from the same datastore + libp2p = await createLibp2p({ + datastore, + transports: [ + webSockets() + ], + connectionEncryption: [ + plaintext() + ] + }) + + // the new node should have read the PeerId from the datastore + // instead of creating a new one + expect(libp2p.peerId.toString()).to.equal(peerId.toString()) + }) + + it('should retrieve the PeerId from the datastore with a keychain password', async () => { + const datastore = new MemoryDatastore() + const keychain = { + pass: 'very-long-password-must-be-over-twenty-characters-long', + dek: { + salt: 'CpjNIxMqAZ+aJg+ezLfuzG4a' + } + } + + libp2p = await createLibp2p({ + datastore, + keychain, + transports: [ + webSockets() + ], + connectionEncryption: [ + plaintext() + ] + }) + + // this PeerId was created by default + const peerId = libp2p.peerId + + await libp2p.stop() + + // create a new node from the same datastore + libp2p = await createLibp2p({ + datastore, + keychain, + transports: [ + webSockets() + ], + connectionEncryption: [ + plaintext() + ] + }) + + // the new node should have read the PeerId from the datastore + // instead of creating a new one + expect(libp2p.peerId.toString()).to.equal(peerId.toString()) + }) + + it('should fail to start if retrieving the PeerId from the datastore fails', async () => { + const datastore = new MemoryDatastore() + const keychain = { + pass: 'very-long-password-must-be-over-twenty-characters-long', + dek: { + salt: 'CpjNIxMqAZ+aJg+ezLfuzG4a' + } + } + + libp2p = await createLibp2p({ + datastore, + keychain, + transports: [ + webSockets() + ], + connectionEncryption: [ + plaintext() + ] + }) + await libp2p.stop() + + // creating a new node from the same datastore but with the wrong keychain config should fail + await expect(createLibp2p({ + datastore, + keychain: { + pass: 'different-very-long-password-must-be-over-twenty-characters-long', + dek: { + salt: 'different-CpjNIxMqAZ+aJg+ezLfuzG4a' + } + }, + transports: [ + webSockets() + ], + connectionEncryption: [ + plaintext() + ] + })).to.eventually.rejectedWith('Invalid PEM formatted message') + }) +}) From f82e6b86e375b86e71cd339660a348ecba4bf68d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Petruni=C4=87?= Date: Tue, 17 Jan 2023 11:13:55 +0100 Subject: [PATCH 5/6] fix: allow configuring circuit stream limits (#1542) Co-authored-by: Alex Potsides --- src/circuit/index.ts | 3 ++- src/circuit/transport.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/circuit/index.ts b/src/circuit/index.ts index 387dc02a7e..a5870fbc71 100644 --- a/src/circuit/index.ts +++ b/src/circuit/index.ts @@ -16,8 +16,9 @@ import type { ContentRouting } from '@libp2p/interface-content-routing' import type { ConnectionManager } from '@libp2p/interface-connection-manager' import type { TransportManager } from '@libp2p/interface-transport' import type { PeerId } from '@libp2p/interface-peer-id' +import type { StreamHandlerOptions } from '@libp2p/interface-registrar' -export interface RelayConfig { +export interface RelayConfig extends StreamHandlerOptions { enabled: boolean advertise: RelayAdvertiseConfig hop: HopConfig diff --git a/src/circuit/transport.ts b/src/circuit/transport.ts index 95b56ddc99..ebb793ca18 100644 --- a/src/circuit/transport.ts +++ b/src/circuit/transport.ts @@ -67,7 +67,7 @@ export class Circuit implements Transport, Startable { void this._onProtocol(data).catch(err => { log.error(err) }) - }) + }, { ...this._init }) .catch(err => { log.error(err) }) From 40841637ab36c3163e36afce4050a07ea2f614af Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 18 Jan 2023 09:52:26 +0000 Subject: [PATCH 6/6] chore: release 0.42.2 (#1551) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 12 ++++++++++++ package.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1baf146e1f..833a952ac9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,18 @@ +### [0.42.2](https://www.github.com/libp2p/js-libp2p/compare/v0.42.1...v0.42.2) (2023-01-17) + + +### Bug Fixes + +* allow configuring circuit stream limits ([#1542](https://www.github.com/libp2p/js-libp2p/issues/1542)) ([f82e6b8](https://www.github.com/libp2p/js-libp2p/commit/f82e6b86e375b86e71cd339660a348ecba4bf68d)) +* allow dialing multiaddrs without peer ids ([#1548](https://www.github.com/libp2p/js-libp2p/issues/1548)) ([398e231](https://www.github.com/libp2p/js-libp2p/commit/398e231337c3db1ccd5b4254fb18ab1903aa68b2)) +* allow exporting PeerIds from the keychain ([#1546](https://www.github.com/libp2p/js-libp2p/issues/1546)) ([141e072](https://www.github.com/libp2p/js-libp2p/commit/141e0722ee2cd92b2b928767710de7443b5a4c56)) +* allow reading PeerId from keychain ([#1552](https://www.github.com/libp2p/js-libp2p/issues/1552)) ([0831cd9](https://www.github.com/libp2p/js-libp2p/commit/0831cd960d423545ee60b457d66a6a996888804b)) +* do not append peer id to path addresses ([#1547](https://www.github.com/libp2p/js-libp2p/issues/1547)) ([bd2bdf7](https://www.github.com/libp2p/js-libp2p/commit/bd2bdf7ca0d87ab63b2e9acf7edf7a5752e0559c)) +* improve pubsub example ([#1549](https://www.github.com/libp2p/js-libp2p/issues/1549)) ([ba8527c](https://www.github.com/libp2p/js-libp2p/commit/ba8527c317b9f1f31f5066b6204fda35d393058f)) + ### [0.42.1](https://www.github.com/libp2p/js-libp2p/compare/v0.42.0...v0.42.1) (2023-01-11) diff --git a/package.json b/package.json index 75159c5676..8f340b2262 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libp2p", - "version": "0.42.1", + "version": "0.42.2", "description": "JavaScript implementation of libp2p, a modular peer to peer network stack", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/js-libp2p#readme",