Skip to content

deps!: update to libp2p 0.46.x #596

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

Merged
merged 3 commits into from
Aug 5, 2023
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
2 changes: 1 addition & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
/** @type {import('aegir').PartialOptions} */
export default {
build: {
bundlesizeMax: '32KB'
bundlesizeMax: '33KB'
}
}
28 changes: 10 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,10 @@
"docs": "aegir docs"
},
"dependencies": {
"@libp2p/interface-connection": "^5.1.0",
"@libp2p/interface-libp2p": "^3.1.0",
"@libp2p/interface-peer-id": "^2.0.0",
"@libp2p/interface-peer-info": "^1.0.8",
"@libp2p/interface-registrar": "^2.0.8",
"@libp2p/interfaces": "^3.2.0",
"@libp2p/logger": "^2.0.5",
"@libp2p/topology": "^4.0.0",
"@libp2p/tracked-map": "^3.0.0",
"@libp2p/interface": "^0.1.1",
"@libp2p/logger": "^3.0.1",
"@multiformats/multiaddr": "^12.1.0",
"@vascosantos/moving-average": "^1.1.0",
"abortable-iterator": "^5.0.1",
"any-signal": "^4.1.1",
"blockstore-core": "^4.0.0",
"events": "^3.3.0",
Expand All @@ -166,7 +158,7 @@
"it-pipe": "^3.0.1",
"it-take": "^3.0.1",
"just-debounce-it": "^3.0.1",
"multiformats": "^11.0.0",
"multiformats": "^12.0.1",
"progress-events": "^1.0.0",
"protons-runtime": "^5.0.0",
"timeout-abort-controller": "^3.0.0",
Expand All @@ -176,12 +168,12 @@
"varint-decoder": "^1.0.0"
},
"devDependencies": {
"@chainsafe/libp2p-noise": "^12.0.0",
"@libp2p/kad-dht": "^9.3.3",
"@libp2p/mplex": "^8.0.3",
"@libp2p/peer-id": "^2.0.0",
"@libp2p/peer-id-factory": "^2.0.0",
"@libp2p/tcp": "^7.0.1",
"@chainsafe/libp2p-noise": "^13.0.0",
"@libp2p/kad-dht": "^10.0.2",
"@libp2p/mplex": "^9.0.2",
"@libp2p/peer-id": "^3.0.1",
"@libp2p/peer-id-factory": "^3.0.2",
"@libp2p/tcp": "^8.0.2",
"@nodeutils/defaults-deep": "^1.1.0",
"@types/lodash.difference": "^4.5.7",
"@types/lodash.flatten": "^4.4.7",
Expand All @@ -195,7 +187,7 @@
"iso-random-stream": "^2.0.0",
"it-all": "^3.0.1",
"it-drain": "^3.0.1",
"libp2p": "^0.45.1",
"libp2p": "^0.46.3",
"lodash.difference": "^4.5.0",
"lodash.flatten": "^4.4.0",
"lodash.range": "^3.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/bitswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { logger } from './utils/index.js'
import { WantManager } from './want-manager/index.js'
import type { BitswapOptions, Bitswap, MultihashHasherLoader, WantListEntry, BitswapWantProgressEvents, BitswapNotifyProgressEvents } from './index.js'
import type { BitswapMessage } from './message/index.js'
import type { Libp2p } from '@libp2p/interface-libp2p'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { Libp2p } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Logger } from '@libp2p/logger'
import type { AbortOptions } from '@multiformats/multiaddr'
import type { Blockstore, Pair } from 'interface-blockstore'
Expand Down
6 changes: 3 additions & 3 deletions src/decision-engine/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { trackedMap } from '@libp2p/tracked-map'
import { trackedMap } from '@libp2p/interface/metrics/tracked-map'
import { base58btc } from 'multiformats/bases/base58'
import { CID } from 'multiformats/cid'
import { BitswapMessage as Message } from '../message/index.js'
Expand All @@ -12,8 +12,8 @@ import type { Message as PBMessage } from '../message/message.js'
import type { Network } from '../network.js'
import type { Stats } from '../stats/index.js'
import type { WantListEntry } from '../wantlist/entry.js'
import type { Libp2p } from '@libp2p/interface-libp2p'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { Libp2p } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Logger } from '@libp2p/logger'
import type { Blockstore } from 'interface-blockstore'

Expand Down
2 changes: 1 addition & 1 deletion src/decision-engine/ledger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Wantlist } from '../wantlist/index.js'
import type { Message } from '../message/message.js'
import type { WantListEntry } from '../wantlist/entry.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { CID } from 'multiformats/cid'

export class Ledger {
Expand Down
2 changes: 1 addition & 1 deletion src/decision-engine/req-queue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SortedMap } from '../utils/sorted-map.js'
import type { Task, TaskMerger } from './index.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'

