Skip to content

Commit

Permalink
deps!: update libp2p to v1
Browse files Browse the repository at this point in the history
Updates all libp2p deps to the v1 release.
  • Loading branch information
achingbrain committed Nov 30, 2023
1 parent ee728e7 commit 5f22a17
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 95 deletions.
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@
"docs": "aegir docs"
},
"dependencies": {
"@libp2p/interface": "^0.1.1",
"@libp2p/logger": "^3.0.1",
"@libp2p/identify": "^1.0.0",
"@libp2p/interface": "^1.0.0",
"@libp2p/logger": "^4.0.0",
"@libp2p/utils": "^5.0.0",
"@multiformats/multiaddr": "^12.1.0",
"@vascosantos/moving-average": "^1.1.0",
"any-signal": "^4.1.1",
Expand All @@ -169,17 +171,17 @@
"varint-decoder": "^1.0.0"
},
"devDependencies": {
"@chainsafe/libp2p-noise": "^13.0.0",
"@libp2p/kad-dht": "^10.0.2",
"@libp2p/mplex": "^9.0.2",
"@libp2p/peer-id": "^3.0.1",
"@chainsafe/libp2p-noise": "^14.0.0",
"@libp2p/kad-dht": "^11.0.0",
"@libp2p/mplex": "^10.0.0",
"@libp2p/peer-id": "^4.0.0",
"@libp2p/peer-id-factory": "^3.0.2",
"@libp2p/tcp": "^8.0.2",
"@libp2p/tcp": "^9.0.0",
"@nodeutils/defaults-deep": "^1.1.0",
"@types/lodash.difference": "^4.5.7",
"@types/lodash.flatten": "^4.4.7",
"@types/lodash.range": "^3.2.7",
"@types/sinon": "^10.0.15",
"@types/sinon": "^17.0.2",
"@types/stats-lite": "^2.2.0",
"@types/varint": "^6.0.0",
"aegir": "^41.0.0",
Expand All @@ -188,7 +190,7 @@
"iso-random-stream": "^2.0.0",
"it-all": "^3.0.1",
"it-drain": "^3.0.1",
"libp2p": "^0.46.3",
"libp2p": "^1.0.0",
"lodash.difference": "^4.5.0",
"lodash.flatten": "^4.4.0",
"lodash.range": "^3.2.0",
Expand Down
3 changes: 1 addition & 2 deletions src/bitswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ 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'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Libp2p, PeerId } from '@libp2p/interface'
import type { Logger } from '@libp2p/logger'
import type { AbortOptions } from '@multiformats/multiaddr'
import type { Blockstore, Pair } from 'interface-blockstore'
Expand Down
5 changes: 2 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/interface/metrics/tracked-map'
import { trackedMap } from '@libp2p/utils/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,7 @@ 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'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Libp2p, PeerId } from '@libp2p/interface'
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'
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'

