Skip to content

Commit b0aa059

Browse files
authored
Merge branch 'main' into release-v2.0
2 parents 86a62f5 + 1675ade commit b0aa059

File tree

19 files changed

+227
-54
lines changed

19 files changed

+227
-54
lines changed

.release-please-manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"packages/connection-encrypter-plaintext":"1.1.5","packages/connection-encrypter-tls":"1.1.5","packages/crypto":"4.1.9","packages/interface":"1.7.0","packages/interface-compliance-tests":"5.4.12","packages/interface-internal":"1.3.4","packages/kad-dht":"12.1.5","packages/keychain":"4.1.5","packages/libp2p":"1.9.0","packages/logger":"4.0.20","packages/metrics-devtools":"0.2.5","packages/metrics-prometheus":"3.1.5","packages/metrics-simple":"1.1.5","packages/multistream-select":"5.1.17","packages/peer-collections":"5.2.9","packages/peer-discovery-bootstrap":"10.1.5","packages/peer-discovery-mdns":"10.1.5","packages/peer-id":"4.2.4","packages/peer-id-factory":"4.2.4","packages/peer-record":"7.0.25","packages/peer-store":"10.1.5","packages/protocol-autonat":"1.1.5","packages/protocol-dcutr":"1.1.5","packages/protocol-echo":"1.1.5","packages/protocol-fetch":"1.1.5","packages/protocol-identify":"2.1.5","packages/protocol-perf":"3.1.5","packages/protocol-ping":"1.1.5","packages/pubsub":"9.0.26","packages/pubsub-floodsub":"9.1.5","packages/record":"4.0.4","packages/stream-multiplexer-mplex":"10.1.5","packages/transport-circuit-relay-v2":"1.1.5","packages/transport-tcp":"9.1.5","packages/transport-webrtc":"4.1.5","packages/transport-websockets":"8.2.0","packages/transport-webtransport":"4.1.5","packages/upnp-nat":"1.2.5","packages/utils":"5.4.9"}
1+
{"packages/connection-encrypter-plaintext":"1.1.6","packages/connection-encrypter-tls":"1.1.5","packages/crypto":"4.1.9","packages/interface":"1.7.0","packages/interface-compliance-tests":"5.4.12","packages/interface-internal":"1.3.4","packages/kad-dht":"12.1.5","packages/keychain":"4.1.6","packages/libp2p":"1.9.3","packages/logger":"4.0.20","packages/metrics-devtools":"0.2.5","packages/metrics-prometheus":"3.1.5","packages/metrics-simple":"1.1.5","packages/multistream-select":"5.1.17","packages/peer-collections":"5.2.9","packages/peer-discovery-bootstrap":"10.1.5","packages/peer-discovery-mdns":"10.1.5","packages/peer-id":"4.2.4","packages/peer-id-factory":"4.2.4","packages/peer-record":"7.0.25","packages/peer-store":"10.1.5","packages/protocol-autonat":"1.1.5","packages/protocol-dcutr":"1.1.5","packages/protocol-echo":"1.1.5","packages/protocol-fetch":"1.1.5","packages/protocol-identify":"2.1.5","packages/protocol-perf":"3.1.5","packages/protocol-ping":"1.1.6","packages/pubsub":"9.0.26","packages/pubsub-floodsub":"9.1.5","packages/record":"4.0.4","packages/stream-multiplexer-mplex":"10.1.5","packages/transport-circuit-relay-v2":"1.1.5","packages/transport-tcp":"9.1.5","packages/transport-webrtc":"4.1.8","packages/transport-websockets":"8.2.0","packages/transport-webtransport":"4.1.8","packages/upnp-nat":"1.2.5","packages/utils":"5.4.9"}

funding.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"opRetro": {
3-
"projectId": "0x966804cb492e1a4bde5d781a676a44a23d69aa5dd2562fa7a4f95bb606021c8b"
3+
"projectId": "0x5a7e7c7acb21521e99021d746740b368801cbfe531301e50bdbaafdc24a0aac5"
44
}
55
}

packages/connection-encrypter-plaintext/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@
7272
* devDependencies
7373
* @libp2p/interface-compliance-tests bumped from ^5.3.0 to ^5.3.1
7474