export interface PopTaskResult {
peerId?: PeerId
Expand Down
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { DefaultBitswap } from './bitswap.js'
import type { Message } from './message/message'
import type { BitswapNetworkNotifyProgressEvents, BitswapNetworkWantProgressEvents } from './network.js'
import type { Libp2p } from '@libp2p/interface-libp2p'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { AbortOptions } from '@libp2p/interfaces'
import type { Startable } from '@libp2p/interfaces/startable'
import type { Libp2p, AbortOptions } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Startable } from '@libp2p/interface/startable'
import type { IMovingAverage } from '@vascosantos/moving-average'
import type { Blockstore } from 'interface-blockstore'
import type { CID } from 'multiformats/cid'
Expand Down
2 changes: 1 addition & 1 deletion src/message/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'
import { base58btc } from 'multiformats/bases/base58'
import { CID } from 'multiformats/cid'
import { sha256 } from 'multiformats/hashes/sha2'
Expand Down
47 changes: 29 additions & 18 deletions src/network.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createTopology } from '@libp2p/topology'
import { abortableSource } from 'abortable-iterator'
import { CodeError } from '@libp2p/interface/errors'
import drain from 'it-drain'
import * as lp from 'it-length-prefixed'
import map from 'it-map'
Expand All @@ -13,12 +12,12 @@ import { logger } from './utils/index.js'
import type { DefaultBitswap } from './bitswap.js'
import type { MultihashHasherLoader } from './index.js'
import type { Stats } from './stats/index.js'
import type { Connection } from '@libp2p/interface-connection'
import type { Libp2p } from '@libp2p/interface-libp2p'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerInfo } from '@libp2p/interface-peer-info'
import type { IncomingStreamData } from '@libp2p/interface-registrar'
import type { AbortOptions } from '@libp2p/interfaces'
import type { Libp2p, AbortOptions } from '@libp2p/interface'
import type { Connection } from '@libp2p/interface/connection'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { PeerInfo } from '@libp2p/interface/peer-info'
import type { IncomingStreamData } from '@libp2p/interface/stream-handler'
import type { Topology } from '@libp2p/interface/topology'
import type { Logger } from '@libp2p/logger'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { CID } from 'multiformats/cid'
Expand Down Expand Up @@ -107,10 +106,10 @@ export class Network {
})

// register protocol with topology
const topology = createTopology({
const topology: Topology = {
onConnect: this._onPeerConnect,
onDisconnect: this._onPeerDisconnect
})
}

/** @type {string[]} */
this._registrarIds = []
Expand Down Expand Up @@ -153,10 +152,16 @@ export class Network {
const controller = new TimeoutController(this._incomingStreamTimeout)

Promise.resolve().then(async () => {
this._log('incoming new bitswap %s connection from %p', stream.stat.protocol, connection.remotePeer)
this._log('incoming new bitswap %s connection from %p', stream.protocol, connection.remotePeer)
const abortListener = (): void => {
stream.abort(new CodeError('Incoming Bitswap stream timed out', 'ERR_TIMEOUT'))
}

let signal = AbortSignal.timeout(this._incomingStreamTimeout)
signal.addEventListener('abort', abortListener)

await pipe(
abortableSource(stream.source, controller.signal),
stream,
(source) => lp.decode(source),
async (source) => {
for await (const data of source) {
Expand All @@ -169,18 +174,23 @@ export class Network {
}

// we have received some data so reset the timeout controller
controller.reset()
signal.removeEventListener('abort', abortListener)
signal = AbortSignal.timeout(this._incomingStreamTimeout)
signal.addEventListener('abort', abortListener)
}
}
)

await stream.close({
signal
})
})
.catch(err => {
this._log(err)
stream.abort(err)
})
.finally(() => {
controller.clear()
stream.close()
})
}

Expand Down Expand Up @@ -273,7 +283,7 @@ export class Network {
try {
/** @type {Uint8Array} */
let serialized
switch (stream.stat.protocol) {
switch (stream.protocol) {
case BITSWAP100:
serialized = msg.serializeToBitswap100()
break
Expand All @@ -282,19 +292,20 @@ export class Network {
serialized = msg.serializeToBitswap110()
break
default:
throw new Error(`Unknown protocol: ${stream.stat.protocol}`)
throw new Error(`Unknown protocol: ${stream.protocol}`)
}

await pipe(
[serialized],
(source) => lp.encode(source),
stream
)

await stream.close()
} catch (err: any) {
options.onProgress?.(new CustomProgressEvent<{ peer: PeerId, error: Error }>('bitswap:network:send-wantlist:error', { peer: peerId, error: err }))
this._log(err)
} finally {
stream.close()
stream.abort(err)
}
}
}
4 changes: 2 additions & 2 deletions src/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import * as CONSTANTS from './constants.js'
import { logger } from './utils/index.js'
import type { BitswapWantBlockProgressEvents } from './index.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { AbortOptions } from '@libp2p/interfaces'
import type { AbortOptions } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Logger } from '@libp2p/logger'
import type { CID } from 'multiformats/cid'

Expand Down
9 changes: 2 additions & 7 deletions src/stats/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { EventEmitter } from 'events'
import { trackedMap } from '@libp2p/tracked-map'
import { trackedMap } from '@libp2p/interface/metrics/tracked-map'
import { Stat } from './stat.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { IMovingAverage } from '@vascosantos/moving-average'
import type { Libp2p } from 'libp2p'

