@libp2p/kad-dht 14.0.2-d34642db1 → 14.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. package/README.md +36 -0
  2. package/dist/index.min.js +2 -2
  3. package/dist/src/constants.d.ts +4 -3
  4. package/dist/src/constants.d.ts.map +1 -1
  5. package/dist/src/constants.js +8 -3
  6. package/dist/src/constants.js.map +1 -1
  7. package/dist/src/content-fetching/index.d.ts +1 -0
  8. package/dist/src/content-fetching/index.d.ts.map +1 -1
  9. package/dist/src/content-fetching/index.js +5 -3
  10. package/dist/src/content-fetching/index.js.map +1 -1
  11. package/dist/src/index.d.ts +107 -2
  12. package/dist/src/index.d.ts.map +1 -1
  13. package/dist/src/index.js +36 -0
  14. package/dist/src/index.js.map +1 -1
  15. package/dist/src/kad-dht.d.ts +14 -1
  16. package/dist/src/kad-dht.d.ts.map +1 -1
  17. package/dist/src/kad-dht.js +76 -27
  18. package/dist/src/kad-dht.js.map +1 -1
  19. package/dist/src/network.d.ts +1 -0
  20. package/dist/src/network.d.ts.map +1 -1
  21. package/dist/src/network.js +4 -5
  22. package/dist/src/network.js.map +1 -1
  23. package/dist/src/peer-routing/index.d.ts.map +1 -1
  24. package/dist/src/peer-routing/index.js +9 -10
  25. package/dist/src/peer-routing/index.js.map +1 -1
  26. package/dist/src/providers.d.ts +21 -50
  27. package/dist/src/providers.d.ts.map +1 -1
  28. package/dist/src/providers.js +51 -192
  29. package/dist/src/providers.js.map +1 -1
  30. package/dist/src/query/manager.d.ts +1 -1
  31. package/dist/src/query/manager.d.ts.map +1 -1
  32. package/dist/src/query/manager.js +8 -19
  33. package/dist/src/query/manager.js.map +1 -1
  34. package/dist/src/query-self.d.ts +3 -1
  35. package/dist/src/query-self.d.ts.map +1 -1
  36. package/dist/src/query-self.js +17 -16
  37. package/dist/src/query-self.js.map +1 -1
  38. package/dist/src/reprovider.d.ts +63 -0
  39. package/dist/src/reprovider.d.ts.map +1 -0
  40. package/dist/src/reprovider.js +161 -0
  41. package/dist/src/reprovider.js.map +1 -0
  42. package/dist/src/routing-table/closest-peers.d.ts +1 -0
  43. package/dist/src/routing-table/closest-peers.d.ts.map +1 -1
  44. package/dist/src/routing-table/closest-peers.js +7 -0
  45. package/dist/src/routing-table/closest-peers.js.map +1 -1
  46. package/dist/src/routing-table/index.d.ts +1 -0
  47. package/dist/src/routing-table/index.d.ts.map +1 -1
  48. package/dist/src/routing-table/index.js +14 -11
  49. package/dist/src/routing-table/index.js.map +1 -1
  50. package/dist/src/rpc/handlers/get-value.d.ts +1 -0
  51. package/dist/src/rpc/handlers/get-value.d.ts.map +1 -1
  52. package/dist/src/rpc/handlers/get-value.js +3 -1
  53. package/dist/src/rpc/handlers/get-value.js.map +1 -1
  54. package/dist/src/rpc/handlers/put-value.d.ts +1 -0
  55. package/dist/src/rpc/handlers/put-value.d.ts.map +1 -1
  56. package/dist/src/rpc/handlers/put-value.js +3 -1
  57. package/dist/src/rpc/handlers/put-value.js.map +1 -1
  58. package/dist/src/rpc/index.d.ts +1 -0
  59. package/dist/src/rpc/index.d.ts.map +1 -1
  60. package/dist/src/rpc/index.js +9 -10
  61. package/dist/src/rpc/index.js.map +1 -1
  62. package/dist/src/utils.d.ts +20 -1
  63. package/dist/src/utils.d.ts.map +1 -1
  64. package/dist/src/utils.js +87 -4
  65. package/dist/src/utils.js.map +1 -1
  66. package/dist/typedoc-urls.json +59 -0
  67. package/package.json +12 -14
  68. package/src/constants.ts +11 -5
  69. package/src/content-fetching/index.ts +5 -3
  70. package/src/index.ts +116 -2
  71. package/src/kad-dht.ts +94 -41
  72. package/src/network.ts +5 -5
  73. package/src/peer-routing/index.ts +9 -11
  74. package/src/providers.ts +57 -244
  75. package/src/query/manager.ts +12 -28
  76. package/src/query-self.ts +20 -17
  77. package/src/reprovider.ts +226 -0
  78. package/src/routing-table/closest-peers.ts +9 -0
  79. package/src/routing-table/index.ts +16 -11
  80. package/src/rpc/handlers/get-value.ts +3 -1
  81. package/src/rpc/handlers/put-value.ts +3 -1
  82. package/src/rpc/index.ts +10 -10
  83. package/src/utils.ts +102 -4
