@libp2p/kad-dht 15.1.10 → 15.1.11-0f07e3df5
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 +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/constants.d.ts +0 -1
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +0 -1
- package/dist/src/constants.js.map +1 -1
- package/dist/src/content-routing/index.js +3 -3
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/kad-dht.d.ts.map +1 -1
- package/dist/src/kad-dht.js +7 -3
- package/dist/src/kad-dht.js.map +1 -1
- package/dist/src/network.d.ts +1 -1
- package/dist/src/network.d.ts.map +1 -1
- package/dist/src/network.js +3 -6
- package/dist/src/network.js.map +1 -1
- package/dist/src/peer-routing/index.js +1 -1
- package/dist/src/peer-routing/index.js.map +1 -1
- package/dist/src/query/manager.js +1 -1
- package/dist/src/query/manager.js.map +1 -1
- package/dist/src/query/query-path.d.ts +1 -1
- package/dist/src/query/query-path.d.ts.map +1 -1
- package/dist/src/query/query-path.js +4 -4
- package/dist/src/query/query-path.js.map +1 -1
- package/dist/src/reprovider.d.ts +6 -2
- package/dist/src/reprovider.d.ts.map +1 -1
- package/dist/src/reprovider.js +29 -10
- package/dist/src/reprovider.js.map +1 -1
- package/dist/src/routing-table/index.d.ts +1 -1
- package/dist/src/routing-table/index.d.ts.map +1 -1
- package/dist/src/routing-table/index.js +3 -2
- package/dist/src/routing-table/index.js.map +1 -1
- package/dist/src/rpc/handlers/find-node.js +2 -2
- package/dist/src/rpc/handlers/find-node.js.map +1 -1
- package/dist/src/rpc/handlers/get-value.d.ts +1 -1
- package/dist/src/rpc/handlers/get-value.js +3 -3
- package/dist/src/rpc/handlers/get-value.js.map +1 -1
- package/dist/src/rpc/index.d.ts +2 -2
- package/dist/src/rpc/index.d.ts.map +1 -1
- package/dist/src/rpc/index.js +42 -47
- package/dist/src/rpc/index.js.map +1 -1
- package/dist/src/utils.d.ts +0 -3
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +3 -72
- package/dist/src/utils.js.map +1 -1
- package/package.json +33 -35
- package/src/constants.ts +0 -2
- package/src/content-routing/index.ts +3 -3
- package/src/index.ts +1 -1
- package/src/kad-dht.ts +6 -3
- package/src/network.ts +4 -7
- package/src/peer-routing/index.ts +1 -1
- package/src/query/manager.ts +1 -1
- package/src/query/query-path.ts +5 -5
- package/src/reprovider.ts +33 -12
- package/src/routing-table/index.ts +5 -3
- package/src/rpc/handlers/find-node.ts +2 -2
- package/src/rpc/handlers/get-value.ts +3 -3
- package/src/rpc/index.ts +47 -51
- package/src/utils.ts +3 -95
- package/dist/typedoc-urls.json +0 -65
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { peerIdFromMultihash, peerIdFromString } from '@libp2p/peer-id'
|
|
2
2
|
import { Libp2pRecord } from '@libp2p/record'
|
|
3
|
-
import {
|
|
3
|
+
import { isPrivate } from '@libp2p/utils'
|
|
4
4
|
import { Key } from 'interface-datastore/key'
|
|
5
5
|
import { CID } from 'multiformats/cid'
|
|
6
6
|
import * as raw from 'multiformats/codecs/raw'
|
|
@@ -12,7 +12,6 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
|
12
12
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
13
13
|
import type { Operation, OperationMetrics } from './kad-dht.js'
|
|
14
14
|
import type { AbortOptions, PeerId, PeerInfo } from '@libp2p/interface'
|
|
15
|
-
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
16
15
|
|
|
17
16
|
// const IPNS_PREFIX = uint8ArrayFromString('/ipns/')
|
|
18
17
|
const PK_PREFIX = uint8ArrayFromString('/pk/')
|
|
@@ -21,34 +20,7 @@ export function removePrivateAddressesMapper (peer: PeerInfo): PeerInfo {
|
|
|
21
20
|
return {
|
|
22
21
|
...peer,
|
|
23
22
|
multiaddrs: peer.multiaddrs.filter(multiaddr => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// treat /dns, /dns4, and /dns6 addrs as public
|
|
27
|
-
if (type === 53 || type === 54 || type === 55) {
|
|
28
|
-
// localhost can be a dns address but it's private
|
|
29
|
-
if (addr === 'localhost') {
|
|
30
|
-
return false
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return true
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (type !== 4 && type !== 6) {
|
|
37
|
-
return false
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (addr == null) {
|
|
41
|
-
return false
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const isPrivate = isPrivateIp(addr)
|
|
45
|
-
|
|
46
|
-
if (isPrivate == null) {
|
|
47
|
-
// not an ip address
|
|
48
|
-
return true
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return !isPrivate
|
|
23
|
+
return !isPrivate(multiaddr)
|
|
52
24
|
})
|
|
53
25
|
}
|
|
54
26
|
}
|
|
@@ -57,28 +29,7 @@ export function removePublicAddressesMapper (peer: PeerInfo): PeerInfo {
|
|
|
57
29
|
return {
|
|
58
30
|
...peer,
|
|
59
31
|
multiaddrs: peer.multiaddrs.filter(multiaddr => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (addr === 'localhost') {
|
|
63
|
-
return true
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (type !== 4 && type !== 6) {
|
|
67
|
-
return false
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (addr == null) {
|
|
71
|
-
return false
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const isPrivate = isPrivateIp(addr)
|
|
75
|
-
|
|
76
|
-
if (isPrivate == null) {
|
|
77
|
-
// not an ip address
|
|
78
|
-
return false
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return isPrivate
|
|
32
|
+
return isPrivate(multiaddr)
|
|
82
33
|
})
|
|
83
34
|
}
|
|
84
35
|
}
|
|
@@ -160,49 +111,6 @@ export function createPutRecord (key: Uint8Array, value: Uint8Array): Uint8Array
|
|
|
160
111
|
return rec.serialize()
|
|
161
112
|
}
|
|
162
113
|
|
|
163
|
-
export function debounce (callback: () => void, wait: number = 100): () => void {
|
|
164
|
-
let timeout: ReturnType<typeof setTimeout>
|
|
165
|
-
|
|
166
|
-
return (): void => {
|
|
167
|
-
clearTimeout(timeout)
|
|
168
|
-
timeout = setTimeout(() => { callback() }, wait)
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// see https://github.com/multiformats/multiaddr/blob/master/protocols.csv
|
|
173
|
-
const P2P_CIRCUIT_CODE = 290
|
|
174
|
-
const DNS4_CODE = 54
|
|
175
|
-
const DNS6_CODE = 55
|
|
176
|
-
const DNSADDR_CODE = 56
|
|
177
|
-
const IP4_CODE = 4
|
|
178
|
-
const IP6_CODE = 41
|
|
179
|
-
|
|
180
|
-
export function multiaddrIsPublic (multiaddr: Multiaddr): boolean {
|
|
181
|
-
const tuples = multiaddr.stringTuples()
|
|
182
|
-
|
|
183
|
-
// p2p-circuit should not enable server mode
|
|
184
|
-
for (const tuple of tuples) {
|
|
185
|
-
if (tuple[0] === P2P_CIRCUIT_CODE) {
|
|
186
|
-
return false
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// dns4 or dns6 or dnsaddr
|
|
191
|
-
if (tuples[0][0] === DNS4_CODE || tuples[0][0] === DNS6_CODE || tuples[0][0] === DNSADDR_CODE) {
|
|
192
|
-
return true
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// ip4 or ip6
|
|
196
|
-
if (tuples[0][0] === IP4_CODE || tuples[0][0] === IP6_CODE) {
|
|
197
|
-
const result = isPrivateIp(`${tuples[0][1]}`)
|
|
198
|
-
const isPublic = result == null || !result
|
|
199
|
-
|
|
200
|
-
return isPublic
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return false
|
|
204
|
-
}
|
|
205
|
-
|
|
206
114
|
/**
|
|
207
115
|
* Parse the CID and provider peer id from the key
|
|
208
116
|
*/
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,65 +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.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
|
-
"DisjointPath": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.DisjointPath.html",
|
|
13
|
-
".:DisjointPath": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.DisjointPath.html",
|
|
14
|
-
"FinalPeerEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.FinalPeerEvent.html",
|
|
15
|
-
".:FinalPeerEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.FinalPeerEvent.html",
|
|
16
|
-
"KadDHT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.KadDHT.html",
|
|
17
|
-
".:KadDHT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.KadDHT.html",
|
|
18
|
-
"KadDHTComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.KadDHTComponents.html",
|
|
19
|
-
".:KadDHTComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.KadDHTComponents.html",
|
|
20
|
-
"KadDHTInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.KadDHTInit.html",
|
|
21
|
-
".:KadDHTInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.KadDHTInit.html",
|
|
22
|
-
"PathEndedEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.PathEndedEvent.html",
|
|
23
|
-
".:PathEndedEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.PathEndedEvent.html",
|
|
24
|
-
"PeerInfoMapper": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.PeerInfoMapper.html",
|
|
25
|
-
".:PeerInfoMapper": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.PeerInfoMapper.html",
|
|
26
|
-
"PeerResponseEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.PeerResponseEvent.html",
|
|
27
|
-
".:PeerResponseEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.PeerResponseEvent.html",
|
|
28
|
-
"ProviderEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.ProviderEvent.html",
|
|
29
|
-
".:ProviderEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.ProviderEvent.html",
|
|
30
|
-
"ProvidersInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.ProvidersInit.html",
|
|
31
|
-
".:ProvidersInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.ProvidersInit.html",
|
|
32
|
-
"QueryErrorEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.QueryErrorEvent.html",
|
|
33
|
-
".:QueryErrorEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.QueryErrorEvent.html",
|
|
34
|
-
"ReProvideInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.ReProvideInit.html",
|
|
35
|
-
".:ReProvideInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.ReProvideInit.html",
|
|
36
|
-
"RoutingTable": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.RoutingTable.html",
|
|
37
|
-
".:RoutingTable": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.RoutingTable.html",
|
|
38
|
-
"SelectFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.SelectFn.html",
|
|
39
|
-
".:SelectFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.SelectFn.html",
|
|
40
|
-
"SendQueryEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.SendQueryEvent.html",
|
|
41
|
-
".:SendQueryEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.SendQueryEvent.html",
|
|
42
|
-
"SetModeOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.SetModeOptions.html",
|
|
43
|
-
".:SetModeOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.SetModeOptions.html",
|
|
44
|
-
"SingleKadDHT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.SingleKadDHT.html",
|
|
45
|
-
".:SingleKadDHT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.SingleKadDHT.html",
|
|
46
|
-
"ValidateFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.ValidateFn.html",
|
|
47
|
-
".:ValidateFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.ValidateFn.html",
|
|
48
|
-
"ValueEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.ValueEvent.html",
|
|
49
|
-
".:ValueEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad-dht.ValueEvent.html",
|
|
50
|
-
"DHTProgressEvents": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad-dht.DHTProgressEvents.html",
|
|
51
|
-
".:DHTProgressEvents": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad-dht.DHTProgressEvents.html",
|
|
52
|
-
"MessageName": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad-dht.MessageName.html",
|
|
53
|
-
".:MessageName": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad-dht.MessageName.html",
|
|
54
|
-
"QueryEvent": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad-dht.QueryEvent.html",
|
|
55
|
-
".:QueryEvent": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad-dht.QueryEvent.html",
|
|
56
|
-
"Selectors": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad-dht.Selectors.html",
|
|
57
|
-
".:Selectors": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad-dht.Selectors.html",
|
|
58
|
-
"Validators": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad-dht.Validators.html",
|
|
59
|
-
".:Validators": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad-dht.Validators.html",
|
|
60
|
-
"kadDHT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad-dht.kadDHT.html",
|
|
61
|
-
".:kadDHT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad-dht.kadDHT.html",
|
|
62
|
-
"passthroughMapper": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad-dht.passthroughMapper.html",
|
|
63
|
-
"removePrivateAddressesMapper": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad-dht.removePrivateAddressesMapper.html",
|
|
64
|
-
"removePublicAddressesMapper": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad-dht.removePublicAddressesMapper.html"
|
|
65
|
-
}
|