Skip to content

Commit 09d4ff9

Browse files
authored
deps!: update multiformats to v11 (#509)
`multiformats@11.x.x` shipped with a [breaking change](multiformats/js-multiformats#230) so update all deps using multiformats to the latest version.
1 parent cea4404 commit 09d4ff9

18 files changed

+65
-156
lines changed

.gitignore

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,6 @@
1-
# While testing new npm
2-
package-lock.json
3-
yarn.lock
4-
5-
# Logs
6-
logs
7-
*.log
8-
9-
# Runtime data
10-
pids
11-
*.pid
12-
*.seed
13-
14-
# Directory for instrumented libs generated by jscoverage/JSCover
15-
lib-cov
16-
17-
# Coverage directory used by tools like istanbul
18-
coverage
19-
.nyc_output/
20-
21-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
22-
.grunt
23-
24-
# node-waf configuration
25-
.lock-wscript
26-
27-
# Compiled binary addons (http://nodejs.org/api/addons.html)
28-
build/Release
29-
30-
# Dependency directory
31-
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
321
node_modules
33-
342
dist
35-
36-
test/test-repo-for*
37-
docs
38-
39-
test/test-repo/datastore
40-
41-
*.flamegraph
42-
types
3+
.docs
4+
.coverage
5+
package-lock.json
6+
yarn.lock

README.md

Lines changed: 19 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
# ipfs-bitswap <!-- omit in toc -->
22

3-
[![ipfs.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io)
4-
[![IRC](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
5-
[![Discord](https://img.shields.io/discord/806902334369824788?style=flat-square)](https://discord.gg/ipfs)
3+
[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
4+
[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
65
[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs-bitswap.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs-bitswap)
7-
[![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)
6+
[![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)
87

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

1312
- [Install](#install)
14-
- [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)
15-
- [Use in a browser using a script tag](#use-in-a-browser-using-a-script-tag)
16-
- [API](#api)
17-
- [Stats](#stats)
18-
- [Peer accessor:](#peer-accessor)
19-
- [Global snapshot accessor:](#global-snapshot-accessor)
20-
- [Moving average accessor:](#moving-average-accessor)
21-
- [Development](#development)
22-
- [Structure](#structure)
13+
- [Browser `<script>` tag](#browser-script-tag)
14+
- [Stats](#stats)
15+
- [Peer accessor:](#peer-accessor)
16+
- [Global snapshot accessor:](#global-snapshot-accessor)
17+
- [Moving average accessor:](#moving-average-accessor)
2318
- [Performance tests](#performance-tests)
2419
- [Profiling](#profiling)
20+
- [API Docs](#api-docs)
2521
- [License](#license)
2622
- [Contribute](#contribute)
2723

@@ -31,31 +27,15 @@
3127
$ npm i ipfs-bitswap
3228
```
3329

34-
```bash
35-
> npm install ipfs-bitswap
36-
```
37-
38-
### Use in Node.js or in the browser with browserify, webpack or any other bundler
39-
40-
```js
41-
const { createBitswap } from 'ipfs-bitswap'
42-
```
43-
44-
### Use in a browser using a script tag
30+
### Browser `<script>` tag
4531

46-
Loading this module through a script tag will make the `IpfsBitswap` object available in the global namespace.
32+
Loading this module through a script tag will make it's exports available as `IpfsBitswap` in the global namespace.
4733

4834
```html
4935
<script src="https://unpkg.com/ipfs-bitswap/dist/index.min.js"></script>
50-
<!-- OR -->
51-
<script src="https://unpkg.com/ipfs-bitswap/dist/index.js"></script>
5236
```
5337

54-
## API
55-
56-
See <https://ipfs.github.io/js-ipfs-bitswap>
57-
58-
### Stats
38+
## Stats
5939

6040
```js
6141
const bitswapNode = // ...
@@ -73,7 +53,7 @@ stats.on('update', (stats) => {
7353
})
7454
```
7555

76-
#### Peer accessor:
56+
### Peer accessor:
7757

7858
You can get the stats for a specific peer by doing:
7959

@@ -83,7 +63,7 @@ const peerStats = stats.forPeer(peerId)
8363

8464
The returned object behaves like the root stats accessor (has a snapshot, a moving average accessors and is an event emitter).
8565

86-
#### Global snapshot accessor:
66+
### Global snapshot accessor:
8767

8868
```js
8969
const snapshot = stats.snapshot
@@ -107,7 +87,7 @@ the snapshot will contain the following keys, with the values being [bignumber.j
10787
// }
10888
```
10989

110-
#### Moving average accessor:
90+
### Moving average accessor:
11191

11292
```js
11393
const movingAverages = stats.movingAverages
@@ -143,35 +123,6 @@ const oneMinuteDataReceivedMovingAverages = dataReceivedMovingAverages[60000]
143123

144124
This object will be a [movingAverage](https://github.com/pgte/moving-average#readme) instance.
145125

146-
## Development
147-
148-
### Structure
149-
150-
![](/img/architecture.png)
151-
152-
```sh
153-
» tree src
154-
src
155-
├── constants.js
156-
├── decision-engine
157-
│ ├── index.js
158-
│ └── ledger.js
159-
├── index.js
160-
├── network.js # Handles peerSet and open new conns
161-
├── notifications.js # Handles tracking of incomning blocks and wants/unwants.
162-
├─── want-manager # Keeps track of all blocks the peer (self) wants
163-
│ ├── index.js
164-
│ └── msg-queue.js # Messages to send queue, one per peer
165-
└─── types
166-
├── message # (Type) message that is put in the wire
167-
│ ├── entry.js
168-
│ ├── index.js
169-
│ └── message.proto.js
170-
└── wantlist # (Type) track wanted blocks
171-
├── entry.js
172-
└── index.js
173-
```
174-
175126
## Performance tests
176127

177128
You can run performance tests like this:
@@ -199,6 +150,10 @@ Use the browser Chrome to open and inspect the generated graph.
199150

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

153+
## API Docs
154+
155+
- <https://ipfs.github.io/js-ipfs-bitswap>
156+
202157
## License
203158

204159
Licensed under either of

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -162,26 +162,27 @@
162162
"dep-check": "aegir dep-check -i rimraf",
163163
"generate": "run-s generate:*",
164164
"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",
165-
"generate:proto-types": "pbts -o src/message/message.d.ts src/message/message.js"
165+
"generate:proto-types": "pbts -o src/message/message.d.ts src/message/message.js",
166+
"docs": "aegir docs"
166167
},
167168
"dependencies": {
168169
"@libp2p/interface-connection": "^3.0.1",
169-
"@libp2p/interface-peer-id": "^1.0.4",
170+
"@libp2p/interface-peer-id": "^2.0.0",
170171
"@libp2p/interface-peer-store": "^1.2.0",
171-
"@libp2p/topology": "^3.0.0",
172+
"@libp2p/interfaces": "^3.2.0",
173+
"@libp2p/logger": "^2.0.5",
174+
"@libp2p/topology": "^4.0.0",
172175
"@libp2p/tracked-map": "^3.0.0",
173176
"@multiformats/multiaddr": "^11.0.0",
174177
"@vascosantos/moving-average": "^1.1.0",
175178
"abortable-iterator": "^4.0.2",
176179
"any-signal": "^3.0.0",
177-
"blockstore-core": "^2.0.1",
178-
"debug": "^4.2.0",
179-
"err-code": "^3.0.1",
180-
"interface-blockstore": "^3.0.0",
180+
"blockstore-core": "^3.0.0",
181+
"interface-blockstore": "^4.0.0",
181182
"it-length-prefixed": "^8.0.2",
182183
"it-pipe": "^2.0.4",
183184
"just-debounce-it": "^3.0.1",
184-
"multiformats": "^10.0.1",
185+
"multiformats": "^11.0.0",
185186
"protobufjs": "^7.0.0",
186187
"readable-stream": "^4.0.0",
187188
"timeout-abort-controller": "^3.0.0",
@@ -191,16 +192,15 @@
191192
},
192193
"devDependencies": {
193194
"@chainsafe/libp2p-noise": "^10.0.1",
194-
"@libp2p/kad-dht": "^6.0.0",
195+
"@libp2p/kad-dht": "^7.0.0",
195196
"@libp2p/mplex": "^7.0.0",
196-
"@libp2p/peer-id": "^1.1.8",
197-
"@libp2p/peer-id-factory": "^1.0.8",
197+
"@libp2p/peer-id": "^2.0.0",
198+
"@libp2p/peer-id-factory": "^2.0.0",
198199
"@libp2p/tcp": "^6.0.0",
199200
"@nodeutils/defaults-deep": "^1.1.0",
200-
"@types/debug": "^4.1.5",
201201
"@types/stats-lite": "^2.2.0",
202202
"@types/varint": "^6.0.0",
203-
"aegir": "^37.0.4",
203+
"aegir": "^37.10.0",
204204
"assert": "^2.0.0",
205205
"benchmark": "^2.1.4",
206206
"delay": "^5.0.0",
@@ -221,7 +221,7 @@
221221
"promisify-es6": "^1.0.3",
222222
"protobufjs-cli": "^1.0.0",
223223
"rimraf": "^3.0.2",
224-
"sinon": "^14.0.0",
224+
"sinon": "^15.0.1",
225225
"stats-lite": "^2.2.0",
226226
"url": "^0.11.0",
227227
"util": "^0.12.3",

src/bitswap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const statsKeys = [
4343
*/
4444
export class Bitswap extends BaseBlockstore {
4545
/**
46-
* @param {import('libp2p').Libp2p} libp2p
46+
* @param {import('@libp2p/interface-libp2p').Libp2p} libp2p
4747
* @param {Blockstore} blockstore
4848
* @param {object} [options]
4949
* @param {boolean} [options.statsEnabled=false]

src/decision-engine/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class DecisionEngine {
3636
* @param {import('interface-blockstore').Blockstore} blockstore
3737
* @param {import('../network').Network} network
3838
* @param {import('../stats').Stats} stats
39-
* @param {import('libp2p').Libp2p} libp2p
39+
* @param {import('@libp2p/interface-libp2p').Libp2p} libp2p
4040
* @param {object} [opts]
4141
* @param {number} [opts.targetMessageSize]
4242
* @param {number} [opts.maxSizeReplaceHasWithBlock]

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Bitswap } from './bitswap.js'
1111
*/
1212

1313
/**
14-
* @param {import('libp2p').Libp2p} libp2p
14+
* @param {import('@libp2p/interface-libp2p').Libp2p} libp2p
1515
* @param {Blockstore} blockstore
1616
* @param {object} [options]
1717
* @param {boolean} [options.statsEnabled=false]

src/message/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ve from '../utils/varint-encoder.js'
77
import { isMapEqual } from '../utils/index.js'
88
import { Message } from './message.js'
99
import { BitswapMessageEntry as Entry } from './entry.js'
10-
import errcode from 'err-code'
10+
import { CodeError } from '@libp2p/interfaces/errors'
1111

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

293293
if (!hasher) {
294-
throw errcode(new Error('Unknown hash algorithm'), 'ERR_UNKNOWN_HASH_ALG')
294+
throw new CodeError('Unknown hash algorithm', 'ERR_UNKNOWN_HASH_ALG')
295295
}
296296

297297
// const hashLen = values[3] // We haven't need to use this so far

src/network.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const DEFAULT_INCOMING_STREAM_TIMEOUT = 30000
3232

3333
export class Network {
3434
/**
35-
* @param {import('libp2p').Libp2p} libp2p
35+
* @param {import('@libp2p/interface-libp2p').Libp2p} libp2p
3636
* @param {import('./bitswap').Bitswap} bitswap
3737
* @param {import('./stats').Stats} stats
3838
* @param {object} [options]
@@ -84,7 +84,7 @@ export class Network {
8484
this._registrarIds = []
8585

8686
for (const protocol of this._protocols) {
87-
this._registrarIds.push(await this._libp2p.registrar.register(protocol, topology))
87+
this._registrarIds.push(await this._libp2p.register(protocol, topology))
8888
}
8989

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

108108
this._registrarIds = []

src/stats/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const defaultOptions = {
2323

2424
export class Stats extends EventEmitter {
2525
/**
26-
* @param {import('libp2p').Libp2p} libp2p
26+
* @param {import('@libp2p/interface-libp2p').Libp2p} libp2p
2727
* @param {string[]} [initialCounters]
2828
* @param {object} _options
2929
* @param {boolean} _options.enabled

src/utils/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import debug from 'debug'
1+
import { logger as createLogger } from '@libp2p/logger'
22
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
33
import { BitswapMessageEntry } from '../message/entry.js'
44

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

20-
return Object.assign(debug(name.join(':')), {
21-
error: debug(name.concat(['error']).join(':'))
22-
})
20+
return createLogger(name.join(':'))
2321
}
2422

2523
/**

src/want-manager/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class WantManager {
1717
* @param {PeerId} peerId
1818
* @param {import('../network').Network} network
1919
* @param {import('../stats').Stats} stats
20-
* @param {import('libp2p').Libp2p} libp2p
20+
* @param {import('@libp2p/interface-libp2p').Libp2p} libp2p
2121
*/
2222
constructor (peerId, network, stats, libp2p) {
2323
/** @type {Map<string, MsgQueue>} */

src/wantlist/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const sortBy = (fn, list) => {
3030
export class Wantlist {
3131
/**
3232
* @param {import('../stats').Stats} [stats]
33-
* @param {import('libp2p').Libp2p} [libp2p]
33+
* @param {import('@libp2p/interface-libp2p').Libp2p} [libp2p]
3434
*/
3535
constructor (stats, libp2p) {
3636
/** @type {Map<string, Entry>} */

test/bitswap-stats.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { makeBlocks } from './utils/make-blocks.js'
1111
import { makePeerIds } from './utils/make-peer-id.js'
1212

1313
/**
14-
* @typedef {import('libp2p').Libp2p} Libp2p
14+
* @typedef {import('@libp2p/interface-libp2p').Libp2p} Libp2p
1515
* @typedef {import('multiformats/cid').CID} CID
1616
*/
1717

0 commit comments

Comments
 (0)