@libp2p/kad-dht 9.3.4 → 9.3.6-3dfc236e
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/README.md +3 -3
- package/dist/index.min.js +23 -23
- package/dist/src/kad-dht.d.ts.map +1 -1
- package/dist/src/kad-dht.js +4 -4
- package/dist/src/kad-dht.js.map +1 -1
- package/dist/src/query-self.d.ts +9 -6
- package/dist/src/query-self.d.ts.map +1 -1
- package/dist/src/query-self.js +31 -47
- package/dist/src/query-self.js.map +1 -1
- package/dist/src/routing-table/index.d.ts +6 -1
- package/dist/src/routing-table/index.d.ts.map +1 -1
- package/dist/src/routing-table/index.js +7 -3
- package/dist/src/routing-table/index.js.map +1 -1
- package/package.json +43 -135
- package/src/kad-dht.ts +6 -4
- package/src/query-self.ts +67 -85
- package/src/routing-table/index.ts +15 -3
- package/dist/typedoc-urls.json +0 -29
package/package.json
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/kad-dht",
|
|
3
|
-
"version": "9.3.
|
|
3
|
+
"version": "9.3.6-3dfc236e",
|
|
4
4
|
"description": "JavaScript implementation of the Kad-DHT for libp2p",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
|
-
"homepage": "https://github.com/libp2p/js-libp2p
|
|
6
|
+
"homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/kad-dht#readme",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/libp2p/js-libp2p
|
|
9
|
+
"url": "git+https://github.com/libp2p/js-libp2p.git"
|
|
10
10
|
},
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/libp2p/js-libp2p
|
|
12
|
+
"url": "https://github.com/libp2p/js-libp2p/issues"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"IPFS"
|
|
16
16
|
],
|
|
17
|
-
"engines": {
|
|
18
|
-
"node": ">=16.0.0",
|
|
19
|
-
"npm": ">=7.0.0"
|
|
20
|
-
},
|
|
21
17
|
"type": "module",
|
|
22
18
|
"types": "./dist/src/index.d.ts",
|
|
23
19
|
"files": [
|
|
@@ -41,91 +37,6 @@
|
|
|
41
37
|
"src/message/dht.d.ts"
|
|
42
38
|
]
|
|
43
39
|
},
|
|
44
|
-
"release": {
|
|
45
|
-
"branches": [
|
|
46
|
-
"master"
|
|
47
|
-
],
|
|
48
|
-
"plugins": [
|
|
49
|
-
[
|
|
50
|
-
"@semantic-release/commit-analyzer",
|
|
51
|
-
{
|
|
52
|
-
"preset": "conventionalcommits",
|
|
53
|
-
"releaseRules": [
|
|
54
|
-
{
|
|
55
|
-
"breaking": true,
|
|
56
|
-
"release": "major"
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
"revert": true,
|
|
60
|
-
"release": "patch"
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
"type": "feat",
|
|
64
|
-
"release": "minor"
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
"type": "fix",
|
|
68
|
-
"release": "patch"
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
"type": "docs",
|
|
72
|
-
"release": "patch"
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
"type": "test",
|
|
76
|
-
"release": "patch"
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
"type": "deps",
|
|
80
|
-
"release": "patch"
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
"scope": "no-release",
|
|
84
|
-
"release": false
|
|
85
|
-
}
|
|
86
|
-
]
|
|
87
|
-
}
|
|
88
|
-
],
|
|
89
|
-
[
|
|
90
|
-
"@semantic-release/release-notes-generator",
|
|
91
|
-
{
|
|
92
|
-
"preset": "conventionalcommits",
|
|
93
|
-
"presetConfig": {
|
|
94
|
-
"types": [
|
|
95
|
-
{
|
|
96
|
-
"type": "feat",
|
|
97
|
-
"section": "Features"
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
"type": "fix",
|
|
101
|
-
"section": "Bug Fixes"
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
"type": "chore",
|
|
105
|
-
"section": "Trivial Changes"
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
"type": "docs",
|
|
109
|
-
"section": "Documentation"
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
"type": "deps",
|
|
113
|
-
"section": "Dependencies"
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
"type": "test",
|
|
117
|
-
"section": "Tests"
|
|
118
|
-
}
|
|
119
|
-
]
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
],
|
|
123
|
-
"@semantic-release/changelog",
|
|
124
|
-
"@semantic-release/npm",
|
|
125
|
-
"@semantic-release/github",
|
|
126
|
-
"@semantic-release/git"
|
|
127
|
-
]
|
|
128
|
-
},
|
|
129
40
|
"scripts": {
|
|
130
41
|
"clean": "aegir clean",
|
|
131
42
|
"lint": "aegir lint",
|
|
@@ -137,70 +48,69 @@
|
|
|
137
48
|
"test:chrome-webworker": "aegir test -t webworker",
|
|
138
49
|
"test:firefox": "aegir test -t browser -- --browser firefox",
|
|
139
50
|
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
|
|
140
|
-
"dep-check": "aegir dep-check -i protons -i events"
|
|
141
|
-
"release": "aegir release",
|
|
142
|
-
"docs": "aegir docs"
|
|
51
|
+
"dep-check": "aegir dep-check -i protons -i events"
|
|
143
52
|
},
|
|
144
53
|
"dependencies": {
|
|
145
|
-
"@libp2p/crypto": "
|
|
146
|
-
"@libp2p/interface-address-manager": "
|
|
147
|
-
"@libp2p/interface-connection": "
|
|
148
|
-
"@libp2p/interface-connection-manager": "
|
|
149
|
-
"@libp2p/interface-content-routing": "
|
|
150
|
-
"@libp2p/interface-metrics": "
|
|
151
|
-
"@libp2p/interface-peer-discovery": "
|
|
152
|
-
"@libp2p/interface-peer-id": "
|
|
153
|
-
"@libp2p/interface-peer-info": "
|
|
154
|
-
"@libp2p/interface-peer-routing": "
|
|
155
|
-
"@libp2p/interface-peer-store": "
|
|
156
|
-
"@libp2p/interface-registrar": "
|
|
157
|
-
"@libp2p/interfaces": "
|
|
158
|
-
"@libp2p/logger": "
|
|
159
|
-
"@libp2p/peer-collections": "
|
|
160
|
-
"@libp2p/peer-id": "
|
|
161
|
-
"@libp2p/record": "
|
|
162
|
-
"@libp2p/topology": "
|
|
163
|
-
"@multiformats/multiaddr": "^12.
|
|
164
|
-
"@types/sinon": "^10.0.
|
|
54
|
+
"@libp2p/crypto": "1.0.17-3dfc236e",
|
|
55
|
+
"@libp2p/interface-address-manager": "3.0.1-3dfc236e",
|
|
56
|
+
"@libp2p/interface-connection": "5.1.1-3dfc236e",
|
|
57
|
+
"@libp2p/interface-connection-manager": "3.0.1-3dfc236e",
|
|
58
|
+
"@libp2p/interface-content-routing": "2.1.1-3dfc236e",
|
|
59
|
+
"@libp2p/interface-metrics": "4.0.8-3dfc236e",
|
|
60
|
+
"@libp2p/interface-peer-discovery": "2.0.0-3dfc236e",
|
|
61
|
+
"@libp2p/interface-peer-id": "2.0.2-3dfc236e",
|
|
62
|
+
"@libp2p/interface-peer-info": "1.0.10-3dfc236e",
|
|
63
|
+
"@libp2p/interface-peer-routing": "1.1.1-3dfc236e",
|
|
64
|
+
"@libp2p/interface-peer-store": "2.0.4-3dfc236e",
|
|
65
|
+
"@libp2p/interface-registrar": "2.0.12-3dfc236e",
|
|
66
|
+
"@libp2p/interfaces": "3.3.2-3dfc236e",
|
|
67
|
+
"@libp2p/logger": "2.1.1-3dfc236e",
|
|
68
|
+
"@libp2p/peer-collections": "3.0.2-3dfc236e",
|
|
69
|
+
"@libp2p/peer-id": "2.0.3-3dfc236e",
|
|
70
|
+
"@libp2p/record": "3.0.4-3dfc236e",
|
|
71
|
+
"@libp2p/topology": "4.0.3-3dfc236e",
|
|
72
|
+
"@multiformats/multiaddr": "^12.1.3",
|
|
73
|
+
"@types/sinon": "^10.0.15",
|
|
165
74
|
"abortable-iterator": "^5.0.1",
|
|
166
75
|
"any-signal": "^4.1.1",
|
|
167
76
|
"datastore-core": "^9.0.1",
|
|
168
77
|
"events": "^3.3.0",
|
|
169
78
|
"hashlru": "^2.3.0",
|
|
170
|
-
"interface-datastore": "^8.
|
|
171
|
-
"it-all": "^3.0.
|
|
79
|
+
"interface-datastore": "^8.2.0",
|
|
80
|
+
"it-all": "^3.0.2",
|
|
172
81
|
"it-drain": "^3.0.1",
|
|
173
82
|
"it-first": "^3.0.1",
|
|
174
83
|
"it-length": "^3.0.1",
|
|
175
|
-
"it-length-prefixed": "^9.0.
|
|
176
|
-
"it-map": "^3.0.
|
|
84
|
+
"it-length-prefixed": "^9.0.1",
|
|
85
|
+
"it-map": "^3.0.2",
|
|
177
86
|
"it-merge": "^3.0.0",
|
|
178
87
|
"it-parallel": "^3.0.0",
|
|
179
|
-
"it-pipe": "^3.0.
|
|
88
|
+
"it-pipe": "^3.0.1",
|
|
180
89
|
"it-stream-types": "^2.0.1",
|
|
181
90
|
"it-take": "^3.0.1",
|
|
182
|
-
"multiformats": "^11.0.
|
|
91
|
+
"multiformats": "^11.0.2",
|
|
183
92
|
"p-defer": "^4.0.0",
|
|
93
|
+
"p-event": "^6.0.0",
|
|
184
94
|
"p-queue": "^7.3.4",
|
|
185
95
|
"private-ip": "^3.0.0",
|
|
186
96
|
"progress-events": "^1.0.0",
|
|
187
97
|
"protons-runtime": "^5.0.0",
|
|
188
|
-
"uint8arraylist": "^2.
|
|
189
|
-
"uint8arrays": "^4.0.
|
|
98
|
+
"uint8arraylist": "^2.4.3",
|
|
99
|
+
"uint8arrays": "^4.0.3",
|
|
190
100
|
"varint": "^6.0.0"
|
|
191
101
|
},
|
|
192
102
|
"devDependencies": {
|
|
193
|
-
"@libp2p/interface-libp2p": "
|
|
194
|
-
"@libp2p/interface-mocks": "
|
|
195
|
-
"@libp2p/peer-id-factory": "
|
|
196
|
-
"@libp2p/peer-store": "
|
|
103
|
+
"@libp2p/interface-libp2p": "3.2.0-3dfc236e",
|
|
104
|
+
"@libp2p/interface-mocks": "12.0.1-3dfc236e",
|
|
105
|
+
"@libp2p/peer-id-factory": "2.0.3-3dfc236e",
|
|
106
|
+
"@libp2p/peer-store": "8.2.1-3dfc236e",
|
|
197
107
|
"@types/lodash.random": "^3.2.6",
|
|
198
108
|
"@types/lodash.range": "^3.2.6",
|
|
199
109
|
"@types/varint": "^6.0.0",
|
|
200
110
|
"@types/which": "^3.0.0",
|
|
201
|
-
"aegir": "^39.0.
|
|
111
|
+
"aegir": "^39.0.10",
|
|
202
112
|
"datastore-level": "^10.0.0",
|
|
203
|
-
"delay": "^
|
|
113
|
+
"delay": "^6.0.0",
|
|
204
114
|
"execa": "^7.0.0",
|
|
205
115
|
"it-filter": "^3.0.1",
|
|
206
116
|
"it-last": "^3.0.1",
|
|
@@ -209,16 +119,14 @@
|
|
|
209
119
|
"p-retry": "^5.0.0",
|
|
210
120
|
"p-wait-for": "^5.0.0",
|
|
211
121
|
"protons": "^7.0.2",
|
|
212
|
-
"sinon": "^15.
|
|
122
|
+
"sinon": "^15.1.0",
|
|
213
123
|
"ts-sinon": "^2.0.2",
|
|
214
124
|
"which": "^3.0.0"
|
|
215
125
|
},
|
|
216
126
|
"browser": {
|
|
217
127
|
"./dist/src/routing-table/generated-prefix-list.js": "./dist/src/routing-table/generated-prefix-list-browser.js"
|
|
218
128
|
},
|
|
219
|
-
"
|
|
220
|
-
"
|
|
221
|
-
"KadDHTInit": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/KadDHTInit.html",
|
|
222
|
-
"kadDHT": "https://libp2p.github.io/js-libp2p-kad-dht/functions/kadDHT.html"
|
|
129
|
+
"typedoc": {
|
|
130
|
+
"entryPoint": "./src/index.ts"
|
|
223
131
|
}
|
|
224
132
|
}
|
package/src/kad-dht.ts
CHANGED
|
@@ -285,10 +285,11 @@ export class DefaultKadDHT extends EventEmitter<PeerDiscoveryEvents> implements
|
|
|
285
285
|
this.queryManager.start(),
|
|
286
286
|
this.network.start(),
|
|
287
287
|
this.routingTable.start(),
|
|
288
|
-
this.topologyListener.start()
|
|
289
|
-
this.querySelf.start()
|
|
288
|
+
this.topologyListener.start()
|
|
290
289
|
])
|
|
291
290
|
|
|
291
|
+
this.querySelf.start()
|
|
292
|
+
|
|
292
293
|
await this.routingTableRefresh.start()
|
|
293
294
|
}
|
|
294
295
|
|
|
@@ -299,14 +300,15 @@ export class DefaultKadDHT extends EventEmitter<PeerDiscoveryEvents> implements
|
|
|
299
300
|
async stop (): Promise<void> {
|
|
300
301
|
this.running = false
|
|
301
302
|
|
|
303
|
+
this.querySelf.stop()
|
|
304
|
+
|
|
302
305
|
await Promise.all([
|
|
303
306
|
this.providers.stop(),
|
|
304
307
|
this.queryManager.stop(),
|
|
305
308
|
this.network.stop(),
|
|
306
309
|
this.routingTable.stop(),
|
|
307
310
|
this.routingTableRefresh.stop(),
|
|
308
|
-
this.topologyListener.stop()
|
|
309
|
-
this.querySelf.stop()
|
|
311
|
+
this.topologyListener.stop()
|
|
310
312
|
])
|
|
311
313
|
}
|
|
312
314
|
|
package/src/query-self.ts
CHANGED
|
@@ -4,10 +4,12 @@ import { anySignal } from 'any-signal'
|
|
|
4
4
|
import length from 'it-length'
|
|
5
5
|
import { pipe } from 'it-pipe'
|
|
6
6
|
import take from 'it-take'
|
|
7
|
+
import pDefer from 'p-defer'
|
|
8
|
+
import { pEvent } from 'p-event'
|
|
7
9
|
import { QUERY_SELF_INTERVAL, QUERY_SELF_TIMEOUT, K, QUERY_SELF_INITIAL_INTERVAL } from './constants.js'
|
|
8
|
-
import type { KadDHTComponents } from './index.js'
|
|
9
10
|
import type { PeerRouting } from './peer-routing/index.js'
|
|
10
11
|
import type { RoutingTable } from './routing-table/index.js'
|
|
12
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
11
13
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
12
14
|
import type { DeferredPromise } from 'p-defer'
|
|
13
15
|
|
|
@@ -22,18 +24,8 @@ export interface QuerySelfInit {
|
|
|
22
24
|
initialQuerySelfHasRun: DeferredPromise<void>
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return function () {
|
|
29
|
-
const later = function (): void {
|
|
30
|
-
timeout = undefined
|
|
31
|
-
func()
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
clearTimeout(timeout)
|
|
35
|
-
timeout = setTimeout(later, wait)
|
|
36
|
-
}
|
|
27
|
+
export interface QuerySelfComponents {
|
|
28
|
+
peerId: PeerId
|
|
37
29
|
}
|
|
38
30
|
|
|
39
31
|
/**
|
|
@@ -41,7 +33,7 @@ function debounce (func: () => void, wait: number): () => void {
|
|
|
41
33
|
*/
|
|
42
34
|
export class QuerySelf implements Startable {
|
|
43
35
|
private readonly log: Logger
|
|
44
|
-
private readonly components:
|
|
36
|
+
private readonly components: QuerySelfComponents
|
|
45
37
|
private readonly peerRouting: PeerRouting
|
|
46
38
|
private readonly routingTable: RoutingTable
|
|
47
39
|
private readonly count: number
|
|
@@ -49,17 +41,16 @@ export class QuerySelf implements Startable {
|
|
|
49
41
|
private readonly initialInterval: number
|
|
50
42
|
private readonly queryTimeout: number
|
|
51
43
|
private started: boolean
|
|
52
|
-
private running: boolean
|
|
53
44
|
private timeoutId?: NodeJS.Timer
|
|
54
45
|
private controller?: AbortController
|
|
55
46
|
private initialQuerySelfHasRun?: DeferredPromise<void>
|
|
47
|
+
private querySelfPromise?: DeferredPromise<void>
|
|
56
48
|
|
|
57
|
-
constructor (components:
|
|
49
|
+
constructor (components: QuerySelfComponents, init: QuerySelfInit) {
|
|
58
50
|
const { peerRouting, lan, count, interval, queryTimeout, routingTable } = init
|
|
59
51
|
|
|
60
52
|
this.components = components
|
|
61
53
|
this.log = logger(`libp2p:kad-dht:${lan ? 'lan' : 'wan'}:query-self`)
|
|
62
|
-
this.running = false
|
|
63
54
|
this.started = false
|
|
64
55
|
this.peerRouting = peerRouting
|
|
65
56
|
this.routingTable = routingTable
|
|
@@ -68,25 +59,28 @@ export class QuerySelf implements Startable {
|
|
|
68
59
|
this.initialInterval = init.initialInterval ?? QUERY_SELF_INITIAL_INTERVAL
|
|
69
60
|
this.queryTimeout = queryTimeout ?? QUERY_SELF_TIMEOUT
|
|
70
61
|
this.initialQuerySelfHasRun = init.initialQuerySelfHasRun
|
|
71
|
-
|
|
72
|
-
this.querySelf = debounce(this.querySelf.bind(this), 100)
|
|
73
62
|
}
|
|
74
63
|
|
|
75
64
|
isStarted (): boolean {
|
|
76
65
|
return this.started
|
|
77
66
|
}
|
|
78
67
|
|
|
79
|
-
|
|
68
|
+
start (): void {
|
|
80
69
|
if (this.started) {
|
|
81
70
|
return
|
|
82
71
|
}
|
|
83
72
|
|
|
84
73
|
this.started = true
|
|
85
74
|
clearTimeout(this.timeoutId)
|
|
86
|
-
this.timeoutId = setTimeout(
|
|
75
|
+
this.timeoutId = setTimeout(() => {
|
|
76
|
+
this.querySelf()
|
|
77
|
+
.catch(err => {
|
|
78
|
+
this.log.error('error running self-query', err)
|
|
79
|
+
})
|
|
80
|
+
}, this.initialInterval)
|
|
87
81
|
}
|
|
88
82
|
|
|
89
|
-
|
|
83
|
+
stop (): void {
|
|
90
84
|
this.started = false
|
|
91
85
|
|
|
92
86
|
if (this.timeoutId != null) {
|
|
@@ -98,84 +92,72 @@ export class QuerySelf implements Startable {
|
|
|
98
92
|
}
|
|
99
93
|
}
|
|
100
94
|
|
|
101
|
-
querySelf (): void {
|
|
95
|
+
async querySelf (): Promise<void> {
|
|
102
96
|
if (!this.started) {
|
|
103
97
|
this.log('skip self-query because we are not started')
|
|
104
98
|
return
|
|
105
99
|
}
|
|
106
100
|
|
|
107
|
-
if (this.
|
|
108
|
-
this.log('
|
|
109
|
-
return
|
|
101
|
+
if (this.querySelfPromise != null) {
|
|
102
|
+
this.log('joining existing self query')
|
|
103
|
+
return this.querySelfPromise.promise
|
|
110
104
|
}
|
|
111
105
|
|
|
112
|
-
|
|
113
|
-
let nextInterval = this.interval
|
|
114
|
-
|
|
115
|
-
if (this.initialQuerySelfHasRun != null) {
|
|
116
|
-
// if we've not yet run the first self query, shorten the interval until we try again
|
|
117
|
-
nextInterval = this.initialInterval
|
|
118
|
-
}
|
|
106
|
+
this.querySelfPromise = pDefer()
|
|
119
107
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return
|
|
108
|
+
if (this.routingTable.size === 0) {
|
|
109
|
+
// wait to discover at least one DHT peer
|
|
110
|
+
await pEvent(this.routingTable, 'peer:add')
|
|
124
111
|
}
|
|
125
112
|
|
|
126
|
-
this.
|
|
113
|
+
if (this.started) {
|
|
114
|
+
this.controller = new AbortController()
|
|
115
|
+
const signal = anySignal([this.controller.signal, AbortSignal.timeout(this.queryTimeout)])
|
|
127
116
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (
|
|
131
|
-
|
|
132
|
-
return
|
|
117
|
+
// this controller will get used for lots of dial attempts so make sure we don't cause warnings to be logged
|
|
118
|
+
try {
|
|
119
|
+
if (setMaxListeners != null) {
|
|
120
|
+
setMaxListeners(Infinity, signal)
|
|
133
121
|
}
|
|
122
|
+
} catch {} // fails on node < 15.4
|
|
134
123
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
this.log('run self-query, look for %d peers timing out after %dms', this.count, this.queryTimeout)
|
|
147
|
-
|
|
148
|
-
const found = await pipe(
|
|
149
|
-
this.peerRouting.getClosestPeers(this.components.peerId.toBytes(), {
|
|
150
|
-
signal,
|
|
151
|
-
isSelfQuery: true
|
|
152
|
-
}),
|
|
153
|
-
(source) => take(source, this.count),
|
|
154
|
-
async (source) => length(source)
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
this.log('self-query ran successfully - found %d peers', found)
|
|
158
|
-
|
|
159
|
-
if (this.initialQuerySelfHasRun != null) {
|
|
160
|
-
this.initialQuerySelfHasRun.resolve()
|
|
161
|
-
this.initialQuerySelfHasRun = undefined
|
|
162
|
-
}
|
|
163
|
-
} catch (err: any) {
|
|
164
|
-
this.log.error('self-query error', err)
|
|
165
|
-
} finally {
|
|
166
|
-
signal.clear()
|
|
167
|
-
}
|
|
168
|
-
}).catch(err => {
|
|
169
|
-
this.log('self-query error', err)
|
|
170
|
-
}).finally(() => {
|
|
171
|
-
this.running = false
|
|
124
|
+
try {
|
|
125
|
+
this.log('run self-query, look for %d peers timing out after %dms', this.count, this.queryTimeout)
|
|
126
|
+
|
|
127
|
+
const found = await pipe(
|
|
128
|
+
this.peerRouting.getClosestPeers(this.components.peerId.toBytes(), {
|
|
129
|
+
signal,
|
|
130
|
+
isSelfQuery: true
|
|
131
|
+
}),
|
|
132
|
+
(source) => take(source, this.count),
|
|
133
|
+
async (source) => length(source)
|
|
134
|
+
)
|
|
172
135
|
|
|
173
|
-
|
|
136
|
+
this.log('self-query ran successfully - found %d peers', found)
|
|
174
137
|
|
|
175
|
-
if (this.
|
|
176
|
-
this.
|
|
177
|
-
this.
|
|
138
|
+
if (this.initialQuerySelfHasRun != null) {
|
|
139
|
+
this.initialQuerySelfHasRun.resolve()
|
|
140
|
+
this.initialQuerySelfHasRun = undefined
|
|
178
141
|
}
|
|
179
|
-
})
|
|
142
|
+
} catch (err: any) {
|
|
143
|
+
this.log.error('self-query error', err)
|
|
144
|
+
} finally {
|
|
145
|
+
signal.clear()
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
this.querySelfPromise.resolve()
|
|
150
|
+
this.querySelfPromise = undefined
|
|
151
|
+
|
|
152
|
+
if (!this.started) {
|
|
153
|
+
return
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
this.timeoutId = setTimeout(() => {
|
|
157
|
+
this.querySelf()
|
|
158
|
+
.catch(err => {
|
|
159
|
+
this.log.error('error running self-query', err)
|
|
160
|
+
})
|
|
161
|
+
}, this.interval)
|
|
180
162
|
}
|
|
181
163
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EventEmitter } from '@libp2p/interfaces/events'
|
|
1
2
|
import { logger } from '@libp2p/logger'
|
|
2
3
|
import { PeerSet } from '@libp2p/peer-collections'
|
|
3
4
|
import Queue from 'p-queue'
|
|
@@ -33,11 +34,16 @@ export interface RoutingTableComponents {
|
|
|
33
34
|
metrics?: Metrics
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
export interface RoutingTableEvents {
|
|
38
|
+
'peer:add': CustomEvent<PeerId>
|
|
39
|
+
'peer:remove': CustomEvent<PeerId>
|
|
40
|
+
}
|
|
41
|
+
|
|
36
42
|
/**
|
|
37
43
|
* A wrapper around `k-bucket`, to provide easy store and
|
|
38
44
|
* retrieval for peers.
|
|
39
45
|
*/
|
|
40
|
-
export class RoutingTable implements Startable {
|
|
46
|
+
export class RoutingTable extends EventEmitter<RoutingTableEvents> implements Startable {
|
|
41
47
|
public kBucketSize: number
|
|
42
48
|
public kb?: KBucket
|
|
43
49
|
public pingQueue: Queue
|
|
@@ -58,6 +64,8 @@ export class RoutingTable implements Startable {
|
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
constructor (components: RoutingTableComponents, init: RoutingTableInit) {
|
|
67
|
+
super()
|
|
68
|
+
|
|
61
69
|
const { kBucketSize, pingTimeout, lan, pingConcurrency, protocol, tagName, tagValue } = init
|
|
62
70
|
|
|
63
71
|
this.components = components
|
|
@@ -160,11 +168,15 @@ export class RoutingTable implements Startable {
|
|
|
160
168
|
kClosest = newClosest
|
|
161
169
|
})
|
|
162
170
|
|
|
163
|
-
kBuck.addEventListener('added', () => {
|
|
171
|
+
kBuck.addEventListener('added', (evt) => {
|
|
164
172
|
updatePeerTags()
|
|
173
|
+
|
|
174
|
+
this.safeDispatchEvent('peer:add', { detail: evt.detail.peer })
|
|
165
175
|
})
|
|
166
|
-
kBuck.addEventListener('removed', () => {
|
|
176
|
+
kBuck.addEventListener('removed', (evt) => {
|
|
167
177
|
updatePeerTags()
|
|
178
|
+
|
|
179
|
+
this.safeDispatchEvent('peer:remove', { detail: evt.detail.peer })
|
|
168
180
|
})
|
|
169
181
|
}
|
|
170
182
|
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"ProvidersInit": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/_internal_.ProvidersInit.html",
|
|
3
|
-
"EventTypes": "https://libp2p.github.io/js-libp2p-kad-dht/enums/EventTypes.html",
|
|
4
|
-
"MessageType": "https://libp2p.github.io/js-libp2p-kad-dht/enums/MessageType.html",
|
|
5
|
-
"AddPeerEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/AddPeerEvent.html",
|
|
6
|
-
"DHTRecord": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/DHTRecord.html",
|
|
7
|
-
"DialPeerEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/DialPeerEvent.html",
|
|
8
|
-
"DualKadDHT": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/DualKadDHT.html",
|
|
9
|
-
"FinalPeerEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/FinalPeerEvent.html",
|
|
10
|
-
"KadDHT": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/KadDHT.html",
|
|
11
|
-
"KadDHTComponents": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/KadDHTComponents.html",
|
|
12
|
-
"KadDHTInit": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/KadDHTInit.html",
|
|
13
|
-
"PeerResponseEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/PeerResponseEvent.html",
|
|
14
|
-
"ProviderEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/ProviderEvent.html",
|
|
15
|
-
"QueryErrorEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/QueryErrorEvent.html",
|
|
16
|
-
"QueryOptions": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/QueryOptions.html",
|
|
17
|
-
"RoutingTable": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/RoutingTable.html",
|
|
18
|
-
"SelectFn": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/SelectFn.html",
|
|
19
|
-
"SendQueryEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/SendQueryEvent.html",
|
|
20
|
-
"SingleKadDHT": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/SingleKadDHT.html",
|
|
21
|
-
"ValidateFn": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/ValidateFn.html",
|
|
22
|
-
"ValueEvent": "https://libp2p.github.io/js-libp2p-kad-dht/interfaces/ValueEvent.html",
|
|
23
|
-
"DHTProgressEvents": "https://libp2p.github.io/js-libp2p-kad-dht/types/DHTProgressEvents.html",
|
|
24
|
-
"MessageName": "https://libp2p.github.io/js-libp2p-kad-dht/types/MessageName.html",
|
|
25
|
-
"QueryEvent": "https://libp2p.github.io/js-libp2p-kad-dht/types/QueryEvent.html",
|
|
26
|
-
"Selectors": "https://libp2p.github.io/js-libp2p-kad-dht/types/Selectors.html",
|
|
27
|
-
"Validators": "https://libp2p.github.io/js-libp2p-kad-dht/types/Validators.html",
|
|
28
|
-
"kadDHT": "https://libp2p.github.io/js-libp2p-kad-dht/functions/kadDHT-1.html"
|
|
29
|
-
}
|