@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/dist/index.min.js +2 -5
- package/dist/src/content-fetching/index.d.ts.map +1 -1
- package/dist/src/content-fetching/index.js +14 -2
- package/dist/src/content-fetching/index.js.map +1 -1
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +20 -0
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/network.d.ts.map +1 -1
- package/dist/src/network.js +50 -0
- package/dist/src/network.js.map +1 -1
- package/dist/src/peer-routing/index.d.ts +2 -1
- package/dist/src/peer-routing/index.d.ts.map +1 -1
- package/dist/src/peer-routing/index.js +6 -0
- package/dist/src/peer-routing/index.js.map +1 -1
- package/dist/src/query/manager.d.ts.map +1 -1
- package/dist/src/query/manager.js +1 -0
- package/dist/src/query/manager.js.map +1 -1
- package/dist/src/query/query-path.d.ts.map +1 -1
- package/dist/src/query/query-path.js +1 -0
- package/dist/src/query/query-path.js.map +1 -1
- package/dist/src/query-self.d.ts +2 -1
- package/dist/src/query-self.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/content-fetching/index.ts +15 -2
- package/src/content-routing/index.ts +23 -0
- package/src/network.ts +55 -0
- package/src/peer-routing/index.ts +9 -1
- package/src/query/manager.ts +1 -0
- package/src/query/query-path.ts +1 -0
- package/src/query-self.ts +2 -2
- package/dist/typedoc-urls.json +0 -59
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
|
/**
|
package/src/query/manager.ts
CHANGED
package/src/query/query-path.ts
CHANGED
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
|
/**
|
package/dist/typedoc-urls.json
DELETED
@@ -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
|
-
}
|