ipfs-bitswap
Advanced tools
Comparing version 11.0.4 to 12.0.0
@@ -15,2 +15,4 @@ /** | ||
* @param {number} [options.statsComputeThrottleMaxQueueSize=1000] | ||
* @param {number} [options.maxInboundStreams=32] | ||
* @param {number} [options.maxOutboundStreams=32] | ||
* @param {MultihashHasherLoader} [options.hashLoader] | ||
@@ -22,2 +24,4 @@ */ | ||
statsComputeThrottleMaxQueueSize?: number | undefined; | ||
maxInboundStreams?: number | undefined; | ||
maxOutboundStreams?: number | undefined; | ||
hashLoader?: import("./types").MultihashHasherLoader | undefined; | ||
@@ -37,2 +41,4 @@ } | undefined); | ||
statsComputeThrottleMaxQueueSize?: number | undefined; | ||
maxInboundStreams?: number | undefined; | ||
maxOutboundStreams?: number | undefined; | ||
hashLoader?: import("./types").MultihashHasherLoader | undefined; | ||
@@ -51,3 +57,3 @@ }; | ||
*/ | ||
get peerId(): import("@libp2p/interfaces/peer-id").PeerId; | ||
get peerId(): import("@libp2p/interface-peer-id").PeerId; | ||
/** | ||
@@ -109,3 +115,3 @@ * handle messages received through the network | ||
ledgerForPeer(peerId: PeerId): { | ||
peer: import("@libp2p/interfaces/peer-id").PeerId; | ||
peer: import("@libp2p/interface-peer-id").PeerId; | ||
value: number; | ||
@@ -181,3 +187,3 @@ sent: number; | ||
*/ | ||
peers(): import("@libp2p/interfaces/peer-id").PeerId[]; | ||
peers(): import("@libp2p/interface-peer-id").PeerId[]; | ||
/** | ||
@@ -200,3 +206,3 @@ * Get stats about the bitswap node | ||
export type BitswapMessage = import('./message').BitswapMessage; | ||
export type PeerId = import('@libp2p/interfaces/peer-id').PeerId; | ||
export type PeerId = import('@libp2p/interface-peer-id').PeerId; | ||
export type Blockstore = import('interface-blockstore').Blockstore; | ||
@@ -203,0 +209,0 @@ export type Pair = import('interface-blockstore').Pair; |
@@ -55,3 +55,3 @@ export class DecisionEngine { | ||
ledgerForPeer(peerId: PeerId): { | ||
peer: import("@libp2p/interfaces/peer-id").PeerId; | ||
peer: import("@libp2p/interface-peer-id").PeerId; | ||
value: number; | ||
@@ -155,3 +155,3 @@ sent: number; | ||
export type BitswapMessageEntry = import('../message/entry').BitswapMessageEntry; | ||
export type PeerId = import('@libp2p/interfaces/peer-id').PeerId; | ||
export type PeerId = import('@libp2p/interface-peer-id').PeerId; | ||
import { Ledger } from "./ledger.js"; | ||
@@ -158,0 +158,0 @@ import { RequestQueue } from "./req-queue.js"; |
@@ -6,6 +6,6 @@ /** | ||
/** | ||
* @param {import('@libp2p/interfaces/peer-id').PeerId} peerId | ||
* @param {import('@libp2p/interface-peer-id').PeerId} peerId | ||
*/ | ||
constructor(peerId: import('@libp2p/interfaces/peer-id').PeerId); | ||
partner: import("@libp2p/interfaces/peer-id").PeerId; | ||
constructor(peerId: import('@libp2p/interface-peer-id').PeerId); | ||
partner: import("@libp2p/interface-peer-id").PeerId; | ||
wantlist: Wantlist; | ||
@@ -12,0 +12,0 @@ exchangeCount: number; |
@@ -58,3 +58,3 @@ /** | ||
export type PopTaskResult = { | ||
peerId?: import("@libp2p/interfaces/peer-id").PeerId | undefined; | ||
peerId?: import("@libp2p/interface-peer-id").PeerId | undefined; | ||
tasks: Task[]; | ||
@@ -67,3 +67,3 @@ pendingSize: number; | ||
}; | ||
export type PeerId = import('@libp2p/interfaces/peer-id').PeerId; | ||
export type PeerId = import('@libp2p/interface-peer-id').PeerId; | ||
export type Task = import('./types').Task; | ||
@@ -90,3 +90,3 @@ export type TaskMerger = import('./types').TaskMerger; | ||
constructor(peerId: PeerId, taskMerger: TaskMerger); | ||
peerId: import("@libp2p/interfaces/peer-id").PeerId; | ||
peerId: import("@libp2p/interface-peer-id").PeerId; | ||
_taskMerger: import("./types").TaskMerger; | ||
@@ -93,0 +93,0 @@ _activeTotalSize: number; |
@@ -5,2 +5,4 @@ export function createBitswap(libp2p: import('libp2p').Libp2p, blockstore: Blockstore, options?: { | ||
statsComputeThrottleMaxQueueSize?: number | undefined; | ||
maxInboundStreams?: number | undefined; | ||
maxOutboundStreams?: number | undefined; | ||
hashLoader?: import("./types").MultihashHasherLoader | undefined; | ||
@@ -10,3 +12,3 @@ } | undefined): IPFSBitswap; | ||
export type MultihashHasherLoader = import('./types').MultihashHasherLoader; | ||
export type PeerId = import('@libp2p/interfaces/peer-id').PeerId; | ||
export type PeerId = import('@libp2p/interface-peer-id').PeerId; | ||
export type BitswapMessage = typeof import("./message"); | ||
@@ -13,0 +15,0 @@ export type Blockstore = import('interface-blockstore').Blockstore; |
@@ -9,2 +9,4 @@ export class Network { | ||
* @param {MultihashHasherLoader} [options.hashLoader] | ||
* @param {number} [options.maxInboundStreams=32] | ||
* @param {number} [options.maxOutboundStreams=32] | ||
*/ | ||
@@ -14,2 +16,4 @@ constructor(libp2p: import('libp2p').Libp2p, bitswap: import('./bitswap').Bitswap, stats: import('./stats').Stats, options?: { | ||
hashLoader?: import("./types").MultihashHasherLoader | undefined; | ||
maxInboundStreams?: number | undefined; | ||
maxOutboundStreams?: number | undefined; | ||
} | undefined); | ||
@@ -39,3 +43,2 @@ _log: import("debug").Debugger & { | ||
* @param {object} connection | ||
* @param {string} connection.protocol - The protocol the stream is running | ||
* @param {Stream} connection.stream - A duplex iterable stream | ||
@@ -46,4 +49,7 @@ * @param {Connection} connection.connection - A libp2p Connection | ||
_hashLoader: import("./types").MultihashHasherLoader | undefined; | ||
_maxInboundStreams: number; | ||
_maxOutboundStreams: number; | ||
start(): Promise<void>; | ||
_registrarId: string | undefined; | ||
/** @type {string[]} */ | ||
_registrarIds: string[] | undefined; | ||
stop(): Promise<void>; | ||
@@ -107,7 +113,7 @@ /** | ||
} | ||
export type PeerId = import('@libp2p/interfaces/peer-id').PeerId; | ||
export type PeerId = import('@libp2p/interface-peer-id').PeerId; | ||
export type CID = import('multiformats').CID; | ||
export type Multiaddr = import('@multiformats/multiaddr').Multiaddr; | ||
export type Connection = import('@libp2p/interfaces/connection').Connection; | ||
export type Stream = import('@libp2p/interfaces/connection').Stream; | ||
export type Connection = import('@libp2p/interface-connection').Connection; | ||
export type Stream = import('@libp2p/interface-connection').Stream; | ||
export type MultihashHasherLoader = import('./types').MultihashHasherLoader; | ||
@@ -114,0 +120,0 @@ export type Provider = { |
@@ -43,4 +43,4 @@ export class Notifications extends EventEmitter { | ||
export type CID = import('multiformats').CID; | ||
export type PeerId = import('@libp2p/interfaces/peer-id').PeerId; | ||
export type PeerId = import('@libp2p/interface-peer-id').PeerId; | ||
import { EventEmitter } from "events"; | ||
//# sourceMappingURL=notifications.d.ts.map |
@@ -53,3 +53,3 @@ export class Stats extends EventEmitter { | ||
export type CID = import('multiformats').CID; | ||
export type PeerId = import('@libp2p/interfaces/peer-id').PeerId; | ||
export type PeerId = import('@libp2p/interface-peer-id').PeerId; | ||
export type AverageIntervals = [number, number, number]; | ||
@@ -56,0 +56,0 @@ import { EventEmitter } from "events"; |
import type { Blockstore } from 'interface-blockstore'; | ||
import type { PeerId } from '@libp2p/interfaces/peer-id'; | ||
import type { PeerId } from '@libp2p/interface-peer-id'; | ||
import type { CID } from 'multiformats/cid'; | ||
@@ -4,0 +4,0 @@ import type { Message } from './message/message'; |
@@ -1,2 +0,2 @@ | ||
export function logger(id?: import("@libp2p/interfaces/peer-id").PeerId | undefined, subsystem?: string | undefined): debug.Debugger & { | ||
export function logger(id?: import("@libp2p/interface-peer-id").PeerId | undefined, subsystem?: string | undefined): debug.Debugger & { | ||
error: debug.Debugger; | ||
@@ -3,0 +3,0 @@ }; |
/** | ||
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId | ||
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId | ||
* @typedef {import('multiformats').CID} CID | ||
@@ -18,3 +18,3 @@ */ | ||
_stats: import("../stats").Stats; | ||
_peerId: import("@libp2p/interfaces/peer-id").PeerId; | ||
_peerId: import("@libp2p/interface-peer-id").PeerId; | ||
_log: import("debug").Debugger & { | ||
@@ -77,3 +77,3 @@ error: import("debug").Debugger; | ||
} | ||
export type PeerId = import('@libp2p/interfaces/peer-id').PeerId; | ||
export type PeerId = import('@libp2p/interface-peer-id').PeerId; | ||
export type CID = import('multiformats').CID; | ||
@@ -80,0 +80,0 @@ import { MsgQueue } from "./msg-queue.js"; |
/** | ||
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId | ||
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId | ||
* @typedef {import('multiformats').CID} CID | ||
@@ -13,3 +13,3 @@ * @typedef {import('../network').Network} Network | ||
constructor(selfPeerId: PeerId, otherPeerId: PeerId, network: Network); | ||
peerId: import("@libp2p/interfaces/peer-id").PeerId; | ||
peerId: import("@libp2p/interface-peer-id").PeerId; | ||
network: import("../network").Network; | ||
@@ -48,3 +48,3 @@ refcnt: number; | ||
} | ||
export type PeerId = import('@libp2p/interfaces/peer-id').PeerId; | ||
export type PeerId = import('@libp2p/interface-peer-id').PeerId; | ||
export type CID = import('multiformats').CID; | ||
@@ -51,0 +51,0 @@ export type Network = import('../network').Network; |
{ | ||
"name": "ipfs-bitswap", | ||
"version": "11.0.4", | ||
"description": "Node.js implementation of the Bitswap data exchange protocol used by IPFS", | ||
"version": "12.0.0", | ||
"description": "JavaScript implementation of the Bitswap data exchange protocol used by IPFS", | ||
"license": "Apache-2.0 OR MIT", | ||
@@ -24,3 +24,2 @@ "homepage": "https://github.com/ipfs/js-ipfs-bitswap#readme", | ||
}, | ||
"main": "src/index.js", | ||
"type": "module", | ||
@@ -45,9 +44,10 @@ "types": "./dist/src/index.d.ts", | ||
"files": [ | ||
"src", | ||
"dist", | ||
"src", | ||
"!**/*.tsbuildinfo", | ||
"!dist/test" | ||
"!dist/test", | ||
"!**/*.tsbuildinfo" | ||
], | ||
"exports": { | ||
".": { | ||
"types": "./dist/src/index.d.ts", | ||
"import": "./src/index.js" | ||
@@ -166,4 +166,6 @@ } | ||
"dependencies": { | ||
"@libp2p/interfaces": "^2.0.2", | ||
"@libp2p/topology": "^1.1.6", | ||
"@libp2p/interface-connection": "^2.1.1", | ||
"@libp2p/interface-peer-id": "^1.0.4", | ||
"@libp2p/interface-peer-store": "^1.2.0", | ||
"@libp2p/topology": "^3.0.0", | ||
"@libp2p/tracked-map": "^1.0.4", | ||
@@ -182,3 +184,3 @@ "@multiformats/multiaddr": "^10.1.8", | ||
"protobufjs": "^6.10.2", | ||
"readable-stream": "^3.6.0", | ||
"readable-stream": "^4.0.0", | ||
"uint8arrays": "^3.0.0", | ||
@@ -189,8 +191,8 @@ "varint": "^6.0.0", | ||
"devDependencies": { | ||
"@chainsafe/libp2p-noise": "^6.2.0", | ||
"@libp2p/kad-dht": "^1.0.3", | ||
"@libp2p/mplex": "^1.0.2", | ||
"@chainsafe/libp2p-noise": "^7.0.1", | ||
"@libp2p/kad-dht": "^3.0.0", | ||
"@libp2p/mplex": "^3.0.0", | ||
"@libp2p/peer-id": "^1.1.8", | ||
"@libp2p/peer-id-factory": "^1.0.8", | ||
"@libp2p/tcp": "^1.0.6", | ||
"@libp2p/tcp": "^3.0.1", | ||
"@nodeutils/defaults-deep": "^1.1.0", | ||
@@ -208,3 +210,3 @@ "@types/debug": "^4.1.5", | ||
"it-drain": "^1.0.4", | ||
"libp2p": "^0.37.3", | ||
"libp2p": "next", | ||
"lodash.difference": "^4.5.0", | ||
@@ -211,0 +213,0 @@ "lodash.flatten": "^4.4.0", |
# ipfs-bitswap <!-- omit in toc --> | ||
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) | ||
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) | ||
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) | ||
[![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) | ||
[![](https://coveralls.io/repos/github/ipfs/js-ipfs-bitswap/badge.svg?branch=master)](https://coveralls.io/github/ipfs/js-ipfs-bitswap?branch=master) | ||
[![](https://david-dm.org/ipfs/js-ipfs-bitswap.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-bitswap) | ||
[![](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) | ||
[![](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) | ||
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square) | ||
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square) | ||
[![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) | ||
[![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/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) | ||
> JavaScript implementation of the Bitswap 'data exchange' protocol used by IPFS | ||
> JavaScript implementation of the Bitswap data exchange protocol used by IPFS | ||
## Table of Contents <!-- omit in toc --> | ||
## Table of contents <!-- omit in toc --> | ||
- [Install](#install) | ||
- [npm](#npm) | ||
- [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) | ||
@@ -31,8 +25,10 @@ - [Use in a browser using a script tag](#use-in-a-browser-using-a-script-tag) | ||
- [Profiling](#profiling) | ||
- [License](#license) | ||
- [Contribute](#contribute) | ||
- [License](#license) | ||
## Install | ||
### npm | ||
```console | ||
$ npm i ipfs-bitswap | ||
``` | ||
@@ -61,3 +57,3 @@ ```bash | ||
See https://ipfs.github.io/js-ipfs-bitswap | ||
See <https://ipfs.github.io/js-ipfs-bitswap> | ||
@@ -124,11 +120,11 @@ ### Stats | ||
* 'blocksReceived', | ||
* 'dataReceived', | ||
* 'dupBlksReceived', | ||
* 'dupDataReceived', | ||
* 'blocksSent', | ||
* 'dataSent', | ||
* 'providesBufferLength', | ||
* 'wantListLength', | ||
* 'peerCount' | ||
- 'blocksReceived', | ||
- 'dataReceived', | ||
- 'dupBlksReceived', | ||
- 'dupDataReceived', | ||
- 'blocksSent', | ||
- 'dataSent', | ||
- 'providesBufferLength', | ||
- 'wantListLength', | ||
- 'peerCount' | ||
@@ -141,5 +137,5 @@ ```js | ||
* 60000 (1 minute) | ||
* 300000 (5 minutes) | ||
* 900000 (15 minutes) | ||
- 60000 (1 minute) | ||
- 300000 (5 minutes) | ||
- 900000 (15 minutes) | ||
@@ -165,4 +161,4 @@ You can then select one of them | ||
├── decision-engine | ||
│ ├── index.js | ||
│ └── ledger.js | ||
│ ├── index.js | ||
│ └── ledger.js | ||
├── index.js | ||
@@ -172,9 +168,9 @@ ├── network.js # Handles peerSet and open new conns | ||
├─── want-manager # Keeps track of all blocks the peer (self) wants | ||
│ ├── index.js | ||
│ └── msg-queue.js # Messages to send queue, one per peer | ||
│ ├── index.js | ||
│ └── msg-queue.js # Messages to send queue, one per peer | ||
└─── types | ||
├── message # (Type) message that is put in the wire | ||
│ ├── entry.js | ||
│ ├── index.js | ||
│ └── message.proto.js | ||
│ ├── entry.js | ||
│ ├── index.js | ||
│ └── message.proto.js | ||
└── wantlist # (Type) track wanted blocks | ||
@@ -189,5 +185,3 @@ ├── entry.js | ||
``` | ||
$ npm run benchmarks | ||
``` | ||
$ npm run benchmarks | ||
@@ -215,5 +209,12 @@ ### Profiling | ||
## License | ||
Licensed under either of | ||
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>) | ||
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>) | ||
## Contribute | ||
Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfs-bitswap/issues)! | ||
Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfs-unixfs-importer/issues)! | ||
@@ -223,5 +224,1 @@ This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). | ||
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) | ||
## License | ||
[MIT](LICENSE) |
@@ -15,3 +15,3 @@ import { WantManager } from './want-manager/index.js' | ||
* @typedef {import('./message').BitswapMessage} BitswapMessage | ||
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId | ||
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId | ||
* @typedef {import('interface-blockstore').Blockstore} Blockstore | ||
@@ -53,2 +53,4 @@ * @typedef {import('interface-blockstore').Pair} Pair | ||
* @param {number} [options.statsComputeThrottleMaxQueueSize=1000] | ||
* @param {number} [options.maxInboundStreams=32] | ||
* @param {number} [options.maxOutboundStreams=32] | ||
* @param {MultihashHasherLoader} [options.hashLoader] | ||
@@ -73,3 +75,5 @@ */ | ||
this.network = new Network(libp2p, this, this._stats, { | ||
hashLoader: options.hashLoader | ||
hashLoader: options.hashLoader, | ||
maxInboundStreams: options.maxInboundStreams, | ||
maxOutboundStreams: options.maxOutboundStreams | ||
}) | ||
@@ -76,0 +80,0 @@ |
@@ -13,3 +13,3 @@ import { CID } from 'multiformats/cid' | ||
* @typedef {import('../message/entry').BitswapMessageEntry} BitswapMessageEntry | ||
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId | ||
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId | ||
*/ | ||
@@ -16,0 +16,0 @@ |
@@ -9,3 +9,3 @@ import { Wantlist } from '../wantlist/index.js' | ||
/** | ||
* @param {import('@libp2p/interfaces/peer-id').PeerId} peerId | ||
* @param {import('@libp2p/interface-peer-id').PeerId} peerId | ||
*/ | ||
@@ -12,0 +12,0 @@ constructor (peerId) { |
@@ -13,3 +13,3 @@ import { SortedMap } from '../utils/sorted-map.js' | ||
* | ||
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId | ||
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId | ||
* @typedef {import('./types').Task} Task | ||
@@ -16,0 +16,0 @@ * @typedef {import('./types').TaskMerger} TaskMerger |
@@ -6,3 +6,3 @@ import { Bitswap } from './bitswap.js' | ||
* @typedef {import('./types').MultihashHasherLoader} MultihashHasherLoader | ||
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId | ||
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId | ||
* @typedef {import('./message')} BitswapMessage | ||
@@ -21,2 +21,4 @@ * @typedef {import('interface-blockstore').Blockstore} Blockstore | ||
* @param {number} [options.statsComputeThrottleMaxQueueSize=1000] | ||
* @param {number} [options.maxInboundStreams=32] | ||
* @param {number} [options.maxOutboundStreams=128] | ||
* @param {MultihashHasherLoader} [options.hashLoader] | ||
@@ -23,0 +25,0 @@ * @returns {IPFSBitswap} |
@@ -9,7 +9,7 @@ import * as lp from 'it-length-prefixed' | ||
/** | ||
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId | ||
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId | ||
* @typedef {import('multiformats').CID} CID | ||
* @typedef {import('@multiformats/multiaddr').Multiaddr} Multiaddr | ||
* @typedef {import('@libp2p/interfaces/connection').Connection} Connection | ||
* @typedef {import('@libp2p/interfaces/connection').Stream} Stream | ||
* @typedef {import('@libp2p/interface-connection').Connection} Connection | ||
* @typedef {import('@libp2p/interface-connection').Stream} Stream | ||
* @typedef {import('./types').MultihashHasherLoader} MultihashHasherLoader | ||
@@ -28,2 +28,5 @@ * | ||
const DEFAULT_MAX_INBOUND_STREAMS = 32 | ||
const DEFAULT_MAX_OUTBOUND_STREAMS = 128 | ||
export class Network { | ||
@@ -37,2 +40,4 @@ /** | ||
* @param {MultihashHasherLoader} [options.hashLoader] | ||
* @param {number} [options.maxInboundStreams=32] | ||
* @param {number} [options.maxOutboundStreams=32] | ||
*/ | ||
@@ -59,2 +64,4 @@ constructor (libp2p, bitswap, stats, options = {}) { | ||
this._hashLoader = options.hashLoader | ||
this._maxInboundStreams = options.maxInboundStreams ?? DEFAULT_MAX_INBOUND_STREAMS | ||
this._maxOutboundStreams = options.maxOutboundStreams ?? DEFAULT_MAX_OUTBOUND_STREAMS | ||
} | ||
@@ -64,3 +71,6 @@ | ||
this._running = true | ||
await this._libp2p.handle(this._protocols, this._onConnection) | ||
await this._libp2p.handle(this._protocols, this._onConnection, { | ||
maxInboundStreams: this._maxInboundStreams, | ||
maxOutboundStreams: this._maxOutboundStreams | ||
}) | ||
@@ -72,4 +82,10 @@ // register protocol with topology | ||
}) | ||
this._registrarId = await this._libp2p.registrar.register(this._protocols, topology) | ||
/** @type {string[]} */ | ||
this._registrarIds = [] | ||
for (const protocol of this._protocols) { | ||
this._registrarIds.push(await this._libp2p.registrar.register(protocol, topology)) | ||
} | ||
// All existing connections are like new ones for us | ||
@@ -88,4 +104,8 @@ this._libp2p.getConnections().forEach(conn => { | ||
// unregister protocol and handlers | ||
if (this._registrarId != null) { | ||
this._libp2p.registrar.unregister(this._registrarId) | ||
if (this._registrarIds != null) { | ||
for (const id of this._registrarIds) { | ||
this._libp2p.registrar.unregister(id) | ||
} | ||
this._registrarIds = [] | ||
} | ||
@@ -99,7 +119,6 @@ } | ||
* @param {object} connection | ||
* @param {string} connection.protocol - The protocol the stream is running | ||
* @param {Stream} connection.stream - A duplex iterable stream | ||
* @param {Connection} connection.connection - A libp2p Connection | ||
*/ | ||
_onConnection ({ protocol, stream, connection }) { | ||
_onConnection ({ stream, connection }) { | ||
if (!this._running) { | ||
@@ -110,3 +129,3 @@ return | ||
Promise.resolve().then(async () => { | ||
this._log('incoming new bitswap %s connection from %p', protocol, connection.remotePeer) | ||
this._log('incoming new bitswap %s connection from %p', stream.stat.protocol, connection.remotePeer) | ||
@@ -218,7 +237,7 @@ await pipe( | ||
const connection = await this._libp2p.dial(peer) | ||
const { stream, protocol } = await connection.newStream([BITSWAP120, BITSWAP110, BITSWAP100]) | ||
const stream = await connection.newStream([BITSWAP120, BITSWAP110, BITSWAP100]) | ||
/** @type {Uint8Array} */ | ||
let serialized | ||
switch (protocol) { | ||
switch (stream.stat.protocol) { | ||
case BITSWAP100: | ||
@@ -232,3 +251,3 @@ serialized = msg.serializeToBitswap100() | ||
default: | ||
throw new Error('Unknown protocol: ' + protocol) | ||
throw new Error('Unknown protocol: ' + stream.stat.protocol) | ||
} | ||
@@ -235,0 +254,0 @@ |
@@ -8,3 +8,3 @@ import { EventEmitter } from 'events' | ||
* @typedef {import('multiformats').CID} CID | ||
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId | ||
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId | ||
*/ | ||
@@ -11,0 +11,0 @@ |
@@ -7,3 +7,3 @@ import { EventEmitter } from 'events' | ||
* @typedef {import('multiformats').CID} CID | ||
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId | ||
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId | ||
*/ | ||
@@ -10,0 +10,0 @@ |
import type { Blockstore } from 'interface-blockstore' | ||
import type { PeerId } from '@libp2p/interfaces/peer-id' | ||
import type { PeerId } from '@libp2p/interface-peer-id' | ||
import type { CID } from 'multiformats/cid' | ||
@@ -4,0 +4,0 @@ import type { Message } from './message/message' |
@@ -8,3 +8,3 @@ import debug from 'debug' | ||
* | ||
* @param {import('@libp2p/interfaces/peer-id').PeerId} [id] | ||
* @param {import('@libp2p/interface-peer-id').PeerId} [id] | ||
* @param {string} [subsystem] | ||
@@ -11,0 +11,0 @@ */ |
@@ -11,3 +11,3 @@ | ||
/** | ||
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId | ||
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId | ||
* @typedef {import('multiformats').CID} CID | ||
@@ -14,0 +14,0 @@ */ |
@@ -9,3 +9,3 @@ | ||
/** | ||
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId | ||
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId | ||
* @typedef {import('multiformats').CID} CID | ||
@@ -12,0 +12,0 @@ * @typedef {import('../network').Network} Network |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
329074
6357
21
216
+ Added@chainsafe/is-ip@2.1.0(transitive)
+ Added@chainsafe/netmask@2.0.0(transitive)
+ Added@leichtgewicht/ip-codec@2.0.5(transitive)
+ Added@libp2p/interface-connection@2.1.15.1.1(transitive)
+ Added@libp2p/interface-peer-id@1.1.22.0.2(transitive)
+ Added@libp2p/interface-peer-info@1.0.10(transitive)
+ Added@libp2p/interface-peer-store@1.2.9(transitive)
+ Added@libp2p/interface-record@2.0.7(transitive)
+ Added@libp2p/interface-registrar@2.0.12(transitive)
+ Added@libp2p/interfaces@3.3.2(transitive)
+ Added@libp2p/logger@2.1.1(transitive)
+ Added@libp2p/topology@3.0.2(transitive)
+ Added@multiformats/dns@1.0.6(transitive)
+ Added@multiformats/multiaddr@12.3.5(transitive)
+ Added@types/dns-packet@5.6.5(transitive)
+ Addedabort-controller@3.0.0(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addeddns-packet@5.6.1(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
+ Addedeventemitter3@5.0.1(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedhashlru@2.3.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedinterface-datastore@8.3.1(transitive)
+ Addedinterface-store@6.0.2(transitive)
+ Addedit-all@2.0.1(transitive)
+ Addedit-stream-types@2.0.2(transitive)
+ Addedmultiformats@10.0.311.0.213.3.1(transitive)
+ Addedp-queue@8.1.0(transitive)
+ Addedp-timeout@6.1.4(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedprogress-events@1.0.1(transitive)
+ Addedreadable-stream@4.7.0(transitive)
+ Addeduint8-varint@2.0.4(transitive)
+ Addeduint8arraylist@2.4.8(transitive)
+ Addeduint8arrays@5.1.0(transitive)
- Removed@libp2p/interfaces@^2.0.2
- Removed@libp2p/logger@1.1.6(transitive)
- Removed@libp2p/topology@1.1.9(transitive)
- Removedinherits@2.0.4(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedutil-deprecate@1.0.2(transitive)
Updated@libp2p/topology@^3.0.0
Updatedreadable-stream@^4.0.0