75+
## [1.1.6](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.1.5...plaintext-v1.1.6) (2024-08-16)
76+
77+
78+
### Bug Fixes
79+
80+
* send raw plaintext public key during handshake ([#2599](https://github.com/libp2p/js-libp2p/issues/2599)) ([359265a](https://github.com/libp2p/js-libp2p/commit/359265a3a842698b5bdf93c6be64e3bcfee745bf))
81+
7582
## [1.1.5](https://github.com/libp2p/js-libp2p/compare/plaintext-v1.1.4...plaintext-v1.1.5) (2024-08-15)
7683

7784

packages/connection-encrypter-plaintext/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@libp2p/plaintext",
3-
"version": "1.1.5",
3+
"version": "1.1.6",
44
"description": "An insecure connection encrypter",
55
"license": "Apache-2.0 OR MIT",
66
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/connection-encrypter-plaintext#readme",

packages/keychain/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
* devDependencies
4848
* @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4
4949

50+
## [4.1.6](https://github.com/libp2p/js-libp2p/compare/keychain-v4.1.5...keychain-v4.1.6) (2024-08-29)
51+
52+
53+
### Documentation
54+
55+
* update keychain examples ([#2640](https://github.com/libp2p/js-libp2p/issues/2640)) ([e211b46](https://github.com/libp2p/js-libp2p/commit/e211b46cc9f3b83180f00c09d17fd32c7607d7d2))
56+
5057
## [4.1.5](https://github.com/libp2p/js-libp2p/compare/keychain-v4.1.4...keychain-v4.1.5) (2024-08-15)
5158

5259

packages/keychain/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@libp2p/keychain",
3-
"version": "4.1.5",
3+
"version": "4.1.6",
44
"description": "Key management and cryptographically protected messages",
55
"license": "Apache-2.0 OR MIT",
66
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/keychain#readme",

packages/keychain/src/index.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ export interface Keychain {
9292
* @example
9393
*
9494
* ```TypeScript
95-
* await libp2p.keychain.createKey('keyTest', 'RSA', 4096)
96-
* const pemKey = await libp2p.keychain.exportKey('keyTest', 'password123')
95+
* await libp2p.services.keychain.createKey('keyTest', 'RSA', 4096)
96+
* const pemKey = await libp2p.services.keychain.exportKey('keyTest', 'password123')
9797
* ```
9898
*/
9999
exportKey(name: string, password: string): Promise<Multibase<'m'>>
@@ -104,9 +104,9 @@ export interface Keychain {
104104
* @example
105105
*
106106
* ```TypeScript
107-
* await libp2p.keychain.createKey('keyTest', 'RSA', 4096)
108-
* const pemKey = await libp2p.keychain.exportKey('keyTest', 'password123')
109-
* const keyInfo = await libp2p.keychain.importKey('keyTestImport', pemKey, 'password123')
107+
* await libp2p.services.keychain.createKey('keyTest', 'RSA', 4096)
108+
* const pemKey = await libp2p.services.keychain.exportKey('keyTest', 'password123')
109+
* const keyInfo = await libp2p.services.keychain.importKey('keyTestImport', pemKey, 'password123')
110110
* ```
111111
*/
112112
importKey(name: string, pem: string, password: string): Promise<KeyInfo>
@@ -117,7 +117,7 @@ export interface Keychain {
117117
* @example
118118
*
119119
* ```TypeScript
120-
* const keyInfo = await libp2p.keychain.importPeer('keyTestImport', peerIdFromString('12D3Foo...'))
120+
* const keyInfo = await libp2p.services.keychain.importPeer('keyTestImport', peerIdFromString('12D3Foo...'))
121121
* ```
122122
*/
123123
importPeer(name: string, peerId: PeerId): Promise<KeyInfo>
@@ -128,7 +128,7 @@ export interface Keychain {
128128
* @example
129129
*
130130
* ```TypeScript
131-
* const peerId = await libp2p.keychain.exportPeerId('key-name')
131+
* const peerId = await libp2p.services.keychain.exportPeerId('key-name')
132132
* ```
133133
*/
134134
exportPeerId(name: string): Promise<PeerId>
@@ -139,7 +139,7 @@ export interface Keychain {
139139
* @example
140140
*
141141
* ```TypeScript
142-
* const keyInfo = await libp2p.keychain.createKey('keyTest', 'RSA', 4096)
142+
* const keyInfo = await libp2p.services.keychain.createKey('keyTest', 'RSA', 4096)
143143
* ```
144144
*/
145145
createKey(name: string, type: KeyType, size?: number): Promise<KeyInfo>
@@ -150,7 +150,7 @@ export interface Keychain {
150150
* @example
151151
*
152152
* ```TypeScript
153-
* const keyInfos = await libp2p.keychain.listKeys()
153+
* const keyInfos = await libp2p.services.keychain.listKeys()
154154
* ```
155155
*/
156156
listKeys(): Promise<KeyInfo[]>
@@ -161,8 +161,8 @@ export interface Keychain {
161161
* @example
162162
*
163163
* ```TypeScript
164-
* await libp2p.keychain.createKey('keyTest', 'RSA', 4096)
165-
* const keyInfo = await libp2p.keychain.removeKey('keyTest')
164+
* await libp2p.services.keychain.createKey('keyTest', 'RSA', 4096)
165+
* const keyInfo = await libp2p.services.keychain.removeKey('keyTest')
166166
* ```
167167
*/
168168
removeKey(name: string): Promise<KeyInfo>
@@ -173,8 +173,8 @@ export interface Keychain {
173173
* @example
174174
*
175175
* ```TypeScript
176-
* await libp2p.keychain.createKey('keyTest', 'RSA', 4096)
177-
* const keyInfo = await libp2p.keychain.renameKey('keyTest', 'keyNewNtest')
176+
* await libp2p.services.keychain.createKey('keyTest', 'RSA', 4096)
177+
* const keyInfo = await libp2p.services.keychain.renameKey('keyTest', 'keyNewNtest')
178178
* ```
179179
*/
180180
renameKey(oldName: string, newName: string): Promise<KeyInfo>
@@ -185,8 +185,8 @@ export interface Keychain {
185185
* @example
186186
*
187187
* ```TypeScript
188-
* const keyInfo = await libp2p.keychain.createKey('keyTest', 'RSA', 4096)
189-
* const keyInfo2 = await libp2p.keychain.findKeyById(keyInfo.id)
188+
* const keyInfo = await libp2p.services.keychain.createKey('keyTest', 'RSA', 4096)
189+
* const keyInfo2 = await libp2p.services.keychain.findKeyById(keyInfo.id)
190190
* ```
191191
*/
192192
findKeyById(id: string): Promise<KeyInfo>
@@ -197,8 +197,8 @@ export interface Keychain {
197197
* @example
198198
*
199199
* ```TypeScript
200-
* const keyInfo = await libp2p.keychain.createKey('keyTest', 'RSA', 4096)
201-
* const keyInfo2 = await libp2p.keychain.findKeyByName('keyTest')
200+
* const keyInfo = await libp2p.services.keychain.createKey('keyTest', 'RSA', 4096)
201+
* const keyInfo2 = await libp2p.services.keychain.findKeyByName('keyTest')
202202
* ```
203203
*/
204204
findKeyByName(name: string): Promise<KeyInfo>
@@ -209,7 +209,7 @@ export interface Keychain {
209209
* @example
210210
*
211211
* ```TypeScript
212-
* await libp2p.keychain.rotateKeychainPass('oldPassword', 'newPassword')
212+
* await libp2p.services.keychain.rotateKeychainPass('oldPassword', 'newPassword')
213213
* ```
214214
*/
215215
rotateKeychainPass(oldPass: string, newPass: string): Promise<void>

packages/libp2p/CHANGELOG.md

+23
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,29 @@
110110
* @libp2p/tcp bumped from ^9.0.14 to ^9.0.15
111111
* @libp2p/websockets bumped from ^8.0.14 to ^8.0.15
112112

113+
## [1.9.3](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.9.2...libp2p-v1.9.3) (2024-08-29)
114+
115+
116+
### Bug Fixes
117+
118+
* connection monitor compatible with other ping implementations ([#2671](https://github.com/libp2p/js-libp2p/issues/2671)) ([7655e52](https://github.com/libp2p/js-libp2p/commit/7655e5200d32e7fe59387cedacb0fe640e260f1e))
119+
120+
## [1.9.2](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.9.1...libp2p-v1.9.2) (2024-08-17)
121+
122+
123+
### Bug Fixes
124+
125+
* accept custom ping protocol prefix in connection monitor ([#2667](https://github.com/libp2p/js-libp2p/issues/2667)) ([3c8dd5b](https://github.com/libp2p/js-libp2p/commit/3c8dd5bbfc57489a0b10b555c81e773058a58156))
126+
127+
## [1.9.1](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.9.0...libp2p-v1.9.1) (2024-08-16)
128+
129+
130+
### Dependencies
131+
132+
* The following workspace dependencies were updated
133+
* devDependencies
134+
* @libp2p/plaintext bumped from ^1.1.5 to ^1.1.6
135+
113136
## [1.9.0](https://github.com/libp2p/js-libp2p/compare/libp2p-v1.8.3...libp2p-v1.9.0) (2024-08-15)
114137

115138

packages/libp2p/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "libp2p",
3-
"version": "1.9.0",
3+
"version": "1.9.3",
44
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
55
"license": "Apache-2.0 OR MIT",
66
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/libp2p#readme",
@@ -119,7 +119,7 @@
119119
"@libp2p/identify": "^2.1.5",
120120
"@libp2p/interface-compliance-tests": "^5.4.12",
121121
"@libp2p/mplex": "^10.1.5",
122-
"@libp2p/plaintext": "^1.1.5",
122+
"@libp2p/plaintext": "^1.1.6",
123123
"@libp2p/tcp": "^9.1.5",
124124
"@libp2p/websockets": "^8.2.0",
125125
"@multiformats/mafmt": "^12.1.6",

packages/libp2p/src/connection-monitor.ts

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { randomBytes } from '@libp2p/crypto'
12
import { serviceCapabilities } from '@libp2p/interface'
23
import { AdaptiveTimeout } from '@libp2p/utils/adaptive-timeout'
34
import { byteStream } from 'it-byte-stream'
@@ -6,6 +7,10 @@ import type { ConnectionManager } from '@libp2p/interface-internal'
67
import type { AdaptiveTimeoutInit } from '@libp2p/utils/adaptive-timeout'
78

89
const DEFAULT_PING_INTERVAL_MS = 10000
10+
const PROTOCOL_VERSION = '1.0.0'
11+
const PROTOCOL_NAME = 'ping'
12+
const PROTOCOL_PREFIX = 'ipfs'
13+
const PING_LENGTH = 32
914

1015
export interface ConnectionMonitorInit {
1116
/**
@@ -37,6 +42,13 @@ export interface ConnectionMonitorInit {
3742
* @default true
3843
*/
3944
abortConnectionOnPingFailure?: boolean
45+
46+
/**
47+
* Override the ping protocol prefix
48+
*
49+
* @default 'ipfs'
50+
*/
51+
protocolPrefix?: string
4052
}
4153

4254
export interface ConnectionMonitorComponents {
@@ -46,6 +58,7 @@ export interface ConnectionMonitorComponents {
4658
}
4759

4860
export class ConnectionMonitor implements Startable {
61+
private readonly protocol: string
4962
private readonly components: ConnectionMonitorComponents
5063
private readonly log: Logger
5164
private heartbeatInterval?: ReturnType<typeof setInterval>
@@ -55,6 +68,7 @@ export class ConnectionMonitor implements Startable {
5568

5669
constructor (components: ConnectionMonitorComponents, init: ConnectionMonitorInit = {}) {
5770
this.components = components
71+
this.protocol = `/${init.protocolPrefix ?? PROTOCOL_PREFIX}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`
5872

5973
this.log = components.logger.forComponent('libp2p:connection-monitor')
6074
this.pingIntervalMs = init.pingInterval ?? DEFAULT_PING_INTERVAL_MS
@@ -83,18 +97,18 @@ export class ConnectionMonitor implements Startable {
8397
const signal = this.timeout.getTimeoutSignal({
8498
signal: this.abortController?.signal
8599
})
86-
const stream = await conn.newStream('/ipfs/ping/1.0.0', {
100+
const stream = await conn.newStream(this.protocol, {
87101
signal,
88102
runOnLimitedConnection: true
89103
})
90104
const bs = byteStream(stream)
91105
start = Date.now()
92106

93107
await Promise.all([
94-
bs.write(new Uint8Array(1), {
108+
bs.write(randomBytes(PING_LENGTH), {
95109
signal
96110
}),
97-
bs.read(1, {
111+
bs.read(PING_LENGTH, {
98112
signal
99113
})
100114
])

packages/libp2p/test/connection-monitor/index.spec.ts

+21
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,27 @@ describe('connection monitor', () => {
5050
expect(connection.rtt).to.be.gte(0)
5151
})
5252

53+
it('should monitor the liveness of a connection with a custom ping protocol prefix', async () => {
54+
monitor = new ConnectionMonitor(components, {
55+
pingInterval: 10,
56+
protocolPrefix: 'foobar'
57+
})
58+
59+
await start(monitor)
60+
61+
const connection = stubInterface<Connection>()
62+
const stream = stubInterface<Stream>({
63+
...pair<any>()
64+
})
65+
connection.newStream.withArgs('/foobar/ping/1.0.0').resolves(stream)
66+
67+
components.connectionManager.getConnections.returns([connection])
68+
69+
await delay(100)
70+
71+
expect(connection.rtt).to.be.gte(0)
72+
})
73+
5374
it('should monitor the liveness of a connection that does not support ping', async () => {
5475
monitor = new ConnectionMonitor(components, {
5576
pingInterval: 10

packages/protocol-ping/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
* devDependencies
5151
* @libp2p/peer-id-factory bumped from ^4.0.3 to ^4.0.4
5252

53+
## [1.1.6](https://github.com/libp2p/js-libp2p/compare/ping-v1.1.5...ping-v1.1.6) (2024-08-29)
54+
55+
56+
### Bug Fixes
57+
58+
* limit incoming ping bytes to 32 ([#2673](https://github.com/libp2p/js-libp2p/issues/2673)) ([50b8971](https://github.com/libp2p/js-libp2p/commit/50b897139cbace820548194191b7481e1379b149))
59+
5360
## [1.1.5](https://github.com/libp2p/js-libp2p/compare/ping-v1.1.4...ping-v1.1.5) (2024-08-15)
5461

5562

packages/protocol-ping/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@libp2p/ping",
3-
"version": "1.1.5",
3+
"version": "1.1.6",
44
"description": "Implementation of Ping Protocol",
55
"license": "Apache-2.0 OR MIT",
66
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-ping#readme",

packages/protocol-ping/src/ping.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { randomBytes } from '@libp2p/crypto'
2-
import { AbortError, ProtocolError } from '@libp2p/interface'
2+
import { AbortError, ProtocolError, InvalidMessageError, TimeoutError } from '@libp2p/interface'
33
import first from 'it-first'
44
import { pipe } from 'it-pipe'
55
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
@@ -61,9 +61,32 @@ export class PingService implements Startable, PingServiceInterface {
6161
const { stream } = data
6262
const start = Date.now()
6363

64-
void pipe(stream, stream)
64+
const signal = AbortSignal.timeout(this.timeout)
65+
signal.addEventListener('abort', () => {
66+
stream?.abort(new TimeoutError('Ping timeout'))
67+
})
68+
69+
void pipe(
70+
stream,
71+
async function * (source) {
72+
let received = 0
73+
74+
for await (const buf of source) {
75+
received += buf.byteLength
76+
77+
if (received > PING_LENGTH) {
78+
stream?.abort(new InvalidMessageError('Too much data received'))
79+
return
80+
}
81+
82+
yield buf
83+
}
84+
},
85+
stream
86+
)
6587
.catch(err => {
6688
this.log.error('incoming ping from %p failed with error', data.connection.remotePeer, err)
89+
stream?.abort(err)
6790
})
6891
.finally(() => {
6992
const ms = Date.now() - start

0 commit comments

Comments
 (0)