@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.
@@ -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.safeDispatchEvent('peer:ping', {
386
- detail: contact.peerId
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
- return true
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)