Skip to content

Commit ec8bf66

Browse files
authored
fix!: update to libp2p@2.x.x (#630)
Updates all deps to the latest libp2p version. BREAKING CHANGE: helia now uses libp2p@2.x.x
1 parent 3bf5ab0 commit ec8bf66

File tree

81 files changed

+1848
-514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1848
-514
lines changed

benchmarks/add-dir/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
"execa": "^8.0.1",
2424
"helia": "^4.1.1",
2525
"ipfs-unixfs-importer": "^15.1.5",
26-
"ipfsd-ctl": "^14.0.0",
26+
"ipfsd-ctl": "^15.0.0",
2727
"it-all": "^3.0.4",
2828
"it-drain": "^3.0.5",
2929
"it-map": "^3.0.5",
3030
"kubo": "^0.28.0",
31-
"kubo-rpc-client": "^4.0.0",
31+
"kubo-rpc-client": "^5.0.0",
3232
"libp2p": "^1.1.0",
3333
"multiformats": "^13.1.0",
3434
"tinybench": "^2.4.0"

benchmarks/gc/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
"datastore-level": "^10.1.5",
1717
"execa": "^8.0.1",
1818
"helia": "^4.1.1",
19-
"ipfsd-ctl": "^14.0.0",
19+
"ipfsd-ctl": "^15.0.0",
2020
"it-all": "^3.0.4",
2121
"it-drain": "^3.0.5",
2222
"it-map": "^3.0.5",
2323
"kubo": "^0.28.0",
24-
"kubo-rpc-client": "^4.0.0",
24+
"kubo-rpc-client": "^5.0.0",
2525
"multiformats": "^13.0.0",
2626
"tinybench": "^2.5.1"
2727
},

benchmarks/transfer/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
"execa": "^8.0.1",
2424
"helia": "^4.1.0",
2525
"ipfs-unixfs-importer": "^15.1.1",
26-
"ipfsd-ctl": "^14.0.0",
26+
"ipfsd-ctl": "^15.0.0",
2727
"it-all": "^3.0.1",
2828
"it-buffer-stream": "^3.0.2",
2929
"it-drain": "^3.0.1",
3030
"it-map": "^3.0.2",
3131
"kubo": "^0.28.0",
32-
"kubo-rpc-client": "^4.0.0",
32+
"kubo-rpc-client": "^5.0.0",
3333
"libp2p": "^1.4.0",
3434
"multiformats": "^13.1.0",
3535
"tinybench": "^2.4.0"