@@ -1,4 +1,6 @@
1
1
  import { Key } from 'interface-datastore/key';
2
+ import { CID } from 'multiformats/cid';
3
+ import type { Operation, OperationMetrics } from './kad-dht.js';
2
4
  import type { PeerId, PeerInfo } from '@libp2p/interface';
3
5
  import type { Multiaddr } from '@multiformats/multiaddr';
4
6
  export declare function removePrivateAddressesMapper(peer: PeerInfo): PeerInfo;
@@ -19,7 +21,7 @@ export declare function bufferToKey(buf: Uint8Array): Key;
19
21
  /**
20
22
  * Convert a Uint8Array to their SHA2-256 hash
21
23
  */
22
- export declare function bufferToRecordKey(buf: Uint8Array): Key;
24
+ export declare function bufferToRecordKey(prefix: string, buf: Uint8Array): Key;
23
25
  /**
24
26
  * Generate the key for a public key.
25
27
  */
@@ -33,4 +35,21 @@ export declare function fromPublicKeyKey(key: Uint8Array): PeerId;
33
35
  export declare function createPutRecord(key: Uint8Array, value: Uint8Array): Uint8Array;
34
36
  export declare function debounce(callback: () => void, wait?: number): () => void;
35
37
  export declare function multiaddrIsPublic(multiaddr: Multiaddr): boolean;
38
+ /**
39
+ * Parse the CID and provider peer id from the key
40
+ */
41
+ export declare function parseProviderKey(key: Key): {
42
+ cid: CID;
43
+ peerId: PeerId;
44
+ };
45
+ /**
46
+ * Encode the given key its matching datastore key
47
+ */
48
+ export declare function toProviderKey(prefix: string, cid: CID | string, peerId?: PeerId): Key;
49
+ export declare function readProviderTime(buf: Uint8Array): Date;
50
+ /**
51
+ * Wraps the passed generator function with timing metrics
52
+ */
53
+ export declare function timeOperationGenerator(fn: (...args: any[]) => AsyncGenerator<any>, operationMetrics: OperationMetrics, type: Operation): (...args: any[]) => AsyncGenerator<any>;
54
+ export declare function timeOperationMethod(fn: (...args: any[]) => Promise<any>, operationMetrics: OperationMetrics, type: Operation): (...args: any[]) => Promise<any>;
36
55
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":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/peer-id';
2
2
  import { Libp2pRecord } from '@libp2p/record';
3
3
  import { isPrivateIp } from '@libp2p/utils/private-ip';
4
4
  import { Key } from 'interface-datastore/key';
5
+ import { CID } from 'multiformats/cid';
6
+ import * as raw from 'multiformats/codecs/raw';
5
7
  import * as Digest from 'multiformats/hashes/digest';
6
8
  import { sha256 } from 'multiformats/hashes/sha2';
9
+ import * as varint from 'uint8-varint';
7
10
  import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
8
11
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
9
12
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
10
- import { RECORD_KEY_PREFIX } from './constants.js';
11
13
  // const IPNS_PREFIX = uint8ArrayFromString('/ipns/')
12
14
  const PK_PREFIX = uint8ArrayFromString('/pk/');
