@libp2p/kad-dht 14.1.6 → 14.2.0-06fc82da8

Sign up to get free protection for your applications and to get access to all the features.
package/src/network.ts CHANGED
@@ -57,6 +57,61 @@ export class Network extends TypedEventEmitter<NetworkEvents> implements Startab
57
57
  operations: components.metrics?.registerCounterGroup(`${init.metricsPrefix}_outbound_rpc_requests_total`),
58
58
  errors: components.metrics?.registerCounterGroup(`${init.metricsPrefix}_outbound_rpc_errors_total`)
59
59
  }
60
+
61
+ this.sendRequest = components.metrics?.traceFunction('libp2p.kadDHT.sendRequest', this.sendRequest.bind(this), {
62
+ optionsIndex: 2,
63
+ getAttributesFromArgs ([to, message], attrs) {
64
+ return {
65
+ ...attrs,
66
+ to: to.toString(),
67
+ 'message type': `${message.type}`
68
+ }
69
+ },
70
+ getAttributesFromYieldedValue: (event, attrs) => {
71
+ if (event.name === 'PEER_RESPONSE') {
72
+ if (event.providers.length > 0) {
73
+ event.providers.forEach((value, index) => {
74
+ attrs[`providers-${index}`] = value.id.toString()
75
+ })
76
+ }
77
+
78
+ if (event.closer.length > 0) {
79
+ event.closer.forEach((value, index) => {
80
+ attrs[`closer-${index}`] = value.id.toString()
81
+ })
82
+ }
83
+ }
84
+
85
+ return attrs
86
+ }
87
+ }) ?? this.sendRequest
88
+ this.sendMessage = components.metrics?.traceFunction('libp2p.kadDHT.sendMessage', this.sendMessage.bind(this), {
89
+ optionsIndex: 2,
90
+ getAttributesFromArgs ([to, message], attrs) {
91
+ return {
92
+ ...attrs,
93
+ to: to.toString(),
94
+ 'message type': `${message.type}`
95
+ }
96
+ },
97
+ getAttributesFromYieldedValue: (event, attrs) => {
98
+ if (event.name === 'PEER_RESPONSE') {
99
+ if (event.providers.length > 0) {
100
+ event.providers.forEach((value, index) => {
101
+ attrs[`providers-${index}`] = value.id.toString()
102
+ })
103
+ }
104
+
105
+ if (event.closer.length > 0) {
106
+ event.closer.forEach((value, index) => {
107
+ attrs[`closer-${index}`] = value.id.toString()
108
+ })
109
+ }
110
+ }
111
+
112
+ return attrs
113
+ }
114
+ }) ?? this.sendMessage
60
115
  }
61
116
 