benchmarks/transports/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"it-buffer-stream": "^3.0.2",
4343
"it-drain": "^3.0.7",
4444
"kubo": "^0.28.0",
45-
"kubo-rpc-client": "^4.1.1",
45+
"kubo-rpc-client": "^5.0.0",
4646
"libp2p": "^1.4.0",
4747
"multiformats": "^13.1.0",
4848
"playwright-test": "^14.1.1",

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@
3434
"npm:release": "aegir exec --bail false npm -- publish",
3535
"release:rc": "aegir release-rc",
3636
"docs": "aegir docs",
37-
"docs:no-publish": "aegir docs --publish false"
37+
"docs:no-publish": "aegir docs --publish false",
38+
"postinstall": "patch-package && rimraf node_modules/@helia/delegated-routing-v1-http-api-client/node_modules"
3839
},
3940
"devDependencies": {
4041
"aegir": "^44.0.1",
41-
"npm-run-all": "^4.1.5"
42+
"npm-run-all": "^4.1.5",
43+
"patch-package": "^8.0.0",
44+
"rimraf": "^6.0.1"
4245
},
4346
"type": "module",
4447
"workspaces": [

packages/bitswap/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@
150150
"dependencies": {
151151
"@helia/interface": "^4.3.1",
152152
"@helia/utils": "^0.3.3",
153-
"@libp2p/interface": "^1.1.4",
154-
"@libp2p/logger": "^4.0.5",
155-
"@libp2p/peer-collections": "^5.1.6",
156-
"@libp2p/utils": "^5.2.3",
153+
"@libp2p/interface": "^2.0.0",
154+
"@libp2p/logger": "^5.0.0",
155+
"@libp2p/peer-collections": "^6.0.0",
156+
"@libp2p/utils": "^6.0.0",
157157
"@multiformats/multiaddr": "^12.1.14",
158158
"any-signal": "^4.1.1",
159159
"interface-blockstore": "^5.2.9",
160-
"interface-store": "^5.1.7",
160+
"interface-store": "^6.0.0",
161161
"it-drain": "^3.0.5",
162162
"it-length-prefixed": "^9.0.0",
163163
"it-length-prefixed-stream": "^1.1.6",
@@ -174,12 +174,12 @@
174174
"uint8arrays": "^5.0.1"
175175
},
176176
"devDependencies": {
177-
"@libp2p/crypto": "^4.0.6",
178-
"@libp2p/interface-compliance-tests": "^5.1.3",
179-
"@libp2p/peer-id-factory": "^4.0.5",
177+
"@libp2p/crypto": "^5.0.0",
178+
"@libp2p/interface-compliance-tests": "^6.0.0",
179+
"@libp2p/peer-id": "^5.0.0",
180180
"@types/sinon": "^17.0.3",
181181
"aegir": "^44.0.1",
182-
"blockstore-core": "^4.3.10",
182+
"blockstore-core": "^5.0.0",
183183
"delay": "^6.0.0",
184184
"it-all": "^3.0.4",
185185
"it-pair": "^2.0.6",

packages/bitswap/src/errors.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export class BlockTooLargeError extends Error {
2+
static name = 'BlockTooLargeError'
3+
4+
constructor (message = 'Block too large') {
5+
super(message)
6+
this.name = 'BlockTooLargeError'
7+
}
8+
}

packages/bitswap/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export interface BitswapOptions {
103103
*
104104
* @default false
105105
*/
106-
runOnTransientConnections?: boolean
106+
runOnLimitedConnections?: boolean
107107

108108
/**
109109
* Enables loading esoteric hash functions

packages/bitswap/src/network.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CodeError, TypedEventEmitter, setMaxListeners } from '@libp2p/interface'
1+
import { InvalidParametersError, NotStartedError, TimeoutError, TypedEventEmitter, UnsupportedProtocolError, setMaxListeners } from '@libp2p/interface'
22
import { PeerQueue, type PeerQueueJobOptions } from '@libp2p/utils/peer-queue'
33
import drain from 'it-drain'
44
import * as lp from 'it-length-prefixed'
@@ -41,7 +41,7 @@ export interface NetworkInit {
4141
messageReceiveTimeout?: number
4242
messageSendConcurrency?: number
4343
protocols?: string[]
44-
runOnTransientConnections?: boolean
44+
runOnLimitedConnections?: boolean
4545
maxOutgoingMessageSize?: number
4646
maxIncomingMessageSize?: number
4747
}
@@ -80,7 +80,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
8080
private registrarIds: string[]
8181
private readonly metrics: { blocksSent?: Counter, dataSent?: Counter }
8282
private readonly sendQueue: PeerQueue<void, SendMessageJobOptions>
83-
private readonly runOnTransientConnections: boolean
83+
private readonly runOnLimitedConnections: boolean
8484
private readonly maxOutgoingMessageSize: number
8585
private readonly maxIncomingMessageSize: number
8686

@@ -99,7 +99,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
9999
this.maxInboundStreams = init.maxInboundStreams ?? DEFAULT_MAX_INBOUND_STREAMS
100100
this.maxOutboundStreams = init.maxOutboundStreams ?? DEFAULT_MAX_OUTBOUND_STREAMS
101101
this.messageReceiveTimeout = init.messageReceiveTimeout ?? DEFAULT_MESSAGE_RECEIVE_TIMEOUT
102-
this.runOnTransientConnections = init.runOnTransientConnections ?? DEFAULT_RUN_ON_TRANSIENT_CONNECTIONS
102+
this.runOnLimitedConnections = init.runOnLimitedConnections ?? DEFAULT_RUN_ON_TRANSIENT_CONNECTIONS
103103
this.maxIncomingMessageSize = init.maxIncomingMessageSize ?? DEFAULT_MAX_OUTGOING_MESSAGE_SIZE
104104
this.maxOutgoingMessageSize = init.maxOutgoingMessageSize ?? init.maxIncomingMessageSize ?? DEFAULT_MAX_INCOMING_MESSAGE_SIZE
105105
this.metrics = {
@@ -127,7 +127,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
127127
await this.libp2p.handle(this.protocols, this._onStream, {
128128
maxInboundStreams: this.maxInboundStreams,
129129
maxOutboundStreams: this.maxOutboundStreams,
130-
runOnTransientConnection: this.runOnTransientConnections
130+
runOnLimitedConnection: this.runOnLimitedConnections
131131
})
132132

133133
// register protocol with topology
@@ -188,7 +188,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
188188
this.log('incoming new bitswap %s stream from %p', stream.protocol, connection.remotePeer)
189189
const abortListener = (): void => {
190190
if (stream.status === 'open') {
191-
stream.abort(new CodeError(`Incoming Bitswap stream timed out after ${this.messageReceiveTimeout}ms`, 'ERR_TIMEOUT'))
191+
stream.abort(new TimeoutError(`Incoming Bitswap stream timed out after ${this.messageReceiveTimeout}ms`))
192192
} else {
193193
this.log('stream aborted with status %s', stream.status)
194194
}
@@ -247,7 +247,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
247247
for await (const provider of this.routing.findProviders(cid, options)) {
248248
// make sure we can dial the provider
249249
const dialable = await this.libp2p.isDialable(provider.multiaddrs, {
250-
runOnTransientConnection: this.runOnTransientConnections
250+
runOnLimitedConnection: this.runOnLimitedConnections
251251
})
252252

253253
if (!dialable) {
@@ -300,7 +300,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
300300
const message = options?.message
301301

302302
if (message == null) {
303-
throw new CodeError('No message to send', 'ERR_NO_MESSAGE')
303+
throw new InvalidParametersError('No message to send')
304304
}
305305

306306
this.log('sendMessage to %p', peerId)
@@ -337,7 +337,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
337337
*/
338338
async connectTo (peer: PeerId, options?: AbortOptions & ProgressOptions<BitswapNetworkProgressEvents>): Promise<Connection> { // eslint-disable-line require-await
339339
if (!this.running) {
340-
throw new CodeError('Network isn\'t running', 'ERR_NOT_STARTED')
340+
throw new NotStartedError('Network isn\'t running')
341341
}
342342

343343
options?.onProgress?.(new CustomProgressEvent<PeerId>('bitswap:network:dial', peer))
@@ -359,7 +359,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> {
359359
return true
360360
}
361361

362-
throw new CodeError(`${peer} did not support ${BITSWAP_120}`, 'ERR_BITSWAP_UNSUPPORTED_BY_PEER')
362+
throw new UnsupportedProtocolError(`${peer} did not support ${BITSWAP_120}`)
363363
}
364364
})
365365
])

