Skip to content

Commit eaf862a

Browse files
authored
fix: add missing events dep (#548)
This module uses the node events api so include a polyfill for non-node environments like the browser.
1 parent 83a06ba commit eaf862a

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

package.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,19 @@
172172
"@libp2p/logger": "^2.0.5",
173173
"@libp2p/topology": "^4.0.0",
174174
"@libp2p/tracked-map": "^3.0.0",
175-
"@multiformats/multiaddr": "^11.0.0",
175+
"@multiformats/multiaddr": "^12.1.0",
176176
"@vascosantos/moving-average": "^1.1.0",
177177
"abortable-iterator": "^4.0.2",
178178
"any-signal": "^3.0.0",
179179
"blockstore-core": "^4.0.0",
180+
"events": "^3.3.0",
180181
"interface-blockstore": "^5.0.0",
181-
"it-length-prefixed": "^8.0.2",
182-
"it-map": "^2.0.1",
183-
"it-pipe": "^2.0.4",
184-
"it-take": "^2.0.1",
182+
"interface-store": "^5.1.0",
183+
"it-foreach": "^2.0.2",
184+
"it-length-prefixed": "^9.0.0",
185+
"it-map": "^3.0.2",
186+
"it-pipe": "^3.0.1",
187+
"it-take": "^3.0.1",
185188
"just-debounce-it": "^3.0.1",
186189
"multiformats": "^11.0.0",
187190
"progress-events": "^1.0.0",
@@ -194,7 +197,7 @@
194197
},
195198
"devDependencies": {
196199
"@chainsafe/libp2p-noise": "^11.0.0",
197-
"@libp2p/kad-dht": "^7.0.0",
200+
"@libp2p/kad-dht": "^8.0.6",
198201
"@libp2p/mplex": "^7.0.0",
199202
"@libp2p/peer-id": "^2.0.0",
200203
"@libp2p/peer-id-factory": "^2.0.0",
@@ -206,9 +209,9 @@
206209
"benchmark": "^2.1.4",
207210
"delay": "^5.0.0",
208211
"iso-random-stream": "^2.0.0",
209-
"it-all": "^2.0.0",
210-
"it-drain": "^2.0.0",
211-
"libp2p": "^0.42.0",
212+
"it-all": "^3.0.1",
213+
"it-drain": "^3.0.1",
214+
"libp2p": "^0.43.3",
212215
"lodash.difference": "^4.5.0",
213216
"lodash.flatten": "^4.4.0",
214217
"lodash.range": "^3.2.0",

src/bitswap.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import { logger } from './utils/index.js'
66
import { Stats } from './stats/index.js'
77
import { anySignal } from 'any-signal'
88
import { CID } from 'multiformats/cid'
9+
import forEach from 'it-foreach'
910
import type { BitswapOptions, Bitswap, MultihashHasherLoader, WantListEntry, BitswapWantProgressEvents, BitswapNotifyProgressEvents } from './index.js'
1011
import type { Libp2p } from '@libp2p/interface-libp2p'
11-
import type { Blockstore, Options, Pair } from 'interface-blockstore'
12+
import type { Blockstore, Pair } from 'interface-blockstore'
1213
import type { Logger } from '@libp2p/logger'
1314
import type { PeerId } from '@libp2p/interface-peer-id'
1415
import type { BitswapMessage } from './message/index.js'
1516
import type { AbortOptions } from '@multiformats/multiaddr'
1617
import type { ProgressOptions } from 'progress-events'
18+
import type { AwaitIterable } from 'interface-store'
1719

1820
const hashLoader: MultihashHasherLoader = {
1921
async getHasher () {
@@ -318,12 +320,10 @@ export class DefaultBitswap implements Bitswap {
318320
* Put the given blocks to the underlying blockstore and
319321
* send it to nodes that have it them their wantlist.
320322
*/
321-
async * putMany (source: Iterable<Pair> | AsyncIterable<Pair>, options?: Options): AsyncGenerator<Pair> {
322-
for await (const { cid, block } of this.blockstore.putMany(source, options)) {
323+
async * putMany (source: Iterable<Pair> | AsyncIterable<Pair>, options?: AbortOptions): AwaitIterable<CID> {
324+
yield * this.blockstore.putMany(forEach(source, ({ cid, block }) => {
323325
this.notify(cid, block)
324-
325-
yield { cid, block }
326-
}
326+
}), options)
327327
}
328328

329329
/**

src/network.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class Network {
157157

158158
await pipe(
159159
abortableSource(stream.source, controller.signal),
160-
lp.decode(),
160+
(source) => lp.decode(source),
161161
async (source) => {
162162
for await (const data of source) {
163163
try {
@@ -287,7 +287,7 @@ export class Network {
287287

288288
await pipe(
289289
[serialized],
290-
lp.encode(),
290+
(source) => lp.encode(source),
291291
stream
292292
)
293293
} catch (err: any) {

test/bitswap-mock-internals.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/* eslint max-nested-callbacks: ["error", 5] */
33

44
import { expect } from 'aegir/chai'
5-
import all from 'it-all'
65
import drain from 'it-drain'
76
import { BitswapMessage as Message } from '../src/message/index.js'
87
import { DefaultBitswap } from '../src/bitswap.js'
@@ -230,7 +229,7 @@ describe('bitswap with mocks', function () {
230229
await drain(blockstore.putMany([{ cid: b1.cid, block: b1.block }, { cid: b2.cid, block: b2.block }, { cid: b3.cid, block: b3.block }]))
231230
const bs = new DefaultBitswap(mockLibp2pNode(), blockstore)
232231

233-
const retrievedBlocks = await all(
232+
const retrievedBlocks = await Promise.all(
234233
[b1.cid, b2.cid, b3.cid].map(async cid => await bs.want(cid))
235234
)
236235

test/network/network.node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ describe('network', () => {
179179

180180
await pipe(
181181
[version.serialize(msg)],
182-
lp.encode(),
182+
(source) => lp.encode(source),
183183
stream
184184
)
185185

test/utils/distribution-test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { expect } from 'aegir/chai'
66
import { createBitswap } from './create-bitswap.js'
77
import { makeBlocks } from './make-blocks.js'
88
import { connectAll } from './connect-all.js'
9-
import all from 'it-all'
109
import type { BitswapNode } from './mocks.js'
1110

1211
export const distributionTest = async (instanceCount: number, blockCount: number, repeats: number, events: any): Promise<void> => {
@@ -35,7 +34,7 @@ export const distributionTest = async (instanceCount: number, blockCount: number
3534

3635
const cids = blocks.map((block) => block.cid)
3736
const start = Date.now()
38-
const result = await all(cids.map(async cid => await node.bitswap.want(cid)))
37+
const result = await Promise.all(cids.map(async cid => await node.bitswap.want(cid)))
3938
const elapsed = Date.now() - start
4039
events.emit('got block', elapsed)
4140

@@ -46,8 +45,7 @@ export const distributionTest = async (instanceCount: number, blockCount: number
4645
try {
4746
expect(results).have.lengthOf(instanceCount)
4847

49-
for (const result of results) {
50-
const nodeBlocks = await all(result)
48+
for (const nodeBlocks of results) {
5149
expect(nodeBlocks).to.have.lengthOf(blocks.length)
5250
nodeBlocks.forEach((block, i) => {
5351
expect(block).to.deep.equal(blocks[i].block)

0 commit comments

Comments
 (0)