@libp2p/kad-dht 16.2.7 → 16.3.0-29797a5bb

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.
Files changed (69) hide show
  1. package/dist/index.min.js +1 -1
  2. package/dist/index.min.js.map +4 -4
  3. package/dist/src/content-fetching/index.d.ts +4 -4
  4. package/dist/src/content-fetching/index.js +8 -8
  5. package/dist/src/content-fetching/index.js.map +1 -1
  6. package/dist/src/content-routing/index.d.ts +6 -6
  7. package/dist/src/content-routing/index.js +4 -4
  8. package/dist/src/index.d.ts +10 -2
  9. package/dist/src/index.d.ts.map +1 -1
  10. package/dist/src/index.js.map +1 -1
  11. package/dist/src/kad-dht.d.ts +3 -3
  12. package/dist/src/kad-dht.d.ts.map +1 -1
  13. package/dist/src/kad-dht.js +2 -2
  14. package/dist/src/kad-dht.js.map +1 -1
  15. package/dist/src/peer-routing/index.d.ts +4 -4
  16. package/dist/src/peer-routing/index.js +6 -6
  17. package/dist/src/query/events.d.ts +1 -1
  18. package/dist/src/query/manager.d.ts +2 -2
  19. package/dist/src/query/manager.js +2 -2
  20. package/dist/src/query/query-path.d.ts +2 -2
  21. package/dist/src/query/query-path.js +1 -1
  22. package/dist/src/query/types.d.ts +1 -1
  23. package/dist/src/record/selectors.d.ts +2 -2
  24. package/dist/src/record/selectors.d.ts.map +1 -1
  25. package/dist/src/record/selectors.js +2 -2
  26. package/dist/src/record/selectors.js.map +1 -1
  27. package/dist/src/record/validators.d.ts +1 -1
  28. package/dist/src/routing-table/closest-peers.js +3 -3
  29. package/dist/src/routing-table/index.d.ts +1 -1
  30. package/dist/src/routing-table/index.js +1 -1
  31. package/dist/src/routing-table/k-bucket.js +2 -2
  32. package/dist/src/routing-table/refresh.d.ts +1 -1
  33. package/dist/src/routing-table/refresh.js +1 -1
  34. package/dist/src/rpc/handlers/add-provider.d.ts +3 -3
  35. package/dist/src/rpc/handlers/find-node.d.ts +4 -4
  36. package/dist/src/rpc/handlers/find-node.js +1 -1
  37. package/dist/src/rpc/handlers/get-providers.d.ts +5 -5
  38. package/dist/src/rpc/handlers/get-providers.js +1 -1
  39. package/dist/src/rpc/handlers/get-value.d.ts +3 -3
  40. package/dist/src/rpc/handlers/get-value.js +3 -3
  41. package/dist/src/rpc/handlers/ping.d.ts +2 -2
  42. package/dist/src/rpc/handlers/put-value.d.ts +3 -3
  43. package/dist/src/rpc/handlers/put-value.js +2 -2
  44. package/dist/src/rpc/index.d.ts +5 -5
  45. package/dist/src/rpc/index.js +1 -1
  46. package/package.json +13 -13
  47. package/src/content-fetching/index.ts +14 -14
  48. package/src/content-routing/index.ts +12 -12
  49. package/src/index.ts +16 -2
  50. package/src/kad-dht.ts +2 -2
  51. package/src/peer-routing/index.ts +12 -12
  52. package/src/query/events.ts +1 -1
  53. package/src/query/manager.ts +4 -4
  54. package/src/query/query-path.ts +3 -3
  55. package/src/query/types.ts +1 -1
  56. package/src/record/selectors.ts +3 -3
  57. package/src/record/validators.ts +1 -1
  58. package/src/routing-table/closest-peers.ts +3 -3
  59. package/src/routing-table/index.ts +2 -2
  60. package/src/routing-table/k-bucket.ts +2 -2
  61. package/src/routing-table/refresh.ts +2 -2
  62. package/src/rpc/handlers/add-provider.ts +3 -3
  63. package/src/rpc/handlers/find-node.ts +5 -5
  64. package/src/rpc/handlers/get-providers.ts +6 -6
  65. package/src/rpc/handlers/get-value.ts +6 -6
  66. package/src/rpc/handlers/ping.ts +2 -2
  67. package/src/rpc/handlers/put-value.ts +5 -5
  68. package/src/rpc/index.ts +5 -5
  69. package/dist/typedoc-urls.json +0 -65
@@ -1,7 +1,7 @@
1
1
  import { Libp2pRecord } from '@libp2p/record';