/**
* @typedef {import('multiformats').CID} CID
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId
*/

export interface StatsOptions {
enabled?: boolean
computeThrottleTimeout?: number
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logger as createLogger, type Logger } from '@libp2p/logger'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import { BitswapMessageEntry } from '../message/entry.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'

/**
* Creates a logger for the given subsystem
Expand Down
6 changes: 3 additions & 3 deletions src/want-manager/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { trackedMap } from '@libp2p/tracked-map'
import { trackedMap } from '@libp2p/interface/metrics/tracked-map'
import { base58btc } from 'multiformats/bases/base58'
import * as CONSTANTS from '../constants.js'
import { BitswapMessage as Message } from '../message/index.js'
Expand All @@ -8,8 +8,8 @@ import { MsgQueue } from './msg-queue.js'
import type { BitswapWantBlockProgressEvents } from '../index.js'
import type { Network } from '../network.js'
import type { Stats } from '../stats/index.js'
import type { Libp2p } from '@libp2p/interface-libp2p'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { Libp2p } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Logger } from '@libp2p/logger'
import type { AbortOptions } from '@multiformats/multiaddr'
import type { CID } from 'multiformats/cid'
Expand Down
2 changes: 1 addition & 1 deletion src/want-manager/msg-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BitswapMessage as Message } from '../message/index.js'
import { logger } from '../utils/index.js'
import type { BitswapWantBlockProgressEvents } from '../index.js'
import type { BitswapNetworkWantProgressEvents, Network } from '../network.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Logger } from '@libp2p/logger'
import type { CID } from 'multiformats/cid'
import type { ProgressOptions } from 'progress-events'
Expand Down
4 changes: 2 additions & 2 deletions src/wantlist/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { trackedMap } from '@libp2p/tracked-map'
import { trackedMap } from '@libp2p/interface/metrics/tracked-map'
import { base58btc } from 'multiformats/bases/base58'
import { Message } from '../message/message.js'
import { WantListEntry as Entry } from './entry.js'
import type { Stats } from '../stats/index.js'
import type { Libp2p } from '@libp2p/interface-libp2p'
import type { Libp2p } from '@libp2p/interface'
import type { CID } from 'multiformats/cid'

const WantType = {
Expand Down
2 changes: 1 addition & 1 deletion test/bitswap-mock-internals.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 5] */

import { isPeerId, type PeerId } from '@libp2p/interface-peer-id'
import { isPeerId, type PeerId } from '@libp2p/interface/peer-id'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { expect } from 'aegir/chai'
import { MemoryBlockstore } from 'blockstore-core/memory'
Expand Down
9 changes: 2 additions & 7 deletions test/bitswap-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@ import { BitswapMessage as Message } from '../src/message/index.js'
import { createLibp2pNode } from './utils/create-libp2p-node.js'
import { makeBlocks } from './utils/make-blocks.js'
import { makePeerIds } from './utils/make-peer-id.js'
import type { Libp2p } from '@libp2p/interface-libp2p'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { Libp2p } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { CID } from 'multiformats/cid'

/**
* @typedef {import('@libp2p/interface-libp2p').Libp2p} Libp2p
* @typedef {import('multiformats/cid').CID} CID
*/

const expectedStats = [
'blocksReceived',
'dataReceived',
Expand Down
2 changes: 1 addition & 1 deletion test/bitswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { BitswapMessage as Message } from '../src/message/index.js'
import { createLibp2pNode } from './utils/create-libp2p-node.js'
import { orderedFinish } from './utils/helpers.js'
import { makeBlocks } from './utils/make-blocks.js'
import type { Libp2p } from '@libp2p/interface-libp2p'
import type { Libp2p } from '@libp2p/interface'
import type { DualKadDHT } from '@libp2p/kad-dht'

/**
Expand Down
2 changes: 1 addition & 1 deletion test/decision-engine/decision-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { makeBlocks } from '../utils/make-blocks.js'
import { makePeerId, makePeerIds } from '../utils/make-peer-id.js'
import { mockNetwork } from '../utils/mocks.js'
import type { Network } from '../../src/network.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Blockstore } from 'interface-blockstore'

const sum = (nums: number[]): number => nums.reduce((a, b) => a + b, 0)
Expand Down
2 changes: 1 addition & 1 deletion test/decision-engine/ledger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { expect } from 'aegir/chai'
import { Ledger } from '../../src/decision-engine/ledger.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'

describe('Ledger', () => {
/** @type {} */
Expand Down
2 changes: 1 addition & 1 deletion test/decision-engine/req-queue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { expect } from 'aegir/chai'
import { RequestQueue } from '../../src/decision-engine/req-queue.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'

describe('Request Queue', () => {
let peerIds: PeerId[]
Expand Down
2 changes: 1 addition & 1 deletion test/decision-engine/task-merger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { expect } from 'aegir/chai'
import { RequestQueue } from '../../src/decision-engine/req-queue.js'
import { DefaultTaskMerger } from '../../src/decision-engine/task-merger.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'

interface Task {
topic: string
Expand Down
Loading