export interface PopTaskResult {
peerId?: PeerId
Expand Down
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { DefaultBitswap } from './bitswap.js'
import type { Message } from './message/message'
import type { BitswapNetworkNotifyProgressEvents, BitswapNetworkWantProgressEvents } from './network.js'
import type { Libp2p, AbortOptions } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Startable } from '@libp2p/interface/startable'
import type { Libp2p, AbortOptions, PeerId, Startable } from '@libp2p/interface'
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/interface/errors'
import { CodeError } from '@libp2p/interface'
import { base58btc } from 'multiformats/bases/base58'
import { CID } from 'multiformats/cid'
import { sha256 } from 'multiformats/hashes/sha2'
Expand Down
9 changes: 2 additions & 7 deletions src/network.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeError } from '@libp2p/interface/errors'
import { CodeError } from '@libp2p/interface'
import drain from 'it-drain'
import * as lp from 'it-length-prefixed'
import map from 'it-map'
Expand All @@ -12,12 +12,7 @@ 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 { 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 { Libp2p, AbortOptions, Connection, PeerId, PeerInfo, IncomingStreamData, Topology } from '@libp2p/interface'
import type { Logger } from '@libp2p/logger'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { CID } from 'multiformats/cid'
Expand Down
3 changes: 1 addition & 2 deletions src/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ 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 { AbortOptions } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { AbortOptions, PeerId } from '@libp2p/interface'
import type { Logger } from '@libp2p/logger'
import type { CID } from 'multiformats/cid'

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

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'

/**
* Creates a logger for the given subsystem
Expand Down
5 changes: 2 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/interface/metrics/tracked-map'
import { trackedMap } from '@libp2p/utils/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,7 @@ 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'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Libp2p, PeerId } from '@libp2p/interface'
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'
import type { Logger } from '@libp2p/logger'
import type { CID } from 'multiformats/cid'
import type { ProgressOptions } from 'progress-events'
Expand Down
2 changes: 1 addition & 1 deletion src/wantlist/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { trackedMap } from '@libp2p/interface/metrics/tracked-map'
import { trackedMap } from '@libp2p/utils/tracked-map'
import { base58btc } from 'multiformats/bases/base58'
import { Message } from '../message/message.js'
import { WantListEntry as Entry } from './entry.js'
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'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { expect } from 'aegir/chai'
import { MemoryBlockstore } from 'blockstore-core/memory'
Expand Down
89 changes: 44 additions & 45 deletions test/bitswap-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ 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'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Libp2p, PeerId } from '@libp2p/interface'
import type { CID } from 'multiformats/cid'

const expectedStats = [
Expand Down Expand Up @@ -75,7 +74,7 @@ describe('bitswap stats', () => {

expectedStats.forEach((key) => {
expect(snapshot).to.have.property(key)
expect(snapshot[key]).to.equal(BigInt(0))
expect(snapshot[key]).to.equal(0n)
})

const movingAverages = stats.movingAverages
Expand All @@ -92,15 +91,15 @@ describe('bitswap stats', () => {

it('updates blocks received', (done) => {
bs.stats.once('update', (stats) => {
expect(stats.blocksReceived).to.equal(BigInt(2))
expect(stats.dataReceived).to.equal(BigInt(96))
expect(stats.dupBlksReceived).to.equal(BigInt(0))
expect(stats.dupDataReceived).to.equal(BigInt(0))
expect(stats.blocksSent).to.equal(BigInt(0))
expect(stats.dataSent).to.equal(BigInt(0))
expect(stats.providesBufferLength).to.equal(BigInt(0))
expect(stats.wantListLength).to.equal(BigInt(0))
expect(stats.peerCount).to.equal(BigInt(1))
expect(stats.blocksReceived).to.equal(2n)
expect(stats.dataReceived).to.equal(96n)
expect(stats.dupBlksReceived).to.equal(0n)
expect(stats.dupDataReceived).to.equal(0n)
expect(stats.blocksSent).to.equal(0n)
expect(stats.dataSent).to.equal(0n)
expect(stats.providesBufferLength).to.equal(0n)
expect(stats.wantListLength).to.equal(0n)
expect(stats.peerCount).to.equal(1n)

// test moving averages
const movingAverages = bs.stats.movingAverages
Expand Down Expand Up @@ -132,13 +131,13 @@ describe('bitswap stats', () => {

it('updates duplicate blocks counters', (done) => {
bs.stats.once('update', (stats) => {
expect(stats.blocksReceived).to.equal(BigInt(4))
expect(stats.dataReceived).to.equal(BigInt(192))
expect(stats.dupBlksReceived).to.equal(BigInt(2))
expect(stats.dupDataReceived).to.equal(BigInt(96))
expect(stats.blocksSent).to.equal(BigInt(0))
expect(stats.dataSent).to.equal(BigInt(0))
expect(stats.providesBufferLength).to.equal(BigInt(0))
expect(stats.blocksReceived).to.equal(4n)
expect(stats.dataReceived).to.equal(192n)
expect(stats.dupBlksReceived).to.equal(2n)
expect(stats.dupDataReceived).to.equal(96n)
expect(stats.blocksSent).to.equal(0n)
expect(stats.dataSent).to.equal(0n)
expect(stats.providesBufferLength).to.equal(0n)
done()
})

Expand Down Expand Up @@ -173,15 +172,15 @@ describe('bitswap stats', () => {
it('updates stats on transfer', async () => {
const originalStats = bs.stats.snapshot

expect(originalStats.blocksReceived).to.equal(BigInt(4))
expect(originalStats.dataReceived).to.equal(BigInt(192))
expect(originalStats.dupBlksReceived).to.equal(BigInt(2))
expect(originalStats.dupDataReceived).to.equal(BigInt(96))
expect(originalStats.blocksSent).to.equal(BigInt(0))
expect(originalStats.dataSent).to.equal(BigInt(0))
expect(originalStats.providesBufferLength).to.equal(BigInt(0))
expect(originalStats.wantListLength).to.equal(BigInt(0))
expect(originalStats.peerCount).to.equal(BigInt(1))
expect(originalStats.blocksReceived).to.equal(4n)
expect(originalStats.dataReceived).to.equal(192n)
expect(originalStats.dupBlksReceived).to.equal(2n)
expect(originalStats.dupDataReceived).to.equal(96n)
expect(originalStats.blocksSent).to.equal(0n)
expect(originalStats.dataSent).to.equal(0n)
expect(originalStats.providesBufferLength).to.equal(0n)
expect(originalStats.wantListLength).to.equal(0n)
expect(originalStats.peerCount).to.equal(1n)

const deferred = pEvent(bs.stats, 'update')

Expand All @@ -190,15 +189,15 @@ describe('bitswap stats', () => {

const nextStats = await deferred

expect(nextStats.blocksReceived).to.equal(BigInt(4))
expect(nextStats.dataReceived).to.equal(BigInt(192))
expect(nextStats.dupBlksReceived).to.equal(BigInt(2))
expect(nextStats.dupDataReceived).to.equal(BigInt(96))
expect(nextStats.blocksSent).to.equal(BigInt(1))
expect(nextStats.blocksReceived).to.equal(4n)
expect(nextStats.dataReceived).to.equal(192n)
expect(nextStats.dupBlksReceived).to.equal(2n)
expect(nextStats.dupDataReceived).to.equal(96n)
expect(nextStats.blocksSent).to.equal(1n)
expect(nextStats.dataSent).to.equal(BigInt(48))
expect(nextStats.providesBufferLength).to.equal(BigInt(0))
expect(nextStats.wantListLength).to.equal(BigInt(0))
expect(nextStats.peerCount).to.equal(BigInt(2))
expect(nextStats.providesBufferLength).to.equal(0n)
expect(nextStats.wantListLength).to.equal(0n)
expect(nextStats.peerCount).to.equal(3n)
})

it('has peer stats', async () => {
Expand All @@ -215,15 +214,15 @@ describe('bitswap stats', () => {

const stats = await pEvent(peerStats, 'update')

expect(stats.blocksReceived).to.equal(BigInt(1))
expect(stats.dataReceived).to.equal(BigInt(49))
expect(stats.dupBlksReceived).to.equal(BigInt(0))
expect(stats.dupDataReceived).to.equal(BigInt(0))
expect(stats.blocksSent).to.equal(BigInt(0))
expect(stats.dataSent).to.equal(BigInt(0))
expect(stats.providesBufferLength).to.equal(BigInt(0))
expect(stats.wantListLength).to.equal(BigInt(0))
expect(stats.peerCount).to.equal(BigInt(1))
expect(stats.blocksReceived).to.equal(1n)
expect(stats.dataReceived).to.equal(49n)
expect(stats.dupBlksReceived).to.equal(0n)
expect(stats.dupDataReceived).to.equal(0n)
expect(stats.blocksSent).to.equal(0n)
expect(stats.dataSent).to.equal(0n)
expect(stats.providesBufferLength).to.equal(0n)
expect(stats.wantListLength).to.equal(0n)
expect(stats.peerCount).to.equal(1n)

const ma = peerStats.movingAverages.dataReceived[60000]
expect(ma.movingAverage()).to.be.above(0)
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'
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'

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'

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'

interface Task {
topic: string
Expand Down
2 changes: 1 addition & 1 deletion test/notifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { Notifications } from '../src/notifications.js'
import { makeBlocks } from './utils/make-blocks.js'
import { makePeerId } from './utils/make-peer-id.js'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { PeerId } from '@libp2p/interface'

describe('Notifications', () => {
let blocks: Array<{ cid: CID, block: Uint8Array }>
Expand Down
Loading

0 comments on commit 5f22a17

Please sign in to comment.