2
- import type { Message } from '../../message/dht.js';
3
- import type { PeerRouting } from '../../peer-routing/index.js';
4
- import type { DHTMessageHandler } from '../index.js';
2
+ import type { Message } from '../../message/dht.ts';
3
+ import type { PeerRouting } from '../../peer-routing/index.ts';
4
+ import type { DHTMessageHandler } from '../index.ts';
5
5
  import type { ComponentLogger, PeerId, PeerStore } from '@libp2p/interface';
6
6
  import type { Datastore } from 'interface-datastore';
7
7
  export interface GetValueHandlerInit {
@@ -1,9 +1,9 @@
1
1
  import { publicKeyToProtobuf } from '@libp2p/crypto/keys';
2
2
  import { InvalidMessageError, NotFoundError } from '@libp2p/interface';
3
3
  import { Libp2pRecord } from '@libp2p/record';
4
- import { PROVIDERS_VALIDITY } from '../../constants.js';
5
- import { MessageType } from '../../message/dht.js';
6
- import { bufferToRecordKey, isPublicKeyKey, fromPublicKeyKey } from '../../utils.js';
4
+ import { PROVIDERS_VALIDITY } from "../../constants.js";
5
+ import { MessageType } from "../../message/dht.js";
6
+ import { bufferToRecordKey, isPublicKeyKey, fromPublicKeyKey } from "../../utils.js";
7
7
  export class GetValueHandler {
8
8
  peerStore;
9
9
  datastore;
@@ -1,5 +1,5 @@
1
- import type { Message } from '../../message/dht.js';
2
- import type { DHTMessageHandler } from '../index.js';
1
+ import type { Message } from '../../message/dht.ts';
2
+ import type { DHTMessageHandler } from '../index.ts';
3
3
  import type { ComponentLogger, PeerId } from '@libp2p/interface';
4
4
  export interface PingComponents {
5
5
  logger: ComponentLogger;
@@ -1,6 +1,6 @@
1
- import type { Validators } from '../../index.js';
2
- import type { Message } from '../../message/dht.js';
3
- import type { DHTMessageHandler } from '../index.js';
1
+ import type { Validators } from '../../index.ts';
2
+ import type { Message } from '../../message/dht.ts';
3
+ import type { DHTMessageHandler } from '../index.ts';
4
4
  import type { ComponentLogger, PeerId } from '@libp2p/interface';
5
5
  import type { Datastore } from 'interface-datastore';
6
6
  export interface PutValueHandlerInit {
@@ -1,7 +1,7 @@
1
1
  import { InvalidMessageError } from '@libp2p/interface';
2
2
  import { Libp2pRecord } from '@libp2p/record';
3
- import { verifyRecord } from '../../record/validators.js';
4
- import { bufferToRecordKey } from '../../utils.js';
3
+ import { verifyRecord } from "../../record/validators.js";
4
+ import { bufferToRecordKey } from "../../utils.js";
5
5
  export class PutValueHandler {
6
6
  components;
7
7
  validators;
@@ -1,12 +1,12 @@
1
- import { Message } from '../message/dht.js';
2
- import type { PeerInfoMapper, Validators } from '../index.js';
3
- import type { PeerRouting } from '../peer-routing/index.js';
4
- import type { Providers } from '../providers.js';
1
+ import { Message } from '../message/dht.ts';
2
+ import type { PeerInfoMapper, Validators } from '../index.ts';
3
+ import type { PeerRouting } from '../peer-routing/index.ts';
4
+ import type { Providers } from '../providers.ts';
5
5
  import type { FindNodeHandlerComponents } from './handlers/find-node.ts';
6
6
  import type { GetProvidersHandlerComponents } from './handlers/get-providers.ts';
7
7
  import type { GetValueHandlerComponents } from './handlers/get-value.ts';
8
8
  import type { PutValueHandlerComponents } from './handlers/put-value.ts';
9
- import type { RoutingTable } from '../routing-table/index.js';
9
+ import type { RoutingTable } from '../routing-table/index.ts';
10
10
  import type { Metrics, PeerId, Connection, Stream } from '@libp2p/interface';
11
11
  export interface DHTMessageHandler {
12
12
  handle(peerId: PeerId, msg: Message): Promise<Message | undefined>;
@@ -1,6 +1,6 @@
1
1
  import { InvalidMessageError, TimeoutError } from '@libp2p/interface';
2
2
  import { pbStream } from '@libp2p/utils';
3
- import { Message, MessageType } from '../message/dht.js';
3
+ import { Message, MessageType } from "../message/dht.js";
4
4
  import { AddProviderHandler } from "./handlers/add-provider.js";
5
5
  import { FindNodeHandler } from "./handlers/find-node.js";
6
6
  import { GetProvidersHandler } from "./handlers/get-providers.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/kad-dht",
3
- "version": "16.2.7",
3
+ "version": "16.3.0-29797a5bb",
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/tree/main/packages/kad-dht#readme",
@@ -48,14 +48,14 @@
48
48
  "doc-check": "aegir doc-check"
49
49
  },
50
50
  "dependencies": {
51
- "@libp2p/crypto": "^5.1.18",
52
- "@libp2p/interface": "^3.2.2",
53
- "@libp2p/interface-internal": "^3.1.5",
54
- "@libp2p/peer-collections": "^7.0.20",
55
- "@libp2p/peer-id": "^6.0.9",
56
- "@libp2p/ping": "^3.1.5",
57
- "@libp2p/record": "^4.0.12",
58
- "@libp2p/utils": "^7.2.1",
51
+ "@libp2p/crypto": "5.1.18-29797a5bb",
52
+ "@libp2p/interface": "3.2.2-29797a5bb",
53
+ "@libp2p/interface-internal": "3.1.5-29797a5bb",
54
+ "@libp2p/peer-collections": "7.0.20-29797a5bb",
55
+ "@libp2p/peer-id": "6.0.9-29797a5bb",
56
+ "@libp2p/ping": "3.1.5-29797a5bb",
57
+ "@libp2p/record": "4.0.12-29797a5bb",
58
+ "@libp2p/utils": "7.2.1-29797a5bb",
59
59
  "@multiformats/multiaddr": "^13.0.1",
60
60
  "@multiformats/multiaddr-matcher": "^3.0.1",
61
61
  "any-signal": "^4.1.1",
@@ -78,16 +78,16 @@
78
78
  "race-signal": "^2.0.0",
79
79
  "uint8-varint": "^2.0.4",
80
80
  "uint8arraylist": "^2.4.8",
81
- "uint8arrays": "^5.1.0"
81
+ "uint8arrays": "^6.1.1"
82
82
  },
83
83
  "devDependencies": {
84
- "@libp2p/logger": "^6.2.7",
85
- "@libp2p/peer-store": "^12.0.20",
84
+ "@libp2p/logger": "6.2.7-29797a5bb",
85
+ "@libp2p/peer-store": "12.0.20-29797a5bb",
86
86
  "@types/lodash.random": "^3.2.9",
87
87
  "@types/lodash.range": "^3.2.9",
88
88
  "@types/sinon": "^21.0.1",
89
89
  "@types/which": "^3.0.4",
90
- "aegir": "^47.0.22",
90
+ "aegir": "^48.0.11",
91
91
  "benchmark": "^2.1.4",
92
92
  "datastore-core": "^11.0.1",
93
93
  "delay": "^7.0.0",
@@ -6,22 +6,22 @@ import { pipe } from 'it-pipe'
6
6
  import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
7
7
  import {
8
8
  ALPHA
9
- } from '../constants.js'
10
- import { QueryError } from '../errors.js'
11
- import { MessageType } from '../message/dht.js'
9
+ } from '../constants.ts'
10
+ import { QueryError } from '../errors.ts'
11
+ import { MessageType } from '../message/dht.ts'
12
12
  import {
13
13
  valueEvent,
14
14
  queryErrorEvent
15
- } from '../query/events.js'
16
- import { bestRecord } from '../record/selectors.js'
17
- import { verifyRecord } from '../record/validators.js'
18
- import { createPutRecord, bufferToRecordKey } from '../utils.js'
19
- import type { KadDHTComponents, Validators, Selectors, ValueEvent, QueryEvent } from '../index.js'
20
- import type { Message } from '../message/dht.js'
21
- import type { Network, SendMessageOptions } from '../network.js'
22
- import type { PeerRouting } from '../peer-routing/index.js'
23
- import type { QueryManager } from '../query/manager.js'
24
- import type { QueryFunc } from '../query/types.js'
15
+ } from '../query/events.ts'
16
+ import { bestRecord } from '../record/selectors.ts'
17
+ import { verifyRecord } from '../record/validators.ts'
18
+ import { createPutRecord, bufferToRecordKey } from '../utils.ts'
19
+ import type { KadDHTComponents, Validators, Selectors, ValueEvent, QueryEvent } from '../index.ts'
20
+ import type { Message } from '../message/dht.ts'
21
+ import type { Network, SendMessageOptions } from '../network.ts'
22
+ import type { PeerRouting } from '../peer-routing/index.ts'
23
+ import type { QueryManager } from '../query/manager.ts'
24
+ import type { QueryFunc } from '../query/types.ts'
25
25
  import type { AbortOptions, Logger, RoutingOptions } from '@libp2p/interface'
26
26
 
27
27
  export interface ContentFetchingInit {
@@ -230,7 +230,7 @@ export class ContentFetching {
230
230
  let i = 0
231
231
 
232
232
  try {
233
- i = bestRecord(this.selectors, key, records)
233
+ i = await bestRecord(this.selectors, key, records)
234
234
  } catch (err: any) {
235
235
  // Assume the first record if no selector available
236
236
  if (err.name !== 'InvalidParametersError') {
@@ -1,22 +1,22 @@
1
1
  import { PeerSet } from '@libp2p/peer-collections'
2
2
  import { Queue } from '@libp2p/utils'
3
3
  import { pushable } from 'it-pushable'
4
- import { ALPHA } from '../constants.js'
5
- import { MessageType } from '../message/dht.js'
6
- import { toPbPeerInfo } from '../message/utils.js'
4
+ import { ALPHA } from '../constants.ts'
5
+ import { MessageType } from '../message/dht.ts'
6
+ import { toPbPeerInfo } from '../message/utils.ts'
7
7
  import {
8
8
  queryErrorEvent,
9
9
  peerResponseEvent,
10
10
  providerEvent
11
- } from '../query/events.js'
12
- import type { FinalPeerEvent, KadDHTComponents, PeerResponseEvent, ProviderEvent, QueryEvent } from '../index.js'
13
- import type { Message } from '../message/dht.js'
14
- import type { Network } from '../network.js'
15
- import type { PeerRouting } from '../peer-routing/index.js'
16
- import type { Providers } from '../providers.js'
17
- import type { QueryManager } from '../query/manager.js'
18
- import type { QueryFunc } from '../query/types.js'
19
- import type { RoutingTable } from '../routing-table/index.js'
11
+ } from '../query/events.ts'
12
+ import type { FinalPeerEvent, KadDHTComponents, PeerResponseEvent, ProviderEvent, QueryEvent } from '../index.ts'
13
+ import type { Message } from '../message/dht.ts'
14
+ import type { Network } from '../network.ts'
15
+ import type { PeerRouting } from '../peer-routing/index.ts'
16
+ import type { Providers } from '../providers.ts'
17
+ import type { QueryManager } from '../query/manager.ts'
18
+ import type { QueryFunc } from '../query/types.ts'
19
+ import type { RoutingTable } from '../routing-table/index.ts'
20
20
  import type { Logger, PeerInfo, RoutingOptions } from '@libp2p/interface'
21
21
  import type { Multiaddr } from '@multiformats/multiaddr'
22
22
  import type { CID } from 'multiformats/cid'
package/src/index.ts CHANGED
@@ -326,6 +326,16 @@ export interface KadDHT {
326
326
  */
327
327
  readonly d: number
328
328
 
329
+ /**
330
+ * Validators validate DHT records that are found
331
+ */
332
+ readonly validators: Record<string, ValidateFn>
333
+
334
+ /**
335
+ * When multiple records for a DHT key are found, selectors choose one record
336
+ */
337
+ readonly selectors: Record<string, SelectFn>
338
+
329
339
  /**
330
340
  * Get a value from the DHT, the final ValueEvent will be the best value
331
341
  */
@@ -387,13 +397,17 @@ export interface SingleKadDHT extends KadDHT {
387
397
  * A selector function takes a DHT key and a list of records and returns the
388
398
  * index of the best record in the list
389
399
  */
390
- export interface SelectFn { (key: Uint8Array, records: Uint8Array[]): number }
400
+ export interface SelectFn {
401
+ (key: Uint8Array, records: Uint8Array[]): number | Promise<number>
402
+ }
391
403
 
392
404
  /**
393
405
  * A validator function takes a DHT key and the value of the record for that key
394
406
  * and throws if the record is invalid
395
407
  */
396
- export interface ValidateFn { (key: Uint8Array, value: Uint8Array, options?: AbortOptions): Promise<void> }
408
+ export interface ValidateFn {
409
+ (key: Uint8Array, value: Uint8Array, options?: AbortOptions): void | Promise<void>
410
+ }
397
411
 
398
412
  /**
399
413
  * Selectors are a map of key prefixes to selector functions
package/src/kad-dht.ts CHANGED
@@ -126,13 +126,13 @@ export class KadDHT extends TypedEventEmitter<PeerDiscoveryEvents> implements Ka
126
126
  public providers: Providers
127
127
  public network: Network
128
128
  public peerRouting: KADDHTPeerRouting
129
+ public readonly validators: Validators
130
+ public readonly selectors: Selectors
129
131
 
130
132
  public readonly components: KadDHTComponents
131
133
  private readonly log: Logger
132
134
  private running: boolean
133
135
  private clientMode: boolean
134
- private readonly validators: Validators
135
- private readonly selectors: Selectors
136
136
  private readonly queryManager: QueryManager
137
137
  private readonly contentFetching: ContentFetching
138
138
  private readonly contentRouting: KADDHTContentRouting
@@ -3,22 +3,22 @@ import { InvalidPublicKeyError, NotFoundError } from '@libp2p/interface'
3
3
  import { peerIdFromPublicKey, peerIdFromMultihash } from '@libp2p/peer-id'
4
4
  import { Libp2pRecord } from '@libp2p/record'
5
5
  import * as Digest from 'multiformats/hashes/digest'
6
- import { QueryError, InvalidRecordError } from '../errors.js'
7
- import { MessageType } from '../message/dht.js'
8
- import { PeerDistanceList } from '../peer-distance-list.js'
6
+ import { QueryError, InvalidRecordError } from '../errors.ts'
7
+ import { MessageType } from '../message/dht.ts'
8
+ import { PeerDistanceList } from '../peer-distance-list.ts'
9
9
  import {
10
10
  queryErrorEvent,
11
11
  finalPeerEvent,
12
12
  valueEvent
13
- } from '../query/events.js'
14
- import { verifyRecord } from '../record/validators.js'
15
- import { convertBuffer, keyForPublicKey } from '../utils.js'
16
- import type { DHTRecord, FinalPeerEvent, QueryEvent, Validators } from '../index.js'
17
- import type { Message } from '../message/dht.js'
18
- import type { Network, SendMessageOptions } from '../network.js'
19
- import type { QueryManager, QueryOptions } from '../query/manager.js'
20
- import type { QueryFunc } from '../query/types.js'
21
- import type { RoutingTable } from '../routing-table/index.js'
13
+ } from '../query/events.ts'
14
+ import { verifyRecord } from '../record/validators.ts'
15
+ import { convertBuffer, keyForPublicKey } from '../utils.ts'
16
+ import type { DHTRecord, FinalPeerEvent, QueryEvent, Validators } from '../index.ts'
17
+ import type { Message } from '../message/dht.ts'
18
+ import type { Network, SendMessageOptions } from '../network.ts'
19
+ import type { QueryManager, QueryOptions } from '../query/manager.ts'
20
+ import type { QueryFunc } from '../query/types.ts'
21
+ import type { RoutingTable } from '../routing-table/index.ts'
22
22
  import type { GetClosestPeersOptions } from '../routing-table/k-bucket.ts'
23
23
  import type { ComponentLogger, Logger, Metrics, PeerId, PeerInfo, PeerStore, RoutingOptions } from '@libp2p/interface'
24
24
  import type { AbortOptions } from 'it-pushable'
@@ -1,4 +1,4 @@
1
- import type { MessageType, SendQueryEvent, PeerResponseEvent, AddPeerEvent, ValueEvent, ProviderEvent, QueryErrorEvent, FinalPeerEvent, DisjointPath, PathEndedEvent, DialPeerEvent } from '../index.js'
1
+ import type { MessageType, SendQueryEvent, PeerResponseEvent, AddPeerEvent, ValueEvent, ProviderEvent, QueryErrorEvent, FinalPeerEvent, DisjointPath, PathEndedEvent, DialPeerEvent } from '../index.ts'
2
2
  import type { PeerId, PeerInfo } from '@libp2p/interface'
3
3
  import type { Libp2pRecord } from '@libp2p/record'
4
4
  import type { ProgressOptions } from 'progress-events'
@@ -7,12 +7,12 @@ import { raceSignal } from 'race-signal'
7
7
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
8
8
  import {
9
9
  ALPHA, K, DEFAULT_QUERY_TIMEOUT
10
- } from '../constants.js'
11
- import { convertBuffer } from '../utils.js'
10
+ } from '../constants.ts'
11
+ import { convertBuffer } from '../utils.ts'
12
12
  import { queryPath } from './query-path.ts'
13
13
  import type { QueryFunc } from './types.ts'
14
- import type { QueryEvent } from '../index.js'
15
- import type { RoutingTable } from '../routing-table/index.js'
14
+ import type { QueryEvent } from '../index.ts'
15
+ import type { RoutingTable } from '../routing-table/index.ts'
16
16
  import type { ComponentLogger, Metrics, PeerId, RoutingOptions, Startable } from '@libp2p/interface'
17
17
  import type { ConnectionManager } from '@libp2p/interface-internal'
18
18
  import type { DeferredPromise } from 'p-defer'
@@ -3,10 +3,10 @@ import { Queue } from '@libp2p/utils'
3
3
  import { pushable } from 'it-pushable'
4
4
  import { xor as uint8ArrayXor } from 'uint8arrays/xor'
5
5
  import { xorCompare as uint8ArrayXorCompare } from 'uint8arrays/xor-compare'
6
- import { convertPeerId, convertBuffer } from '../utils.js'
6
+ import { convertPeerId, convertBuffer } from '../utils.ts'
7
7
  import { pathEndedEvent, queryErrorEvent } from './events.ts'
8
- import type { QueryEvent } from '../index.js'
9
- import type { QueryFunc } from '../query/types.js'
8
+ import type { QueryEvent } from '../index.ts'
9
+ import type { QueryFunc } from '../query/types.ts'
10
10
  import type { Logger, PeerId, RoutingOptions, AbortOptions, PeerInfo } from '@libp2p/interface'
11
11
  import type { ConnectionManager } from '@libp2p/interface-internal'
12
12
  import type { Filter } from '@libp2p/utils'
@@ -1,4 +1,4 @@
1
- import type { DisjointPath, QueryEvent } from '../index.js'
1
+ import type { DisjointPath, QueryEvent } from '../index.ts'
2
2
  import type { PeerInfo } from '@libp2p/interface'
3
3
 
4
4
  export interface QueryContext {
@@ -1,12 +1,12 @@
1
1
  import { InvalidParametersError } from '@libp2p/interface'
2
2
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
3
- import { MissingSelectorError } from '../errors.js'
4
- import type { Selectors } from '../index.js'
3
+ import { MissingSelectorError } from '../errors.ts'
4
+ import type { Selectors } from '../index.ts'
5
5
 
6
6
  /**
7
7
  * Select the best record out of the given records
8
8
  */
9
- export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8Array[]): number {
9
+ export async function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8Array[]): Promise<number> {
10
10
  if (records.length === 0) {
11
11
  throw new InvalidParametersError('No records given')
12
12
  }
@@ -2,7 +2,7 @@ import { publicKeyFromProtobuf } from '@libp2p/crypto/keys'
2
2
  import { InvalidParametersError } from '@libp2p/interface'
3
3
  import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
4
4
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
5
- import type { Validators } from '../index.js'
5
+ import type { Validators } from '../index.ts'
6
6
  import type { Libp2pRecord } from '@libp2p/record'
7
7
  import type { AbortOptions } from 'it-pushable'
8
8
 
@@ -1,7 +1,7 @@
1
1
  import { PeerSet } from '@libp2p/peer-collections'
2
- import { KEEP_ALIVE_TAG } from '../constants.js'
3
- import { PeerDistanceList } from '../peer-distance-list.js'
4
- import { convertPeerId } from '../utils.js'
2
+ import { KEEP_ALIVE_TAG } from '../constants.ts'
3
+ import { PeerDistanceList } from '../peer-distance-list.ts'
4
+ import { convertPeerId } from '../utils.ts'
5
5
  import type { RoutingTable } from './index.ts'
6
6
  import type { ComponentLogger, Logger, Metrics, PeerId, PeerStore, Startable } from '@libp2p/interface'
7
7
 
@@ -3,11 +3,11 @@ import { AdaptiveTimeout, PeerQueue } from '@libp2p/utils'
3
3
  import { anySignal } from 'any-signal'
4
4
  import parallel from 'it-parallel'
5
5
  import { TypedEventEmitter, setMaxListeners } from 'main-event'
6
- import * as utils from '../utils.js'
6
+ import * as utils from '../utils.ts'
7
7
  import { ClosestPeers } from './closest-peers.ts'
8
8
  import { KBucket, isLeafBucket } from './k-bucket.ts'
9
9
  import type { Bucket, GetClosestPeersOptions, LeafBucket, Peer } from './k-bucket.ts'
10
- import type { Network } from '../network.js'
10
+ import type { Network } from '../network.ts'
11
11
  import type { AbortOptions, ComponentLogger, CounterGroup, Logger, Metric, Metrics, PeerId, PeerStore, Startable, Stream } from '@libp2p/interface'
12
12
  import type { Ping } from '@libp2p/ping'
13
13
  import type { AdaptiveTimeoutInit } from '@libp2p/utils'
@@ -3,8 +3,8 @@ import map from 'it-map'
3
3
  import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
4
4
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
5
5
  import { xor as uint8ArrayXor } from 'uint8arrays/xor'
6
- import { PeerDistanceList } from '../peer-distance-list.js'
7
- import { convertPeerId } from '../utils.js'
6
+ import { PeerDistanceList } from '../peer-distance-list.ts'
7
+ import { convertPeerId } from '../utils.ts'
8
8
  import { KBUCKET_SIZE, LAST_PING_THRESHOLD, PING_OLD_CONTACT_COUNT, PREFIX_LENGTH } from './index.ts'
9
9
  import type { PeerId, AbortOptions, Metrics } from '@libp2p/interface'
10
10
 
@@ -6,10 +6,10 @@ import { setMaxListeners } from 'main-event'
6
6
  import * as Digest from 'multiformats/hashes/digest'
7
7
  import { sha256 } from 'multiformats/hashes/sha2'
8
8
  import { xor as uint8ArrayXor } from 'uint8arrays/xor'
9
- import { TABLE_REFRESH_INTERVAL, TABLE_REFRESH_QUERY_TIMEOUT } from '../constants.js'
9
+ import { TABLE_REFRESH_INTERVAL, TABLE_REFRESH_QUERY_TIMEOUT } from '../constants.ts'
10
10
  import GENERATED_PREFIXES from './generated-prefix-list.ts'
11
11
  import type { RoutingTable } from './index.ts'
12
- import type { PeerRouting } from '../peer-routing/index.js'
12
+ import type { PeerRouting } from '../peer-routing/index.ts'
13
13
  import type { AbortOptions, ComponentLogger, Logger, PeerId } from '@libp2p/interface'
14
14
 
15
15
  /**
@@ -3,9 +3,9 @@ import { peerIdFromMultihash } from '@libp2p/peer-id'
3
3
  import { multiaddr } from '@multiformats/multiaddr'
4
4
  import { CID } from 'multiformats/cid'
5
5
  import * as Digest from 'multiformats/hashes/digest'
6
- import type { Message } from '../../message/dht.js'
7
- import type { Providers } from '../../providers.js'
8
- import type { DHTMessageHandler } from '../index.js'
6
+ import type { Message } from '../../message/dht.ts'
7
+ import type { Providers } from '../../providers.ts'
8
+ import type { DHTMessageHandler } from '../index.ts'
9
9
  import type { ComponentLogger, Logger, PeerId, PeerStore } from '@libp2p/interface'
10
10
 
11
11
  export interface AddProviderComponents {
@@ -1,11 +1,11 @@
1
1
  import { InvalidMessageError } from '@libp2p/interface'
2
2
  import { CODE_P2P } from '@multiformats/multiaddr'
3
3
  import { equals as uint8ArrayEquals } from 'uint8arrays'
4
- import { MessageType } from '../../message/dht.js'
5
- import type { PeerInfoMapper } from '../../index.js'
6
- import type { Message } from '../../message/dht.js'
7
- import type { PeerRouting } from '../../peer-routing/index.js'
8
- import type { DHTMessageHandler } from '../index.js'
4
+ import { MessageType } from '../../message/dht.ts'
5
+ import type { PeerInfoMapper } from '../../index.ts'
6
+ import type { Message } from '../../message/dht.ts'
7
+ import type { PeerRouting } from '../../peer-routing/index.ts'
8
+ import type { DHTMessageHandler } from '../index.ts'
9
9
  import type { ComponentLogger, Logger, PeerId, PeerInfo } from '@libp2p/interface'
10
10
  import type { AddressManager } from '@libp2p/interface-internal'
11
11
 
@@ -2,12 +2,12 @@ import { InvalidMessageError } from '@libp2p/interface'
2
2
  import all from 'it-all'
3
3
  import map from 'it-map'
4
4
  import { CID } from 'multiformats/cid'
5
- import { MessageType } from '../../message/dht.js'
6
- import type { PeerInfoMapper } from '../../index.js'
7
- import type { Message } from '../../message/dht.js'
8
- import type { PeerRouting } from '../../peer-routing/index.js'
9
- import type { Providers } from '../../providers.js'
10
- import type { DHTMessageHandler } from '../index.js'
5
+ import { MessageType } from '../../message/dht.ts'
6
+ import type { PeerInfoMapper } from '../../index.ts'
7
+ import type { Message } from '../../message/dht.ts'
8
+ import type { PeerRouting } from '../../peer-routing/index.ts'
9
+ import type { Providers } from '../../providers.ts'
10
+ import type { DHTMessageHandler } from '../index.ts'
11
11
  import type { ComponentLogger, Logger, PeerId, PeerInfo, PeerStore } from '@libp2p/interface'
12
12
  import type { Multiaddr } from '@multiformats/multiaddr'
13
13
 
@@ -3,12 +3,12 @@ import { InvalidMessageError, NotFoundError } from '@libp2p/interface'
3
3
  import { Libp2pRecord } from '@libp2p/record'
4
4
  import {
5
5
  PROVIDERS_VALIDITY
6
- } from '../../constants.js'
7
- import { MessageType } from '../../message/dht.js'
8
- import { bufferToRecordKey, isPublicKeyKey, fromPublicKeyKey } from '../../utils.js'
9
- import type { Message } from '../../message/dht.js'
10
- import type { PeerRouting } from '../../peer-routing/index.js'
11
- import type { DHTMessageHandler } from '../index.js'
6
+ } from '../../constants.ts'
7
+ import { MessageType } from '../../message/dht.ts'
8
+ import { bufferToRecordKey, isPublicKeyKey, fromPublicKeyKey } from '../../utils.ts'
9
+ import type { Message } from '../../message/dht.ts'
10
+ import type { PeerRouting } from '../../peer-routing/index.ts'
11
+ import type { DHTMessageHandler } from '../index.ts'
12
12
  import type { ComponentLogger, Logger, PeerId, PeerStore } from '@libp2p/interface'
13
13
  import type { Datastore } from 'interface-datastore'
14
14
 
@@ -1,5 +1,5 @@
1
- import type { Message } from '../../message/dht.js'
2
- import type { DHTMessageHandler } from '../index.js'
1
+ import type { Message } from '../../message/dht.ts'
2
+ import type { DHTMessageHandler } from '../index.ts'
3
3
  import type { ComponentLogger, Logger, PeerId } from '@libp2p/interface'
4
4
 
5
5
  export interface PingComponents {
@@ -1,10 +1,10 @@
1
1
  import { InvalidMessageError } from '@libp2p/interface'
2
2
  import { Libp2pRecord } from '@libp2p/record'
3
- import { verifyRecord } from '../../record/validators.js'
4
- import { bufferToRecordKey } from '../../utils.js'
5
- import type { Validators } from '../../index.js'
6
- import type { Message } from '../../message/dht.js'
7
- import type { DHTMessageHandler } from '../index.js'
3
+ import { verifyRecord } from '../../record/validators.ts'
4
+ import { bufferToRecordKey } from '../../utils.ts'
5
+ import type { Validators } from '../../index.ts'
6
+ import type { Message } from '../../message/dht.ts'
7
+ import type { DHTMessageHandler } from '../index.ts'
8
8
  import type { ComponentLogger, Logger, PeerId } from '@libp2p/interface'
9
9
  import type { Datastore } from 'interface-datastore'
10
10
 
package/src/rpc/index.ts CHANGED
@@ -1,20 +1,20 @@
1
1
  import { InvalidMessageError, TimeoutError } from '@libp2p/interface'
2
2
  import { pbStream } from '@libp2p/utils'
3
- import { Message, MessageType } from '../message/dht.js'
3
+ import { Message, MessageType } from '../message/dht.ts'
4
4
  import { AddProviderHandler } from './handlers/add-provider.ts'
5
5
  import { FindNodeHandler } from './handlers/find-node.ts'
6
6
  import { GetProvidersHandler } from './handlers/get-providers.ts'
7
7
  import { GetValueHandler } from './handlers/get-value.ts'
8
8
  import { PingHandler } from './handlers/ping.ts'
9
9
  import { PutValueHandler } from './handlers/put-value.ts'
10
- import type { PeerInfoMapper, Validators } from '../index.js'
11
- import type { PeerRouting } from '../peer-routing/index.js'
12
- import type { Providers } from '../providers.js'
10
+ import type { PeerInfoMapper, Validators } from '../index.ts'
11
+ import type { PeerRouting } from '../peer-routing/index.ts'
12
+ import type { Providers } from '../providers.ts'
13
13
  import type { FindNodeHandlerComponents } from './handlers/find-node.ts'
14
14
  import type { GetProvidersHandlerComponents } from './handlers/get-providers.ts'
15
15
  import type { GetValueHandlerComponents } from './handlers/get-value.ts'
16
16
  import type { PutValueHandlerComponents } from './handlers/put-value.ts'
17
- import type { RoutingTable } from '../routing-table/index.js'
17
+ import type { RoutingTable } from '../routing-table/index.ts'
18
18
  import type { CounterGroup, Logger, Metrics, PeerId, MetricGroup, Connection, Stream } from '@libp2p/interface'
19
19
 
20
20
  export interface DHTMessageHandler {