New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ipfs-bitswap

Package Overview
Dependencies
Maintainers
6
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ipfs-bitswap - npm Package Compare versions

Comparing version 18.0.3 to 19.0.0

4

dist/src/bitswap.d.ts

@@ -9,4 +9,4 @@ import { CID } from 'multiformats/cid';

import type { BitswapMessage } from './message/index.js';
import type { Libp2p } from '@libp2p/interface-libp2p';
import type { PeerId } from '@libp2p/interface-peer-id';
import type { Libp2p } from '@libp2p/interface';
import type { PeerId } from '@libp2p/interface/peer-id';
import type { AbortOptions } from '@multiformats/multiaddr';

@@ -13,0 +13,0 @@ import type { Blockstore, Pair } from 'interface-blockstore';

@@ -10,4 +10,4 @@ import { CID } from 'multiformats/cid';

import type { WantListEntry } from '../wantlist/entry.js';
import type { Libp2p } from '@libp2p/interface-libp2p';
import type { PeerId } from '@libp2p/interface-peer-id';
import type { Libp2p } from '@libp2p/interface';
import type { PeerId } from '@libp2p/interface/peer-id';
import type { Blockstore } from 'interface-blockstore';

@@ -14,0 +14,0 @@ export interface TaskMerger {

@@ -1,2 +0,2 @@

import { trackedMap } from '@libp2p/tracked-map';
import { trackedMap } from '@libp2p/interface/metrics/tracked-map';
import { base58btc } from 'multiformats/bases/base58';

@@ -3,0 +3,0 @@ import { CID } from 'multiformats/cid';

import { Wantlist } from '../wantlist/index.js';
import type { Message } from '../message/message.js';
import type { WantListEntry } from '../wantlist/entry.js';
import type { PeerId } from '@libp2p/interface-peer-id';
import type { PeerId } from '@libp2p/interface/peer-id';
import type { CID } from 'multiformats/cid';

@@ -6,0 +6,0 @@ export declare class Ledger {

import { SortedMap } from '../utils/sorted-map.js';
import type { Task, TaskMerger } from './index.js';
import type { PeerId } from '@libp2p/interface-peer-id';
import type { PeerId } from '@libp2p/interface/peer-id';
export interface PopTaskResult {

@@ -5,0 +5,0 @@ peerId?: PeerId;

import type { Message } from './message/message';
import type { BitswapNetworkNotifyProgressEvents, BitswapNetworkWantProgressEvents } from './network.js';
import type { Libp2p } from '@libp2p/interface-libp2p';
import type { PeerId } from '@libp2p/interface-peer-id';
import type { AbortOptions } from '@libp2p/interfaces';
import type { Startable } from '@libp2p/interfaces/startable';
import type { Libp2p, AbortOptions } from '@libp2p/interface';
import type { PeerId } from '@libp2p/interface/peer-id';
import type { Startable } from '@libp2p/interface/startable';
import type { IMovingAverage } from '@vascosantos/moving-average';

@@ -8,0 +7,0 @@ import type { Blockstore } from 'interface-blockstore';

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors';
import { CodeError } from '@libp2p/interface/errors';
import { base58btc } from 'multiformats/bases/base58';

@@ -3,0 +3,0 @@ import { CID } from 'multiformats/cid';

@@ -6,8 +6,7 @@ import { type ProgressEvent, type ProgressOptions } from 'progress-events';

import type { Stats } from './stats/index.js';
import type { Connection } from '@libp2p/interface-connection';
import type { Libp2p } from '@libp2p/interface-libp2p';
import type { PeerId } from '@libp2p/interface-peer-id';
import type { PeerInfo } from '@libp2p/interface-peer-info';
import type { IncomingStreamData } from '@libp2p/interface-registrar';
import type { AbortOptions } from '@libp2p/interfaces';
import type { Libp2p, AbortOptions } from '@libp2p/interface';
import type { Connection } from '@libp2p/interface/connection';
import type { PeerId } from '@libp2p/interface/peer-id';
import type { PeerInfo } from '@libp2p/interface/peer-info';
import type { IncomingStreamData } from '@libp2p/interface/stream-handler';
import type { Multiaddr } from '@multiformats/multiaddr';

@@ -14,0 +13,0 @@ import type { CID } from 'multiformats/cid';

@@ -1,3 +0,2 @@

import { createTopology } from '@libp2p/topology';
import { abortableSource } from 'abortable-iterator';
import { CodeError } from '@libp2p/interface/errors';
import drain from 'it-drain';

@@ -63,6 +62,6 @@ import * as lp from 'it-length-prefixed';

// register protocol with topology
const topology = createTopology({
const topology = {
onConnect: this._onPeerConnect,
onDisconnect: this._onPeerDisconnect
});
};
/** @type {string[]} */

@@ -100,4 +99,9 @@ this._registrarIds = [];

Promise.resolve().then(async () => {
this._log('incoming new bitswap %s connection from %p', stream.stat.protocol, connection.remotePeer);
await pipe(abortableSource(stream.source, controller.signal), (source) => lp.decode(source), async (source) => {
this._log('incoming new bitswap %s connection from %p', stream.protocol, connection.remotePeer);
const abortListener = () => {
stream.abort(new CodeError('Incoming Bitswap stream timed out', 'ERR_TIMEOUT'));
};
let signal = AbortSignal.timeout(this._incomingStreamTimeout);
signal.addEventListener('abort', abortListener);
await pipe(stream, (source) => lp.decode(source), async (source) => {
for await (const data of source) {

@@ -113,5 +117,10 @@ try {

// we have received some data so reset the timeout controller
controller.reset();
signal.removeEventListener('abort', abortListener);
signal = AbortSignal.timeout(this._incomingStreamTimeout);
signal.addEventListener('abort', abortListener);
}
});
await stream.close({
signal
});
})

@@ -124,3 +133,2 @@ .catch(err => {

controller.clear();
stream.close();
});

@@ -198,3 +206,3 @@ }

let serialized;
switch (stream.stat.protocol) {
switch (stream.protocol) {
case BITSWAP100:

@@ -208,5 +216,6 @@ serialized = msg.serializeToBitswap100();

default:
throw new Error(`Unknown protocol: ${stream.stat.protocol}`);
throw new Error(`Unknown protocol: ${stream.protocol}`);
}
await pipe([serialized], (source) => lp.encode(source), stream);
await stream.close();
}

@@ -216,8 +225,6 @@ catch (err) {

this._log(err);
stream.abort(err);
}
finally {
stream.close();
}
}
}
//# sourceMappingURL=network.js.map

@@ -5,4 +5,4 @@ /// <reference types="node" />

import type { BitswapWantBlockProgressEvents } from './index.js';
import type { PeerId } from '@libp2p/interface-peer-id';
import type { AbortOptions } from '@libp2p/interfaces';
import type { AbortOptions } from '@libp2p/interface';
import type { PeerId } from '@libp2p/interface/peer-id';
import type { CID } from 'multiformats/cid';

@@ -9,0 +9,0 @@ export declare class Notifications extends EventEmitter {

/// <reference types="node" />
import { EventEmitter } from 'events';
import { Stat } from './stat.js';
import type { PeerId } from '@libp2p/interface-peer-id';
import type { PeerId } from '@libp2p/interface/peer-id';
import type { IMovingAverage } from '@vascosantos/moving-average';
import type { Libp2p } from 'libp2p';
/**
* @typedef {import('multiformats').CID} CID
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId
*/
export interface StatsOptions {

@@ -12,0 +8,0 @@ enabled?: boolean;

import { EventEmitter } from 'events';
import { trackedMap } from '@libp2p/tracked-map';
import { trackedMap } from '@libp2p/interface/metrics/tracked-map';
import { Stat } from './stat.js';

@@ -4,0 +4,0 @@ const defaultOptions = {

import { type Logger } from '@libp2p/logger';
import { BitswapMessageEntry } from '../message/entry.js';
import type { PeerId } from '@libp2p/interface-peer-id';
import type { PeerId } from '@libp2p/interface/peer-id';
/**

@@ -5,0 +5,0 @@ * Creates a logger for the given subsystem

@@ -6,4 +6,4 @@ import { Wantlist } from '../wantlist/index.js';

import type { Stats } from '../stats/index.js';
import type { Libp2p } from '@libp2p/interface-libp2p';
import type { PeerId } from '@libp2p/interface-peer-id';
import type { Libp2p } from '@libp2p/interface';
import type { PeerId } from '@libp2p/interface/peer-id';
import type { AbortOptions } from '@multiformats/multiaddr';

@@ -10,0 +10,0 @@ import type { CID } from 'multiformats/cid';

@@ -1,2 +0,2 @@

import { trackedMap } from '@libp2p/tracked-map';
import { trackedMap } from '@libp2p/interface/metrics/tracked-map';
import { base58btc } from 'multiformats/bases/base58';

@@ -3,0 +3,0 @@ import * as CONSTANTS from '../constants.js';

import { BitswapMessage as Message } from '../message/index.js';
import type { BitswapWantBlockProgressEvents } from '../index.js';
import type { BitswapNetworkWantProgressEvents, Network } from '../network.js';
import type { PeerId } from '@libp2p/interface-peer-id';
import type { PeerId } from '@libp2p/interface/peer-id';
import type { CID } from 'multiformats/cid';

@@ -6,0 +6,0 @@ import type { ProgressOptions } from 'progress-events';

import { Message } from '../message/message.js';
import { WantListEntry as Entry } from './entry.js';
import type { Stats } from '../stats/index.js';
import type { Libp2p } from '@libp2p/interface-libp2p';
import type { Libp2p } from '@libp2p/interface';
import type { CID } from 'multiformats/cid';

@@ -6,0 +6,0 @@ export declare class Wantlist {

@@ -1,2 +0,2 @@

import { trackedMap } from '@libp2p/tracked-map';
import { trackedMap } from '@libp2p/interface/metrics/tracked-map';
import { base58btc } from 'multiformats/bases/base58';

@@ -3,0 +3,0 @@ import { Message } from '../message/message.js';

{
"name": "ipfs-bitswap",
"version": "18.0.3",
"version": "19.0.0",
"description": "JavaScript implementation of the Bitswap data exchange protocol used by IPFS",

@@ -146,14 +146,6 @@ "license": "Apache-2.0 OR MIT",

"dependencies": {
"@libp2p/interface-connection": "^5.1.0",
"@libp2p/interface-libp2p": "^3.1.0",
"@libp2p/interface-peer-id": "^2.0.0",
"@libp2p/interface-peer-info": "^1.0.8",
"@libp2p/interface-registrar": "^2.0.8",
"@libp2p/interfaces": "^3.2.0",
"@libp2p/logger": "^2.0.5",
"@libp2p/topology": "^4.0.0",
"@libp2p/tracked-map": "^3.0.0",
"@libp2p/interface": "^0.1.1",
"@libp2p/logger": "^3.0.1",
"@multiformats/multiaddr": "^12.1.0",
"@vascosantos/moving-average": "^1.1.0",
"abortable-iterator": "^5.0.1",
"any-signal": "^4.1.1",

@@ -170,3 +162,3 @@ "blockstore-core": "^4.0.0",

"just-debounce-it": "^3.0.1",
"multiformats": "^11.0.0",
"multiformats": "^12.0.1",
"progress-events": "^1.0.0",

@@ -181,8 +173,8 @@ "protons-runtime": "^5.0.0",

"devDependencies": {
"@chainsafe/libp2p-noise": "^12.0.0",
"@libp2p/kad-dht": "^9.3.3",
"@libp2p/mplex": "^8.0.3",
"@libp2p/peer-id": "^2.0.0",
"@libp2p/peer-id-factory": "^2.0.0",
"@libp2p/tcp": "^7.0.1",
"@chainsafe/libp2p-noise": "^13.0.0",
"@libp2p/kad-dht": "^10.0.2",
"@libp2p/mplex": "^9.0.2",
"@libp2p/peer-id": "^3.0.1",
"@libp2p/peer-id-factory": "^3.0.2",
"@libp2p/tcp": "^8.0.2",
"@nodeutils/defaults-deep": "^1.1.0",

@@ -201,3 +193,3 @@ "@types/lodash.difference": "^4.5.7",

"it-drain": "^3.0.1",
"libp2p": "^0.45.1",
"libp2p": "^0.46.3",
"lodash.difference": "^4.5.0",

@@ -204,0 +196,0 @@ "lodash.flatten": "^4.4.0",

@@ -12,4 +12,4 @@ import { anySignal } from 'any-signal'

import type { BitswapMessage } from './message/index.js'
import type { Libp2p } from '@libp2p/interface-libp2p'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { Libp2p } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Logger } from '@libp2p/logger'

@@ -16,0 +16,0 @@ import type { AbortOptions } from '@multiformats/multiaddr'

@@ -1,2 +0,2 @@

import { trackedMap } from '@libp2p/tracked-map'
import { trackedMap } from '@libp2p/interface/metrics/tracked-map'
import { base58btc } from 'multiformats/bases/base58'

@@ -15,4 +15,4 @@ import { CID } from 'multiformats/cid'

import type { WantListEntry } from '../wantlist/entry.js'
import type { Libp2p } from '@libp2p/interface-libp2p'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { Libp2p } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Logger } from '@libp2p/logger'

@@ -19,0 +19,0 @@ import type { Blockstore } from 'interface-blockstore'

import { Wantlist } from '../wantlist/index.js'
import type { Message } from '../message/message.js'
import type { WantListEntry } from '../wantlist/entry.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { CID } from 'multiformats/cid'

@@ -6,0 +6,0 @@

import { SortedMap } from '../utils/sorted-map.js'
import type { Task, TaskMerger } from './index.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'

@@ -5,0 +5,0 @@ export interface PopTaskResult {

import { DefaultBitswap } from './bitswap.js'
import type { Message } from './message/message'
import type { BitswapNetworkNotifyProgressEvents, BitswapNetworkWantProgressEvents } from './network.js'
import type { Libp2p } from '@libp2p/interface-libp2p'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { AbortOptions } from '@libp2p/interfaces'
import type { Startable } from '@libp2p/interfaces/startable'
import type { Libp2p, AbortOptions } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Startable } from '@libp2p/interface/startable'
import type { IMovingAverage } from '@vascosantos/moving-average'

@@ -9,0 +8,0 @@ import type { Blockstore } from 'interface-blockstore'

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'
import { base58btc } from 'multiformats/bases/base58'

@@ -3,0 +3,0 @@ import { CID } from 'multiformats/cid'

@@ -1,3 +0,2 @@

import { createTopology } from '@libp2p/topology'
import { abortableSource } from 'abortable-iterator'
import { CodeError } from '@libp2p/interface/errors'
import drain from 'it-drain'

@@ -16,8 +15,8 @@ import * as lp from 'it-length-prefixed'

import type { Stats } from './stats/index.js'
import type { Connection } from '@libp2p/interface-connection'
import type { Libp2p } from '@libp2p/interface-libp2p'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerInfo } from '@libp2p/interface-peer-info'
import type { IncomingStreamData } from '@libp2p/interface-registrar'
import type { AbortOptions } from '@libp2p/interfaces'
import type { Libp2p, AbortOptions } from '@libp2p/interface'
import type { Connection } from '@libp2p/interface/connection'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { PeerInfo } from '@libp2p/interface/peer-info'
import type { IncomingStreamData } from '@libp2p/interface/stream-handler'
import type { Topology } from '@libp2p/interface/topology'
import type { Logger } from '@libp2p/logger'

@@ -111,6 +110,6 @@ import type { Multiaddr } from '@multiformats/multiaddr'

// register protocol with topology
const topology = createTopology({
const topology: Topology = {
onConnect: this._onPeerConnect,
onDisconnect: this._onPeerDisconnect
})
}

@@ -158,6 +157,12 @@ /** @type {string[]} */

Promise.resolve().then(async () => {
this._log('incoming new bitswap %s connection from %p', stream.stat.protocol, connection.remotePeer)
this._log('incoming new bitswap %s connection from %p', stream.protocol, connection.remotePeer)
const abortListener = (): void => {
stream.abort(new CodeError('Incoming Bitswap stream timed out', 'ERR_TIMEOUT'))
}
let signal = AbortSignal.timeout(this._incomingStreamTimeout)
signal.addEventListener('abort', abortListener)
await pipe(
abortableSource(stream.source, controller.signal),
stream,
(source) => lp.decode(source),

@@ -175,6 +180,12 @@ async (source) => {

// we have received some data so reset the timeout controller
controller.reset()
signal.removeEventListener('abort', abortListener)
signal = AbortSignal.timeout(this._incomingStreamTimeout)
signal.addEventListener('abort', abortListener)
}
}
)
await stream.close({
signal
})
})

@@ -187,3 +198,2 @@ .catch(err => {

controller.clear()
stream.close()
})

@@ -281,3 +291,3 @@ }

let serialized
switch (stream.stat.protocol) {
switch (stream.protocol) {
case BITSWAP100:

@@ -291,3 +301,3 @@ serialized = msg.serializeToBitswap100()

default:
throw new Error(`Unknown protocol: ${stream.stat.protocol}`)
throw new Error(`Unknown protocol: ${stream.protocol}`)
}

@@ -300,9 +310,10 @@

)
await stream.close()
} catch (err: any) {
options.onProgress?.(new CustomProgressEvent<{ peer: PeerId, error: Error }>('bitswap:network:send-wantlist:error', { peer: peerId, error: err }))
this._log(err)
} finally {
stream.close()
stream.abort(err)
}
}
}

@@ -7,4 +7,4 @@ import { EventEmitter } from 'events'

import type { BitswapWantBlockProgressEvents } from './index.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { AbortOptions } from '@libp2p/interfaces'
import type { AbortOptions } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Logger } from '@libp2p/logger'

