@libp2p/kad-dht 14.2.15-4f37aff53 → 14.2.15-53a9be54e
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 +4 -20
- package/dist/index.min.js +1 -1
- package/dist/src/index.d.ts +4 -22
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -20
- package/dist/src/index.js.map +1 -1
- package/dist/src/kad-dht.d.ts.map +1 -1
- package/dist/src/kad-dht.js +1 -2
- package/dist/src/kad-dht.js.map +1 -1
- package/dist/src/routing-table/index.d.ts +0 -2
- package/dist/src/routing-table/index.d.ts.map +1 -1
- package/dist/src/routing-table/index.js +15 -6
- package/dist/src/routing-table/index.js.map +1 -1
- package/package.json +11 -12
- package/src/index.ts +4 -22
- package/src/kad-dht.ts +1 -2
- package/src/routing-table/index.ts +18 -8
|
@@ -3,13 +3,14 @@ import { AdaptiveTimeout } from '@libp2p/utils/adaptive-timeout'
|
|
|
3
3
|
import { PeerQueue } from '@libp2p/utils/peer-queue'
|
|
4
4
|
import { anySignal } from 'any-signal'
|
|
5
5
|
import parallel from 'it-parallel'
|
|
6
|
+
import { EventTypes } from '../index.js'
|
|
7
|
+
import { MessageType } from '../message/dht.js'
|
|
6
8
|
import * as utils from '../utils.js'
|
|
7
9
|
import { ClosestPeers } from './closest-peers.js'
|
|
8
10
|
import { KBucket, isLeafBucket } from './k-bucket.js'
|
|
9
11
|
import type { Bucket, LeafBucket, Peer } from './k-bucket.js'
|
|
10
12
|
import type { Network } from '../network.js'
|
|
11
13
|
import type { AbortOptions, ComponentLogger, CounterGroup, Logger, Metric, Metrics, PeerId, PeerStore, Startable, Stream } from '@libp2p/interface'
|
|
12
|
-
import type { Ping } from '@libp2p/ping'
|
|
13
14
|
import type { AdaptiveTimeoutInit } from '@libp2p/utils/adaptive-timeout'
|
|
14
15
|
|
|
15
16
|
export const KBUCKET_SIZE = 20
|
|
@@ -58,7 +59,6 @@ export interface RoutingTableComponents {
|
|
|
58
59
|
peerStore: PeerStore
|
|
59
60
|
metrics?: Metrics
|
|
60
61
|
logger: ComponentLogger
|
|
61
|
-
ping: Ping
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export interface RoutingTableEvents {
|
|
@@ -379,14 +379,24 @@ export class RoutingTable extends TypedEventEmitter<RoutingTableEvents> implemen
|
|
|
379
379
|
|
|
380
380
|
try {
|
|
381
381
|
this.log('pinging contact %p', contact.peerId)
|
|
382
|
-
await this.components.ping.ping(contact.peerId, options)
|
|
383
|
-
this.log('contact %p ping ok', contact.peerId)
|
|
384
382
|
|
|
385
|
-
this.
|
|
386
|
-
|
|
387
|
-
|
|
383
|
+
for await (const event of this.network.sendRequest(contact.peerId, { type: MessageType.PING }, options)) {
|
|
384
|
+
if (event.type === EventTypes.PEER_RESPONSE) {
|
|
385
|
+
if (event.messageType === MessageType.PING) {
|
|
386
|
+
this.log('contact %p ping ok', contact.peerId)
|
|
387
|
+
|
|
388
|
+
this.safeDispatchEvent('peer:ping', {
|
|
389
|
+
detail: contact.peerId
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
return true
|
|
393
|
+
}
|
|
388
394
|
|
|
389
|
-
|
|
395
|
+
return false
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return false
|
|
390
400
|
} catch (err: any) {
|
|
391
401
|
this.log('error pinging old contact %p - %e', contact.peerId, err)
|
|
392
402
|
stream?.abort(err)
|