13
15
  export function removePrivateAddressesMapper(peer) {
@@ -86,8 +88,8 @@ export function bufferToKey(buf) {
86
88
  /**
87
89
  * Convert a Uint8Array to their SHA2-256 hash
88
90
  */
89
- export function bufferToRecordKey(buf) {
90
- return new Key(`${RECORD_KEY_PREFIX}/${uint8ArrayToString(buf, 'base32')}`, false);
91
+ export function bufferToRecordKey(prefix, buf) {
92
+ return new Key(`${prefix}/${uint8ArrayToString(buf, 'base32')}`, false);
91
93
  }
92
94
  /**
93
95
  * Generate the key for a public key.
@@ -150,4 +152,85 @@ export function multiaddrIsPublic(multiaddr) {
150
152
  }
151
153
  return false;
152
154
  }
155
+ /**
156
+ * Parse the CID and provider peer id from the key
157
+ */
158
+ export function parseProviderKey(key) {
159
+ const parts = key.toString().split('/');
160
+ const peerIdStr = parts.pop();
161
+ const cidStr = parts.pop();
162
+ if (peerIdStr == null || cidStr == null) {
163
+ throw new Error(`incorrectly formatted provider entry key in datastore: ${key.toString()}`);
164
+ }
165
+ return {
166
+ cid: CID.createV1(raw.code, Digest.decode(uint8ArrayFromString(cidStr, 'base32'))),
167
+ peerId: peerIdFromString(peerIdStr)
168
+ };
169
+ }
170
+ /**
171
+ * Encode the given key its matching datastore key
172
+ */
173
+ export function toProviderKey(prefix, cid, peerId) {
174
+ const cidStr = typeof cid === 'string' ? cid : uint8ArrayToString(cid.multihash.bytes, 'base32');
175
+ const parts = [
176
+ prefix,
177
+ cidStr
178
+ ];
179
+ if (peerId != null) {
180
+ parts.push(peerId.toString());
181
+ }
182
+ return new Key(parts.join('/'));
183
+ }
184
+ export function readProviderTime(buf) {
185
+ return new Date(varint.decode(buf));
186
+ }
187
+ /**
188
+ * Wraps the passed generator function with timing metrics
189
+ */
190
+ export function timeOperationGenerator(fn, operationMetrics, type) {
191
+ return async function* (...args) {
192
+ const stopSuccessTimer = operationMetrics.queryTime?.timer(type);
193
+ const stopErrorTimer = operationMetrics.errorTime?.timer(type);
194
+ let errored = false;
195
+ try {
196
+ operationMetrics.queries?.increment({ [type]: true });
197
+ yield* fn(...args);
198
+ }
199
+ catch (err) {
200
+ errored = true;
201
+ stopErrorTimer?.();
202
+ operationMetrics.errors?.increment({ [type]: true });
203
+ throw err;
204
+ }
205
+ finally {
206
+ operationMetrics.queries?.decrement({ [type]: true });
207
+ if (!errored) {
208
+ stopSuccessTimer?.();
209
+ }
210
+ }
211
+ };
212
+ }
213
+ export function timeOperationMethod(fn, operationMetrics, type) {
214
+ return async function (...args) {
215
+ const stopSuccessTimer = operationMetrics?.queryTime?.timer(type);
216
+ const stopErrorTimer = operationMetrics?.errorTime?.timer(type);
217
+ let errored = false;
218
+ try {
219
+ operationMetrics.queries?.increment({ [type]: true });
220
+ return await fn(...args);
221
+ }
222
+ catch (err) {
223
+ errored = true;
224
+ stopErrorTimer?.();
225
+ operationMetrics.errors?.increment({ [type]: true });
226
+ throw err;
227
+ }
228
+ finally {
229
+ operationMetrics.queries?.decrement({ [type]: true });
230
+ if (!errored) {
231
+ stopSuccessTimer?.();
232
+ }
233
+ }
234
+ };
235
+ }
153
236
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.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S,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;YAEpD,MAAM,GAAG,CAAA;QACX,CAAC;gBAAS,CAAC;YACT,gBAAgB,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;YAErD,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,gBAAgB,EAAE,EAAE,CAAA;YACtB,CAAC;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,59 @@
1
+ {
2
+ "codec": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.MessageType.codec.html",
3
+ "EventTypes": "https://libp2p.github.io/js-libp2p/enums/_libp2p_kad_dht.EventTypes.html",
4
+ ".:EventTypes": "https://libp2p.github.io/js-libp2p/enums/_libp2p_kad_dht.EventTypes.html",
5
+ "MessageType": "https://libp2p.github.io/js-libp2p/enums/_libp2p_kad_dht.MessageType-1.html",
6
+ "AddPeerEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.AddPeerEvent.html",
7
+ ".:AddPeerEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.AddPeerEvent.html",
8
+ "DHTRecord": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.DHTRecord.html",
9
+ ".:DHTRecord": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.DHTRecord.html",
10
+ "DialPeerEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.DialPeerEvent.html",
11
+ ".:DialPeerEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.DialPeerEvent.html",
12
+ "FinalPeerEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.FinalPeerEvent.html",
13
+ ".:FinalPeerEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.FinalPeerEvent.html",
14
+ "KadDHT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.KadDHT.html",
15
+ ".:KadDHT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.KadDHT.html",
16
+ "KadDHTComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.KadDHTComponents.html",
17
+ ".:KadDHTComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.KadDHTComponents.html",
18
+ "KadDHTInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.KadDHTInit.html",
19
+ ".:KadDHTInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.KadDHTInit.html",
20
+ "PeerInfoMapper": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.PeerInfoMapper.html",
21
+ ".:PeerInfoMapper": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.PeerInfoMapper.html",
22
+ "PeerResponseEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.PeerResponseEvent.html",
23
+ ".:PeerResponseEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.PeerResponseEvent.html",
24
+ "ProviderEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ProviderEvent.html",
25
+ ".:ProviderEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ProviderEvent.html",
26
+ "ProvidersInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ProvidersInit.html",
27
+ ".:ProvidersInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ProvidersInit.html",
28
+ "QueryErrorEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.QueryErrorEvent.html",
29
+ ".:QueryErrorEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.QueryErrorEvent.html",
30
+ "ReProvideInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ReProvideInit.html",
31
+ ".:ReProvideInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ReProvideInit.html",
32
+ "RoutingTable": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.RoutingTable.html",
33
+ ".:RoutingTable": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.RoutingTable.html",
34
+ "SelectFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SelectFn.html",
35
+ ".:SelectFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SelectFn.html",
36
+ "SendQueryEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SendQueryEvent.html",
37
+ ".:SendQueryEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SendQueryEvent.html",
38
+ "SingleKadDHT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SingleKadDHT.html",
39
+ ".:SingleKadDHT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SingleKadDHT.html",
40
+ "ValidateFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ValidateFn.html",
41
+ ".:ValidateFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ValidateFn.html",
42
+ "ValueEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ValueEvent.html",
43
+ ".:ValueEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ValueEvent.html",
44
+ "DHTProgressEvents": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.DHTProgressEvents.html",
45
+ ".:DHTProgressEvents": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.DHTProgressEvents.html",
46
+ "MessageName": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.MessageName.html",
47
+ ".:MessageName": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.MessageName.html",
48
+ "QueryEvent": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.QueryEvent.html",
49
+ ".:QueryEvent": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.QueryEvent.html",
50
+ "Selectors": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.Selectors.html",
51
+ ".:Selectors": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.Selectors.html",
52
+ "Validators": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.Validators.html",
53
+ ".:Validators": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.Validators.html",
54
+ "kadDHT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.kadDHT-1.html",
55
+ ".:kadDHT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.kadDHT-1.html",
56
+ "passthroughMapper": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.passthroughMapper.html",
57
+ "removePrivateAddressesMapper": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.removePrivateAddressesMapper.html",
58
+ "removePublicAddressesMapper": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.removePublicAddressesMapper.html"
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/kad-dht",
3
- "version": "14.0.2-d34642db1",
3
+ "version": "14.1.0",
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",
@@ -57,16 +57,15 @@
57
57
  "doc-check": "aegir doc-check"
58
58
  },
59
59
  "dependencies": {
60
- "@libp2p/crypto": "5.0.5-d34642db1",
61
- "@libp2p/interface": "2.1.3-d34642db1",
62
- "@libp2p/interface-internal": "2.0.9-d34642db1",
63
- "@libp2p/peer-collections": "6.0.9-d34642db1",
64
- "@libp2p/peer-id": "5.0.6-d34642db1",
65
- "@libp2p/record": "4.0.4-d34642db1",
66
- "@libp2p/utils": "6.1.2-d34642db1",
60
+ "@libp2p/crypto": "^5.0.6",
61
+ "@libp2p/interface": "^2.2.0",
62
+ "@libp2p/interface-internal": "^2.0.10",
63
+ "@libp2p/peer-collections": "^6.0.10",
64
+ "@libp2p/peer-id": "^5.0.7",
65
+ "@libp2p/record": "^4.0.4",
66
+ "@libp2p/utils": "^6.1.3",
67
67
  "@multiformats/multiaddr": "^12.2.3",
68
68
  "any-signal": "^4.1.1",
69
- "hashlru": "^2.3.0",
70
69
  "interface-datastore": "^8.3.0",
71
70
  "it-drain": "^3.0.7",
72
71
  "it-length": "^3.0.6",
@@ -77,10 +76,10 @@
77
76
  "it-pipe": "^3.0.1",
78
77
  "it-protobuf-stream": "^1.1.3",
79
78
  "it-take": "^3.0.5",
79
+ "mortice": "^3.0.4",
80
80
  "multiformats": "^13.1.0",
81
81
  "p-defer": "^4.0.1",
82
82
  "p-event": "^6.0.1",
83
- "p-queue": "^8.0.1",
84
83
  "progress-events": "^1.0.0",
85
84
  "protons-runtime": "^5.4.0",
86
85
  "race-signal": "^1.0.2",
@@ -89,16 +88,15 @@
89
88
  "uint8arrays": "^5.1.0"
90
89
  },
91
90
  "devDependencies": {
92
- "@libp2p/interface-compliance-tests": "6.1.7-d34642db1",
93
- "@libp2p/logger": "5.1.2-d34642db1",
94
- "@libp2p/peer-store": "11.0.9-d34642db1",
91
+ "@libp2p/interface-compliance-tests": "^6.1.8",
92
+ "@libp2p/logger": "^5.1.3",
93
+ "@libp2p/peer-store": "^11.0.10",
95
94
  "@types/lodash.random": "^3.2.9",
96
95
  "@types/lodash.range": "^3.2.9",
97
96
  "@types/sinon": "^17.0.3",
98
97
  "@types/which": "^3.0.3",
99
98
  "aegir": "^44.0.1",
100
99
  "datastore-core": "^10.0.0",
101
- "datastore-level": "^11.0.0",
102
100
  "delay": "^6.0.0",
103
101
  "execa": "^9.1.0",
104
102
  "it-all": "^3.0.6",
package/src/constants.ts CHANGED
@@ -15,15 +15,21 @@ export const MAX_RECORD_AGE = 36 * hour
15
15
 
16
16
  export const PROTOCOL = '/ipfs/kad/1.0.0'
17
17
 
18
- export const RECORD_KEY_PREFIX = '/dht/record'
18
+ export const PROVIDERS_VALIDITY = 24 * hour
19
19
 
20
- export const PROVIDER_KEY_PREFIX = '/dht/provider'
20
+ export const PROVIDERS_CLEANUP_INTERVAL = hour
21
21
 
22
- export const PROVIDERS_LRU_CACHE_SIZE = 256
22
+ // Re-run the provide operation when the expiry of our provider records is within this amount
23
+ export const REPROVIDE_THRESHOLD = 2 * hour
23
24
 
24
- export const PROVIDERS_VALIDITY = 24 * hour
25
+ // How many reprovide operations to run at once
26
+ export const REPROVIDE_CONCURRENCY = 10
25
27
 
26
- export const PROVIDERS_CLEANUP_INTERVAL = hour
28
+ // How long to let the reprovide queue grow before we wait for capacity
29
+ export const REPROVIDE_MAX_QUEUE_SIZE = 16_384
30
+
31
+ // How often to check if records need reproviding
32
+ export const REPROVIDE_INTERVAL = hour
27
33
 
28
34
  export const READ_MESSAGE_TIMEOUT = 10 * second
29
35
 
@@ -41,12 +41,14 @@ export class ContentFetching {
41
41
  private readonly peerRouting: PeerRouting
42
42
  private readonly queryManager: QueryManager
43
43
  private readonly network: Network
44
+ private readonly datastorePrefix: string
44
45
 
45
46
  constructor (components: KadDHTComponents, init: ContentFetchingInit) {
46
47
  const { validators, selectors, peerRouting, queryManager, network, logPrefix } = init
47
48
 
48
49
  this.components = components
49
50
  this.log = components.logger.forComponent(`${logPrefix}:content-fetching`)
51
+ this.datastorePrefix = `/${init.logPrefix.replaceAll(':', '/')}/record`
50
52
  this.validators = validators
51
53
  this.selectors = selectors
52
54
  this.peerRouting = peerRouting
@@ -61,7 +63,7 @@ export class ContentFetching {
61
63
  async getLocal (key: Uint8Array): Promise<Libp2pRecord> {
62
64
  this.log('getLocal %b', key)
63
65
 
64
- const dsKey = bufferToRecordKey(key)
66
+ const dsKey = bufferToRecordKey(this.datastorePrefix, key)
65
67
 
66
68
  this.log('fetching record for key %k', dsKey)
67
69
 
@@ -92,7 +94,7 @@ export class ContentFetching {
92
94
  // correct ourself
93
95
  if (this.components.peerId.equals(from)) {
94
96
  try {
95
- const dsKey = bufferToRecordKey(key)
97
+ const dsKey = bufferToRecordKey(this.datastorePrefix, key)
96
98
  this.log(`Storing corrected record for key ${dsKey.toString()}`)
97
99
  await this.components.datastore.put(dsKey, fixupRec.subarray())
98
100
  } catch (err: any) {
@@ -136,7 +138,7 @@ export class ContentFetching {
136
138
  const record = createPutRecord(key, value)
137
139
 
138
140
  // store the record locally
139
- const dsKey = bufferToRecordKey(key)
141
+ const dsKey = bufferToRecordKey(this.datastorePrefix, key)
140
142
  this.log(`storing record for key ${dsKey.toString()}`)
141
143
  await this.components.datastore.put(dsKey, record.subarray())
142
144
 
package/src/index.ts CHANGED
@@ -78,12 +78,47 @@
78
78
  *
79
79
  * console.info(peerInfo) // peer id, multiaddrs
80
80
  * ```
81
+ *
82
+ * @example Connecting to both a LAN-only DHT and the IPFS Amino DHT
83
+ *
84
+ * When using multiple DHTs, you should specify distinct datastore, metrics and
85
+ * log prefixes to ensure that data is kept separate for each instance.
86
+ *
87
+ * ```TypeScript
88
+ * import { kadDHT, removePublicAddressesMapper, removePrivateAddressesMapper } from '@libp2p/kad-dht'
89
+ * import { createLibp2p } from 'libp2p'
90
+ * import { peerIdFromString } from '@libp2p/peer-id'
91
+ *
92
+ * const node = await createLibp2p({
93
+ * services: {
94
+ * lanDHT: kadDHT({
95
+ * protocol: '/ipfs/lan/kad/1.0.0',
96
+ * peerInfoMapper: removePublicAddressesMapper,
97
+ * clientMode: false,
98
+ * logPrefix: 'libp2p:dht-lan',
99
+ * datastorePrefix: '/dht-lan',
100
+ * metricsPrefix: 'libp2p_dht_lan'
101
+ * }),
102
+ * aminoDHT: kadDHT({
103
+ * protocol: '/ipfs/kad/1.0.0',
104
+ * peerInfoMapper: removePrivateAddressesMapper,
105
+ * logPrefix: 'libp2p:dht-amino',
106
+ * datastorePrefix: '/dht-amino',
107
+ * metricsPrefix: 'libp2p_dht_amino'
108
+ * })
109
+ * }
110
+ * })
111
+ *
112
+ * const peerId = peerIdFromString('QmFoo')
113
+ * const peerInfo = await node.peerRouting.findPeer(peerId)
114
+ *
115
+ * console.info(peerInfo) // peer id, multiaddrs
116
+ * ```
81
117
  */
82
118
 
83
119
  import { KadDHT as KadDHTClass } from './kad-dht.js'
84
120
  import { MessageType } from './message/dht.js'
85
121
  import { removePrivateAddressesMapper, removePublicAddressesMapper, passthroughMapper } from './utils.js'
86
- import type { ProvidersInit } from './providers.js'
87
122
  import type { Libp2pEvents, ComponentLogger, TypedEventTarget, Metrics, PeerId, PeerInfo, PeerStore, RoutingOptions, PrivateKey } from '@libp2p/interface'
88
123
  import type { AddressManager, ConnectionManager, Registrar } from '@libp2p/interface-internal'
89
124
  import type { AdaptiveTimeoutInit } from '@libp2p/utils/src/adaptive-timeout.js'
@@ -251,6 +286,12 @@ export interface KadDHT {
251
286
  */
252
287
  provide(key: CID, options?: RoutingOptions): AsyncIterable<QueryEvent>
253
288
 
289
+ /**
290
+ * Provider records must be re-published every 24 hours - pass a previously
291
+ * provided CID here to not re-publish a record for it any more
292
+ */
293
+ cancelReprovide(key: CID): Promise<void>
294
+
254
295
  /**
255
296
  * Store the passed value under the passed key on the DHT
256
297
  */
@@ -299,7 +340,61 @@ export type Selectors = Record<string, SelectFn>
299
340
  */
300
341
  export type Validators = Record<string, ValidateFn>
301
342
 
302
- export type { ProvidersInit }
343
+ export interface ProvidersInit {
344
+ /**
345
+ * @default 256
346
+ */
347
+ cacheSize?: number
348
+ /**
349
+ * How often invalid records are cleaned. (in seconds)
350
+ *
351
+ * @default 5400
352
+ */
353
+ cleanupInterval?: number
354
+ /**
355
+ * How long is a provider valid for. (in seconds)
356
+ *
357
+ * @default 86400
358
+ */
359
+ provideValidity?: number
360
+ }
361
+
362
+ export interface ReProvideInit {
363
+ /**
364
+ * How many re-provide operations to run simultaneously
365
+ *
366
+ * @default 10
367
+ */
368
+ concurrency?: number
369
+
370
+ /**
371
+ * How long to let the re-provide queue grow
372
+ *
373
+ * @default 16384
374
+ */
375
+ maxQueueSize?: number
376
+
377
+ /**
378
+ * How long before the record expiry to re-provide in ms
379
+ *
380
+ * @default 7200000
381
+ */
382
+ threshold?: number
383
+
384
+ /**
385
+ * How often to check which records need reproviding in ms
386
+ *
387
+ * @default 3600000
388
+ */
389
+ interval?: number
390
+
391
+ /**
392
+ * How long provider records are valid for in ms
393
+ *
394
+ * @default 86400000
395
+ */
396
+ validity?: number
397
+ }
303
398
 
304
399
  export interface KadDHTInit {
305
400
  /**
@@ -396,6 +491,20 @@ export interface KadDHTInit {
396
491
  */
397
492
  logPrefix?: string
398
493
 
494
+ /**
495
+ * The datastore prefix to use
496
+ *
497
+ * @default "/dht"
498
+ */
499
+ datastorePrefix?: string
500
+
501
+ /**
502
+ * The metrics prefix to use
503
+ *
504
+ * @default "libp2p_kad_dht"
505
+ */
506
+ metricsPrefix?: string
507
+
399
508
  /**
400
509
  * Settings for how long to wait in ms when pinging DHT peers to decide if
401
510
  * they should be evicted from the routing table or not.
@@ -459,6 +568,11 @@ export interface KadDHTInit {
459
568
  */
460
569
  providers?: ProvidersInit
461
570
 
571
+ /**
572
+ * Initialization options for the Reprovider component
573
+ */
574
+ reprovide?: ReProvideInit
575
+
462
576
  /**
463
577
  * For every incoming and outgoing PeerInfo, override address configuration
464
578
  * with this filter.