@libp2p/kad-dht 9.1.1 → 9.1.2
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 +18 -18
- package/dist/src/content-fetching/index.d.ts +3 -3
- package/dist/src/content-fetching/index.d.ts.map +1 -1
- package/dist/src/content-fetching/index.js +14 -6
- package/dist/src/content-fetching/index.js.map +1 -1
- package/dist/src/content-routing/index.d.ts +5 -5
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +12 -5
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/dual-kad-dht.d.ts +7 -7
- package/dist/src/dual-kad-dht.d.ts.map +1 -1
- package/dist/src/dual-kad-dht.js +9 -10
- package/dist/src/dual-kad-dht.js.map +1 -1
- package/dist/src/index.d.ts +9 -9
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/kad-dht.d.ts +8 -8
- package/dist/src/kad-dht.d.ts.map +1 -1
- package/dist/src/kad-dht.js +35 -17
- package/dist/src/kad-dht.js.map +1 -1
- package/dist/src/message/index.d.ts.map +1 -1
- package/dist/src/message/index.js +7 -1
- package/dist/src/message/index.js.map +1 -1
- package/dist/src/network.d.ts +4 -4
- package/dist/src/network.d.ts.map +1 -1
- package/dist/src/network.js +9 -5
- package/dist/src/network.js.map +1 -1
- package/dist/src/peer-list/index.js +1 -0
- package/dist/src/peer-list/index.js.map +1 -1
- package/dist/src/peer-list/peer-distance-list.js +10 -1
- package/dist/src/peer-list/peer-distance-list.js.map +1 -1
- package/dist/src/peer-routing/index.d.ts +6 -6
- package/dist/src/peer-routing/index.d.ts.map +1 -1
- package/dist/src/peer-routing/index.js +12 -6
- package/dist/src/peer-routing/index.js.map +1 -1
- package/dist/src/providers.d.ts +2 -2
- package/dist/src/providers.d.ts.map +1 -1
- package/dist/src/providers.js +12 -5
- package/dist/src/providers.js.map +1 -1
- package/dist/src/query/events.d.ts +1 -1
- package/dist/src/query/events.d.ts.map +1 -1
- package/dist/src/query/manager.d.ts +3 -3
- package/dist/src/query/manager.d.ts.map +1 -1
- package/dist/src/query/manager.js +15 -6
- package/dist/src/query/manager.js.map +1 -1
- package/dist/src/query/query-path.d.ts +3 -3
- package/dist/src/query/query-path.d.ts.map +1 -1
- package/dist/src/query/query-path.js +4 -4
- package/dist/src/query/query-path.js.map +1 -1
- package/dist/src/query/types.d.ts +1 -1
- package/dist/src/query/types.d.ts.map +1 -1
- package/dist/src/query-self.d.ts +2 -2
- package/dist/src/query-self.d.ts.map +1 -1
- package/dist/src/query-self.js +18 -5
- package/dist/src/query-self.js.map +1 -1
- package/dist/src/routing-table/index.d.ts +3 -3
- package/dist/src/routing-table/index.d.ts.map +1 -1
- package/dist/src/routing-table/index.js +16 -3
- package/dist/src/routing-table/index.js.map +1 -1
- package/dist/src/routing-table/refresh.d.ts.map +1 -1
- package/dist/src/routing-table/refresh.js +11 -4
- package/dist/src/routing-table/refresh.js.map +1 -1
- package/dist/src/rpc/handlers/add-provider.d.ts +2 -2
- package/dist/src/rpc/handlers/add-provider.d.ts.map +1 -1
- package/dist/src/rpc/handlers/add-provider.js +2 -1
- package/dist/src/rpc/handlers/add-provider.js.map +1 -1
- package/dist/src/rpc/handlers/find-node.d.ts +2 -2
- package/dist/src/rpc/handlers/find-node.d.ts.map +1 -1
- package/dist/src/rpc/handlers/find-node.js +6 -3
- package/dist/src/rpc/handlers/find-node.js.map +1 -1
- package/dist/src/rpc/handlers/get-providers.d.ts +2 -2
- package/dist/src/rpc/handlers/get-providers.d.ts.map +1 -1
- package/dist/src/rpc/handlers/get-providers.js +6 -2
- package/dist/src/rpc/handlers/get-providers.js.map +1 -1
- package/dist/src/rpc/handlers/get-value.d.ts +1 -1
- package/dist/src/rpc/handlers/get-value.d.ts.map +1 -1
- package/dist/src/rpc/handlers/get-value.js +5 -3
- package/dist/src/rpc/handlers/get-value.js.map +1 -1
- package/dist/src/rpc/handlers/put-value.d.ts +1 -1
- package/dist/src/rpc/handlers/put-value.d.ts.map +1 -1
- package/dist/src/rpc/handlers/put-value.js +5 -2
- package/dist/src/rpc/handlers/put-value.js.map +1 -1
- package/dist/src/rpc/index.d.ts +8 -8
- package/dist/src/rpc/index.d.ts.map +1 -1
- package/dist/src/rpc/index.js +6 -3
- package/dist/src/rpc/index.js.map +1 -1
- package/dist/src/topology-listener.d.ts +2 -2
- package/dist/src/topology-listener.d.ts.map +1 -1
- package/dist/src/topology-listener.js +6 -1
- package/dist/src/topology-listener.js.map +1 -1
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +6 -6
- package/dist/src/utils.js.map +1 -1
- package/package.json +3 -2
- package/src/content-fetching/index.ts +14 -14
- package/src/content-routing/index.ts +13 -13
- package/src/dual-kad-dht.ts +9 -13
- package/src/index.ts +13 -13
- package/src/kad-dht.ts +16 -20
- package/src/message/index.ts +1 -1
- package/src/network.ts +9 -9
- package/src/peer-list/peer-distance-list.ts +1 -1
- package/src/peer-routing/index.ts +13 -13
- package/src/providers.ts +7 -7
- package/src/query/events.ts +1 -1
- package/src/query/manager.ts +10 -10
- package/src/query/query-path.ts +8 -8
- package/src/query/types.ts +1 -1
- package/src/query-self.ts +7 -7
- package/src/routing-table/index.ts +6 -6
- package/src/routing-table/refresh.ts +5 -5
- package/src/rpc/handlers/add-provider.ts +3 -3
- package/src/rpc/handlers/find-node.ts +6 -6
- package/src/rpc/handlers/get-providers.ts +4 -4
- package/src/rpc/handlers/get-value.ts +4 -4
- package/src/rpc/handlers/put-value.ts +3 -3
- package/src/rpc/index.ts +11 -11
- package/src/topology-listener.ts +4 -4
- package/src/utils.ts +8 -8
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { createTopology } from '@libp2p/topology';
|
|
2
1
|
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events';
|
|
3
2
|
import { logger } from '@libp2p/logger';
|
|
3
|
+
import { createTopology } from '@libp2p/topology';
|
|
4
4
|
/**
|
|
5
5
|
* Receives notifications of new peers joining the network that support the DHT protocol
|
|
6
6
|
*/
|
|
7
7
|
export class TopologyListener extends EventEmitter {
|
|
8
|
+
log;
|
|
9
|
+
components;
|
|
10
|
+
protocol;
|
|
11
|
+
running;
|
|
12
|
+
registrarId;
|
|
8
13
|
constructor(components, init) {
|
|
9
14
|
super();
|
|
10
15
|
const { protocol, lan } = init;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topology-listener.js","sourceRoot":"","sources":["../../src/topology-listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"topology-listener.js","sourceRoot":"","sources":["../../src/topology-listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAejD;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,YAAoC;IACvD,GAAG,CAAQ;IACX,UAAU,CAAkB;IAC5B,QAAQ,CAAQ;IACzB,OAAO,CAAS;IAChB,WAAW,CAAS;IAE5B,YAAa,UAA4B,EAAE,IAA0B;QACnE,KAAK,EAAE,CAAA;QAEP,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;QAE9B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,oCAAoC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAA;QAC5E,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACpB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,OAAM;SACP;QAED,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QAEnB,kCAAkC;QAClC,MAAM,QAAQ,GAAG,cAAc,CAAC;YAC9B,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE;gBACpB,IAAI,CAAC,GAAG,CAAC,mCAAmC,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;gBACpE,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,MAAM,EAAE;oBACzC,MAAM,EAAE,MAAM;iBACf,CAAC,CAAC,CAAA;YACL,CAAC;SACF,CAAC,CAAA;QACF,IAAI,CAAC,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IACtF,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QAEpB,mCAAmC;QACnC,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,EAAE;YAC5B,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;YACtD,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;SAC7B;IACH,CAAC;CACF"}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Key } from 'interface-datastore/key';
|
|
2
|
-
import type { PeerInfo } from '@libp2p/interface-peer-info';
|
|
3
2
|
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
3
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info';
|
|
4
4
|
export declare function removePrivateAddresses(peer: PeerInfo): PeerInfo;
|
|
5
5
|
export declare function removePublicAddresses(peer: PeerInfo): PeerInfo;
|
|
6
6
|
/**
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAO7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAK3D,wBAAgB,sBAAsB,CAAE,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAkChE;AAED,wBAAgB,qBAAqB,CAAE,IAAI,EAAE,QAAQ,GAAG,QAAQ,CA4B/D;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAIzE;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAExE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAE,GAAG,EAAE,UAAU,GAAG,GAAG,CAEjD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAE,GAAG,EAAE,UAAU,GAAG,GAAG,CAEvD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAKzD;AAED,wBAAgB,cAAc,CAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAExD;AAED,wBAAgB,SAAS,CAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAEnD;AAED,wBAAgB,gBAAgB,CAAE,GAAG,EAAE,UAAU,GAAG,MAAM,CAEzD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,UAAU,CAK/E;AAED,wBAAgB,QAAQ,CAAE,QAAQ,EAAE,MAAM,IAAI,EAAE,IAAI,GAAE,MAAY,GAAG,MAAM,IAAI,CAO9E"}
|
package/dist/src/utils.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Key } from 'interface-datastore/key';
|
|
1
|
+
import { peerIdFromBytes } from '@libp2p/peer-id';
|
|
3
2
|
import { Libp2pRecord } from '@libp2p/record';
|
|
3
|
+
import { Key } from 'interface-datastore/key';
|
|
4
|
+
import { sha256 } from 'multiformats/hashes/sha2';
|
|
5
|
+
import isPrivateIp from 'private-ip';
|
|
6
|
+
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
|
|
4
7
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
5
8
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
6
|
-
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
|
|
7
|
-
import isPrivateIp from 'private-ip';
|
|
8
|
-
import { peerIdFromBytes } from '@libp2p/peer-id';
|
|
9
9
|
import { RECORD_KEY_PREFIX } from './constants.js';
|
|
10
10
|
// const IPNS_PREFIX = uint8ArrayFromString('/ipns/')
|
|
11
11
|
const PK_PREFIX = uint8ArrayFromString('/pk/');
|
|
@@ -71,7 +71,7 @@ export async function convertBuffer(buf) {
|
|
|
71
71
|
* Creates a DHT ID by hashing a Peer ID
|
|
72
72
|
*/
|
|
73
73
|
export async function convertPeerId(peerId) {
|
|
74
|
-
return
|
|
74
|
+
return convertBuffer(peerId.toBytes());
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* Convert a Uint8Array to their SHA2-256 hash
|
package/dist/src/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,e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AAC,EAAE,IAAI,CAAC,CAAA;IAClD,CAAC,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/kad-dht",
|
|
3
|
-
"version": "9.1.
|
|
3
|
+
"version": "9.1.2",
|
|
4
4
|
"description": "JavaScript implementation of the Kad-DHT for libp2p",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p-kad-dht#readme",
|
|
@@ -162,6 +162,7 @@
|
|
|
162
162
|
"@libp2p/record": "^3.0.0",
|
|
163
163
|
"@libp2p/topology": "^4.0.0",
|
|
164
164
|
"@multiformats/multiaddr": "^12.0.0",
|
|
165
|
+
"@types/sinon": "^10.0.14",
|
|
165
166
|
"abortable-iterator": "^5.0.1",
|
|
166
167
|
"any-signal": "^4.1.1",
|
|
167
168
|
"datastore-core": "^9.0.1",
|
|
@@ -197,7 +198,7 @@
|
|
|
197
198
|
"@types/lodash.range": "^3.2.6",
|
|
198
199
|
"@types/varint": "^6.0.0",
|
|
199
200
|
"@types/which": "^3.0.0",
|
|
200
|
-
"aegir": "^
|
|
201
|
+
"aegir": "^39.0.5",
|
|
201
202
|
"datastore-level": "^10.0.0",
|
|
202
203
|
"delay": "^5.0.0",
|
|
203
204
|
"execa": "^7.0.0",
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { CodeError } from '@libp2p/interfaces/errors'
|
|
2
|
-
import {
|
|
2
|
+
import { logger } from '@libp2p/logger'
|
|
3
3
|
import { Libp2pRecord } from '@libp2p/record'
|
|
4
|
-
import { verifyRecord } from '@libp2p/record/validators'
|
|
5
4
|
import { bestRecord } from '@libp2p/record/selectors'
|
|
6
|
-
import
|
|
5
|
+
import { verifyRecord } from '@libp2p/record/validators'
|
|
7
6
|
import map from 'it-map'
|
|
8
|
-
import
|
|
9
|
-
valueEvent,
|
|
10
|
-
queryErrorEvent
|
|
11
|
-
} from '../query/events.js'
|
|
12
|
-
import { Message, MESSAGE_TYPE } from '../message/index.js'
|
|
7
|
+
import parallel from 'it-parallel'
|
|
13
8
|
import { pipe } from 'it-pipe'
|
|
9
|
+
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
14
10
|
import {
|
|
15
11
|
ALPHA
|
|
16
12
|
} from '../constants.js'
|
|
13
|
+
import { Message, MESSAGE_TYPE } from '../message/index.js'
|
|
14
|
+
import {
|
|
15
|
+
valueEvent,
|
|
16
|
+
queryErrorEvent
|
|
17
|
+
} from '../query/events.js'
|
|
17
18
|
import { createPutRecord, convertBuffer, bufferToRecordKey } from '../utils.js'
|
|
18
|
-
import {
|
|
19
|
-
import type {
|
|
19
|
+
import type { KadDHTComponents } from '../index.js'
|
|
20
|
+
import type { Network } from '../network.js'
|
|
20
21
|
import type { PeerRouting } from '../peer-routing/index.js'
|
|
21
22
|
import type { QueryManager } from '../query/manager.js'
|
|
23
|
+
import type { QueryFunc } from '../query/types.js'
|
|
22
24
|
import type { RoutingTable } from '../routing-table/index.js'
|
|
23
|
-
import type {
|
|
24
|
-
import type { Logger } from '@libp2p/logger'
|
|
25
|
+
import type { Validators, Selectors, ValueEvent, QueryOptions, QueryEvent } from '@libp2p/interface-dht'
|
|
25
26
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
26
|
-
import type {
|
|
27
|
-
import type { KadDHTComponents } from '../index.js'
|
|
27
|
+
import type { Logger } from '@libp2p/logger'
|
|
28
28
|
|
|
29
29
|
export interface ContentFetchingInit {
|
|
30
30
|
validators: Validators
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import parallel from 'it-parallel'
|
|
1
|
+
import { logger } from '@libp2p/logger'
|
|
3
2
|
import map from 'it-map'
|
|
4
|
-
import
|
|
5
|
-
import { ALPHA } from '../constants.js'
|
|
3
|
+
import parallel from 'it-parallel'
|
|
6
4
|
import { pipe } from 'it-pipe'
|
|
5
|
+
import { ALPHA } from '../constants.js'
|
|
6
|
+
import { Message, MESSAGE_TYPE } from '../message/index.js'
|
|
7
7
|
import {
|
|
8
8
|
queryErrorEvent,
|
|
9
9
|
peerResponseEvent,
|
|
10
10
|
providerEvent
|
|
11
11
|
} from '../query/events.js'
|
|
12
|
-
import {
|
|
13
|
-
import type {
|
|
14
|
-
import type { PeerRouting } from '../peer-routing/index.js'
|
|
15
|
-
import type { QueryManager } from '../query/manager.js'
|
|
16
|
-
import type { RoutingTable } from '../routing-table/index.js'
|
|
12
|
+
import { convertBuffer } from '../utils.js'
|
|
13
|
+
import type { KadDHTComponents } from '../index.js'
|
|
17
14
|
import type { Network } from '../network.js'
|
|
18
|
-
import type {
|
|
15
|
+
import type { PeerRouting } from '../peer-routing/index.js'
|
|
19
16
|
import type { Providers } from '../providers.js'
|
|
17
|
+
import type { QueryManager } from '../query/manager.js'
|
|
20
18
|
import type { QueryFunc } from '../query/types.js'
|
|
21
|
-
import type {
|
|
19
|
+
import type { RoutingTable } from '../routing-table/index.js'
|
|
20
|
+
import type { PeerResponseEvent, ProviderEvent, QueryEvent, QueryOptions } from '@libp2p/interface-dht'
|
|
21
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
22
22
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
23
|
+
import type { Logger } from '@libp2p/logger'
|
|
23
24
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
24
|
-
import type {
|
|
25
|
-
import type { KadDHTComponents } from '../index.js'
|
|
25
|
+
import type { CID } from 'multiformats/cid'
|
|
26
26
|
|
|
27
27
|
export interface ContentRoutingInit {
|
|
28
28
|
network: Network
|
package/src/dual-kad-dht.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { symbol } from '@libp2p/interface-peer-discovery'
|
|
2
2
|
import { CodeError } from '@libp2p/interfaces/errors'
|
|
3
|
+
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
|
|
4
|
+
import { logger } from '@libp2p/logger'
|
|
3
5
|
import merge from 'it-merge'
|
|
4
6
|
import { queryErrorEvent } from './query/events.js'
|
|
7
|
+
import type { KadDHTComponents } from './index.js'
|
|
5
8
|
import type { KadDHT } from './kad-dht.js'
|
|
6
9
|
import type { DualDHT, QueryEvent, QueryOptions } from '@libp2p/interface-dht'
|
|
10
|
+
import type { PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery'
|
|
11
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
7
12
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
8
|
-
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
|
|
9
13
|
import type { CID } from 'multiformats'
|
|
10
|
-
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
11
|
-
import type { PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery'
|
|
12
|
-
import { symbol } from '@libp2p/interface-peer-discovery'
|
|
13
|
-
import type { KadDHTComponents } from './index.js'
|
|
14
14
|
|
|
15
15
|
const log = logger('libp2p:kad-dht')
|
|
16
16
|
|
|
@@ -43,13 +43,9 @@ export class DualKadDHT extends EventEmitter<PeerDiscoveryEvents> implements Dua
|
|
|
43
43
|
})
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
return true
|
|
48
|
-
}
|
|
46
|
+
readonly [symbol] = true
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
return '@libp2p/dual-kad-dht'
|
|
52
|
-
}
|
|
48
|
+
readonly [Symbol.toStringTag] = '@libp2p/dual-kad-dht'
|
|
53
49
|
|
|
54
50
|
/**
|
|
55
51
|
* Is this DHT running.
|
|
@@ -62,7 +58,7 @@ export class DualKadDHT extends EventEmitter<PeerDiscoveryEvents> implements Dua
|
|
|
62
58
|
* If 'server' this node will respond to DHT queries, if 'client' this node will not
|
|
63
59
|
*/
|
|
64
60
|
async getMode (): Promise<'client' | 'server'> {
|
|
65
|
-
return
|
|
61
|
+
return this.wan.getMode()
|
|
66
62
|
}
|
|
67
63
|
|
|
68
64
|
/**
|
package/src/index.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { type ContentRouting, contentRouting } from '@libp2p/interface-content-routing'
|
|
2
|
+
import { type PeerDiscovery, peerDiscovery } from '@libp2p/interface-peer-discovery'
|
|
3
|
+
import { type PeerRouting, peerRouting } from '@libp2p/interface-peer-routing'
|
|
4
4
|
import { CodeError } from '@libp2p/interfaces/errors'
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import type { AbortOptions } from '@libp2p/interfaces'
|
|
9
|
-
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
5
|
+
import drain from 'it-drain'
|
|
6
|
+
import { DualKadDHT } from './dual-kad-dht.js'
|
|
7
|
+
import { KadDHT as SingleKadDHT } from './kad-dht.js'
|
|
10
8
|
import type { ProvidersInit } from './providers.js'
|
|
11
|
-
import type { Registrar } from '@libp2p/interface-registrar'
|
|
12
9
|
import type { AddressManager } from '@libp2p/interface-address-manager'
|
|
13
|
-
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
14
10
|
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
11
|
+
import type { DHT, DualDHT, Selectors, Validators } from '@libp2p/interface-dht'
|
|
15
12
|
import type { Metrics } from '@libp2p/interface-metrics'
|
|
16
|
-
import type { Datastore } from 'interface-datastore'
|
|
17
|
-
import { PeerRouting, peerRouting } from '@libp2p/interface-peer-routing'
|
|
18
|
-
import { PeerDiscovery, peerDiscovery } from '@libp2p/interface-peer-discovery'
|
|
19
13
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
14
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
15
|
+
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
16
|
+
import type { Registrar } from '@libp2p/interface-registrar'
|
|
17
|
+
import type { AbortOptions } from '@libp2p/interfaces'
|
|
18
|
+
import type { Datastore } from 'interface-datastore'
|
|
19
|
+
import type { CID } from 'multiformats/cid'
|
|
20
20
|
|
|
21
21
|
export interface KadDHTInit {
|
|
22
22
|
/**
|
package/src/kad-dht.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { symbol } from '@libp2p/interface-peer-discovery'
|
|
2
|
+
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
|
|
3
|
+
import { type Logger, logger } from '@libp2p/logger'
|
|
4
|
+
import { selectors as recordSelectors } from '@libp2p/record/selectors'
|
|
5
|
+
import { validators as recordValidators } from '@libp2p/record/validators'
|
|
6
|
+
import pDefer from 'p-defer'
|
|
7
|
+
import { PROTOCOL_DHT, PROTOCOL_PREFIX, LAN_PREFIX } from './constants.js'
|
|
4
8
|
import { ContentFetching } from './content-fetching/index.js'
|
|
5
9
|
import { ContentRouting } from './content-routing/index.js'
|
|
10
|
+
import { Network } from './network.js'
|
|
6
11
|
import { PeerRouting } from './peer-routing/index.js'
|
|
7
12
|
import { Providers } from './providers.js'
|
|
8
13
|
import { QueryManager } from './query/manager.js'
|
|
14
|
+
import { QuerySelf } from './query-self.js'
|
|
15
|
+
import { RoutingTable } from './routing-table/index.js'
|
|
16
|
+
import { RoutingTableRefresh } from './routing-table/refresh.js'
|
|
9
17
|
import { RPC } from './rpc/index.js'
|
|
10
18
|
import { TopologyListener } from './topology-listener.js'
|
|
11
|
-
import { QuerySelf } from './query-self.js'
|
|
12
19
|
import {
|
|
13
20
|
removePrivateAddresses,
|
|
14
21
|
removePublicAddresses
|
|
15
22
|
} from './utils.js'
|
|
16
|
-
import {
|
|
23
|
+
import type { KadDHTComponents, KadDHTInit } from './index.js'
|
|
17
24
|
import type { QueryOptions, Validators, Selectors, DHT, QueryEvent } from '@libp2p/interface-dht'
|
|
18
|
-
import type {
|
|
19
|
-
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
|
|
25
|
+
import type { PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery'
|
|
20
26
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
27
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
21
28
|
import type { CID } from 'multiformats/cid'
|
|
22
|
-
import type { PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery'
|
|
23
|
-
import type { KadDHTComponents, KadDHTInit } from './index.js'
|
|
24
|
-
import { validators as recordValidators } from '@libp2p/record/validators'
|
|
25
|
-
import { selectors as recordSelectors } from '@libp2p/record/selectors'
|
|
26
|
-
import { symbol } from '@libp2p/interface-peer-discovery'
|
|
27
|
-
import { PROTOCOL_DHT, PROTOCOL_PREFIX, LAN_PREFIX } from './constants.js'
|
|
28
|
-
import pDefer from 'p-defer'
|
|
29
29
|
|
|
30
30
|
export const DEFAULT_MAX_INBOUND_STREAMS = 32
|
|
31
31
|
export const DEFAULT_MAX_OUTBOUND_STREAMS = 64
|
|
@@ -219,13 +219,9 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT {
|
|
|
219
219
|
})
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
|
|
223
|
-
return true
|
|
224
|
-
}
|
|
222
|
+
readonly [symbol] = true
|
|
225
223
|
|
|
226
|
-
|
|
227
|
-
return '@libp2p/kad-dht'
|
|
228
|
-
}
|
|
224
|
+
readonly [Symbol.toStringTag] = '@libp2p/kad-dht'
|
|
229
225
|
|
|
230
226
|
async onPeerConnect (peerData: PeerInfo): Promise<void> {
|
|
231
227
|
this.log('peer %p connected with protocols', peerData.id, peerData.protocols)
|
package/src/message/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { peerIdFromBytes } from '@libp2p/peer-id'
|
|
2
|
-
import { multiaddr } from '@multiformats/multiaddr'
|
|
3
2
|
import { Libp2pRecord } from '@libp2p/record'
|
|
3
|
+
import { multiaddr } from '@multiformats/multiaddr'
|
|
4
4
|
import { Message as PBMessage } from './dht.js'
|
|
5
5
|
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
6
6
|
import type { Uint8ArrayList } from 'uint8arraylist'
|
package/src/network.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { CodeError } from '@libp2p/interfaces/errors'
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
|
|
3
|
+
import { logger } from '@libp2p/logger'
|
|
4
|
+
import { abortableDuplex } from 'abortable-iterator'
|
|
4
5
|
import drain from 'it-drain'
|
|
5
6
|
import first from 'it-first'
|
|
7
|
+
import * as lp from 'it-length-prefixed'
|
|
8
|
+
import { pipe } from 'it-pipe'
|
|
6
9
|
import { Message } from './message/index.js'
|
|
7
|
-
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
|
|
8
10
|
import {
|
|
9
11
|
dialingPeerEvent,
|
|
10
12
|
sendingQueryEvent,
|
|
11
13
|
peerResponseEvent,
|
|
12
14
|
queryErrorEvent
|
|
13
15
|
} from './query/events.js'
|
|
14
|
-
import {
|
|
16
|
+
import type { KadDHTComponents } from './index.js'
|
|
17
|
+
import type { Stream } from '@libp2p/interface-connection'
|
|
18
|
+
import type { QueryEvent } from '@libp2p/interface-dht'
|
|
15
19
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
20
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
16
21
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
17
22
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
18
23
|
import type { Logger } from '@libp2p/logger'
|
|
19
24
|
import type { Duplex, Source } from 'it-stream-types'
|
|
20
|
-
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
21
|
-
import type { Stream } from '@libp2p/interface-connection'
|
|
22
|
-
import { abortableDuplex } from 'abortable-iterator'
|
|
23
25
|
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
24
|
-
import type { KadDHTComponents } from './index.js'
|
|
25
|
-
import type { QueryEvent } from '@libp2p/interface-dht'
|
|
26
26
|
|
|
27
27
|
export interface NetworkInit {
|
|
28
28
|
protocol: string
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as utils from '../utils.js'
|
|
2
1
|
import { compare as uint8ArrayCompare } from 'uint8arrays/compare'
|
|
3
2
|
import { xor as uint8ArrayXor } from 'uint8arrays/xor'
|
|
3
|
+
import * as utils from '../utils.js'
|
|
4
4
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
5
5
|
|
|
6
6
|
interface PeerDistance {
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
+
import { keys } from '@libp2p/crypto'
|
|
1
2
|
import { CodeError } from '@libp2p/interfaces/errors'
|
|
3
|
+
import { logger } from '@libp2p/logger'
|
|
4
|
+
import { peerIdFromKeys } from '@libp2p/peer-id'
|
|
5
|
+
import { Libp2pRecord } from '@libp2p/record'
|
|
2
6
|
import { verifyRecord } from '@libp2p/record/validators'
|
|
3
7
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
4
8
|
import { Message, MESSAGE_TYPE } from '../message/index.js'
|
|
5
|
-
import
|
|
9
|
+
import { PeerDistanceList } from '../peer-list/peer-distance-list.js'
|
|
6
10
|
import {
|
|
7
11
|
queryErrorEvent,
|
|
8
12
|
finalPeerEvent,
|
|
9
13
|
valueEvent
|
|
10
14
|
} from '../query/events.js'
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import { logger } from '@libp2p/logger'
|
|
14
|
-
import { keys } from '@libp2p/crypto'
|
|
15
|
-
import { peerIdFromKeys } from '@libp2p/peer-id'
|
|
16
|
-
import type { DHTRecord, DialingPeerEvent, FinalPeerEvent, QueryEvent, Validators } from '@libp2p/interface-dht'
|
|
17
|
-
import type { RoutingTable } from '../routing-table/index.js'
|
|
18
|
-
import type { QueryManager, QueryOptions } from '../query/manager.js'
|
|
15
|
+
import * as utils from '../utils.js'
|
|
16
|
+
import type { KadDHTComponents } from '../index.js'
|
|
19
17
|
import type { Network } from '../network.js'
|
|
20
|
-
import type {
|
|
21
|
-
import type { AbortOptions } from '@libp2p/interfaces'
|
|
18
|
+
import type { QueryManager, QueryOptions } from '../query/manager.js'
|
|
22
19
|
import type { QueryFunc } from '../query/types.js'
|
|
23
|
-
import type {
|
|
20
|
+
import type { RoutingTable } from '../routing-table/index.js'
|
|
21
|
+
import type { DHTRecord, DialingPeerEvent, FinalPeerEvent, QueryEvent, Validators } from '@libp2p/interface-dht'
|
|
24
22
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
25
|
-
import type {
|
|
23
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
24
|
+
import type { AbortOptions } from '@libp2p/interfaces'
|
|
25
|
+
import type { Logger } from '@libp2p/logger'
|
|
26
26
|
|
|
27
27
|
export interface PeerRoutingInit {
|
|
28
28
|
routingTable: RoutingTable
|
package/src/providers.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
+
import { logger } from '@libp2p/logger'
|
|
2
|
+
import { peerIdFromString } from '@libp2p/peer-id'
|
|
1
3
|
import cache from 'hashlru'
|
|
2
|
-
import varint from 'varint'
|
|
3
4
|
import { Key } from 'interface-datastore/key'
|
|
4
5
|
import Queue from 'p-queue'
|
|
6
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
7
|
+
import varint from 'varint'
|
|
5
8
|
import {
|
|
6
9
|
PROVIDERS_CLEANUP_INTERVAL,
|
|
7
10
|
PROVIDERS_VALIDITY,
|
|
8
11
|
PROVIDERS_LRU_CACHE_SIZE,
|
|
9
12
|
PROVIDER_KEY_PREFIX
|
|
10
13
|
} from './constants.js'
|
|
11
|
-
import {
|
|
12
|
-
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
13
|
-
import { peerIdFromString } from '@libp2p/peer-id'
|
|
14
|
-
import type { Datastore } from 'interface-datastore'
|
|
14
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
15
15
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
16
|
+
import type { Datastore } from 'interface-datastore'
|
|
16
17
|
import type { CID } from 'multiformats'
|
|
17
|
-
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
18
18
|
|
|
19
19
|
const log = logger('libp2p:kad-dht:providers')
|
|
20
20
|
|
|
@@ -209,7 +209,7 @@ export class Providers implements Startable {
|
|
|
209
209
|
* Get a list of providers for the given CID
|
|
210
210
|
*/
|
|
211
211
|
async getProviders (cid: CID): Promise<PeerId[]> {
|
|
212
|
-
return
|
|
212
|
+
return this.syncQueue.add(async () => {
|
|
213
213
|
log('get providers for %s', cid)
|
|
214
214
|
const provs = await this._getProvidersMap(cid)
|
|
215
215
|
|
package/src/query/events.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MESSAGE_TYPE_LOOKUP } from '../message/index.js'
|
|
2
2
|
import type { Message } from '../message/dht.js'
|
|
3
3
|
import type { SendingQueryEvent, PeerResponseEvent, DialingPeerEvent, AddingPeerEvent, ValueEvent, ProviderEvent, QueryErrorEvent, FinalPeerEvent } from '@libp2p/interface-dht'
|
|
4
|
-
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
5
4
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
5
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
6
6
|
import type { Libp2pRecord } from '@libp2p/record'
|
|
7
7
|
|
|
8
8
|
export interface QueryEventFields {
|
package/src/query/manager.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
+
import { setMaxListeners } from 'events'
|
|
2
|
+
import { AbortError } from '@libp2p/interfaces/errors'
|
|
3
|
+
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
|
|
4
|
+
import { logger } from '@libp2p/logger'
|
|
5
|
+
import { PeerSet } from '@libp2p/peer-collections'
|
|
1
6
|
import { anySignal } from 'any-signal'
|
|
7
|
+
import merge from 'it-merge'
|
|
8
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
2
9
|
import {
|
|
3
10
|
ALPHA, K, DEFAULT_QUERY_TIMEOUT
|
|
4
11
|
} from '../constants.js'
|
|
5
|
-
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
6
12
|
import { queryPath } from './query-path.js'
|
|
7
|
-
import merge from 'it-merge'
|
|
8
|
-
import { setMaxListeners } from 'events'
|
|
9
|
-
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
|
|
10
|
-
import { logger } from '@libp2p/logger'
|
|
11
|
-
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
12
|
-
import type { Startable } from '@libp2p/interfaces/startable'
|
|
13
13
|
import type { QueryFunc } from './types.js'
|
|
14
14
|
import type { QueryEvent } from '@libp2p/interface-dht'
|
|
15
|
-
import { PeerSet } from '@libp2p/peer-collections'
|
|
16
15
|
import type { Metric, Metrics } from '@libp2p/interface-metrics'
|
|
17
|
-
import type {
|
|
16
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
18
17
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
19
|
-
import {
|
|
18
|
+
import type { Startable } from '@libp2p/interfaces/startable'
|
|
19
|
+
import type { DeferredPromise } from 'p-defer'
|
|
20
20
|
|
|
21
21
|
export interface CleanUpEvents {
|
|
22
22
|
'cleanup': CustomEvent
|
package/src/query/query-path.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
+
import { CodeError } from '@libp2p/interfaces/errors'
|
|
2
|
+
import { anySignal } from 'any-signal'
|
|
3
|
+
import defer from 'p-defer'
|
|
1
4
|
import Queue from 'p-queue'
|
|
2
|
-
import { xor } from 'uint8arrays/xor'
|
|
3
5
|
import { toString } from 'uint8arrays/to-string'
|
|
4
|
-
import
|
|
5
|
-
import { CodeError } from '@libp2p/interfaces/errors'
|
|
6
|
+
import { xor } from 'uint8arrays/xor'
|
|
6
7
|
import { convertPeerId, convertBuffer } from '../utils.js'
|
|
7
|
-
import {
|
|
8
|
-
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
9
|
-
import type { EventEmitter } from '@libp2p/interfaces/events'
|
|
8
|
+
import { queryErrorEvent } from './events.js'
|
|
10
9
|
import type { CleanUpEvents } from './manager.js'
|
|
11
|
-
import type { Logger } from '@libp2p/logger'
|
|
12
10
|
import type { QueryFunc } from '../query/types.js'
|
|
13
11
|
import type { QueryEvent } from '@libp2p/interface-dht'
|
|
12
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
13
|
+
import type { EventEmitter } from '@libp2p/interfaces/events'
|
|
14
|
+
import type { Logger } from '@libp2p/logger'
|
|
14
15
|
import type { PeerSet } from '@libp2p/peer-collections'
|
|
15
|
-
import { queryErrorEvent } from './events.js'
|
|
16
16
|
|
|
17
17
|
const MAX_XOR = BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF')
|
|
18
18
|
|
package/src/query/types.ts
CHANGED
package/src/query-self.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { setMaxListeners } from 'events'
|
|
2
|
-
import
|
|
2
|
+
import { logger, type Logger } from '@libp2p/logger'
|
|
3
|
+
import { anySignal } from 'any-signal'
|
|
3
4
|
import length from 'it-length'
|
|
5
|
+
import { pipe } from 'it-pipe'
|
|
6
|
+
import take from 'it-take'
|
|
4
7
|
import { QUERY_SELF_INTERVAL, QUERY_SELF_TIMEOUT, K, QUERY_SELF_INITIAL_INTERVAL } from './constants.js'
|
|
5
|
-
import {
|
|
6
|
-
import { logger, Logger } from '@libp2p/logger'
|
|
8
|
+
import type { KadDHTComponents } from './index.js'
|
|
7
9
|
import type { PeerRouting } from './peer-routing/index.js'
|
|
10
|
+
import type { RoutingTable } from './routing-table/index.js'
|
|
8
11
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
9
|
-
import { pipe } from 'it-pipe'
|
|
10
|
-
import type { KadDHTComponents } from './index.js'
|
|
11
12
|
import type { DeferredPromise } from 'p-defer'
|
|
12
|
-
import type { RoutingTable } from './routing-table/index.js'
|
|
13
13
|
|
|
14
14
|
export interface QuerySelfInit {
|
|
15
15
|
lan: boolean
|
|
@@ -146,7 +146,7 @@ export class QuerySelf implements Startable {
|
|
|
146
146
|
isSelfQuery: true
|
|
147
147
|
}),
|
|
148
148
|
(source) => take(source, this.count),
|
|
149
|
-
async (source) =>
|
|
149
|
+
async (source) => length(source)
|
|
150
150
|
)
|
|
151
151
|
|
|
152
152
|
this.log('self-query ran successfully - found %d peers', found)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { logger } from '@libp2p/logger'
|
|
2
|
+
import { PeerSet } from '@libp2p/peer-collections'
|
|
1
3
|
// @ts-expect-error no types
|
|
2
4
|
import KBuck from 'k-bucket'
|
|
3
|
-
import * as utils from '../utils.js'
|
|
4
5
|
import Queue from 'p-queue'
|
|
5
|
-
import
|
|
6
|
+
import * as utils from '../utils.js'
|
|
7
|
+
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
8
|
+
import type { Metric, Metrics } from '@libp2p/interface-metrics'
|
|
6
9
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
10
|
+
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
7
11
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
8
12
|
import type { Logger } from '@libp2p/logger'
|
|
9
|
-
import { PeerSet } from '@libp2p/peer-collections'
|
|
10
|
-
import type { Metric, Metrics } from '@libp2p/interface-metrics'
|
|
11
|
-
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
12
|
-
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
13
13
|
|
|
14
14
|
export const KAD_CLOSE_TAG_NAME = 'kad-close'
|
|
15
15
|
export const KAD_CLOSE_TAG_VALUE = 50
|