@libp2p/kad-dht 14.2.15-4c64bd06d → 14.2.15-4f37aff53

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,14 +3,13 @@ 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'
8
6
  import * as utils from '../utils.js'
9
7
  import { ClosestPeers } from './closest-peers.js'
10
8
  import { KBucket, isLeafBucket } from './k-bucket.js'
11
9
  import type { Bucket, LeafBucket, Peer } from './k-bucket.js'
12
10
  import type { Network } from '../network.js'
13
11
  import type { AbortOptions, ComponentLogger, CounterGroup, Logger, Metric, Metrics, PeerId, PeerStore, Startable, Stream } from '@libp2p/interface'
12
+ import type { Ping } from '@libp2p/ping'
14
13
  import type { AdaptiveTimeoutInit } from '@libp2p/utils/adaptive-timeout'
15
14
 
16
15
  export const KBUCKET_SIZE = 20
@@ -59,6 +58,7 @@ export interface RoutingTableComponents {
59
58
  peerStore: PeerStore
60
59
  metrics?: Metrics
61
60
  logger: ComponentLogger
61
+ ping: Ping
62
62
  }
63
63
 
64
64
  export interface RoutingTableEvents {
@@ -379,24 +379,14 @@ 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)
382
384
 
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
- }
394
-
395
- return false
396
- }
397
- }
385
+ this.safeDispatchEvent('peer:ping', {
386
+ detail: contact.peerId
387
+ })
398
388
 
399
- return false
389
+ return true
400
390
  } catch (err: any) {
401
391
  this.log('error pinging old contact %p - %e', contact.peerId, err)
402
392
  stream?.abort(err)