@libp2p/kad-dht 14.2.15 → 15.0.0-b9e32cc37
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 +20 -4
- package/dist/index.min.js +1 -1
- package/dist/src/index.d.ts +22 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +20 -4
- package/dist/src/index.js.map +1 -1
- package/dist/src/kad-dht.d.ts.map +1 -1
- package/dist/src/kad-dht.js +2 -1
- package/dist/src/kad-dht.js.map +1 -1
- package/dist/src/routing-table/index.d.ts +2 -0
- package/dist/src/routing-table/index.d.ts.map +1 -1
- package/dist/src/routing-table/index.js +6 -15
- package/dist/src/routing-table/index.js.map +1 -1
- package/dist/src/routing-table/k-bucket.d.ts +1 -2
- package/dist/src/routing-table/k-bucket.d.ts.map +1 -1
- package/dist/src/routing-table/k-bucket.js.map +1 -1
- package/package.json +13 -12
- package/src/index.ts +22 -4
- package/src/kad-dht.ts +2 -1
- package/src/routing-table/index.ts +8 -18
- package/src/routing-table/k-bucket.ts +1 -2
- package/dist/typedoc-urls.json +0 -59
package/src/index.ts
CHANGED
|
@@ -11,12 +11,16 @@
|
|
|
11
11
|
* import { kadDHT } from '@libp2p/kad-dht'
|
|
12
12
|
* import { createLibp2p } from 'libp2p'
|
|
13
13
|
* import { peerIdFromString } from '@libp2p/peer-id'
|
|
14
|
+
* import { ping } from '@libp2p/ping'
|
|
15
|
+
* import { identify } from '@libp2p/identify'
|
|
14
16
|
*
|
|
15
17
|
* const node = await createLibp2p({
|
|
16
18
|
* services: {
|
|
17
19
|
* dht: kadDHT({
|
|
18
20
|
* // DHT options
|
|
19
|
-
* })
|
|
21
|
+
* }),
|
|
22
|
+
* ping: ping(),
|
|
23
|
+
* identify: identify()
|
|
20
24
|
* }
|
|
21
25
|
* })
|
|
22
26
|
*
|
|
@@ -36,13 +40,17 @@
|
|
|
36
40
|
* import { kadDHT, removePrivateAddressesMapper } from '@libp2p/kad-dht'
|
|
37
41
|
* import { createLibp2p } from 'libp2p'
|
|
38
42
|
* import { peerIdFromString } from '@libp2p/peer-id'
|
|
43
|
+
* import { ping } from '@libp2p/ping'
|
|
44
|
+
* import { identify } from '@libp2p/identify'
|
|
39
45
|
*
|
|
40
46
|
* const node = await createLibp2p({
|
|
41
47
|
* services: {
|
|
42
48
|
* aminoDHT: kadDHT({
|
|
43
49
|
* protocol: '/ipfs/kad/1.0.0',
|
|
44
50
|
* peerInfoMapper: removePrivateAddressesMapper
|
|
45
|
-
* })
|
|
51
|
+
* }),
|
|
52
|
+
* ping: ping(),
|
|
53
|
+
* identify: identify()
|
|
46
54
|
* }
|
|
47
55
|
* })
|
|
48
56
|
*
|
|
@@ -62,6 +70,8 @@
|
|
|
62
70
|
* import { kadDHT, removePublicAddressesMapper } from '@libp2p/kad-dht'
|
|
63
71
|
* import { createLibp2p } from 'libp2p'
|
|
64
72
|
* import { peerIdFromString } from '@libp2p/peer-id'
|
|
73
|
+
* import { ping } from '@libp2p/ping'
|
|
74
|
+
* import { identify } from '@libp2p/identify'
|
|
65
75
|
*
|
|
66
76
|
* const node = await createLibp2p({
|
|
67
77
|
* services: {
|
|
@@ -69,7 +79,9 @@
|
|
|
69
79
|
* protocol: '/ipfs/lan/kad/1.0.0',
|
|
70
80
|
* peerInfoMapper: removePublicAddressesMapper,
|
|
71
81
|
* clientMode: false
|
|
72
|
-
* })
|
|
82
|
+
* }),
|
|
83
|
+
* ping: ping(),
|
|
84
|
+
* identify: identify()
|
|
73
85
|
* }
|
|
74
86
|
* })
|
|
75
87
|
*
|
|
@@ -88,6 +100,8 @@
|
|
|
88
100
|
* import { kadDHT, removePublicAddressesMapper, removePrivateAddressesMapper } from '@libp2p/kad-dht'
|
|
89
101
|
* import { createLibp2p } from 'libp2p'
|
|
90
102
|
* import { peerIdFromString } from '@libp2p/peer-id'
|
|
103
|
+
* import { ping } from '@libp2p/ping'
|
|
104
|
+
* import { identify } from '@libp2p/identify'
|
|
91
105
|
*
|
|
92
106
|
* const node = await createLibp2p({
|
|
93
107
|
* services: {
|
|
@@ -105,7 +119,9 @@
|
|
|
105
119
|
* logPrefix: 'libp2p:dht-amino',
|
|
106
120
|
* datastorePrefix: '/dht-amino',
|
|
107
121
|
* metricsPrefix: 'libp2p_dht_amino'
|
|
108
|
-
* })
|
|
122
|
+
* }),
|
|
123
|
+
* ping: ping(),
|
|
124
|
+
* identify: identify()
|
|
109
125
|
* }
|
|
110
126
|
* })
|
|
111
127
|
*
|
|
@@ -121,6 +137,7 @@ import { MessageType } from './message/dht.js'
|
|
|
121
137
|
import { removePrivateAddressesMapper, removePublicAddressesMapper, passthroughMapper } from './utils.js'
|
|
122
138
|
import type { Libp2pEvents, ComponentLogger, TypedEventTarget, Metrics, PeerId, PeerInfo, PeerStore, RoutingOptions, PrivateKey } from '@libp2p/interface'
|
|
123
139
|
import type { AddressManager, ConnectionManager, Registrar } from '@libp2p/interface-internal'
|
|
140
|
+
import type { Ping } from '@libp2p/ping'
|
|
124
141
|
import type { AdaptiveTimeoutInit } from '@libp2p/utils/src/adaptive-timeout.js'
|
|
125
142
|
import type { Datastore } from 'interface-datastore'
|
|
126
143
|
import type { CID } from 'multiformats/cid'
|
|
@@ -617,6 +634,7 @@ export interface KadDHTComponents {
|
|
|
617
634
|
datastore: Datastore
|
|
618
635
|
events: TypedEventTarget<Libp2pEvents>
|
|
619
636
|
logger: ComponentLogger
|
|
637
|
+
ping: Ping
|
|
620
638
|
}
|
|
621
639
|
|
|
622
640
|
/**
|
package/src/kad-dht.ts
CHANGED
|
@@ -366,7 +366,8 @@ export class KadDHT extends TypedEventEmitter<PeerDiscoveryEvents> implements Ka
|
|
|
366
366
|
]
|
|
367
367
|
|
|
368
368
|
readonly [serviceDependencies]: string[] = [
|
|
369
|
-
'@libp2p/identify'
|
|
369
|
+
'@libp2p/identify',
|
|
370
|
+
'@libp2p/ping'
|
|
370
371
|
]
|
|
371
372
|
|
|
372
373
|
get [contentRoutingSymbol] (): ContentRouting {
|
|
@@ -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
|
-
|
|
384
|
-
|
|
385
|
-
|
|
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
|
|
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)
|
|
@@ -6,8 +6,7 @@ import { xor as uint8ArrayXor } from 'uint8arrays/xor'
|
|
|
6
6
|
import { PeerDistanceList } from '../peer-distance-list.js'
|
|
7
7
|
import { convertPeerId } from '../utils.js'
|
|
8
8
|
import { KBUCKET_SIZE, LAST_PING_THRESHOLD, PING_OLD_CONTACT_COUNT, PREFIX_LENGTH } from './index.js'
|
|
9
|
-
import type { PeerId } from '@libp2p/interface'
|
|
10
|
-
import type { AbortOptions } from 'it-protobuf-stream'
|
|
9
|
+
import type { PeerId, AbortOptions } from '@libp2p/interface'
|
|
11
10
|
|
|
12
11
|
export interface PingFunction {
|
|
13
12
|
/**
|
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
|
-
}
|