packages/bitswap/src/pb/message.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
55
/* eslint-disable @typescript-eslint/no-empty-interface */
66

7-
import { type Codec, CodeError, decodeMessage, type DecodeOptions, encodeMessage, enumeration, message } from 'protons-runtime'
7+
import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, MaxLengthError, message } from 'protons-runtime'
88
import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc'
99
import type { Uint8ArrayList } from 'uint8arraylist'
1010

@@ -167,7 +167,7 @@ export namespace Wantlist {
167167
switch (tag >>> 3) {
168168
case 1: {
169169
if (opts.limits?.entries != null && obj.entries.length === opts.limits.entries) {
170-
throw new CodeError('decode error - map field "entries" had too many elements', 'ERR_MAX_LENGTH')
170+
throw new MaxLengthError('Decode error - map field "entries" had too many elements')
171171
}
172172

173173
obj.entries.push(WantlistEntry.codec().decode(reader, reader.uint32(), {
@@ -424,7 +424,7 @@ export namespace BitswapMessage {
424424
}
425425
case 3: {
426426
if (opts.limits?.blocks != null && obj.blocks.length === opts.limits.blocks) {
427-
throw new CodeError('decode error - map field "blocks" had too many elements', 'ERR_MAX_LENGTH')
427+
throw new MaxLengthError('Decode error - map field "blocks" had too many elements')
428428
}
429429

430430
obj.blocks.push(Block.codec().decode(reader, reader.uint32(), {
@@ -434,7 +434,7 @@ export namespace BitswapMessage {
434434
}
435435
case 4: {
436436
if (opts.limits?.blockPresences != null && obj.blockPresences.length === opts.limits.blockPresences) {
437-
throw new CodeError('decode error - map field "blockPresences" had too many elements', 'ERR_MAX_LENGTH')
437+
throw new MaxLengthError('Decode error - map field "blockPresences" had too many elements')
438438
}
439439

440440
obj.blockPresences.push(BlockPresence.codec().decode(reader, reader.uint32(), {

packages/bitswap/src/peer-want-lists/ledger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class Ledger {
125125
})
126126
}
127127
} catch (err: any) {
128-
if (err.code !== 'ERR_NOT_FOUND') {
128+
if (err.name !== 'NotFoundError') {
129129
throw err
130130
}
131131

packages/bitswap/src/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class BitswapSession extends AbstractSession<PeerId, BitswapWantProgressEvents>
4848
}
4949

5050
toEvictionKey (provider: PeerId): Uint8Array | string {
51-
return provider.toBytes()
51+
return provider.toMultihash().bytes
5252
}
5353

5454
equals (providerA: PeerId, providerB: PeerId): boolean {

packages/bitswap/src/stats.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class Stats {
1919
}
2020

2121
updateBlocksReceived (count: number = 1, peerId?: PeerId): void {
22-
const stats: Record<string, number | unknown> = {
22+
const stats: Record<string, number | true> = {
2323
global: count
2424
}
2525

@@ -31,7 +31,7 @@ export class Stats {
3131
}
3232

3333
updateDuplicateBlocksReceived (count: number = 1, peerId?: PeerId): void {
34-
const stats: Record<string, number | unknown> = {
34+
const stats: Record<string, number | true> = {
3535
global: count
3636
}
3737

packages/bitswap/src/utils/split-message.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable complexity */
2-
import { CodeError } from '@libp2p/interface'
2+
33
import { encodingLength } from 'uint8-varint'
4+
import { BlockTooLargeError } from '../errors.js'
45
import { BitswapMessage, Block, BlockPresence, WantlistEntry } from '../pb/message.js'
56
import type { QueuedBitswapMessage } from './bitswap-message.js'
67

@@ -93,7 +94,7 @@ function addToMessage <T> (input: T[], output: T[], start: number, maxSize: numb
9394
const itemSize = calculateSize(item)
9495

9596
if (itemSize > MAX_ENCODED_BLOCK_SIZE) {
96-
throw new CodeError('Cannot send block as after encoding it is over the max message size', 'ERR_BLOCK_TOO_LARGE')
97+
throw new BlockTooLargeError('Cannot send block as after encoding it is over the max message size')
9798
}
9899

99100
const newSize = size + itemSize

packages/bitswap/test/bitswap.spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { generateKeyPair } from '@libp2p/crypto/keys'
12
import { start, stop } from '@libp2p/interface'
23
import { defaultLogger } from '@libp2p/logger'
3-
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
4+
import { peerIdFromPrivateKey } from '@libp2p/peer-id'
45
import { expect } from 'aegir/chai'
56
import { MemoryBlockstore } from 'blockstore-core'
67
import { CID } from 'multiformats/cid'
@@ -35,7 +36,7 @@ describe('bitswap', () => {
3536
cid = CID.createV0(mh).toV1()
3637

3738
components = {
38-
peerId: await createEd25519PeerId(),
39+
peerId: peerIdFromPrivateKey(await generateKeyPair('Ed25519')),
3940
routing: stubInterface<Routing>(),
4041
blockstore: new MemoryBlockstore(),
4142
libp2p: stubInterface<Libp2p>({
@@ -61,7 +62,7 @@ describe('bitswap', () => {
6162

6263
describe('want', () => {
6364
it('should want a block that is available on the network', async () => {
64-
const remotePeer = await createEd25519PeerId()
65+
const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519'))
6566
const findProvsSpy = bitswap.network.findAndConnect = Sinon.stub()
6667
findProvsSpy.resolves()
6768

@@ -112,7 +113,7 @@ describe('bitswap', () => {
112113
})
113114

114115
await expect(p).to.eventually.be.rejected
115-
.with.property('code', 'ABORT_ERR')
116+
.with.property('name', 'AbortError')
116117
})
117118

118119
it('should notify peers we have a block', async () => {
@@ -126,7 +127,7 @@ describe('bitswap', () => {
126127

127128
describe('wantlist', () => {
128129
it('should remove CIDs from the wantlist when the block arrives', async () => {
129-
const remotePeer = await createEd25519PeerId()
130+
const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519'))
130131
expect(bitswap.getWantlist()).to.be.empty()
131132

132133
const findProvsSpy = bitswap.network.findAndConnect = Sinon.stub()
@@ -182,15 +183,15 @@ describe('bitswap', () => {
182183
expect(bitswap.getWantlist().map(w => w.cid)).to.include(cid)
183184

184185
await expect(p).to.eventually.be.rejected
185-
.with.property('code', 'ABORT_ERR')
186+
.with.property('name', 'AbortError')
186187

187188
expect(bitswap.getWantlist()).to.be.empty()
188189
})
189190
})
190191

191192
describe('peer wantlist', () => {
192193
it('should return a peer wantlist', async () => {
193-
const remotePeer = await createEd25519PeerId()
194+
const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519'))
194195

195196
// don't have this peer yet
196197
expect(bitswap.getPeerWantlist(remotePeer)).to.be.undefined()

0 commit comments

Comments
 (0)