Skip to content

fix: add missing events dep #548

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
Apr 4, 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
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,19 @@
"@libp2p/logger": "^2.0.5",
"@libp2p/topology": "^4.0.0",
"@libp2p/tracked-map": "^3.0.0",
"@multiformats/multiaddr": "^11.0.0",
"@multiformats/multiaddr": "^12.1.0",
"@vascosantos/moving-average": "^1.1.0",
"abortable-iterator": "^4.0.2",
"any-signal": "^3.0.0",
"blockstore-core": "^4.0.0",
"events": "^3.3.0",
"interface-blockstore": "^5.0.0",
"it-length-prefixed": "^8.0.2",
"it-map": "^2.0.1",
"it-pipe": "^2.0.4",
"it-take": "^2.0.1",
"interface-store": "^5.1.0",
"it-foreach": "^2.0.2",
"it-length-prefixed": "^9.0.0",
"it-map": "^3.0.2",
"it-pipe": "^3.0.1",
"it-take": "^3.0.1",
"just-debounce-it": "^3.0.1",
"multiformats": "^11.0.0",
"progress-events": "^1.0.0",
Expand All @@ -194,7 +197,7 @@
},
"devDependencies": {
"@chainsafe/libp2p-noise": "^11.0.0",
"@libp2p/kad-dht": "^7.0.0",
"@libp2p/kad-dht": "^8.0.6",
"@libp2p/mplex": "^7.0.0",
"@libp2p/peer-id": "^2.0.0",
"@libp2p/peer-id-factory": "^2.0.0",
Expand All @@ -206,9 +209,9 @@
"benchmark": "^2.1.4",
"delay": "^5.0.0",
"iso-random-stream": "^2.0.0",
"it-all": "^2.0.0",
"it-drain": "^2.0.0",
"libp2p": "^0.42.0",
"it-all": "^3.0.1",
"it-drain": "^3.0.1",
"libp2p": "^0.43.3",
"lodash.difference": "^4.5.0",
"lodash.flatten": "^4.4.0",
"lodash.range": "^3.2.0",
Expand Down
12 changes: 6 additions & 6 deletions src/bitswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import { logger } from './utils/index.js'
import { Stats } from './stats/index.js'
import { anySignal } from 'any-signal'
import { CID } from 'multiformats/cid'
import forEach from 'it-foreach'
import type { BitswapOptions, Bitswap, MultihashHasherLoader, WantListEntry, BitswapWantProgressEvents, BitswapNotifyProgressEvents } from './index.js'
import type { Libp2p } from '@libp2p/interface-libp2p'
import type { Blockstore, Options, Pair } from 'interface-blockstore'
import type { Blockstore, Pair } from 'interface-blockstore'
import type { Logger } from '@libp2p/logger'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { BitswapMessage } from './message/index.js'
import type { AbortOptions } from '@multiformats/multiaddr'
import type { ProgressOptions } from 'progress-events'
import type { AwaitIterable } from 'interface-store'

const hashLoader: MultihashHasherLoader = {
async getHasher () {
Expand Down Expand Up @@ -318,12 +320,10 @@ export class DefaultBitswap implements Bitswap {
* Put the given blocks to the underlying blockstore and
* send it to nodes that have it them their wantlist.
*/
async * putMany (source: Iterable<Pair> | AsyncIterable<Pair>, options?: Options): AsyncGenerator<Pair> {
for await (const { cid, block } of this.blockstore.putMany(source, options)) {
async * putMany (source: Iterable<Pair> | AsyncIterable<Pair>, options?: AbortOptions): AwaitIterable<CID> {
yield * this.blockstore.putMany(forEach(source, ({ cid, block }) => {
this.notify(cid, block)

yield { cid, block }
}
}), options)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class Network {

await pipe(
abortableSource(stream.source, controller.signal),
lp.decode(),
(source) => lp.decode(source),
async (source) => {
for await (const data of source) {
try {
Expand Down Expand Up @@ -287,7 +287,7 @@ export class Network {

await pipe(
[serialized],
lp.encode(),
(source) => lp.encode(source),
stream
)
} catch (err: any) {
Expand Down
3 changes: 1 addition & 2 deletions test/bitswap-mock-internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/* eslint max-nested-callbacks: ["error", 5] */

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

const retrievedBlocks = await all(
const retrievedBlocks = await Promise.all(
[b1.cid, b2.cid, b3.cid].map(async cid => await bs.want(cid))
)

Expand Down
2 changes: 1 addition & 1 deletion test/network/network.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe('network', () => {

await pipe(
[version.serialize(msg)],
lp.encode(),
(source) => lp.encode(source),
stream
)

Expand Down
6 changes: 2 additions & 4 deletions test/utils/distribution-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { expect } from 'aegir/chai'
import { createBitswap } from './create-bitswap.js'
import { makeBlocks } from './make-blocks.js'
import { connectAll } from './connect-all.js'
import all from 'it-all'
import type { BitswapNode } from './mocks.js'

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

const cids = blocks.map((block) => block.cid)
const start = Date.now()
const result = await all(cids.map(async cid => await node.bitswap.want(cid)))
const result = await Promise.all(cids.map(async cid => await node.bitswap.want(cid)))
const elapsed = Date.now() - start
events.emit('got block', elapsed)

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

for (const result of results) {
const nodeBlocks = await all(result)
for (const nodeBlocks of results) {
expect(nodeBlocks).to.have.lengthOf(blocks.length)
nodeBlocks.forEach((block, i) => {
expect(block).to.deep.equal(blocks[i].block)
Expand Down