@libp2p/kad-dht 7.0.1 → 7.0.3
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 +19 -19
- package/dist/src/content-fetching/index.d.ts +5 -5
- package/dist/src/content-fetching/index.d.ts.map +1 -1
- package/dist/src/content-fetching/index.js +2 -2
- package/dist/src/content-fetching/index.js.map +1 -1
- package/dist/src/content-routing/index.d.ts +3 -3
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +1 -1
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/dual-kad-dht.d.ts +9 -9
- package/dist/src/dual-kad-dht.d.ts.map +1 -1
- package/dist/src/kad-dht.d.ts +9 -9
- package/dist/src/kad-dht.d.ts.map +1 -1
- package/dist/src/kad-dht.js +1 -1
- package/dist/src/kad-dht.js.map +1 -1
- package/dist/src/message/dht.d.ts +4 -4
- package/dist/src/message/dht.d.ts.map +1 -1
- package/dist/src/message/dht.js +40 -46
- package/dist/src/message/dht.js.map +1 -1
- package/dist/src/message/index.d.ts.map +1 -1
- package/dist/src/network.d.ts +3 -2
- package/dist/src/network.d.ts.map +1 -1
- package/dist/src/network.js.map +1 -1
- package/dist/src/peer-list/index.d.ts.map +1 -1
- package/dist/src/peer-list/peer-distance-list.d.ts.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 +2 -2
- package/dist/src/peer-routing/index.js.map +1 -1
- package/dist/src/providers.d.ts.map +1 -1
- package/dist/src/providers.js +3 -3
- package/dist/src/providers.js.map +1 -1
- package/dist/src/query/manager.d.ts +2 -2
- package/dist/src/query/manager.d.ts.map +1 -1
- package/dist/src/query/query-path.d.ts.map +1 -1
- package/dist/src/query/query-path.js.map +1 -1
- package/dist/src/query-self.d.ts.map +1 -1
- package/dist/src/routing-table/index.d.ts.map +1 -1
- package/dist/src/routing-table/index.js +1 -1
- package/dist/src/routing-table/index.js.map +1 -1
- package/dist/src/routing-table/refresh.d.ts +3 -2
- package/dist/src/routing-table/refresh.d.ts.map +1 -1
- package/dist/src/routing-table/refresh.js.map +1 -1
- package/dist/src/rpc/handlers/add-provider.d.ts +1 -1
- package/dist/src/rpc/handlers/add-provider.d.ts.map +1 -1
- package/dist/src/rpc/handlers/find-node.d.ts.map +1 -1
- package/dist/src/rpc/handlers/get-providers.d.ts +2 -1
- package/dist/src/rpc/handlers/get-providers.d.ts.map +1 -1
- 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 +1 -1
- package/dist/src/rpc/handlers/ping.d.ts.map +1 -1
- package/dist/src/rpc/handlers/put-value.d.ts.map +1 -1
- package/dist/src/rpc/index.d.ts.map +1 -1
- package/dist/src/topology-listener.d.ts +1 -1
- package/dist/src/topology-listener.d.ts.map +1 -1
- package/dist/src/topology-listener.js +1 -1
- package/dist/src/topology-listener.js.map +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +1 -1
- package/dist/src/utils.js.map +1 -1
- package/package.json +6 -8
- package/src/content-fetching/index.ts +9 -9
- package/src/content-routing/index.ts +4 -4
- package/src/dual-kad-dht.ts +14 -14
- package/src/kad-dht.ts +16 -16
- package/src/message/dht.ts +46 -49
- package/src/message/index.ts +5 -5
- package/src/network.ts +8 -7
- package/src/peer-list/index.ts +5 -5
- package/src/peer-list/peer-distance-list.ts +4 -4
- package/src/peer-routing/index.ts +10 -10
- package/src/providers.ts +14 -14
- package/src/query/manager.ts +5 -5
- package/src/query/query-path.ts +4 -4
- package/src/query-self.ts +4 -4
- package/src/routing-table/index.ts +10 -10
- package/src/routing-table/refresh.ts +11 -10
- package/src/rpc/handlers/add-provider.ts +1 -1
- package/src/rpc/handlers/find-node.ts +1 -1
- package/src/rpc/handlers/get-providers.ts +4 -3
- package/src/rpc/handlers/get-value.ts +3 -3
- package/src/rpc/handlers/ping.ts +1 -1
- package/src/rpc/handlers/put-value.ts +1 -1
- package/src/rpc/index.ts +2 -2
- package/src/topology-listener.ts +3 -3
- package/src/utils.ts +12 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/rpc/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,OAAO,EAAgB,MAAM,qBAAqB,CAAA;AAE3D,OAAO,EAAmB,yBAAyB,EAAE,MAAM,yBAAyB,CAAA;AACpF,OAAO,EAAuB,6BAA6B,EAAE,MAAM,6BAA6B,CAAA;AAChG,OAAO,EAAmB,yBAAyB,EAAE,MAAM,yBAAyB,CAAA;AAEpF,OAAO,EAAmB,yBAAyB,EAAE,MAAM,yBAAyB,CAAA;AACpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAEvD,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;CACvE;AAED,MAAM,WAAW,OAAO;IACtB,YAAY,EAAE,YAAY,CAAA;IAC1B,SAAS,EAAE,SAAS,CAAA;IACpB,WAAW,EAAE,WAAW,CAAA;IACxB,UAAU,EAAE,UAAU,CAAA;IACtB,GAAG,EAAE,OAAO,CAAA;CACb;AAED,MAAM,WAAW,aAAc,SAAQ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AM,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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAM7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAE3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAMvD,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,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAM7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAE3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAMvD,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
|
@@ -115,7 +115,7 @@ export function debounce(callback, wait = 100) {
|
|
|
115
115
|
let timeout;
|
|
116
116
|
return () => {
|
|
117
117
|
clearTimeout(timeout);
|
|
118
|
-
timeout = setTimeout(() => callback(), wait);
|
|
118
|
+
timeout = setTimeout(() => { callback(); }, wait);
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
//# sourceMappingURL=utils.js.map
|
package/dist/src/utils.js.map
CHANGED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CAAC,OAAO,CAAC,CAAA;QACrB,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAA,CAAC,CAAC,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": "7.0.
|
|
3
|
+
"version": "7.0.3",
|
|
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",
|
|
@@ -137,7 +137,7 @@
|
|
|
137
137
|
"test:chrome-webworker": "aegir test -t webworker",
|
|
138
138
|
"test:firefox": "aegir test -t browser -- --browser firefox",
|
|
139
139
|
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
|
|
140
|
-
"dep-check": "aegir dep-check",
|
|
140
|
+
"dep-check": "aegir dep-check -i protons",
|
|
141
141
|
"release": "aegir release",
|
|
142
142
|
"docs": "aegir docs"
|
|
143
143
|
},
|
|
@@ -163,7 +163,6 @@
|
|
|
163
163
|
"abortable-iterator": "^4.0.2",
|
|
164
164
|
"any-signal": "^3.0.0",
|
|
165
165
|
"datastore-core": "^8.0.1",
|
|
166
|
-
"events": "^3.3.0",
|
|
167
166
|
"hashlru": "^2.3.0",
|
|
168
167
|
"interface-datastore": "^7.0.0",
|
|
169
168
|
"it-all": "^2.0.0",
|
|
@@ -182,7 +181,7 @@
|
|
|
182
181
|
"p-defer": "^4.0.0",
|
|
183
182
|
"p-queue": "^7.2.0",
|
|
184
183
|
"private-ip": "^3.0.0",
|
|
185
|
-
"protons-runtime": "^
|
|
184
|
+
"protons-runtime": "^5.0.0",
|
|
186
185
|
"timeout-abort-controller": "^3.0.0",
|
|
187
186
|
"uint8arraylist": "^2.0.0",
|
|
188
187
|
"uint8arrays": "^4.0.2",
|
|
@@ -196,18 +195,17 @@
|
|
|
196
195
|
"@types/lodash.range": "^3.2.6",
|
|
197
196
|
"@types/varint": "^6.0.0",
|
|
198
197
|
"@types/which": "^2.0.1",
|
|
199
|
-
"aegir": "^
|
|
198
|
+
"aegir": "^38.1.2",
|
|
200
199
|
"datastore-level": "^9.0.0",
|
|
201
200
|
"delay": "^5.0.0",
|
|
202
|
-
"execa": "^
|
|
201
|
+
"execa": "^7.0.0",
|
|
203
202
|
"it-filter": "^2.0.0",
|
|
204
203
|
"it-last": "^2.0.0",
|
|
205
|
-
"it-pair": "^2.0.2",
|
|
206
204
|
"lodash.random": "^3.2.0",
|
|
207
205
|
"lodash.range": "^3.2.0",
|
|
208
206
|
"p-retry": "^5.0.0",
|
|
209
207
|
"p-wait-for": "^5.0.0",
|
|
210
|
-
"protons": "^
|
|
208
|
+
"protons": "^7.0.2",
|
|
211
209
|
"sinon": "^15.0.0",
|
|
212
210
|
"ts-sinon": "^2.0.2",
|
|
213
211
|
"which": "^3.0.0"
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
} from '../constants.js'
|
|
17
17
|
import { createPutRecord, convertBuffer, bufferToRecordKey } from '../utils.js'
|
|
18
18
|
import { logger } from '@libp2p/logger'
|
|
19
|
-
import type { Validators, Selectors, ValueEvent, QueryOptions } from '@libp2p/interface-dht'
|
|
19
|
+
import type { Validators, Selectors, ValueEvent, QueryOptions, QueryEvent } from '@libp2p/interface-dht'
|
|
20
20
|
import type { PeerRouting } from '../peer-routing/index.js'
|
|
21
21
|
import type { QueryManager } from '../query/manager.js'
|
|
22
22
|
import type { RoutingTable } from '../routing-table/index.js'
|
|
@@ -59,7 +59,7 @@ export class ContentFetching {
|
|
|
59
59
|
this.network = network
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
async putLocal (key: Uint8Array, rec: Uint8Array) {
|
|
62
|
+
async putLocal (key: Uint8Array, rec: Uint8Array): Promise<void> {
|
|
63
63
|
const dsKey = bufferToRecordKey(key)
|
|
64
64
|
await this.components.datastore.put(dsKey, rec)
|
|
65
65
|
}
|
|
@@ -68,7 +68,7 @@ export class ContentFetching {
|
|
|
68
68
|
* Attempt to retrieve the value for the given key from
|
|
69
69
|
* the local datastore
|
|
70
70
|
*/
|
|
71
|
-
async getLocal (key: Uint8Array) {
|
|
71
|
+
async getLocal (key: Uint8Array): Promise<Libp2pRecord> {
|
|
72
72
|
this.log('getLocal %b', key)
|
|
73
73
|
|
|
74
74
|
const dsKey = bufferToRecordKey(key)
|
|
@@ -88,9 +88,9 @@ export class ContentFetching {
|
|
|
88
88
|
/**
|
|
89
89
|
* Send the best record found to any peers that have an out of date record
|
|
90
90
|
*/
|
|
91
|
-
async * sendCorrectionRecord (key: Uint8Array, vals: ValueEvent[], best: Uint8Array, options: AbortOptions = {}) {
|
|
91
|
+
async * sendCorrectionRecord (key: Uint8Array, vals: ValueEvent[], best: Uint8Array, options: AbortOptions = {}): AsyncGenerator<QueryEvent> {
|
|
92
92
|
this.log('sendCorrection for %b', key)
|
|
93
|
-
const fixupRec =
|
|
93
|
+
const fixupRec = createPutRecord(key, best)
|
|
94
94
|
|
|
95
95
|
for (const { value, from } of vals) {
|
|
96
96
|
// no need to do anything
|
|
@@ -136,11 +136,11 @@ export class ContentFetching {
|
|
|
136
136
|
/**
|
|
137
137
|
* Store the given key/value pair in the DHT
|
|
138
138
|
*/
|
|
139
|
-
async * put (key: Uint8Array, value: Uint8Array, options: AbortOptions = {}) {
|
|
139
|
+
async * put (key: Uint8Array, value: Uint8Array, options: AbortOptions = {}): AsyncGenerator<unknown, void, undefined> {
|
|
140
140
|
this.log('put key %b value %b', key, value)
|
|
141
141
|
|
|
142
142
|
// create record in the dht format
|
|
143
|
-
const record =
|
|
143
|
+
const record = createPutRecord(key, value)
|
|
144
144
|
|
|
145
145
|
// store the record locally
|
|
146
146
|
const dsKey = bufferToRecordKey(key)
|
|
@@ -192,7 +192,7 @@ export class ContentFetching {
|
|
|
192
192
|
/**
|
|
193
193
|
* Get the value to the given key
|
|
194
194
|
*/
|
|
195
|
-
async * get (key: Uint8Array, options: QueryOptions = {}) {
|
|
195
|
+
async * get (key: Uint8Array, options: QueryOptions = {}): AsyncGenerator<QueryEvent | ValueEvent> {
|
|
196
196
|
this.log('get %b', key)
|
|
197
197
|
|
|
198
198
|
const vals: ValueEvent[] = []
|
|
@@ -236,7 +236,7 @@ export class ContentFetching {
|
|
|
236
236
|
/**
|
|
237
237
|
* Get the `n` values to the given key without sorting
|
|
238
238
|
*/
|
|
239
|
-
async * getMany (key: Uint8Array, options: QueryOptions = {}) {
|
|
239
|
+
async * getMany (key: Uint8Array, options: QueryOptions = {}): AsyncGenerator<QueryEvent> {
|
|
240
240
|
this.log('getMany values for %b', key)
|
|
241
241
|
|
|
242
242
|
try {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
providerEvent
|
|
11
11
|
} from '../query/events.js'
|
|
12
12
|
import { logger } from '@libp2p/logger'
|
|
13
|
-
import type { QueryEvent, QueryOptions } from '@libp2p/interface-dht'
|
|
13
|
+
import type { PeerResponseEvent, ProviderEvent, QueryEvent, QueryOptions } from '@libp2p/interface-dht'
|
|
14
14
|
import type { PeerRouting } from '../peer-routing/index.js'
|
|
15
15
|
import type { QueryManager } from '../query/manager.js'
|
|
16
16
|
import type { RoutingTable } from '../routing-table/index.js'
|
|
@@ -58,7 +58,7 @@ export class ContentRouting {
|
|
|
58
58
|
* Announce to the network that we can provide the value for a given key and
|
|
59
59
|
* are contactable on the given multiaddrs
|
|
60
60
|
*/
|
|
61
|
-
async * provide (key: CID, multiaddrs: Multiaddr[], options: AbortOptions = {}) {
|
|
61
|
+
async * provide (key: CID, multiaddrs: Multiaddr[], options: AbortOptions = {}): AsyncGenerator<QueryEvent, void, undefined> {
|
|
62
62
|
this.log('provide %s', key)
|
|
63
63
|
|
|
64
64
|
// Add peer as provider
|
|
@@ -124,7 +124,7 @@ export class ContentRouting {
|
|
|
124
124
|
/**
|
|
125
125
|
* Search the dht for up to `K` providers of the given CID.
|
|
126
126
|
*/
|
|
127
|
-
async * findProviders (key: CID, options: QueryOptions) {
|
|
127
|
+
async * findProviders (key: CID, options: QueryOptions): AsyncGenerator<PeerResponseEvent | ProviderEvent | QueryEvent> {
|
|
128
128
|
const toFind = this.routingTable.kBucketSize
|
|
129
129
|
const target = key.multihash.bytes
|
|
130
130
|
const id = await convertBuffer(target)
|
|
@@ -147,7 +147,7 @@ export class ContentRouting {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
yield peerResponseEvent({ from: this.components.peerId, messageType: MESSAGE_TYPE.GET_PROVIDERS, providers })
|
|
150
|
-
yield providerEvent({ from: this.components.peerId, providers
|
|
150
|
+
yield providerEvent({ from: this.components.peerId, providers })
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
// All done
|
package/src/dual-kad-dht.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { CodeError } from '@libp2p/interfaces/errors'
|
|
|
3
3
|
import merge from 'it-merge'
|
|
4
4
|
import { queryErrorEvent } from './query/events.js'
|
|
5
5
|
import type { KadDHT } from './kad-dht.js'
|
|
6
|
-
import type { DualDHT, QueryOptions } from '@libp2p/interface-dht'
|
|
6
|
+
import type { DualDHT, QueryEvent, QueryOptions } from '@libp2p/interface-dht'
|
|
7
7
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
8
8
|
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'
|
|
9
9
|
import type { CID } from 'multiformats'
|
|
@@ -47,35 +47,35 @@ export class DualKadDHT extends EventEmitter<PeerDiscoveryEvents> implements Dua
|
|
|
47
47
|
return true
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
get [Symbol.toStringTag] () {
|
|
50
|
+
get [Symbol.toStringTag] (): '@libp2p/dual-kad-dht' {
|
|
51
51
|
return '@libp2p/dual-kad-dht'
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* Is this DHT running.
|
|
56
56
|
*/
|
|
57
|
-
isStarted () {
|
|
57
|
+
isStarted (): boolean {
|
|
58
58
|
return this.wan.isStarted() && this.lan.isStarted()
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* If 'server' this node will respond to DHT queries, if 'client' this node will not
|
|
63
63
|
*/
|
|
64
|
-
async getMode () {
|
|
64
|
+
async getMode (): Promise<'client' | 'server'> {
|
|
65
65
|
return await this.wan.getMode()
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
69
|
* If 'server' this node will respond to DHT queries, if 'client' this node will not
|
|
70
70
|
*/
|
|
71
|
-
async setMode (mode: 'client' | 'server') {
|
|
71
|
+
async setMode (mode: 'client' | 'server'): Promise<void> {
|
|
72
72
|
await this.wan.setMode(mode)
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* Start listening to incoming connections.
|
|
77
77
|
*/
|
|
78
|
-
async start () {
|
|
78
|
+
async start (): Promise<void> {
|
|
79
79
|
await Promise.all([
|
|
80
80
|
this.lan.start(),
|
|
81
81
|
this.wan.start()
|
|
@@ -86,7 +86,7 @@ export class DualKadDHT extends EventEmitter<PeerDiscoveryEvents> implements Dua
|
|
|
86
86
|
* Stop accepting incoming connections and sending outgoing
|
|
87
87
|
* messages.
|
|
88
88
|
*/
|
|
89
|
-
async stop () {
|
|
89
|
+
async stop (): Promise<void> {
|
|
90
90
|
await Promise.all([
|
|
91
91
|
this.lan.stop(),
|
|
92
92
|
this.wan.stop()
|
|
@@ -96,7 +96,7 @@ export class DualKadDHT extends EventEmitter<PeerDiscoveryEvents> implements Dua
|
|
|
96
96
|
/**
|
|
97
97
|
* Store the given key/value pair in the DHT
|
|
98
98
|
*/
|
|
99
|
-
async * put (key: Uint8Array, value: Uint8Array, options: QueryOptions = {}) {
|
|
99
|
+
async * put (key: Uint8Array, value: Uint8Array, options: QueryOptions = {}): AsyncGenerator<QueryEvent> {
|
|
100
100
|
for await (const event of merge(
|
|
101
101
|
this.lan.put(key, value, options),
|
|
102
102
|
this.wan.put(key, value, options)
|
|
@@ -108,7 +108,7 @@ export class DualKadDHT extends EventEmitter<PeerDiscoveryEvents> implements Dua
|
|
|
108
108
|
/**
|
|
109
109
|
* Get the value that corresponds to the passed key
|
|
110
110
|
*/
|
|
111
|
-
async * get (key: Uint8Array, options: QueryOptions = {}) {
|
|
111
|
+
async * get (key: Uint8Array, options: QueryOptions = {}): AsyncGenerator<QueryEvent> {
|
|
112
112
|
let queriedPeers = false
|
|
113
113
|
let foundValue = false
|
|
114
114
|
|
|
@@ -152,7 +152,7 @@ export class DualKadDHT extends EventEmitter<PeerDiscoveryEvents> implements Dua
|
|
|
152
152
|
/**
|
|
153
153
|
* Announce to the network that we can provide given key's value
|
|
154
154
|
*/
|
|
155
|
-
async * provide (key: CID, options: AbortOptions = {}) {
|
|
155
|
+
async * provide (key: CID, options: AbortOptions = {}): AsyncGenerator<QueryEvent> {
|
|
156
156
|
let sent = 0
|
|
157
157
|
let success = 0
|
|
158
158
|
const errors = []
|
|
@@ -194,7 +194,7 @@ export class DualKadDHT extends EventEmitter<PeerDiscoveryEvents> implements Dua
|
|
|
194
194
|
/**
|
|
195
195
|
* Search the dht for up to `K` providers of the given CID
|
|
196
196
|
*/
|
|
197
|
-
async * findProviders (key: CID, options: QueryOptions = {}) {
|
|
197
|
+
async * findProviders (key: CID, options: QueryOptions = {}): AsyncGenerator<QueryEvent, void, undefined> {
|
|
198
198
|
yield * merge(
|
|
199
199
|
this.lan.findProviders(key, options),
|
|
200
200
|
this.wan.findProviders(key, options)
|
|
@@ -206,7 +206,7 @@ export class DualKadDHT extends EventEmitter<PeerDiscoveryEvents> implements Dua
|
|
|
206
206
|
/**
|
|
207
207
|
* Search for a peer with the given ID
|
|
208
208
|
*/
|
|
209
|
-
async * findPeer (id: PeerId, options: QueryOptions = {}) {
|
|
209
|
+
async * findPeer (id: PeerId, options: QueryOptions = {}): AsyncGenerator<QueryEvent> {
|
|
210
210
|
let queriedPeers = false
|
|
211
211
|
|
|
212
212
|
for await (const event of merge(
|
|
@@ -228,14 +228,14 @@ export class DualKadDHT extends EventEmitter<PeerDiscoveryEvents> implements Dua
|
|
|
228
228
|
/**
|
|
229
229
|
* Kademlia 'node lookup' operation
|
|
230
230
|
*/
|
|
231
|
-
async * getClosestPeers (key: Uint8Array, options: QueryOptions = {}) {
|
|
231
|
+
async * getClosestPeers (key: Uint8Array, options: QueryOptions = {}): AsyncGenerator<QueryEvent, void, undefined> {
|
|
232
232
|
yield * merge(
|
|
233
233
|
this.lan.getClosestPeers(key, options),
|
|
234
234
|
this.wan.getClosestPeers(key, options)
|
|
235
235
|
)
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
async refreshRoutingTable () {
|
|
238
|
+
async refreshRoutingTable (): Promise<void> {
|
|
239
239
|
await Promise.all([
|
|
240
240
|
this.lan.refreshRoutingTable(),
|
|
241
241
|
this.wan.refreshRoutingTable()
|
package/src/kad-dht.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
removePublicAddresses
|
|
15
15
|
} from './utils.js'
|
|
16
16
|
import { Logger, logger } from '@libp2p/logger'
|
|
17
|
-
import type { QueryOptions, Validators, Selectors, DHT } from '@libp2p/interface-dht'
|
|
17
|
+
import type { QueryOptions, Validators, Selectors, DHT, QueryEvent } from '@libp2p/interface-dht'
|
|
18
18
|
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
19
19
|
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
|
|
20
20
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
@@ -207,11 +207,11 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT {
|
|
|
207
207
|
return true
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
get [Symbol.toStringTag] () {
|
|
210
|
+
get [Symbol.toStringTag] (): '@libp2p/kad-dht' {
|
|
211
211
|
return '@libp2p/kad-dht'
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
async onPeerConnect (peerData: PeerInfo) {
|
|
214
|
+
async onPeerConnect (peerData: PeerInfo): Promise<void> {
|
|
215
215
|
this.log('peer %p connected with protocols %s', peerData.id, peerData.protocols)
|
|
216
216
|
|
|
217
217
|
if (this.lan) {
|
|
@@ -235,21 +235,21 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT {
|
|
|
235
235
|
/**
|
|
236
236
|
* Is this DHT running.
|
|
237
237
|
*/
|
|
238
|
-
isStarted () {
|
|
238
|
+
isStarted (): boolean {
|
|
239
239
|
return this.running
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
/**
|
|
243
243
|
* If 'server' this node will respond to DHT queries, if 'client' this node will not
|
|
244
244
|
*/
|
|
245
|
-
async getMode () {
|
|
245
|
+
async getMode (): Promise<'client' | 'server'> {
|
|
246
246
|
return this.clientMode ? 'client' : 'server'
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
/**
|
|
250
250
|
* If 'server' this node will respond to DHT queries, if 'client' this node will not
|
|
251
251
|
*/
|
|
252
|
-
async setMode (mode: 'client' | 'server') {
|
|
252
|
+
async setMode (mode: 'client' | 'server'): Promise<void> {
|
|
253
253
|
await this.components.registrar.unhandle(this.protocol)
|
|
254
254
|
|
|
255
255
|
if (mode === 'client') {
|
|
@@ -268,7 +268,7 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT {
|
|
|
268
268
|
/**
|
|
269
269
|
* Start listening to incoming connections.
|
|
270
270
|
*/
|
|
271
|
-
async start () {
|
|
271
|
+
async start (): Promise<void> {
|
|
272
272
|
this.running = true
|
|
273
273
|
|
|
274
274
|
// Only respond to queries when not in client mode
|
|
@@ -290,7 +290,7 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT {
|
|
|
290
290
|
* Stop accepting incoming connections and sending outgoing
|
|
291
291
|
* messages.
|
|
292
292
|
*/
|
|
293
|
-
async stop () {
|
|
293
|
+
async stop (): Promise<void> {
|
|
294
294
|
this.running = false
|
|
295
295
|
|
|
296
296
|
await Promise.all([
|
|
@@ -307,14 +307,14 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT {
|
|
|
307
307
|
/**
|
|
308
308
|
* Store the given key/value pair in the DHT
|
|
309
309
|
*/
|
|
310
|
-
async * put (key: Uint8Array, value: Uint8Array, options: QueryOptions = {})
|
|
310
|
+
async * put (key: Uint8Array, value: Uint8Array, options: QueryOptions = {}): AsyncGenerator<any, void, undefined> {
|
|
311
311
|
yield * this.contentFetching.put(key, value, options)
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
/**
|
|
315
315
|
* Get the value that corresponds to the passed key
|
|
316
316
|
*/
|
|
317
|
-
async * get (key: Uint8Array, options: QueryOptions = {})
|
|
317
|
+
async * get (key: Uint8Array, options: QueryOptions = {}): AsyncGenerator<QueryEvent, void, undefined> {
|
|
318
318
|
yield * this.contentFetching.get(key, options)
|
|
319
319
|
}
|
|
320
320
|
|
|
@@ -323,14 +323,14 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT {
|
|
|
323
323
|
/**
|
|
324
324
|
* Announce to the network that we can provide given key's value
|
|
325
325
|
*/
|
|
326
|
-
async * provide (key: CID, options: QueryOptions = {})
|
|
326
|
+
async * provide (key: CID, options: QueryOptions = {}): AsyncGenerator<QueryEvent, void, undefined> {
|
|
327
327
|
yield * this.contentRouting.provide(key, this.components.addressManager.getAddresses(), options)
|
|
328
328
|
}
|
|
329
329
|
|
|
330
330
|
/**
|
|
331
331
|
* Search the dht for providers of the given CID
|
|
332
332
|
*/
|
|
333
|
-
async * findProviders (key: CID, options: QueryOptions = {}) {
|
|
333
|
+
async * findProviders (key: CID, options: QueryOptions = {}): AsyncGenerator<QueryEvent, any, unknown> {
|
|
334
334
|
yield * this.contentRouting.findProviders(key, options)
|
|
335
335
|
}
|
|
336
336
|
|
|
@@ -339,18 +339,18 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT {
|
|
|
339
339
|
/**
|
|
340
340
|
* Search for a peer with the given ID
|
|
341
341
|
*/
|
|
342
|
-
async * findPeer (id: PeerId, options: QueryOptions = {})
|
|
342
|
+
async * findPeer (id: PeerId, options: QueryOptions = {}): AsyncGenerator<QueryEvent, any, unknown> {
|
|
343
343
|
yield * this.peerRouting.findPeer(id, options)
|
|
344
344
|
}
|
|
345
345
|
|
|
346
346
|
/**
|
|
347
347
|
* Kademlia 'node lookup' operation
|
|
348
348
|
*/
|
|
349
|
-
async * getClosestPeers (key: Uint8Array, options: QueryOptions = {}) {
|
|
349
|
+
async * getClosestPeers (key: Uint8Array, options: QueryOptions = {}): AsyncGenerator<QueryEvent, any, unknown> {
|
|
350
350
|
yield * this.peerRouting.getClosestPeers(key, options)
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
-
async refreshRoutingTable () {
|
|
354
|
-
|
|
353
|
+
async refreshRoutingTable (): Promise<void> {
|
|
354
|
+
this.routingTableRefresh.refreshTable(true)
|
|
355
355
|
}
|
|
356
356
|
}
|