Skip to content

Commit 2383088

Browse files
authored
feat!: update libp2p deps (#453)
BREAKING CHANGE: uses libp2p with protocol stream limiting
1 parent cb941f9 commit 2383088

26 files changed

+125
-99
lines changed

README.md

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
# ipfs-bitswap <!-- omit in toc -->
22

3-
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
4-
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
5-
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
6-
[![Build Status](https://github.com/ipfs/js-ipfs-bitswap/actions/workflows/js-test-and-release.yml/badge.svg?branch=master)](https://github.com/ipfs/js-ipfs-bitswap/actions/workflows/js-test-and-release.yml)
7-
[![](https://coveralls.io/repos/github/ipfs/js-ipfs-bitswap/badge.svg?branch=master)](https://coveralls.io/github/ipfs/js-ipfs-bitswap?branch=master)
8-
[![](https://david-dm.org/ipfs/js-ipfs-bitswap.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-bitswap)
9-
[![](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
10-
[![](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
11-
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
12-
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square)
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)
6+
[![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/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/ipfs/js-ipfs-bitswap/actions/workflows/js-test-and-release.yml)
138

14-
> JavaScript implementation of the Bitswap 'data exchange' protocol used by IPFS
9+
> JavaScript implementation of the Bitswap data exchange protocol used by IPFS
1510
16-
## Table of Contents <!-- omit in toc -->
11+
## Table of contents <!-- omit in toc -->
1712

1813
- [Install](#install)
19-
- [npm](#npm)
2014
- [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)
2115
- [Use in a browser using a script tag](#use-in-a-browser-using-a-script-tag)
2216
- [API](#api)
@@ -28,12 +22,14 @@
2822
- [Structure](#structure)
2923
- [Performance tests](#performance-tests)
3024
- [Profiling](#profiling)
31-
- [Contribute](#contribute)
3225
- [License](#license)
26+
- [Contribute](#contribute)
3327

3428
## Install
3529

36-
### npm
30+
```console
31+
$ npm i ipfs-bitswap
32+
```
3733

3834
```bash
3935
> npm install ipfs-bitswap
@@ -57,7 +53,7 @@ Loading this module through a script tag will make the `IpfsBitswap` object avai
5753

5854
## API
5955

60-
See https://ipfs.github.io/js-ipfs-bitswap
56+
See <https://ipfs.github.io/js-ipfs-bitswap>
6157

6258
### Stats
6359

@@ -119,25 +115,25 @@ const movingAverages = stats.movingAverages
119115

120116
This object contains these properties:
121117

122-
* 'blocksReceived',
123-
* 'dataReceived',
124-
* 'dupBlksReceived',
125-
* 'dupDataReceived',
126-
* 'blocksSent',
127-
* 'dataSent',
128-
* 'providesBufferLength',
129-
* 'wantListLength',
130-
* 'peerCount'
118+
- 'blocksReceived',
119+
- 'dataReceived',
120+
- 'dupBlksReceived',
121+
- 'dupDataReceived',
122+
- 'blocksSent',
123+
- 'dataSent',
124+
- 'providesBufferLength',
125+
- 'wantListLength',
126+
- 'peerCount'
131127

132128
```js
133129
const dataReceivedMovingAverages = movingAverages.dataReceived
134130
```
135131

136132
Each one of these will contain one key per interval (miliseconds), being the default intervals defined:
137133

138-
* 60000 (1 minute)
139-
* 300000 (5 minutes)
140-
* 900000 (15 minutes)
134+
- 60000 (1 minute)
135+
- 300000 (5 minutes)
136+
- 900000 (15 minutes)
141137

142138
You can then select one of them
143139

@@ -158,19 +154,19 @@ This object will be a [movingAverage](https://github.com/pgte/moving-average#rea
158154
src
159155
├── constants.js
160156
├── decision-engine
161-
   ├── index.js
162-
   └── ledger.js
157+
├── index.js
158+
└── ledger.js
163159
├── index.js
164160
├── network.js # Handles peerSet and open new conns
165161
├── notifications.js # Handles tracking of incomning blocks and wants/unwants.
166162
├─── want-manager # Keeps track of all blocks the peer (self) wants
167-
   ├── index.js
168-
   └── msg-queue.js # Messages to send queue, one per peer
163+
├── index.js
164+
└── msg-queue.js # Messages to send queue, one per peer
169165
└─── types
170166
├── message # (Type) message that is put in the wire
171-
   ├── entry.js
172-
   ├── index.js
173-
   └── message.proto.js
167+
├── entry.js
168+
├── index.js
169+
└── message.proto.js
174170
└── wantlist # (Type) track wanted blocks
175171
├── entry.js
176172
└── index.js
@@ -180,9 +176,7 @@ src
180176

181177
You can run performance tests like this:
182178

183-
```
184-
$ npm run benchmarks
185-
```
179+
$ npm run benchmarks
186180

187181
### Profiling
188182

@@ -205,14 +199,17 @@ Use the browser Chrome to open and inspect the generated graph.
205199

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

202+
## License
203+
204+
Licensed under either of
205+
206+
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
207+
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
208+
208209
## Contribute
209210

210-
Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfs-bitswap/issues)!
211+
Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfs-unixfs-importer/issues)!
211212

212213
This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
213214

214215
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
215-
216-
## License
217-
218-
[MIT](LICENSE)

package.json

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ipfs-bitswap",
33
"version": "11.0.4",
4-
"description": "Node.js implementation of the Bitswap data exchange protocol used by IPFS",
4+
"description": "JavaScript implementation of the Bitswap data exchange protocol used by IPFS",
55
"license": "Apache-2.0 OR MIT",
66
"homepage": "https://github.com/ipfs/js-ipfs-bitswap#readme",
77
"repository": {
@@ -21,7 +21,6 @@
2121
"node": ">=16.0.0",
2222
"npm": ">=7.0.0"
2323
},
24-
"main": "src/index.js",
2524
"type": "module",
2625
"types": "./dist/src/index.d.ts",
2726
"typesVersions": {
@@ -41,13 +40,14 @@
4140
}
4241
},
4342
"files": [
44-
"dist",
4543
"src",
46-
"!**/*.tsbuildinfo",
47-
"!dist/test"
44+
"dist",
45+
"!dist/test",
46+
"!**/*.tsbuildinfo"
4847
],
4948
"exports": {
5049
".": {
50+
"types": "./dist/src/index.d.ts",
5151
"import": "./src/index.js"
5252
}
5353
},
@@ -161,8 +161,10 @@
161161
"generate:proto-types": "pbts -o src/message/message.d.ts src/message/message.js"
162162
},
163163
"dependencies": {
164-
"@libp2p/interfaces": "^2.0.2",
165-
"@libp2p/topology": "^1.1.6",
164+
"@libp2p/interface-connection": "^2.1.1",
165+
"@libp2p/interface-peer-id": "^1.0.4",
166+
"@libp2p/interface-peer-store": "^1.2.0",
167+
"@libp2p/topology": "^3.0.0",
166168
"@libp2p/tracked-map": "^1.0.4",
167169
"@multiformats/multiaddr": "^10.1.8",
168170
"@vascosantos/moving-average": "^1.1.0",
@@ -176,18 +178,18 @@
176178
"just-debounce-it": "^3.0.1",
177179
"multiformats": "^9.0.4",
178180
"protobufjs": "^6.10.2",
179-
"readable-stream": "^3.6.0",
181+
"readable-stream": "^4.0.0",
180182
"uint8arrays": "^3.0.0",
181183
"varint": "^6.0.0",
182184
"varint-decoder": "^1.0.0"
183185
},
184186
"devDependencies": {
185-
"@chainsafe/libp2p-noise": "^6.2.0",
186-
"@libp2p/kad-dht": "^1.0.3",
187-
"@libp2p/mplex": "^1.0.2",
187+
"@chainsafe/libp2p-noise": "^7.0.1",
188+
"@libp2p/kad-dht": "^3.0.0",
189+
"@libp2p/mplex": "^3.0.0",
188190
"@libp2p/peer-id": "^1.1.8",
189191
"@libp2p/peer-id-factory": "^1.0.8",
190-
"@libp2p/tcp": "^1.0.6",
192+
"@libp2p/tcp": "^3.0.1",
191193
"@nodeutils/defaults-deep": "^1.1.0",
192194
"@types/debug": "^4.1.5",
193195
"@types/stats-lite": "^2.2.0",
@@ -200,7 +202,7 @@
200202
"iso-random-stream": "^2.0.0",
201203
"it-all": "^1.0.5",
202204
"it-drain": "^1.0.4",
203-
"libp2p": "^0.37.3",
205+
"libp2p": "next",
204206
"lodash.difference": "^4.5.0",
205207
"lodash.flatten": "^4.4.0",
206208
"lodash.range": "^3.2.0",

src/bitswap.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { CID } from 'multiformats/cid'
1212
* @typedef {import('./types').IPFSBitswap} IPFSBitswap
1313
* @typedef {import('./types').MultihashHasherLoader} MultihashHasherLoader
1414
* @typedef {import('./message').BitswapMessage} BitswapMessage
15-
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId
15+
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId
1616
* @typedef {import('interface-blockstore').Blockstore} Blockstore
1717
* @typedef {import('interface-blockstore').Pair} Pair
1818
* @typedef {import('interface-blockstore').Options} Options
@@ -49,6 +49,8 @@ export class Bitswap extends BaseBlockstore {
4949
* @param {boolean} [options.statsEnabled=false]
5050
* @param {number} [options.statsComputeThrottleTimeout=1000]
5151
* @param {number} [options.statsComputeThrottleMaxQueueSize=1000]
52+
* @param {number} [options.maxInboundStreams=32]
53+
* @param {number} [options.maxOutboundStreams=32]
5254
* @param {MultihashHasherLoader} [options.hashLoader]
5355
*/
5456
constructor (libp2p, blockstore, options = {}) {
@@ -68,7 +70,9 @@ export class Bitswap extends BaseBlockstore {
6870

6971
// the network delivers messages
7072
this.network = new Network(libp2p, this, this._stats, {
71-
hashLoader: options.hashLoader
73+
hashLoader: options.hashLoader,
74+
maxInboundStreams: options.maxInboundStreams,
75+
maxOutboundStreams: options.maxOutboundStreams
7276
})
7377

7478
// local database

src/decision-engine/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { trackedMap } from '@libp2p/tracked-map'
1010

1111
/**
1212
* @typedef {import('../message/entry').BitswapMessageEntry} BitswapMessageEntry
13-
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId
13+
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId
1414
*/
1515

1616
const WantType = Message.WantType

src/decision-engine/ledger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Wantlist } from '../wantlist/index.js'
66

77
export class Ledger {
88
/**
9-
* @param {import('@libp2p/interfaces/peer-id').PeerId} peerId
9+
* @param {import('@libp2p/interface-peer-id').PeerId} peerId
1010
*/
1111
constructor (peerId) {
1212
this.partner = peerId

src/decision-engine/req-queue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { SortedMap } from '../utils/sorted-map.js'
1010
* @property {number} created
1111
* @property {Task} task
1212
*
13-
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId
13+
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId
1414
* @typedef {import('./types').Task} Task
1515
* @typedef {import('./types').TaskMerger} TaskMerger
1616
*/

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Bitswap } from './bitswap.js'
33
/**
44
* @typedef {import('./types').IPFSBitswap} IPFSBitswap
55
* @typedef {import('./types').MultihashHasherLoader} MultihashHasherLoader
6-
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId
6+
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId
77
* @typedef {import('./message')} BitswapMessage
88
* @typedef {import('interface-blockstore').Blockstore} Blockstore
99
* @typedef {import('interface-blockstore').Pair} Pair
@@ -17,6 +17,8 @@ import { Bitswap } from './bitswap.js'
1717
* @param {boolean} [options.statsEnabled=false]
1818
* @param {number} [options.statsComputeThrottleTimeout=1000]
1919
* @param {number} [options.statsComputeThrottleMaxQueueSize=1000]
20+
* @param {number} [options.maxInboundStreams=32]
21+
* @param {number} [options.maxOutboundStreams=128]
2022
* @param {MultihashHasherLoader} [options.hashLoader]
2123
* @returns {IPFSBitswap}
2224
*/

0 commit comments

Comments
 (0)