Skip to content

Commit 4910ba8

Browse files
committed
deps!: update multiformats to v11
`[email protected]` shipped with a [breaking change](multiformats/js-multiformats#230) so update all deps using multiformats to the latest version.
1 parent cea4404 commit 4910ba8

File tree

18 files changed

+62
-104
lines changed

18 files changed

+62
-104
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: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
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)
13+
- [Browser `<script>` tag](#browser-script-tag)
1414
- [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)
1515
- [Use in a browser using a script tag](#use-in-a-browser-using-a-script-tag)
1616
- [API](#api)
@@ -22,6 +22,7 @@
2222
- [Structure](#structure)
2323
- [Performance tests](#performance-tests)
2424
- [Profiling](#profiling)
25+
- [API Docs](#api-docs)
2526
- [License](#license)
2627
- [Contribute](#contribute)
2728

@@ -31,6 +32,14 @@
3132
$ npm i ipfs-bitswap
3233
```
3334

35+
### Browser `<script>` tag
36+
37+
Loading this module through a script tag will make it's exports available as `IpfsBitswap` in the global namespace.
38+
39+
```html
40+
<script src="https://unpkg.com/ipfs-bitswap/dist/index.min.js"></script>
41+
```
42+
3443
```bash
3544
> npm install ipfs-bitswap
3645
```
@@ -43,14 +52,6 @@ const { createBitswap } from 'ipfs-bitswap'
4352

4453
### Use in a browser using a script tag
4554

46-
Loading this module through a script tag will make the `IpfsBitswap` object available in the global namespace.
47-
48-
```html
49-
<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>
52-
```
53-
5455
## API
5556

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

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

203+
## API Docs
204+
205+
- <https://ipfs.github.io/js-ipfs-bitswap>
206+
202207
## License
203208

204209
Licensed under either of

package.json

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -162,26 +162,26 @@
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/logger": "^2.0.5",
173+
"@libp2p/topology": "^4.0.0",
172174
"@libp2p/tracked-map": "^3.0.0",
173175
"@multiformats/multiaddr": "^11.0.0",
174176
"@vascosantos/moving-average": "^1.1.0",
175177
"abortable-iterator": "^4.0.2",
176178
"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",
179+
"blockstore-core": "^3.0.0",
180+
"interface-blockstore": "^4.0.0",
181181
"it-length-prefixed": "^8.0.2",
182182
"it-pipe": "^2.0.4",
183183
"just-debounce-it": "^3.0.1",
184-
"multiformats": "^10.0.1",
184+
"multiformats": "^11.0.0",
185185
"protobufjs": "^7.0.0",
186186
"readable-stream": "^4.0.0",
187187
"timeout-abort-controller": "^3.0.0",
@@ -191,16 +191,15 @@
191191
},
192192
"devDependencies": {
193193
"@chainsafe/libp2p-noise": "^10.0.1",
194-
"@libp2p/kad-dht": "^6.0.0",
194+
"@libp2p/kad-dht": "^7.0.0",
195195
"@libp2p/mplex": "^7.0.0",
196-
"@libp2p/peer-id": "^1.1.8",
197-
"@libp2p/peer-id-factory": "^1.0.8",
196+
"@libp2p/peer-id": "^2.0.0",
197+
"@libp2p/peer-id-factory": "^2.0.0",
198198
"@libp2p/tcp": "^6.0.0",
199199
"@nodeutils/defaults-deep": "^1.1.0",
200-
"@types/debug": "^4.1.5",
201200
"@types/stats-lite": "^2.2.0",
202201
"@types/varint": "^6.0.0",
203-
"aegir": "^37.0.4",
202+
"aegir": "^37.10.0",
204203
"assert": "^2.0.0",
205204
"benchmark": "^2.1.4",
206205
"delay": "^5.0.0",
@@ -221,7 +220,7 @@
221220
"promisify-es6": "^1.0.3",
222221
"protobufjs-cli": "^1.0.0",
223222
"rimraf": "^3.0.2",
224-
"sinon": "^14.0.0",
223+
"sinon": "^15.0.1",
225224
"stats-lite": "^2.2.0",
226225
"url": "^0.11.0",
227226
"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

test/bitswap.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { BitswapMessage as Message } from '../src/message/index.js'
1212
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
1313

1414
/**
15-
* @typedef {import('libp2p').Libp2p} Libp2p
15+
* @typedef {import('@libp2p/interface-libp2p').Libp2p} Libp2p
1616
*/
1717

1818
/**
@@ -34,10 +34,8 @@ describe('start/stop', () => {
3434
const libp2p = {
3535
handle: () => {},
3636
unhandle: () => {},
37-
registrar: {
38-
register: () => {},
39-
unregister: () => {}
40-
},
37+
register: () => {},
38+
unregister: () => {},
4139
getConnections: () => []
4240
}
4341
// @ts-ignore not a full libp2p

test/network/network.node.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { CID } from 'multiformats/cid'
1414
import delay from 'delay'
1515

1616
/**
17-
* @typedef {import('libp2p').Libp2p} Libp2p
17+
* @typedef {import('@libp2p/interface-libp2p').Libp2p} Libp2p
1818
* @typedef {import('../../src/bitswap').Bitswap} Bitswap
1919
*/
2020

@@ -304,11 +304,8 @@ describe('network', () => {
304304
contentRouting: {
305305
findProviders: mockFindProviders
306306
},
307-
// @ts-expect-error incomplete implementation
308-
registrar: {
309-
register: sinon.stub(),
310-
unregister: sinon.stub()
311-
},
307+
register: sinon.stub(),
308+
unregister: sinon.stub(),
312309
getConnections: () => [],
313310
dial: mockDial,
314311
handle: sinon.stub()
@@ -345,9 +342,8 @@ describe('network', () => {
345342

346343
const libp2p = {
347344
handle: sinon.stub(),
348-
registrar: {
349-
register: sinon.stub()
350-
},
345+
register: sinon.stub(),
346+
unregister: sinon.stub(),
351347
getConnections: () => []
352348
}
353349

test/utils/create-libp2p-node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { createEd25519PeerId } from '@libp2p/peer-id-factory'
1010
import defaultsDeep from '@nodeutils/defaults-deep'
1111

1212
/**
13-
* @typedef {import('libp2p').Libp2p} Libp2p
13+
* @typedef {import('@libp2p/interface-libp2p').Libp2p} Libp2p
1414
* @typedef {import('libp2p').Libp2pOptions & { DHT?: boolean}} NodeOptions
1515
*/
1616

test/utils/distribution-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { connectAll } from './connect-all.js'
1010
import all from 'it-all'
1111

1212
/**
13-
* @typedef {import('libp2p').Libp2p} Libp2p
13+
* @typedef {import('@libp2p/interface-libp2p').Libp2p} Libp2p
1414
* @typedef {import('../../src/types').IPFSBitswap} Bitswap
1515
*/
1616

0 commit comments

Comments
 (0)