Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: update to [email protected] #630

Merged
merged 3 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benchmarks/add-dir/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"execa": "^8.0.1",
"helia": "^4.1.1",
"ipfs-unixfs-importer": "^15.1.5",
"ipfsd-ctl": "^14.0.0",
"ipfsd-ctl": "^15.0.0",
"it-all": "^3.0.4",
"it-drain": "^3.0.5",
"it-map": "^3.0.5",
"kubo": "^0.28.0",
"kubo-rpc-client": "^4.0.0",
"kubo-rpc-client": "^5.0.0",
"libp2p": "^1.1.0",
"multiformats": "^13.1.0",
"tinybench": "^2.4.0"
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/gc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"datastore-level": "^10.1.5",
"execa": "^8.0.1",
"helia": "^4.1.1",
"ipfsd-ctl": "^14.0.0",
"ipfsd-ctl": "^15.0.0",
"it-all": "^3.0.4",
"it-drain": "^3.0.5",
"it-map": "^3.0.5",
"kubo": "^0.28.0",
"kubo-rpc-client": "^4.0.0",
"kubo-rpc-client": "^5.0.0",
"multiformats": "^13.0.0",
"tinybench": "^2.5.1"
},
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/transfer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"execa": "^8.0.1",
"helia": "^4.1.0",
"ipfs-unixfs-importer": "^15.1.1",
"ipfsd-ctl": "^14.0.0",
"ipfsd-ctl": "^15.0.0",
"it-all": "^3.0.1",
"it-buffer-stream": "^3.0.2",
"it-drain": "^3.0.1",
"it-map": "^3.0.2",
"kubo": "^0.28.0",
"kubo-rpc-client": "^4.0.0",
"kubo-rpc-client": "^5.0.0",
"libp2p": "^1.4.0",
"multiformats": "^13.1.0",
"tinybench": "^2.4.0"
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/transports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"it-buffer-stream": "^3.0.2",
"it-drain": "^3.0.7",
"kubo": "^0.28.0",
"kubo-rpc-client": "^4.1.1",
"kubo-rpc-client": "^5.0.0",
"libp2p": "^1.4.0",
"multiformats": "^13.1.0",
"playwright-test": "^14.1.1",
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@
"npm:release": "aegir exec --bail false npm -- publish",
"release:rc": "aegir release-rc",
"docs": "aegir docs",
"docs:no-publish": "aegir docs --publish false"
"docs:no-publish": "aegir docs --publish false",
"postinstall": "patch-package && rimraf node_modules/@helia/delegated-routing-v1-http-api-client/node_modules"
},
"devDependencies": {
"aegir": "^44.0.1",
"npm-run-all": "^4.1.5"
"npm-run-all": "^4.1.5",
"patch-package": "^8.0.0",
"rimraf": "^6.0.1"
},
"type": "module",
"workspaces": [
Expand Down
18 changes: 9 additions & 9 deletions packages/bitswap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@
"dependencies": {
"@helia/interface": "^4.3.1",
"@helia/utils": "^0.3.3",
"@libp2p/interface": "^1.1.4",
"@libp2p/logger": "^4.0.5",
"@libp2p/peer-collections": "^5.1.6",
"@libp2p/utils": "^5.2.3",
"@libp2p/interface": "^2.0.0",
"@libp2p/logger": "^5.0.0",
"@libp2p/peer-collections": "^6.0.0",
"@libp2p/utils": "^6.0.0",
"@multiformats/multiaddr": "^12.1.14",
"any-signal": "^4.1.1",
"interface-blockstore": "^5.2.9",
"interface-store": "^5.1.7",
"interface-store": "^6.0.0",
"it-drain": "^3.0.5",
"it-length-prefixed": "^9.0.0",
"it-length-prefixed-stream": "^1.1.6",
Expand All @@ -174,12 +174,12 @@
"uint8arrays": "^5.0.1"
},
"devDependencies": {
"@libp2p/crypto": "^4.0.6",
"@libp2p/interface-compliance-tests": "^5.1.3",
"@libp2p/peer-id-factory": "^4.0.5",
"@libp2p/crypto": "^5.0.0",
"@libp2p/interface-compliance-tests": "^6.0.0",
"@libp2p/peer-id": "^5.0.0",
"@types/sinon": "^17.0.3",
"aegir": "^44.0.1",
"blockstore-core": "^4.3.10",
"blockstore-core": "^5.0.0",
"delay": "^6.0.0",
"it-all": "^3.0.4",
"it-pair": "^2.0.6",
Expand Down
8 changes: 8 additions & 0 deletions packages/bitswap/src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class BlockTooLargeError extends Error {
static name = 'BlockTooLargeError'

constructor (message = 'Block too large') {
super(message)
this.name = 'BlockTooLargeError'
}
}
2 changes: 1 addition & 1 deletion packages/bitswap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export interface BitswapOptions {
*
* @default false
*/
runOnTransientConnections?: boolean
runOnLimitedConnections?: boolean

/**
* Enables loading esoteric hash functions
Expand Down
20 changes: 10 additions & 10 deletions packages/bitswap/src/network.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeError, TypedEventEmitter, setMaxListeners } from '@libp2p/interface'
import { InvalidParametersError, NotStartedError, TimeoutError, TypedEventEmitter, UnsupportedProtocolError, setMaxListeners } from '@libp2p/interface'
import { PeerQueue, type PeerQueueJobOptions } from '@libp2p/utils/peer-queue'
import drain from 'it-drain'
import * as lp from 'it-length-prefixed'
Expand Down Expand Up @@ -41,7 +41,7 @@
messageReceiveTimeout?: number
messageSendConcurrency?: number
protocols?: string[]
runOnTransientConnections?: boolean
runOnLimitedConnections?: boolean
maxOutgoingMessageSize?: number
maxIncomingMessageSize?: number
}
Expand Down Expand Up @@ -80,7 +80,7 @@
private registrarIds: string[]
private readonly metrics: { blocksSent?: Counter, dataSent?: Counter }
private readonly sendQueue: PeerQueue<void, SendMessageJobOptions>
private readonly runOnTransientConnections: boolean
private readonly runOnLimitedConnections: boolean
private readonly maxOutgoingMessageSize: number
private readonly maxIncomingMessageSize: number

Expand All @@ -99,7 +99,7 @@
this.maxInboundStreams = init.maxInboundStreams ?? DEFAULT_MAX_INBOUND_STREAMS
this.maxOutboundStreams = init.maxOutboundStreams ?? DEFAULT_MAX_OUTBOUND_STREAMS
this.messageReceiveTimeout = init.messageReceiveTimeout ?? DEFAULT_MESSAGE_RECEIVE_TIMEOUT
this.runOnTransientConnections = init.runOnTransientConnections ?? DEFAULT_RUN_ON_TRANSIENT_CONNECTIONS
this.runOnLimitedConnections = init.runOnLimitedConnections ?? DEFAULT_RUN_ON_TRANSIENT_CONNECTIONS
this.maxIncomingMessageSize = init.maxIncomingMessageSize ?? DEFAULT_MAX_OUTGOING_MESSAGE_SIZE
this.maxOutgoingMessageSize = init.maxOutgoingMessageSize ?? init.maxIncomingMessageSize ?? DEFAULT_MAX_INCOMING_MESSAGE_SIZE
this.metrics = {
Expand Down Expand Up @@ -127,7 +127,7 @@
await this.libp2p.handle(this.protocols, this._onStream, {
maxInboundStreams: this.maxInboundStreams,
maxOutboundStreams: this.maxOutboundStreams,
runOnTransientConnection: this.runOnTransientConnections
runOnLimitedConnection: this.runOnLimitedConnections
})

// register protocol with topology
Expand Down Expand Up @@ -188,7 +188,7 @@
this.log('incoming new bitswap %s stream from %p', stream.protocol, connection.remotePeer)
const abortListener = (): void => {
if (stream.status === 'open') {
stream.abort(new CodeError(`Incoming Bitswap stream timed out after ${this.messageReceiveTimeout}ms`, 'ERR_TIMEOUT'))
stream.abort(new TimeoutError(`Incoming Bitswap stream timed out after ${this.messageReceiveTimeout}ms`))
} else {
this.log('stream aborted with status %s', stream.status)
}
Expand Down Expand Up @@ -247,7 +247,7 @@
for await (const provider of this.routing.findProviders(cid, options)) {
// make sure we can dial the provider
const dialable = await this.libp2p.isDialable(provider.multiaddrs, {
runOnTransientConnection: this.runOnTransientConnections
runOnLimitedConnection: this.runOnLimitedConnections
})

if (!dialable) {
Expand Down Expand Up @@ -300,7 +300,7 @@
const message = options?.message

if (message == null) {
throw new CodeError('No message to send', 'ERR_NO_MESSAGE')
throw new InvalidParametersError('No message to send')

Check warning on line 303 in packages/bitswap/src/network.ts

View check run for this annotation

Codecov / codecov/patch

packages/bitswap/src/network.ts#L303

Added line #L303 was not covered by tests
}

this.log('sendMessage to %p', peerId)
Expand Down Expand Up @@ -337,7 +337,7 @@
*/
async connectTo (peer: PeerId, options?: AbortOptions & ProgressOptions<BitswapNetworkProgressEvents>): Promise<Connection> { // eslint-disable-line require-await
if (!this.running) {
throw new CodeError('Network isn\'t running', 'ERR_NOT_STARTED')
throw new NotStartedError('Network isn\'t running')
}

options?.onProgress?.(new CustomProgressEvent<PeerId>('bitswap:network:dial', peer))
Expand All @@ -359,7 +359,7 @@
return true
}

throw new CodeError(`${peer} did not support ${BITSWAP_120}`, 'ERR_BITSWAP_UNSUPPORTED_BY_PEER')
throw new UnsupportedProtocolError(`${peer} did not support ${BITSWAP_120}`)

Check warning on line 362 in packages/bitswap/src/network.ts

View check run for this annotation

Codecov / codecov/patch

packages/bitswap/src/network.ts#L362

Added line #L362 was not covered by tests
}
})
])
Expand Down
8 changes: 4 additions & 4 deletions packages/bitswap/src/pb/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
/* eslint-disable @typescript-eslint/no-empty-interface */

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