62
117
  /**
@@ -22,12 +22,13 @@ import type { Network } from '../network.js'
22
22
  import type { QueryManager, QueryOptions } from '../query/manager.js'
23
23
  import type { QueryFunc } from '../query/types.js'
24
24
  import type { RoutingTable } from '../routing-table/index.js'
25
- import type { ComponentLogger, Logger, PeerId, PeerInfo, PeerStore, RoutingOptions } from '@libp2p/interface'
25
+ import type { ComponentLogger, Logger, Metrics, PeerId, PeerInfo, PeerStore, RoutingOptions } from '@libp2p/interface'
26
26
 
27
27
  export interface PeerRoutingComponents {
28
28
  peerId: PeerId
29
29
  peerStore: PeerStore
30
30
  logger: ComponentLogger
31
+ metrics?: Metrics
31
32
  }
32
33
 
33
34
  export interface PeerRoutingInit {
@@ -55,6 +56,13 @@ export class PeerRouting {
55
56
  this.peerStore = components.peerStore
56
57
  this.peerId = components.peerId
57
58
  this.log = components.logger.forComponent(`${init.logPrefix}:peer-routing`)
59
+
60
+ this.findPeer = components.metrics?.traceFunction('libp2p.kadDHT.findPeer', this.findPeer.bind(this), {
61
+ optionsIndex: 1
62
+ }) ?? this.findPeer
63
+ this.getClosestPeers = components.metrics?.traceFunction('libp2p.kadDHT.getClosestPeers', this.getClosestPeers.bind(this), {
64
+ optionsIndex: 1
65
+ }) ?? this.getClosestPeers
58
66
  }
59
67
 
60
68
  /**
@@ -171,6 +171,7 @@ export class QueryManager implements Startable {
171
171
  // Create query paths from the starting peers
172
172
  const paths = peersToQuery.map((peer, index) => {
173
173
  return queryPath({
174
+ ...options,
174
175
  key,
175
176
  startingPeer: peer,
176
177
  ourPeerId: this.peerId,
@@ -121,6 +121,7 @@ export async function * queryPath (options: QueryPathOptions): AsyncGenerator<Qu
121
121
 
122
122
  try {
123
123
  for await (const event of query({
124
+ ...options,
124
125
  key,
125
126
  peer,
126
127
  signal: compoundSignal,
package/src/query-self.ts CHANGED
@@ -10,9 +10,8 @@ import { timeOperationMethod } from './utils.js'
10
10
  import type { OperationMetrics } from './kad-dht.js'
11
11
  import type { PeerRouting } from './peer-routing/index.js'
12
12
  import type { RoutingTable } from './routing-table/index.js'
13
- import type { ComponentLogger, Logger, PeerId, Startable } from '@libp2p/interface'
13
+ import type { ComponentLogger, Logger, Metrics, PeerId, Startable } from '@libp2p/interface'
14
14
  import type { DeferredPromise } from 'p-defer'
15
-
16
15
  export interface QuerySelfInit {
17
16
  logPrefix: string
18
17
  peerRouting: PeerRouting
@@ -28,6 +27,7 @@ export interface QuerySelfInit {
28
27
  export interface QuerySelfComponents {
29
28
  peerId: PeerId
30
29
  logger: ComponentLogger
30
+ metrics?: Metrics
31
31
  }
32
32
 
33
33
  /**
@@ -1,59 +0,0 @@
1
- {
2
- "codec": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.MessageType.codec.html",
3
- "EventTypes": "https://libp2p.github.io/js-libp2p/enums/_libp2p_kad_dht.EventTypes.html",
4
- ".:EventTypes": "https://libp2p.github.io/js-libp2p/enums/_libp2p_kad_dht.EventTypes.html",
5
- "MessageType": "https://libp2p.github.io/js-libp2p/enums/_libp2p_kad_dht.MessageType-1.html",
6
- "AddPeerEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.AddPeerEvent.html",
7
- ".:AddPeerEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.AddPeerEvent.html",
8
- "DHTRecord": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.DHTRecord.html",
9
- ".:DHTRecord": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.DHTRecord.html",
10
- "DialPeerEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.DialPeerEvent.html",
11
- ".:DialPeerEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.DialPeerEvent.html",
12
- "FinalPeerEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.FinalPeerEvent.html",
13
- ".:FinalPeerEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.FinalPeerEvent.html",
14
- "KadDHT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.KadDHT.html",
15
- ".:KadDHT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.KadDHT.html",
16
- "KadDHTComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.KadDHTComponents.html",
17
- ".:KadDHTComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.KadDHTComponents.html",
18
- "KadDHTInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.KadDHTInit.html",
19
- ".:KadDHTInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.KadDHTInit.html",
20
- "PeerInfoMapper": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.PeerInfoMapper.html",
21
- ".:PeerInfoMapper": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.PeerInfoMapper.html",
22
- "PeerResponseEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.PeerResponseEvent.html",
23
- ".:PeerResponseEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.PeerResponseEvent.html",
24
- "ProviderEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ProviderEvent.html",
25
- ".:ProviderEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ProviderEvent.html",
26
- "ProvidersInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ProvidersInit.html",
27
- ".:ProvidersInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ProvidersInit.html",
28
- "QueryErrorEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.QueryErrorEvent.html",
29
- ".:QueryErrorEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.QueryErrorEvent.html",
30
- "ReProvideInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ReProvideInit.html",
31
- ".:ReProvideInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ReProvideInit.html",
32
- "RoutingTable": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.RoutingTable.html",
33
- ".:RoutingTable": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.RoutingTable.html",
34
- "SelectFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SelectFn.html",
35
- ".:SelectFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SelectFn.html",
36
- "SendQueryEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SendQueryEvent.html",
37
- ".:SendQueryEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SendQueryEvent.html",
38
- "SingleKadDHT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SingleKadDHT.html",
39
- ".:SingleKadDHT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SingleKadDHT.html",
40
- "ValidateFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ValidateFn.html",
41
- ".:ValidateFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ValidateFn.html",
42
- "ValueEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ValueEvent.html",
43
- ".:ValueEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ValueEvent.html",
44
- "DHTProgressEvents": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.DHTProgressEvents.html",
45
- ".:DHTProgressEvents": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.DHTProgressEvents.html",
46
- "MessageName": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.MessageName.html",
47
- ".:MessageName": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.MessageName.html",
48
- "QueryEvent": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.QueryEvent.html",
49
- ".:QueryEvent": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.QueryEvent.html",
50
- "Selectors": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.Selectors.html",
51
- ".:Selectors": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.Selectors.html",
52
- "Validators": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.Validators.html",
53
- ".:Validators": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.Validators.html",
54
- "kadDHT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.kadDHT-1.html",
55
- ".:kadDHT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.kadDHT-1.html",
56
- "passthroughMapper": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.passthroughMapper.html",
57
- "removePrivateAddressesMapper": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.removePrivateAddressesMapper.html",
58
- "removePublicAddressesMapper": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.removePublicAddressesMapper.html"
59
- }