Skip to content

Commit

Permalink
deps!: update multiformats to v11
Browse files Browse the repository at this point in the history
`[email protected]` shipped with a [breaking change](multiformats/js-multiformats#230) so update all deps using multiformats to
the latest version.
  • Loading branch information
achingbrain committed Jan 7, 2023
1 parent cea4404 commit 4910ba8
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 104 deletions.
44 changes: 4 additions & 40 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,42 +1,6 @@
# While testing new npm
package-lock.json
yarn.lock

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
.nyc_output/

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

dist

test/test-repo-for*
docs

test/test-repo/datastore

*.flamegraph
types
.docs
.coverage
package-lock.json
yarn.lock
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# ipfs-bitswap <!-- omit in toc -->

[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)
[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)
[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs-bitswap.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs-bitswap)
[![CI](https://img.shields.io/github/workflow/status/ipfs/js-ipfs-bitswap/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs-bitswap/actions/workflows/js-test-and-release.yml)
[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-ipfs-bitswap/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/ipfs/js-ipfs-bitswap/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)

> JavaScript implementation of the Bitswap data exchange protocol used by IPFS
## Table of contents <!-- omit in toc -->

- [Install](#install)
- [Browser `<script>` tag](#browser-script-tag)
- [Use in Node.js or in the browser with browserify, webpack or any other bundler](#use-in-nodejs-or-in-the-browser-with-browserify-webpack-or-any-other-bundler)
- [Use in a browser using a script tag](#use-in-a-browser-using-a-script-tag)
- [API](#api)
Expand All @@ -22,6 +22,7 @@
- [Structure](#structure)
- [Performance tests](#performance-tests)
- [Profiling](#profiling)
- [API Docs](#api-docs)
- [License](#license)
- [Contribute](#contribute)

Expand All @@ -31,6 +32,14 @@
$ npm i ipfs-bitswap
```

### Browser `<script>` tag

Loading this module through a script tag will make it's exports available as `IpfsBitswap` in the global namespace.

```html
<script src="https://unpkg.com/ipfs-bitswap/dist/index.min.js"></script>
```

```bash
> npm install ipfs-bitswap
```
Expand All @@ -43,14 +52,6 @@ const { createBitswap } from 'ipfs-bitswap'

### Use in a browser using a script tag

Loading this module through a script tag will make the `IpfsBitswap` object available in the global namespace.

```html
<script src="https://unpkg.com/ipfs-bitswap/dist/index.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/ipfs-bitswap/dist/index.js"></script>
```

## API

See <https://ipfs.github.io/js-ipfs-bitswap>
Expand Down Expand Up @@ -199,6 +200,10 @@ Use the browser Chrome to open and inspect the generated graph.

![Flame graph](https://ipfs.io/ipfs/QmVbyLgYfkLewNtzTAFwAEMmP2hTJgs8sSqsRTBNBjyQ1y)

## API Docs

- <https://ipfs.github.io/js-ipfs-bitswap>

## License

Licensed under either of
Expand Down
27 changes: 13 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,26 @@
"dep-check": "aegir dep-check -i rimraf",
"generate": "run-s generate:*",
"generate:proto": "pbjs -t static-module -w es6 -r ipfs-bitswap --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/message/message.js src/message/message.proto",
"generate:proto-types": "pbts -o src/message/message.d.ts src/message/message.js"
"generate:proto-types": "pbts -o src/message/message.d.ts src/message/message.js",
"docs": "aegir docs"
},
"dependencies": {
"@libp2p/interface-connection": "^3.0.1",
"@libp2p/interface-peer-id": "^1.0.4",
"@libp2p/interface-peer-id": "^2.0.0",
"@libp2p/interface-peer-store": "^1.2.0",
"@libp2p/topology": "^3.0.0",
"@libp2p/logger": "^2.0.5",
"@libp2p/topology": "^4.0.0",
"@libp2p/tracked-map": "^3.0.0",
"@multiformats/multiaddr": "^11.0.0",
"@vascosantos/moving-average": "^1.1.0",
"abortable-iterator": "^4.0.2",
"any-signal": "^3.0.0",
"blockstore-core": "^2.0.1",
"debug": "^4.2.0",
"err-code": "^3.0.1",
"interface-blockstore": "^3.0.0",
"blockstore-core": "^3.0.0",
"interface-blockstore": "^4.0.0",
"it-length-prefixed": "^8.0.2",
"it-pipe": "^2.0.4",
"just-debounce-it": "^3.0.1",
"multiformats": "^10.0.1",
"multiformats": "^11.0.0",
"protobufjs": "^7.0.0",
"readable-stream": "^4.0.0",
"timeout-abort-controller": "^3.0.0",
Expand All @@ -191,16 +191,15 @@
},
"devDependencies": {
"@chainsafe/libp2p-noise": "^10.0.1",
"@libp2p/kad-dht": "^6.0.0",
"@libp2p/kad-dht": "^7.0.0",
"@libp2p/mplex": "^7.0.0",
"@libp2p/peer-id": "^1.1.8",
"@libp2p/peer-id-factory": "^1.0.8",
"@libp2p/peer-id": "^2.0.0",
"@libp2p/peer-id-factory": "^2.0.0",
"@libp2p/tcp": "^6.0.0",
"@nodeutils/defaults-deep": "^1.1.0",
"@types/debug": "^4.1.5",
"@types/stats-lite": "^2.2.0",
"@types/varint": "^6.0.0",
"aegir": "^37.0.4",
"aegir": "^37.10.0",
"assert": "^2.0.0",
"benchmark": "^2.1.4",
"delay": "^5.0.0",
Expand All @@ -221,7 +220,7 @@
"promisify-es6": "^1.0.3",
"protobufjs-cli": "^1.0.0",
"rimraf": "^3.0.2",
"sinon": "^14.0.0",
"sinon": "^15.0.1",
"stats-lite": "^2.2.0",
"url": "^0.11.0",
"util": "^0.12.3",
Expand Down
2 changes: 1 addition & 1 deletion src/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const statsKeys = [
*/
export class Bitswap extends BaseBlockstore {
/**
* @param {import('libp2p').Libp2p} libp2p
* @param {import('@libp2p/interface-libp2p').Libp2p} libp2p
* @param {Blockstore} blockstore
* @param {object} [options]
* @param {boolean} [options.statsEnabled=false]
Expand Down
2 changes: 1 addition & 1 deletion src/decision-engine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class DecisionEngine {
* @param {import('interface-blockstore').Blockstore} blockstore
* @param {import('../network').Network} network
* @param {import('../stats').Stats} stats
* @param {import('libp2p').Libp2p} libp2p
* @param {import('@libp2p/interface-libp2p').Libp2p} libp2p
* @param {object} [opts]
* @param {number} [opts.targetMessageSize]
* @param {number} [opts.maxSizeReplaceHasWithBlock]
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Bitswap } from './bitswap.js'
*/

/**
* @param {import('libp2p').Libp2p} libp2p
* @param {import('@libp2p/interface-libp2p').Libp2p} libp2p
* @param {Blockstore} blockstore
* @param {object} [options]
* @param {boolean} [options.statsEnabled=false]
Expand Down
4 changes: 2 additions & 2 deletions src/message/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ve from '../utils/varint-encoder.js'
import { isMapEqual } from '../utils/index.js'
import { Message } from './message.js'
import { BitswapMessageEntry as Entry } from './entry.js'
import errcode from 'err-code'
import { CodeError } from '@libp2p/interfaces/errors'

/**
* @typedef {import('../types').MultihashHasherLoader} MultihashHasherLoader
Expand Down Expand Up @@ -291,7 +291,7 @@ BitswapMessage.deserialize = async (raw, hashLoader) => {
const hasher = hashAlg === sha256.code ? sha256 : hashLoader && await hashLoader.getHasher(hashAlg)

if (!hasher) {
throw errcode(new Error('Unknown hash algorithm'), 'ERR_UNKNOWN_HASH_ALG')
throw new CodeError('Unknown hash algorithm', 'ERR_UNKNOWN_HASH_ALG')
}

// const hashLen = values[3] // We haven't need to use this so far
Expand Down
6 changes: 3 additions & 3 deletions src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const DEFAULT_INCOMING_STREAM_TIMEOUT = 30000

export class Network {
/**
* @param {import('libp2p').Libp2p} libp2p
* @param {import('@libp2p/interface-libp2p').Libp2p} libp2p
* @param {import('./bitswap').Bitswap} bitswap
* @param {import('./stats').Stats} stats
* @param {object} [options]
Expand Down Expand Up @@ -84,7 +84,7 @@ export class Network {
this._registrarIds = []

for (const protocol of this._protocols) {
this._registrarIds.push(await this._libp2p.registrar.register(protocol, topology))
this._registrarIds.push(await this._libp2p.register(protocol, topology))
}

// All existing connections are like new ones for us
Expand All @@ -102,7 +102,7 @@ export class Network {
// unregister protocol and handlers
if (this._registrarIds != null) {
for (const id of this._registrarIds) {
this._libp2p.registrar.unregister(id)
this._libp2p.unregister(id)
}

this._registrarIds = []
Expand Down
2 changes: 1 addition & 1 deletion src/stats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const defaultOptions = {

export class Stats extends EventEmitter {
/**
* @param {import('libp2p').Libp2p} libp2p
* @param {import('@libp2p/interface-libp2p').Libp2p} libp2p
* @param {string[]} [initialCounters]
* @param {object} _options
* @param {boolean} _options.enabled
Expand Down
6 changes: 2 additions & 4 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import debug from 'debug'
import { logger as createLogger } from '@libp2p/logger'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import { BitswapMessageEntry } from '../message/entry.js'

Expand All @@ -17,9 +17,7 @@ export const logger = (id, subsystem) => {
name.push(`${id.toString().slice(0, 8)}`)
}

return Object.assign(debug(name.join(':')), {
error: debug(name.concat(['error']).join(':'))
})
return createLogger(name.join(':'))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/want-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class WantManager {
* @param {PeerId} peerId
* @param {import('../network').Network} network
* @param {import('../stats').Stats} stats
* @param {import('libp2p').Libp2p} libp2p
* @param {import('@libp2p/interface-libp2p').Libp2p} libp2p
*/
constructor (peerId, network, stats, libp2p) {
/** @type {Map<string, MsgQueue>} */
Expand Down
2 changes: 1 addition & 1 deletion src/wantlist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const sortBy = (fn, list) => {
export class Wantlist {
/**
* @param {import('../stats').Stats} [stats]
* @param {import('libp2p').Libp2p} [libp2p]
* @param {import('@libp2p/interface-libp2p').Libp2p} [libp2p]
*/
constructor (stats, libp2p) {
/** @type {Map<string, Entry>} */
Expand Down
2 changes: 1 addition & 1 deletion test/bitswap-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { makeBlocks } from './utils/make-blocks.js'
import { makePeerIds } from './utils/make-peer-id.js'

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

Expand Down
8 changes: 3 additions & 5 deletions test/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { BitswapMessage as Message } from '../src/message/index.js'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'

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

/**
Expand All @@ -34,10 +34,8 @@ describe('start/stop', () => {
const libp2p = {
handle: () => {},
unhandle: () => {},
registrar: {
register: () => {},
unregister: () => {}
},
register: () => {},
unregister: () => {},
getConnections: () => []
}
// @ts-ignore not a full libp2p
Expand Down
14 changes: 5 additions & 9 deletions test/network/network.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { CID } from 'multiformats/cid'
import delay from 'delay'

/**
* @typedef {import('libp2p').Libp2p} Libp2p
* @typedef {import('@libp2p/interface-libp2p').Libp2p} Libp2p
* @typedef {import('../../src/bitswap').Bitswap} Bitswap
*/

Expand Down Expand Up @@ -304,11 +304,8 @@ describe('network', () => {
contentRouting: {
findProviders: mockFindProviders
},
// @ts-expect-error incomplete implementation
registrar: {
register: sinon.stub(),
unregister: sinon.stub()
},
register: sinon.stub(),
unregister: sinon.stub(),
getConnections: () => [],
dial: mockDial,
handle: sinon.stub()
Expand Down Expand Up @@ -345,9 +342,8 @@ describe('network', () => {

const libp2p = {
handle: sinon.stub(),
registrar: {
register: sinon.stub()
},
register: sinon.stub(),
unregister: sinon.stub(),
getConnections: () => []
}

Expand Down
2 changes: 1 addition & 1 deletion test/utils/create-libp2p-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import defaultsDeep from '@nodeutils/defaults-deep'

/**
* @typedef {import('libp2p').Libp2p} Libp2p
* @typedef {import('@libp2p/interface-libp2p').Libp2p} Libp2p
* @typedef {import('libp2p').Libp2pOptions & { DHT?: boolean}} NodeOptions
*/

Expand Down
2 changes: 1 addition & 1 deletion test/utils/distribution-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { connectAll } from './connect-all.js'
import all from 'it-all'

/**
* @typedef {import('libp2p').Libp2p} Libp2p
* @typedef {import('@libp2p/interface-libp2p').Libp2p} Libp2p
* @typedef {import('../../src/types').IPFSBitswap} Bitswap
*/

Expand Down
Loading

0 comments on commit 4910ba8

Please sign in to comment.