@@ -11,0 +11,0 @@ import type { CID } from 'multiformats/cid'

import { EventEmitter } from 'events'
import { trackedMap } from '@libp2p/tracked-map'
import { trackedMap } from '@libp2p/interface/metrics/tracked-map'
import { Stat } from './stat.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { IMovingAverage } from '@vascosantos/moving-average'
import type { Libp2p } from 'libp2p'
/**
* @typedef {import('multiformats').CID} CID
* @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId
*/
export interface StatsOptions {

@@ -14,0 +9,0 @@ enabled?: boolean

import { logger as createLogger, type Logger } from '@libp2p/logger'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import { BitswapMessageEntry } from '../message/entry.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'

@@ -6,0 +6,0 @@ /**

@@ -1,2 +0,2 @@

import { trackedMap } from '@libp2p/tracked-map'
import { trackedMap } from '@libp2p/interface/metrics/tracked-map'
import { base58btc } from 'multiformats/bases/base58'

@@ -11,4 +11,4 @@ import * as CONSTANTS from '../constants.js'

import type { Stats } from '../stats/index.js'
import type { Libp2p } from '@libp2p/interface-libp2p'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { Libp2p } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Logger } from '@libp2p/logger'

@@ -15,0 +15,0 @@ import type { AbortOptions } from '@multiformats/multiaddr'

@@ -7,3 +7,3 @@ import debounce from 'just-debounce-it'

import type { BitswapNetworkWantProgressEvents, Network } from '../network.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { Logger } from '@libp2p/logger'

@@ -10,0 +10,0 @@ import type { CID } from 'multiformats/cid'

@@ -1,2 +0,2 @@

import { trackedMap } from '@libp2p/tracked-map'
import { trackedMap } from '@libp2p/interface/metrics/tracked-map'
import { base58btc } from 'multiformats/bases/base58'

@@ -6,3 +6,3 @@ import { Message } from '../message/message.js'

import type { Stats } from '../stats/index.js'
import type { Libp2p } from '@libp2p/interface-libp2p'
import type { Libp2p } from '@libp2p/interface'
import type { CID } from 'multiformats/cid'

@@ -9,0 +9,0 @@

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc