@helia/bitswap 3.1.3 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/dist/src/bitswap.d.ts +5 -5
- package/dist/src/bitswap.js +5 -5
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +1 -1
- package/dist/src/network.d.ts +5 -5
- package/dist/src/network.js +4 -4
- package/dist/src/peer-want-lists/index.d.ts +4 -4
- package/dist/src/peer-want-lists/index.js +1 -1
- package/dist/src/peer-want-lists/ledger.d.ts +3 -3
- package/dist/src/peer-want-lists/ledger.js +4 -4
- package/dist/src/session.d.ts +4 -3
- package/dist/src/session.d.ts.map +1 -1
- package/dist/src/session.js +6 -3
- package/dist/src/session.js.map +1 -1
- package/dist/src/utils/bitswap-message.d.ts +1 -1
- package/dist/src/utils/cid-prefix.js +1 -1
- package/dist/src/utils/merge-messages.d.ts +1 -1
- package/dist/src/utils/split-message.d.ts +1 -1
- package/dist/src/utils/split-message.js +2 -2
- package/dist/src/want-list.d.ts +3 -3
- package/dist/src/want-list.js +4 -4
- package/package.json +1 -1
- package/src/bitswap.ts +6 -6
- package/src/index.ts +3 -3
- package/src/network.ts +8 -8
- package/src/peer-want-lists/index.ts +4 -4
- package/src/peer-want-lists/ledger.ts +6 -6
- package/src/session.ts +10 -6
- package/src/utils/bitswap-message.ts +1 -1
- package/src/utils/cid-prefix.ts +1 -1
- package/src/utils/merge-messages.ts +1 -1
- package/src/utils/split-message.ts +3 -3
- package/src/want-list.ts +7 -7
package/dist/src/bitswap.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Network } from './network.
|
|
2
|
-
import { PeerWantLists } from './peer-want-lists/index.
|
|
3
|
-
import { Stats } from './stats.
|
|
4
|
-
import { WantList } from './want-list.
|
|
5
|
-
import type { BitswapOptions, Bitswap as BitswapInterface, BitswapWantProgressEvents, BitswapNotifyProgressEvents, WantListEntry, BitswapComponents, PeerWantListEntry } from './index.
|
|
1
|
+
import { Network } from './network.ts';
|
|
2
|
+
import { PeerWantLists } from './peer-want-lists/index.ts';
|
|
3
|
+
import { Stats } from './stats.ts';
|
|
4
|
+
import { WantList } from './want-list.ts';
|
|
5
|
+
import type { BitswapOptions, Bitswap as BitswapInterface, BitswapWantProgressEvents, BitswapNotifyProgressEvents, WantListEntry, BitswapComponents, PeerWantListEntry } from './index.ts';
|
|
6
6
|
import type { CreateSessionOptions, ProviderOptions, SessionBlockBroker } from '@helia/interface';
|
|
7
7
|
import type { Libp2p, PeerId, AbortOptions } from '@libp2p/interface';
|
|
8
8
|
import type { Blockstore } from 'interface-blockstore';
|
package/dist/src/bitswap.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { setMaxListeners } from '@libp2p/interface';
|
|
2
2
|
import { anySignal } from 'any-signal';
|
|
3
3
|
import { CustomProgressEvent } from 'progress-events';
|
|
4
|
-
import { Network } from
|
|
5
|
-
import { PeerWantLists } from
|
|
6
|
-
import { createBitswapSession } from
|
|
7
|
-
import { Stats } from
|
|
8
|
-
import { WantList } from
|
|
4
|
+
import { Network } from "./network.js";
|
|
5
|
+
import { PeerWantLists } from "./peer-want-lists/index.js";
|
|
6
|
+
import { createBitswapSession } from "./session.js";
|
|
7
|
+
import { Stats } from "./stats.js";
|
|
8
|
+
import { WantList } from "./want-list.js";
|
|
9
9
|
/**
|
|
10
10
|
* JavaScript implementation of the Bitswap 'data exchange' protocol
|
|
11
11
|
* used by IPFS.
|
package/dist/src/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* It supersedes the older [ipfs-bitswap](https://www.npmjs.com/package/ipfs-bitswap) module with the aim of being smaller, faster, better integrated with libp2p/helia, having fewer dependencies and using standard JavaScript instead of Node.js APIs.
|
|
7
7
|
*/
|
|
8
|
-
import type { BitswapNetworkNotifyProgressEvents, BitswapNetworkWantProgressEvents, BitswapNetworkProgressEvents } from './network.
|
|
9
|
-
import type { WantType } from './pb/message.
|
|
8
|
+
import type { BitswapNetworkNotifyProgressEvents, BitswapNetworkWantProgressEvents, BitswapNetworkProgressEvents } from './network.ts';
|
|
9
|
+
import type { WantType } from './pb/message.ts';
|
|
10
10
|
import type { CreateSessionOptions, ProviderOptions, SessionBlockBroker } from '@helia/interface';
|
|
11
11
|
import type { Routing } from '@helia/interface/routing';
|
|
12
12
|
import type { Libp2p, AbortOptions, Startable, ComponentLogger, Metrics, PeerId } from '@libp2p/interface';
|
package/dist/src/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* It supersedes the older [ipfs-bitswap](https://www.npmjs.com/package/ipfs-bitswap) module with the aim of being smaller, faster, better integrated with libp2p/helia, having fewer dependencies and using standard JavaScript instead of Node.js APIs.
|
|
7
7
|
*/
|
|
8
|
-
import { Bitswap as BitswapClass } from
|
|
8
|
+
import { Bitswap as BitswapClass } from "./bitswap.js";
|
|
9
9
|
export const createBitswap = (components, options = {}) => {
|
|
10
10
|
return new BitswapClass(components, options);
|
|
11
11
|
};
|
package/dist/src/network.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { TypedEventEmitter } from '@libp2p/interface';
|
|
2
|
-
import { BitswapMessage } from './pb/message.
|
|
3
|
-
import type { WantOptions } from './bitswap.
|
|
4
|
-
import type { MultihashHasherLoader } from './index.
|
|
5
|
-
import type { Block } from './pb/message.
|
|
6
|
-
import type { QueuedBitswapMessage } from './utils/bitswap-message.
|
|
2
|
+
import { BitswapMessage } from './pb/message.ts';
|
|
3
|
+
import type { WantOptions } from './bitswap.ts';
|
|
4
|
+
import type { MultihashHasherLoader } from './index.ts';
|
|
5
|
+
import type { Block } from './pb/message.ts';
|
|
6
|
+
import type { QueuedBitswapMessage } from './utils/bitswap-message.ts';
|
|
7
7
|
import type { Provider, Routing } from '@helia/interface/routing';
|
|
8
8
|
import type { Libp2p, AbortOptions, Connection, PeerId, ComponentLogger, Metrics, Stream } from '@libp2p/interface';
|
|
9
9
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
package/dist/src/network.js
CHANGED
|
@@ -7,10 +7,10 @@ import { pushable } from 'it-pushable';
|
|
|
7
7
|
import take from 'it-take';
|
|
8
8
|
import { CustomProgressEvent } from 'progress-events';
|
|
9
9
|
import { raceEvent } from 'race-event';
|
|
10
|
-
import { BITSWAP_120, DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_INCOMING_MESSAGE_SIZE, DEFAULT_MAX_OUTBOUND_STREAMS, DEFAULT_MAX_OUTGOING_MESSAGE_SIZE, DEFAULT_MAX_PROVIDERS_PER_REQUEST, DEFAULT_MESSAGE_RECEIVE_TIMEOUT, DEFAULT_MESSAGE_SEND_CONCURRENCY, DEFAULT_RUN_ON_TRANSIENT_CONNECTIONS } from
|
|
11
|
-
import { BitswapMessage } from
|
|
12
|
-
import { mergeMessages } from
|
|
13
|
-
import { splitMessage } from
|
|
10
|
+
import { BITSWAP_120, DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_INCOMING_MESSAGE_SIZE, DEFAULT_MAX_OUTBOUND_STREAMS, DEFAULT_MAX_OUTGOING_MESSAGE_SIZE, DEFAULT_MAX_PROVIDERS_PER_REQUEST, DEFAULT_MESSAGE_RECEIVE_TIMEOUT, DEFAULT_MESSAGE_SEND_CONCURRENCY, DEFAULT_RUN_ON_TRANSIENT_CONNECTIONS } from "./constants.js";
|
|
11
|
+
import { BitswapMessage } from "./pb/message.js";
|
|
12
|
+
import { mergeMessages } from "./utils/merge-messages.js";
|
|
13
|
+
import { splitMessage } from "./utils/split-message.js";
|
|
14
14
|
export class Network extends TypedEventEmitter {
|
|
15
15
|
log;
|
|
16
16
|
libp2p;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CID } from 'multiformats/cid';
|
|
2
|
-
import { Ledger } from './ledger.
|
|
3
|
-
import type { BitswapNotifyProgressEvents, PeerWantListEntry } from '../index.
|
|
4
|
-
import type { Network } from '../network.
|
|
5
|
-
import type { BitswapMessage } from '../pb/message.
|
|
2
|
+
import { Ledger } from './ledger.ts';
|
|
3
|
+
import type { BitswapNotifyProgressEvents, PeerWantListEntry } from '../index.ts';
|
|
4
|
+
import type { Network } from '../network.ts';
|
|
5
|
+
import type { BitswapMessage } from '../pb/message.ts';
|
|
6
6
|
import type { AbortOptions, ComponentLogger, Libp2p, Metrics, PeerId } from '@libp2p/interface';
|
|
7
7
|
import type { PeerMap } from '@libp2p/peer-collections';
|
|
8
8
|
import type { Blockstore } from 'interface-blockstore';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CID } from 'multiformats/cid';
|
|
2
|
-
import { WantType } from '../pb/message.
|
|
3
|
-
import type { Network } from '../network.
|
|
4
|
-
import type { Wantlist } from '../pb/message.
|
|
2
|
+
import { WantType } from '../pb/message.ts';
|
|
3
|
+
import type { Network } from '../network.ts';
|
|
4
|
+
import type { Wantlist } from '../pb/message.ts';
|
|
5
5
|
import type { AbortOptions, ComponentLogger, PeerId } from '@libp2p/interface';
|
|
6
6
|
import type { Blockstore } from 'interface-blockstore';
|
|
7
7
|
export interface LedgerComponents {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import toBuffer from 'it-to-buffer';
|
|
2
2
|
import { CID } from 'multiformats/cid';
|
|
3
3
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
4
|
-
import { DEFAULT_MAX_SIZE_REPLACE_HAS_WITH_BLOCK, DEFAULT_DO_NOT_RESEND_BLOCK_WINDOW, DEFAULT_MAX_WANTLIST_SIZE } from
|
|
5
|
-
import { BlockPresenceType, WantType } from
|
|
6
|
-
import { QueuedBitswapMessage } from
|
|
7
|
-
import { cidToPrefix } from
|
|
4
|
+
import { DEFAULT_MAX_SIZE_REPLACE_HAS_WITH_BLOCK, DEFAULT_DO_NOT_RESEND_BLOCK_WINDOW, DEFAULT_MAX_WANTLIST_SIZE } from "../constants.js";
|
|
5
|
+
import { BlockPresenceType, WantType } from "../pb/message.js";
|
|
6
|
+
import { QueuedBitswapMessage } from "../utils/bitswap-message.js";
|
|
7
|
+
import { cidToPrefix } from "../utils/cid-prefix.js";
|
|
8
8
|
export class Ledger {
|
|
9
9
|
peerId;
|
|
10
10
|
blockstore;
|
package/dist/src/session.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AbstractSession } from '@helia/utils';
|
|
2
|
-
import type { BitswapWantProgressEvents } from './index.
|
|
3
|
-
import type { Network } from './network.
|
|
4
|
-
import type { WantList } from './want-list.
|
|
2
|
+
import type { BitswapWantProgressEvents } from './index.ts';
|
|
3
|
+
import type { Network } from './network.ts';
|
|
4
|
+
import type { WantList } from './want-list.ts';
|
|
5
5
|
import type { BlockRetrievalOptions, CreateSessionOptions } from '@helia/interface';
|
|
6
6
|
import type { ComponentLogger, Libp2p, PeerId } from '@libp2p/interface';
|
|
7
7
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
@@ -16,6 +16,7 @@ export interface BitswapSessionComponents {
|
|
|
16
16
|
interface ProviderPeer {
|
|
17
17
|
peerId: PeerId;
|
|
18
18
|
routing: string;
|
|
19
|
+
toString(): string;
|
|
19
20
|
}
|
|
20
21
|
declare class BitswapSession extends AbstractSession<ProviderPeer, BitswapWantProgressEvents> {
|
|
21
22
|
readonly name = "bitswap-session";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C,OAAO,KAAK,EAAmB,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAC5E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE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,8 @@ class BitswapSession extends AbstractSession {
|
|
|
28
28
|
for await (const provider of this.network.findProviders(cid, options)) {
|
|
29
29
|
yield {
|
|
30
30
|
peerId: provider.id,
|
|
31
|
-
routing: provider.routing
|
|
31
|
+
routing: provider.routing,
|
|
32
|
+
toString: () => `Bitswap(${provider.id})`
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
}
|
|
@@ -42,7 +43,8 @@ class BitswapSession extends AbstractSession {
|
|
|
42
43
|
if (isPeerId(provider)) {
|
|
43
44
|
return {
|
|
44
45
|
peerId: provider,
|
|
45
|
-
routing
|
|
46
|
+
routing,
|
|
47
|
+
toString: () => `Bitswap(${provider})`
|
|
46
48
|
};
|
|
47
49
|
}
|
|
48
50
|
if (await this.libp2p.isDialable(provider) === false) {
|
|
@@ -52,7 +54,8 @@ class BitswapSession extends AbstractSession {
|
|
|
52
54
|
const connection = await this.libp2p.dial(provider, options);
|
|
53
55
|
return {
|
|
54
56
|
peerId: connection.remotePeer,
|
|
55
|
-
routing
|
|
57
|
+
routing,
|
|
58
|
+
toString: () => `Bitswap(${connection.remotePeer})`
|
|
56
59
|
};
|
|
57
60
|
}
|
|
58
61
|
catch { }
|
package/dist/src/session.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;A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H,QAAQ,EAAE;gBACR,EAAE,EAAE,QAAQ,CAAC,MAAM;gBACnB,UAAU,EAAE,EAAE;gBACd,OAAO,EAAE,QAAQ,CAAC,OAAO;aAC1B;YACD,OAAO,EAAE,QAAQ,CAAC,OAAO;SAC1B,CAAC,CAAC,CAAA;IACL,CAAC;CACF;AAED,MAAM,UAAU,oBAAoB,CAAE,UAAoC,EAAE,IAA0B;IACpG,OAAO,IAAI,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AAC7C,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Block, BlockPresence, WantlistEntry } from '../pb/message.
|
|
1
|
+
import type { Block, BlockPresence, WantlistEntry } from '../pb/message.ts';
|
|
2
2
|
import type { CID } from 'multiformats';
|
|
3
3
|
/**
|
|
4
4
|
* A bitswap message that is in the send queue. So implemented to be
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { QueuedBitswapMessage } from './bitswap-message.
|
|
1
|
+
import type { QueuedBitswapMessage } from './bitswap-message.ts';
|
|
2
2
|
export declare function mergeMessages(existingMessage: QueuedBitswapMessage, newMessage: QueuedBitswapMessage): QueuedBitswapMessage;
|
|
3
3
|
//# sourceMappingURL=merge-messages.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { encodingLength } from 'uint8-varint';
|
|
2
|
-
import { BlockTooLargeError } from
|
|
3
|
-
import { BitswapMessage, Block, BlockPresence, WantlistEntry } from
|
|
2
|
+
import { BlockTooLargeError } from "../errors.js";
|
|
3
|
+
import { BitswapMessage, Block, BlockPresence, WantlistEntry } from "../pb/message.js";
|
|
4
4
|
/**
|
|
5
5
|
* https://github.com/ipfs/kubo/issues/4473#issuecomment-350390693
|
|
6
6
|
*/
|
package/dist/src/want-list.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TypedEventEmitter } from '@libp2p/interface';
|
|
2
2
|
import { CID } from 'multiformats/cid';
|
|
3
|
-
import { WantType } from './pb/message.
|
|
4
|
-
import type { BitswapNotifyProgressEvents, MultihashHasherLoader } from './index.
|
|
5
|
-
import type { BitswapNetworkWantProgressEvents, Network } from './network.
|
|
3
|
+
import { WantType } from './pb/message.ts';
|
|
4
|
+
import type { BitswapNotifyProgressEvents, MultihashHasherLoader } from './index.ts';
|
|
5
|
+
import type { BitswapNetworkWantProgressEvents, Network } from './network.ts';
|
|
6
6
|
import type { ComponentLogger, PeerId, Startable, AbortOptions, Libp2p, TypedEventTarget, Metrics } from '@libp2p/interface';
|
|
7
7
|
import type { PeerMap } from '@libp2p/peer-collections';
|
|
8
8
|
import type { ProgressOptions } from 'progress-events';
|
package/dist/src/want-list.js
CHANGED
|
@@ -7,10 +7,10 @@ import pDefer from 'p-defer';
|
|
|
7
7
|
import { raceEvent } from 'race-event';
|
|
8
8
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
|
|
9
9
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
10
|
-
import { DEFAULT_MESSAGE_SEND_DELAY } from
|
|
11
|
-
import { BlockPresenceType, WantType } from
|
|
12
|
-
import { QueuedBitswapMessage } from
|
|
13
|
-
import vd from
|
|
10
|
+
import { DEFAULT_MESSAGE_SEND_DELAY } from "./constants.js";
|
|
11
|
+
import { BlockPresenceType, WantType } from "./pb/message.js";
|
|
12
|
+
import { QueuedBitswapMessage } from "./utils/bitswap-message.js";
|
|
13
|
+
import vd from "./utils/varint-decoder.js";
|
|
14
14
|
export class WantList extends TypedEventEmitter {
|
|
15
15
|
/**
|
|
16
16
|
* Tracks what CIDs we've previously sent to which peers
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/bitswap",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.4",
|
|
4
4
|
"description": "JavaScript implementation of the Bitswap data exchange protocol used by Helia",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/bitswap#readme",
|
package/src/bitswap.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { setMaxListeners } from '@libp2p/interface'
|
|
2
2
|
import { anySignal } from 'any-signal'
|
|
3
3
|
import { CustomProgressEvent } from 'progress-events'
|
|
4
|
-
import { Network } from './network.
|
|
5
|
-
import { PeerWantLists } from './peer-want-lists/index.
|
|
6
|
-
import { createBitswapSession } from './session.
|
|
7
|
-
import { Stats } from './stats.
|
|
8
|
-
import { WantList } from './want-list.
|
|
9
|
-
import type { BitswapOptions, Bitswap as BitswapInterface, BitswapWantProgressEvents, BitswapNotifyProgressEvents, WantListEntry, BitswapComponents, PeerWantListEntry } from './index.
|
|
4
|
+
import { Network } from './network.ts'
|
|
5
|
+
import { PeerWantLists } from './peer-want-lists/index.ts'
|
|
6
|
+
import { createBitswapSession } from './session.ts'
|
|
7
|
+
import { Stats } from './stats.ts'
|
|
8
|
+
import { WantList } from './want-list.ts'
|
|
9
|
+
import type { BitswapOptions, Bitswap as BitswapInterface, BitswapWantProgressEvents, BitswapNotifyProgressEvents, WantListEntry, BitswapComponents, PeerWantListEntry } from './index.ts'
|
|
10
10
|
import type { CreateSessionOptions, ProviderOptions, SessionBlockBroker } from '@helia/interface'
|
|
11
11
|
import type { ComponentLogger, Libp2p, PeerId, AbortOptions } from '@libp2p/interface'
|
|
12
12
|
import type { Logger } from '@libp2p/logger'
|
package/src/index.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* It supersedes the older [ipfs-bitswap](https://www.npmjs.com/package/ipfs-bitswap) module with the aim of being smaller, faster, better integrated with libp2p/helia, having fewer dependencies and using standard JavaScript instead of Node.js APIs.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { Bitswap as BitswapClass } from './bitswap.
|
|
10
|
-
import type { BitswapNetworkNotifyProgressEvents, BitswapNetworkWantProgressEvents, BitswapNetworkProgressEvents } from './network.
|
|
11
|
-
import type { WantType } from './pb/message.
|
|
9
|
+
import { Bitswap as BitswapClass } from './bitswap.ts'
|
|
10
|
+
import type { BitswapNetworkNotifyProgressEvents, BitswapNetworkWantProgressEvents, BitswapNetworkProgressEvents } from './network.ts'
|
|
11
|
+
import type { WantType } from './pb/message.ts'
|
|
12
12
|
import type { CreateSessionOptions, ProviderOptions, SessionBlockBroker } from '@helia/interface'
|
|
13
13
|
import type { Routing } from '@helia/interface/routing'
|
|
14
14
|
import type { Libp2p, AbortOptions, Startable, ComponentLogger, Metrics, PeerId } from '@libp2p/interface'
|
package/src/network.ts
CHANGED
|
@@ -7,14 +7,14 @@ import { pushable } from 'it-pushable'
|
|
|
7
7
|
import take from 'it-take'
|
|
8
8
|
import { CustomProgressEvent } from 'progress-events'
|
|
9
9
|
import { raceEvent } from 'race-event'
|
|
10
|
-
import { BITSWAP_120, DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_INCOMING_MESSAGE_SIZE, DEFAULT_MAX_OUTBOUND_STREAMS, DEFAULT_MAX_OUTGOING_MESSAGE_SIZE, DEFAULT_MAX_PROVIDERS_PER_REQUEST, DEFAULT_MESSAGE_RECEIVE_TIMEOUT, DEFAULT_MESSAGE_SEND_CONCURRENCY, DEFAULT_RUN_ON_TRANSIENT_CONNECTIONS } from './constants.
|
|
11
|
-
import { BitswapMessage } from './pb/message.
|
|
12
|
-
import { mergeMessages } from './utils/merge-messages.
|
|
13
|
-
import { splitMessage } from './utils/split-message.
|
|
14
|
-
import type { WantOptions } from './bitswap.
|
|
15
|
-
import type { MultihashHasherLoader } from './index.
|
|
16
|
-
import type { Block } from './pb/message.
|
|
17
|
-
import type { QueuedBitswapMessage } from './utils/bitswap-message.
|
|
10
|
+
import { BITSWAP_120, DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_INCOMING_MESSAGE_SIZE, DEFAULT_MAX_OUTBOUND_STREAMS, DEFAULT_MAX_OUTGOING_MESSAGE_SIZE, DEFAULT_MAX_PROVIDERS_PER_REQUEST, DEFAULT_MESSAGE_RECEIVE_TIMEOUT, DEFAULT_MESSAGE_SEND_CONCURRENCY, DEFAULT_RUN_ON_TRANSIENT_CONNECTIONS } from './constants.ts'
|
|
11
|
+
import { BitswapMessage } from './pb/message.ts'
|
|
12
|
+
import { mergeMessages } from './utils/merge-messages.ts'
|
|
13
|
+
import { splitMessage } from './utils/split-message.ts'
|
|
14
|
+
import type { WantOptions } from './bitswap.ts'
|
|
15
|
+
import type { MultihashHasherLoader } from './index.ts'
|
|
16
|
+
import type { Block } from './pb/message.ts'
|
|
17
|
+
import type { QueuedBitswapMessage } from './utils/bitswap-message.ts'
|
|
18
18
|
import type { Provider, Routing } from '@helia/interface/routing'
|
|
19
19
|
import type { Libp2p, AbortOptions, Connection, PeerId, Topology, ComponentLogger, IdentifyResult, Counter, Metrics, Stream } from '@libp2p/interface'
|
|
20
20
|
import type { Logger } from '@libp2p/logger'
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { trackedPeerMap } from '@libp2p/peer-collections'
|
|
2
2
|
import { CID } from 'multiformats/cid'
|
|
3
|
-
import { Ledger } from './ledger.
|
|
4
|
-
import type { BitswapNotifyProgressEvents, PeerWantListEntry } from '../index.
|
|
5
|
-
import type { Network } from '../network.
|
|
6
|
-
import type { BitswapMessage } from '../pb/message.
|
|
3
|
+
import { Ledger } from './ledger.ts'
|
|
4
|
+
import type { BitswapNotifyProgressEvents, PeerWantListEntry } from '../index.ts'
|
|
5
|
+
import type { Network } from '../network.ts'
|
|
6
|
+
import type { BitswapMessage } from '../pb/message.ts'
|
|
7
7
|
import type { AbortOptions, ComponentLogger, Libp2p, Logger, Metrics, PeerId } from '@libp2p/interface'
|
|
8
8
|
import type { PeerMap } from '@libp2p/peer-collections'
|
|
9
9
|
import type { Blockstore } from 'interface-blockstore'
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import toBuffer from 'it-to-buffer'
|
|
2
2
|
import { CID } from 'multiformats/cid'
|
|
3
3
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
4
|
-
import { DEFAULT_MAX_SIZE_REPLACE_HAS_WITH_BLOCK, DEFAULT_DO_NOT_RESEND_BLOCK_WINDOW, DEFAULT_MAX_WANTLIST_SIZE } from '../constants.
|
|
5
|
-
import { BlockPresenceType, WantType } from '../pb/message.
|
|
6
|
-
import { QueuedBitswapMessage } from '../utils/bitswap-message.
|
|
7
|
-
import { cidToPrefix } from '../utils/cid-prefix.
|
|
8
|
-
import type { Network } from '../network.
|
|
9
|
-
import type { Wantlist } from '../pb/message.
|
|
4
|
+
import { DEFAULT_MAX_SIZE_REPLACE_HAS_WITH_BLOCK, DEFAULT_DO_NOT_RESEND_BLOCK_WINDOW, DEFAULT_MAX_WANTLIST_SIZE } from '../constants.ts'
|
|
5
|
+
import { BlockPresenceType, WantType } from '../pb/message.ts'
|
|
6
|
+
import { QueuedBitswapMessage } from '../utils/bitswap-message.ts'
|
|
7
|
+
import { cidToPrefix } from '../utils/cid-prefix.ts'
|
|
8
|
+
import type { Network } from '../network.ts'
|
|
9
|
+
import type { Wantlist } from '../pb/message.ts'
|
|
10
10
|
import type { AbortOptions, ComponentLogger, Logger, PeerId } from '@libp2p/interface'
|
|
11
11
|
import type { Blockstore } from 'interface-blockstore'
|
|
12
12
|
|
package/src/session.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AbstractSession } from '@helia/utils'
|
|
2
2
|
import { isPeerId } from '@libp2p/interface'
|
|
3
3
|
import { CustomProgressEvent } from 'progress-events'
|
|
4
|
-
import type { BitswapProvider, BitswapWantProgressEvents } from './index.
|
|
5
|
-
import type { Network } from './network.
|
|
6
|
-
import type { WantList } from './want-list.
|
|
4
|
+
import type { BitswapProvider, BitswapWantProgressEvents } from './index.ts'
|
|
5
|
+
import type { Network } from './network.ts'
|
|
6
|
+
import type { WantList } from './want-list.ts'
|
|
7
7
|
import type { BlockRetrievalOptions, CreateSessionOptions } from '@helia/interface'
|
|
8
8
|
import type { ComponentLogger, Libp2p, PeerId } from '@libp2p/interface'
|
|
9
9
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
@@ -20,6 +20,7 @@ export interface BitswapSessionComponents {
|
|
|
20
20
|
interface ProviderPeer {
|
|
21
21
|
peerId: PeerId
|
|
22
22
|
routing: string
|
|
23
|
+
toString(): string
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
class BitswapSession extends AbstractSession<ProviderPeer, BitswapWantProgressEvents> {
|
|
@@ -57,7 +58,8 @@ class BitswapSession extends AbstractSession<ProviderPeer, BitswapWantProgressEv
|
|
|
57
58
|
for await (const provider of this.network.findProviders(cid, options)) {
|
|
58
59
|
yield {
|
|
59
60
|
peerId: provider.id,
|
|
60
|
-
routing: provider.routing
|
|
61
|
+
routing: provider.routing,
|
|
62
|
+
toString: () => `Bitswap(${provider.id})`
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
}
|
|
@@ -74,7 +76,8 @@ class BitswapSession extends AbstractSession<ProviderPeer, BitswapWantProgressEv
|
|
|
74
76
|
if (isPeerId(provider)) {
|
|
75
77
|
return {
|
|
76
78
|
peerId: provider,
|
|
77
|
-
routing
|
|
79
|
+
routing,
|
|
80
|
+
toString: () => `Bitswap(${provider})`
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
|
|
@@ -87,7 +90,8 @@ class BitswapSession extends AbstractSession<ProviderPeer, BitswapWantProgressEv
|
|
|
87
90
|
|
|
88
91
|
return {
|
|
89
92
|
peerId: connection.remotePeer,
|
|
90
|
-
routing
|
|
93
|
+
routing,
|
|
94
|
+
toString: () => `Bitswap(${connection.remotePeer})`
|
|
91
95
|
}
|
|
92
96
|
} catch {}
|
|
93
97
|
}
|
package/src/utils/cid-prefix.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { QueuedBitswapMessage } from './bitswap-message.
|
|
1
|
+
import type { QueuedBitswapMessage } from './bitswap-message.ts'
|
|
2
2
|
|
|
3
3
|
export function mergeMessages (existingMessage: QueuedBitswapMessage, newMessage: QueuedBitswapMessage): QueuedBitswapMessage {
|
|
4
4
|
for (const [key, entry] of newMessage.wantlist.entries()) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { encodingLength } from 'uint8-varint'
|
|
2
|
-
import { BlockTooLargeError } from '../errors.
|
|
3
|
-
import { BitswapMessage, Block, BlockPresence, WantlistEntry } from '../pb/message.
|
|
4
|
-
import type { QueuedBitswapMessage } from './bitswap-message.
|
|
2
|
+
import { BlockTooLargeError } from '../errors.ts'
|
|
3
|
+
import { BitswapMessage, Block, BlockPresence, WantlistEntry } from '../pb/message.ts'
|
|
4
|
+
import type { QueuedBitswapMessage } from './bitswap-message.ts'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* https://github.com/ipfs/kubo/issues/4473#issuecomment-350390693
|
package/src/want-list.ts
CHANGED
|
@@ -7,13 +7,13 @@ import pDefer from 'p-defer'
|
|
|
7
7
|
import { raceEvent } from 'race-event'
|
|
8
8
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
9
9
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
10
|
-
import { DEFAULT_MESSAGE_SEND_DELAY } from './constants.
|
|
11
|
-
import { BlockPresenceType, WantType } from './pb/message.
|
|
12
|
-
import { QueuedBitswapMessage } from './utils/bitswap-message.
|
|
13
|
-
import vd from './utils/varint-decoder.
|
|
14
|
-
import type { BitswapNotifyProgressEvents, MultihashHasherLoader } from './index.
|
|
15
|
-
import type { BitswapNetworkWantProgressEvents, Network } from './network.
|
|
16
|
-
import type { BitswapMessage } from './pb/message.
|
|
10
|
+
import { DEFAULT_MESSAGE_SEND_DELAY } from './constants.ts'
|
|
11
|
+
import { BlockPresenceType, WantType } from './pb/message.ts'
|
|
12
|
+
import { QueuedBitswapMessage } from './utils/bitswap-message.ts'
|
|
13
|
+
import vd from './utils/varint-decoder.ts'
|
|
14
|
+
import type { BitswapNotifyProgressEvents, MultihashHasherLoader } from './index.ts'
|
|
15
|
+
import type { BitswapNetworkWantProgressEvents, Network } from './network.ts'
|
|
16
|
+
import type { BitswapMessage } from './pb/message.ts'
|
|
17
17
|
import type { ComponentLogger, PeerId, Startable, AbortOptions, Libp2p, TypedEventTarget, Metrics } from '@libp2p/interface'
|
|
18
18
|
import type { Logger } from '@libp2p/logger'
|
|
19
19
|
import type { PeerMap } from '@libp2p/peer-collections'
|