Skip to content

Commit 90691b9

Browse files
deps!: bump libp2p from 0.43.4 to 0.45.1 (#579)
* deps(dev): bump libp2p from 0.43.4 to 0.45.1 Bumps [libp2p](https://github.com/libp2p/js-libp2p) from 0.43.4 to 0.45.1. - [Release notes](https://github.com/libp2p/js-libp2p/releases) - [Changelog](https://github.com/libp2p/js-libp2p/blob/master/CHANGELOG.md) - [Commits](libp2p/js-libp2p@v0.43.4...v0.45.1) --- updated-dependencies: - dependency-name: libp2p dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * chore: update deps and fix tests * chore: remove unused dep --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: achingbrain <[email protected]>
1 parent 09718b8 commit 90691b9

File tree

7 files changed

+48
-44
lines changed

7 files changed

+48
-44
lines changed

package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@
143143
"docs": "aegir docs"
144144
},
145145
"dependencies": {
146-
"@libp2p/interface-connection": "^3.0.1",
147-
"@libp2p/interface-libp2p": "^1.1.1",
146+
"@libp2p/interface-connection": "^5.1.0",
147+
"@libp2p/interface-libp2p": "^3.1.0",
148148
"@libp2p/interface-peer-id": "^2.0.0",
149149
"@libp2p/interface-peer-info": "^1.0.8",
150150
"@libp2p/interface-registrar": "^2.0.8",
@@ -154,8 +154,8 @@
154154
"@libp2p/tracked-map": "^3.0.0",
155155
"@multiformats/multiaddr": "^12.1.0",
156156
"@vascosantos/moving-average": "^1.1.0",
157-
"abortable-iterator": "^4.0.2",
158-
"any-signal": "^3.0.0",
157+
"abortable-iterator": "^5.0.1",
158+
"any-signal": "^4.1.1",
159159
"blockstore-core": "^4.0.0",
160160
"interface-blockstore": "^5.0.0",
161161
"interface-store": "^5.1.0",
@@ -175,12 +175,12 @@
175175
"varint-decoder": "^1.0.0"
176176
},
177177
"devDependencies": {
178-
"@chainsafe/libp2p-noise": "^11.0.0",
179-
"@libp2p/kad-dht": "^8.0.6",
180-
"@libp2p/mplex": "^7.0.0",
178+
"@chainsafe/libp2p-noise": "^12.0.0",
179+
"@libp2p/kad-dht": "^9.3.3",
180+
"@libp2p/mplex": "^8.0.3",
181181
"@libp2p/peer-id": "^2.0.0",
182182
"@libp2p/peer-id-factory": "^2.0.0",
183-
"@libp2p/tcp": "^6.0.0",
183+
"@libp2p/tcp": "^7.0.1",
184184
"@nodeutils/defaults-deep": "^1.1.0",
185185
"@types/lodash.difference": "^4.5.7",
186186
"@types/lodash.flatten": "^4.4.7",
@@ -194,14 +194,13 @@
194194
"iso-random-stream": "^2.0.0",
195195
"it-all": "^3.0.1",
196196
"it-drain": "^3.0.1",
197-
"libp2p": "^0.43.3",
197+
"libp2p": "^0.45.1",
198198
"lodash.difference": "^4.5.0",
199199
"lodash.flatten": "^4.4.0",
200200
"lodash.range": "^3.2.0",
201201
"lodash.without": "^4.4.0",
202202
"p-defer": "^4.0.0",
203203
"p-event": "^5.0.1",
204-
"p-wait-for": "^5.0.0",
205204
"protons": "^7.0.2",
206205
"sinon": "^15.0.1",
207206
"stats-lite": "^2.2.0",

src/bitswap.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,7 @@ export class DefaultBitswap implements Bitswap {
258258
// a race condition, so register for incoming block notifications as well
259259
// as trying to get it from the datastore
260260
const controller = new AbortController()
261-
const signal = (options.signal != null)
262-
? anySignal([options.signal, controller.signal])
263-
: controller.signal
261+
const signal = anySignal([controller.signal, options.signal])
264262

265263
try {
266264
const block = await Promise.race([
@@ -279,6 +277,7 @@ export class DefaultBitswap implements Bitswap {
279277
// since we have the block we can now abort any outstanding attempts to
280278
// fetch it
281279
controller.abort()
280+
signal.clear()
282281
}
283282
}
284283

src/network.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ export class Network {
252252
}
253253

254254
options.onProgress?.(new CustomProgressEvent<PeerId>('bitswap:network:dial', peer))
255-
// @ts-expect-error types are not aligned
256255
return this._libp2p.dial(peer, options)
257256
}
258257

test/bitswap.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import { expect } from 'aegir/chai'
55
import { MemoryBlockstore } from 'blockstore-core/memory'
66
import drain from 'it-drain'
77
import { CID } from 'multiformats/cid'
8-
import pWaitFor from 'p-wait-for'
98
import sinon from 'sinon'
109
import { DefaultBitswap } from '../src/bitswap.js'
1110
import { BitswapMessage as Message } from '../src/message/index.js'
1211
import { createLibp2pNode } from './utils/create-libp2p-node.js'
1312
import { orderedFinish } from './utils/helpers.js'
1413
import { makeBlocks } from './utils/make-blocks.js'
1514
import type { Libp2p } from '@libp2p/interface-libp2p'
15+
import type { DualKadDHT } from '@libp2p/kad-dht'
1616

1717
/**
1818
* Creates a repo + libp2pNode + Bitswap with or without DHT
1919
*/
20-
async function createThing (dht: boolean): Promise<{ libp2pNode: Libp2p, bitswap: DefaultBitswap }> {
20+
async function createThing (dht: boolean): Promise<{ libp2pNode: Libp2p<{ dht: DualKadDHT }>, bitswap: DefaultBitswap }> {
2121
const libp2pNode = await createLibp2pNode({
2222
DHT: dht
2323
})
@@ -167,7 +167,7 @@ describe('bitswap without DHT', function () {
167167
describe('bitswap with DHT', function () {
168168
this.timeout(60 * 1000)
169169

170-
let nodes: Array<{ libp2pNode: Libp2p, bitswap: DefaultBitswap }>
170+
let nodes: Array<{ libp2pNode: Libp2p<{ dht: DualKadDHT }>, bitswap: DefaultBitswap }>
171171

172172
before(async () => {
173173
nodes = await Promise.all([
@@ -184,13 +184,6 @@ describe('bitswap with DHT', function () {
184184
nodes[0].libp2pNode.dial(ma1),
185185
nodes[1].libp2pNode.dial(ma2)
186186
])
187-
188-
// wait until dht routing tables are updated
189-
await Promise.all([
190-
pWaitFor(() => nodes[0].libp2pNode.dht?.lan?.routingTable?.size != null && nodes[0].libp2pNode.dht?.lan?.routingTable?.size >= 1),
191-
pWaitFor(() => nodes[1].libp2pNode.dht?.lan?.routingTable?.size != null && nodes[1].libp2pNode.dht?.lan?.routingTable?.size >= 2),
192-
pWaitFor(() => nodes[2].libp2pNode.dht?.lan?.routingTable?.size != null && nodes[2].libp2pNode.dht?.lan?.routingTable?.size >= 1)
193-
])
194187
})
195188

196189
after(async () => {
@@ -203,11 +196,11 @@ describe('bitswap with DHT', function () {
203196
it('put a block in 2, get it in 0', async () => {
204197
const [block] = await makeBlocks(1)
205198

206-
if (nodes[2].libp2pNode.dht == null) {
199+
if (nodes[2].libp2pNode.services.dht == null) {
207200
throw new Error('DHT was not configured')
208201
}
209202

210-
const provideSpy = sinon.spy(nodes[2].libp2pNode.dht, 'provide')
203+
const provideSpy = sinon.spy(nodes[2].libp2pNode.services.dht, 'provide')
211204
await nodes[2].bitswap.put(block.cid, block.block)
212205

213206
// wait for the DHT to finish providing

test/network/network.node.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ describe('network', () => {
104104
})
105105

106106
it('connectTo success', async () => {
107-
await p2pA.peerStore.addressBook.add(p2pB.peerId, p2pB.getMultiaddrs())
107+
await p2pA.peerStore.merge(p2pB.peerId, {
108+
multiaddrs: p2pB.getMultiaddrs()
109+
})
108110
await networkA.connectTo(p2pB.peerId)
109111
})
110112

@@ -200,7 +202,9 @@ describe('network', () => {
200202

201203
// In a real network scenario, peers will be discovered and their addresses
202204
// will be added to the addressBook before bitswap kicks in
203-
await p2pA.peerStore.addressBook.set(p2pB.peerId, p2pB.getMultiaddrs())
205+
await p2pA.peerStore.patch(p2pB.peerId, {
206+
multiaddrs: p2pB.getMultiaddrs()
207+
})
204208

205209
bitswapMockB._receiveMessage = async (peerId, msgReceived) => { // eslint-disable-line require-await
206210
// cannot do deep comparison on objects as one has Buffers and one has Uint8Arrays
@@ -236,7 +240,9 @@ describe('network', () => {
236240

237241
// In a real network scenario, peers will be discovered and their addresses
238242
// will be added to the addressBook before bitswap kicks in
239-
await p2pA.peerStore.addressBook.set(p2pC.peerId, p2pC.getMultiaddrs())
243+
await p2pA.peerStore.patch(p2pC.peerId, {
244+
multiaddrs: p2pC.getMultiaddrs()
245+
})
240246

241247
bitswapMockC._receiveMessage = async (peerId, msgReceived) => { // eslint-disable-line require-await
242248
// cannot do deep comparison on objects as one has Buffers and one has Uint8Arrays
@@ -265,7 +271,9 @@ describe('network', () => {
265271

266272
// In a real network scenario, peers will be discovered and their addresses
267273
// will be added to the addressBook before bitswap kicks in
268-
await p2pA.peerStore.addressBook.set(p2pB.peerId, p2pB.getMultiaddrs())
274+
await p2pA.peerStore.patch(p2pB.peerId, {
275+
multiaddrs: p2pB.getMultiaddrs()
276+
})
269277

270278
const deferred = pDefer()
271279

test/utils/create-libp2p-node.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11

22
import { noise } from '@chainsafe/libp2p-noise'
3-
import { kadDHT } from '@libp2p/kad-dht'
3+
import { type DualKadDHT, kadDHT } from '@libp2p/kad-dht'
44
import { mplex } from '@libp2p/mplex'
55
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
66
import { tcp } from '@libp2p/tcp'
77
// @ts-expect-error no types
88
import defaultsDeep from '@nodeutils/defaults-deep'
99
import { createLibp2p, type Libp2pOptions } from 'libp2p'
10-
import type { Libp2p } from '@libp2p/interface-libp2p'
10+
import { identifyService } from 'libp2p/identify'
11+
import type { Libp2p, ServiceMap } from '@libp2p/interface-libp2p'
1112

1213
export interface NodeOptions extends Libp2pOptions {
1314
DHT?: boolean
1415
}
1516

16-
export async function createLibp2pNode (options: NodeOptions = {}): Promise<Libp2p> {
17-
const node = await createLibp2p(defaultsDeep({
17+
export async function createLibp2pNode (options: NodeOptions = {}): Promise<Libp2p<{ dht: DualKadDHT }>> {
18+
const services: ServiceMap = {
19+
identify: identifyService()
20+
}
21+
22+
if (options.DHT === true) {
23+
services.dht = kadDHT({
24+
clientMode: false
25+
})
26+
}
27+
28+
const node = await createLibp2p<{ dht: DualKadDHT }>(defaultsDeep({
1829
peerId: await createEd25519PeerId(),
1930
addresses: {
2031
listen: ['/ip4/0.0.0.0/tcp/0']
@@ -28,11 +39,7 @@ export async function createLibp2pNode (options: NodeOptions = {}): Promise<Libp
2839
connectionEncryption: [
2940
noise()
3041
],
31-
dht: options.DHT === true
32-
? kadDHT({
33-
clientMode: false
34-
})
35-
: undefined
42+
services
3643
}, options))
3744

3845
await node.start()

test/utils/mocks.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,7 @@ export const genBitswapNetwork = async (n: number, enableDHT: boolean = false):
151151
peers.map(async (peerId, i) => {
152152
const libp2p = await createLibp2pNode({
153153
peerId,
154-
DHT: enableDHT,
155-
nat: {
156-
enabled: false
157-
}
154+
DHT: enableDHT
158155
})
159156

160157
await libp2p.start()
@@ -180,7 +177,9 @@ export const genBitswapNetwork = async (n: number, enableDHT: boolean = false):
180177

181178
const netB = netArray[j]
182179

183-
await netA.libp2p.peerStore.addressBook.set(netB.libp2p.peerId, netB.libp2p.getMultiaddrs())
180+
await netA.libp2p.peerStore.patch(netB.libp2p.peerId, {
181+
multiaddrs: netB.libp2p.getMultiaddrs()
182+
})
184183
}
185184
}
186185

0 commit comments

Comments
 (0)