Expand Down Expand Up @@ -167,7 +167,7 @@
switch (tag >>> 3) {
case 1: {
if (opts.limits?.entries != null && obj.entries.length === opts.limits.entries) {
throw new CodeError('decode error - map field "entries" had too many elements', 'ERR_MAX_LENGTH')
throw new MaxLengthError('Decode error - map field "entries" had too many elements')

Check warning on line 170 in packages/bitswap/src/pb/message.ts

View check run for this annotation

Codecov / codecov/patch

packages/bitswap/src/pb/message.ts#L170

Added line #L170 was not covered by tests
}

obj.entries.push(WantlistEntry.codec().decode(reader, reader.uint32(), {
Expand Down Expand Up @@ -424,7 +424,7 @@
}
case 3: {
if (opts.limits?.blocks != null && obj.blocks.length === opts.limits.blocks) {
throw new CodeError('decode error - map field "blocks" had too many elements', 'ERR_MAX_LENGTH')
throw new MaxLengthError('Decode error - map field "blocks" had too many elements')

Check warning on line 427 in packages/bitswap/src/pb/message.ts

View check run for this annotation

Codecov / codecov/patch

packages/bitswap/src/pb/message.ts#L427

Added line #L427 was not covered by tests
}

obj.blocks.push(Block.codec().decode(reader, reader.uint32(), {
Expand All @@ -434,7 +434,7 @@
}
case 4: {
if (opts.limits?.blockPresences != null && obj.blockPresences.length === opts.limits.blockPresences) {
throw new CodeError('decode error - map field "blockPresences" had too many elements', 'ERR_MAX_LENGTH')
throw new MaxLengthError('Decode error - map field "blockPresences" had too many elements')

Check warning on line 437 in packages/bitswap/src/pb/message.ts

View check run for this annotation

Codecov / codecov/patch

packages/bitswap/src/pb/message.ts#L437

Added line #L437 was not covered by tests
}

obj.blockPresences.push(BlockPresence.codec().decode(reader, reader.uint32(), {
Expand Down
2 changes: 1 addition & 1 deletion packages/bitswap/src/peer-want-lists/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class Ledger {
})
}
} catch (err: any) {
if (err.code !== 'ERR_NOT_FOUND') {
if (err.name !== 'NotFoundError') {
throw err
}

Expand Down
2 changes: 1 addition & 1 deletion packages/bitswap/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class BitswapSession extends AbstractSession<PeerId, BitswapWantProgressEvents>
}

toEvictionKey (provider: PeerId): Uint8Array | string {
return provider.toBytes()
return provider.toMultihash().bytes
}

equals (providerA: PeerId, providerB: PeerId): boolean {
Expand Down
4 changes: 2 additions & 2 deletions packages/bitswap/src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Stats {
}

updateBlocksReceived (count: number = 1, peerId?: PeerId): void {
const stats: Record<string, number | unknown> = {
const stats: Record<string, number | true> = {
global: count
}

Expand All @@ -31,7 +31,7 @@ export class Stats {
}

updateDuplicateBlocksReceived (count: number = 1, peerId?: PeerId): void {
const stats: Record<string, number | unknown> = {
const stats: Record<string, number | true> = {
global: count
}

Expand Down
5 changes: 3 additions & 2 deletions packages/bitswap/src/utils/split-message.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable complexity */
import { CodeError } from '@libp2p/interface'

import { encodingLength } from 'uint8-varint'
import { BlockTooLargeError } from '../errors.js'
import { BitswapMessage, Block, BlockPresence, WantlistEntry } from '../pb/message.js'
import type { QueuedBitswapMessage } from './bitswap-message.js'

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

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

const newSize = size + itemSize
Expand Down
15 changes: 8 additions & 7 deletions packages/bitswap/test/bitswap.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { generateKeyPair } from '@libp2p/crypto/keys'
import { start, stop } from '@libp2p/interface'
import { defaultLogger } from '@libp2p/logger'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { peerIdFromPrivateKey } from '@libp2p/peer-id'
import { expect } from 'aegir/chai'
import { MemoryBlockstore } from 'blockstore-core'
import { CID } from 'multiformats/cid'
Expand Down Expand Up @@ -35,7 +36,7 @@ describe('bitswap', () => {
cid = CID.createV0(mh).toV1()

components = {
peerId: await createEd25519PeerId(),
peerId: peerIdFromPrivateKey(await generateKeyPair('Ed25519')),
routing: stubInterface<Routing>(),
blockstore: new MemoryBlockstore(),
libp2p: stubInterface<Libp2p>({
Expand All @@ -61,7 +62,7 @@ describe('bitswap', () => {

describe('want', () => {
it('should want a block that is available on the network', async () => {
const remotePeer = await createEd25519PeerId()
const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519'))
const findProvsSpy = bitswap.network.findAndConnect = Sinon.stub()
findProvsSpy.resolves()

Expand Down Expand Up @@ -112,7 +113,7 @@ describe('bitswap', () => {
})

await expect(p).to.eventually.be.rejected
.with.property('code', 'ABORT_ERR')
.with.property('name', 'AbortError')
})

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

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

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

await expect(p).to.eventually.be.rejected
.with.property('code', 'ABORT_ERR')
.with.property('name', 'AbortError')

expect(bitswap.getWantlist()).to.be.empty()
})
})

describe('peer wantlist', () => {
it('should return a peer wantlist', async () => {
const remotePeer = await createEd25519PeerId()
const remotePeer = peerIdFromPrivateKey(await generateKeyPair('Ed25519'))

// don't have this peer yet
expect(bitswap.getPeerWantlist(remotePeer)).to.be.undefined()
Expand Down
Loading
Loading