@libp2p/kad-dht 12.0.13 → 12.0.14-90cfd25e2
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 +2 -2
- package/dist/index.min.js +3 -3
- package/dist/src/rpc/handlers/find-node.d.ts +0 -3
- package/dist/src/rpc/handlers/find-node.d.ts.map +1 -1
- package/dist/src/rpc/handlers/find-node.js +2 -14
- package/dist/src/rpc/handlers/find-node.js.map +1 -1
- package/dist/src/rpc/handlers/get-providers.js +1 -1
- package/dist/src/rpc/handlers/get-providers.js.map +1 -1
- package/package.json +12 -12
- package/src/rpc/handlers/find-node.ts +2 -16
- package/src/rpc/handlers/get-providers.ts +1 -1
- package/dist/typedoc-urls.json +0 -55
|
@@ -3,7 +3,6 @@ import type { Message } from '../../message/dht.js';
|
|
|
3
3
|
import type { PeerRouting } from '../../peer-routing/index.js';
|
|
4
4
|
import type { DHTMessageHandler } from '../index.js';
|
|
5
5
|
import type { ComponentLogger, PeerId } from '@libp2p/interface';
|
|
6
|
-
import type { AddressManager } from '@libp2p/interface-internal';
|
|
7
6
|
export interface FindNodeHandlerInit {
|
|
8
7
|
peerRouting: PeerRouting;
|
|
9
8
|
logPrefix: string;
|
|
@@ -11,14 +10,12 @@ export interface FindNodeHandlerInit {
|
|
|
11
10
|
}
|
|
12
11
|
export interface FindNodeHandlerComponents {
|
|
13
12
|
peerId: PeerId;
|
|
14
|
-
addressManager: AddressManager;
|
|
15
13
|
logger: ComponentLogger;
|
|
16
14
|
}
|
|
17
15
|
export declare class FindNodeHandler implements DHTMessageHandler {
|
|
18
16
|
private readonly peerRouting;
|
|
19
17
|
private readonly peerInfoMapper;
|
|
20
18
|
private readonly peerId;
|
|
21
|
-
private readonly addressManager;
|
|
22
19
|
private readonly log;
|
|
23
20
|
constructor(components: FindNodeHandlerComponents, init: FindNodeHandlerInit);
|
|
24
21
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-node.d.ts","sourceRoot":"","sources":["../../../../src/rpc/handlers/find-node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"find-node.d.ts","sourceRoot":"","sources":["../../../../src/rpc/handlers/find-node.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAAE,eAAe,EAAU,MAAM,EAAY,MAAM,mBAAmB,CAAA;AAElF,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,WAAW,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,cAAc,CAAA;CAC/B;AAED,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,qBAAa,eAAgB,YAAW,iBAAiB;IACvD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAa;IACzC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgB;IAC/C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;gBAEf,UAAU,EAAE,yBAAyB,EAAE,IAAI,EAAE,mBAAmB;IAS7E;;OAEG;IACG,MAAM,CAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;CA6B9D"}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import { CodeError } from '@libp2p/interface';
|
|
2
|
-
import { protocols } from '@multiformats/multiaddr';
|
|
3
|
-
import { equals as uint8ArrayEquals } from 'uint8arrays';
|
|
4
2
|
import { MessageType } from '../../message/dht.js';
|
|
5
3
|
export class FindNodeHandler {
|
|
6
4
|
peerRouting;
|
|
7
5
|
peerInfoMapper;
|
|
8
6
|
peerId;
|
|
9
|
-
addressManager;
|
|
10
7
|
log;
|
|
11
8
|
constructor(components, init) {
|
|
12
9
|
const { peerRouting, logPrefix } = init;
|
|
13
10
|
this.log = components.logger.forComponent(`${logPrefix}:rpc:handlers:find-node`);
|
|
14
11
|
this.peerId = components.peerId;
|
|
15
|
-
this.addressManager = components.addressManager;
|
|
16
12
|
this.peerRouting = peerRouting;
|
|
17
13
|
this.peerInfoMapper = init.peerInfoMapper;
|
|
18
14
|
}
|
|
@@ -21,25 +17,17 @@ export class FindNodeHandler {
|
|
|
21
17
|
*/
|
|
22
18
|
async handle(peerId, msg) {
|
|
23
19
|
this.log('incoming request from %p for peers closer to %b', peerId, msg.key);
|
|
24
|
-
let closer = [];
|
|
25
20
|
if (msg.key == null) {
|
|
26
21
|
throw new CodeError('Invalid FIND_NODE message received - key was missing', 'ERR_INVALID_MESSAGE');
|
|
27
22
|
}
|
|
28
|
-
|
|
29
|
-
closer = [{
|
|
30
|
-
id: this.peerId,
|
|
31
|
-
multiaddrs: this.addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code))
|
|
32
|
-
}];
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
closer = await this.peerRouting.getCloserPeersOffline(msg.key, peerId);
|
|
36
|
-
}
|
|
23
|
+
const closer = await this.peerRouting.getCloserPeersOffline(msg.key, peerId);
|
|
37
24
|
const response = {
|
|
38
25
|
type: MessageType.FIND_NODE,
|
|
39
26
|
clusterLevel: msg.clusterLevel,
|
|
40
27
|
closer: closer
|
|
41
28
|
.map(this.peerInfoMapper)
|
|
42
29
|
.filter(({ multiaddrs }) => multiaddrs.length)
|
|
30
|
+
.filter(({ id }) => !id.equals(this.peerId))
|
|
43
31
|
.map(peerInfo => ({
|
|
44
32
|
id: peerInfo.id.toBytes(),
|
|
45
33
|
multiaddrs: peerInfo.multiaddrs.map(ma => ma.bytes)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-node.js","sourceRoot":"","sources":["../../../../src/rpc/handlers/find-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"find-node.js","sourceRoot":"","sources":["../../../../src/rpc/handlers/find-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAkBlD,MAAM,OAAO,eAAe;IACT,WAAW,CAAa;IACxB,cAAc,CAAgB;IAC9B,MAAM,CAAQ;IACd,GAAG,CAAQ;IAE5B,YAAa,UAAqC,EAAE,IAAyB;QAC3E,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,IAAI,CAAA;QAEvC,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,SAAS,yBAAyB,CAAC,CAAA;QAChF,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAA;QAC/B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAA;IAC3C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CAAE,MAAc,EAAE,GAAY;QACxC,IAAI,CAAC,GAAG,CAAC,iDAAiD,EAAE,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;QAE5E,IAAI,GAAG,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;YACpB,MAAM,IAAI,SAAS,CAAC,sDAAsD,EAAE,qBAAqB,CAAC,CAAA;QACpG,CAAC;QAED,MAAM,MAAM,GAAe,MAAM,IAAI,CAAC,WAAW,CAAC,qBAAqB,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QAExF,MAAM,QAAQ,GAAY;YACxB,IAAI,EAAE,WAAW,CAAC,SAAS;YAC3B,YAAY,EAAE,GAAG,CAAC,YAAY;YAC9B,MAAM,EAAE,MAAM;iBACX,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC;iBACxB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC;iBAC7C,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;iBAC3C,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;gBAChB,EAAE,EAAE,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE;gBACzB,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;aACpD,CAAC,CAAC;YACL,SAAS,EAAE,EAAE;SACd,CAAA;QAED,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjC,IAAI,CAAC,GAAG,CAAC,+CAA+C,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QAC5E,CAAC;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF"}
|
|
@@ -17,7 +17,7 @@ export class GetProvidersHandler {
|
|
|
17
17
|
}
|
|
18
18
|
async handle(peerId, msg) {
|
|
19
19
|
if (msg.key == null) {
|
|
20
|
-
throw new CodeError('Invalid
|
|
20
|
+
throw new CodeError('Invalid GET_PROVIDERS message received - key was missing', 'ERR_INVALID_MESSAGE');
|
|
21
21
|
}
|
|
22
22
|
let cid;
|
|
23
23
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-providers.js","sourceRoot":"","sources":["../../../../src/rpc/handlers/get-providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,S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AM,MAAM,GAAe,EAAE,CAAA;QAE7B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;gBAE7C,MAAM,eAAe,GAAG,IAAI,CAAC,cAAc,CAAC;oBAC1C,EAAE,EAAE,MAAM;oBACV,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC;iBAC7D,CAAC,CAAA;gBAEF,IAAI,eAAe,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC1C,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;gBAC9B,CAAC;YACH,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,IAAI,GAAG,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;oBACjC,MAAM,GAAG,CAAA;gBACX,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/kad-dht",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.14-90cfd25e2",
|
|
4
4
|
"description": "JavaScript implementation of the Kad-DHT for libp2p",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/kad-dht#readme",
|
|
@@ -57,13 +57,13 @@
|
|
|
57
57
|
"doc-check": "aegir doc-check"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@libp2p/crypto": "
|
|
61
|
-
"@libp2p/interface": "
|
|
62
|
-
"@libp2p/interface-internal": "
|
|
63
|
-
"@libp2p/peer-collections": "
|
|
64
|
-
"@libp2p/peer-id": "
|
|
65
|
-
"@libp2p/record": "
|
|
66
|
-
"@libp2p/utils": "
|
|
60
|
+
"@libp2p/crypto": "4.1.0-90cfd25e2",
|
|
61
|
+
"@libp2p/interface": "1.3.0-90cfd25e2",
|
|
62
|
+
"@libp2p/interface-internal": "1.1.1-90cfd25e2",
|
|
63
|
+
"@libp2p/peer-collections": "5.1.11-90cfd25e2",
|
|
64
|
+
"@libp2p/peer-id": "4.1.0-90cfd25e2",
|
|
65
|
+
"@libp2p/record": "4.0.1-90cfd25e2",
|
|
66
|
+
"@libp2p/utils": "5.3.2-90cfd25e2",
|
|
67
67
|
"@multiformats/multiaddr": "^12.2.1",
|
|
68
68
|
"any-signal": "^4.1.1",
|
|
69
69
|
"hashlru": "^2.3.0",
|
|
@@ -90,10 +90,10 @@
|
|
|
90
90
|
"uint8arrays": "^5.0.3"
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
|
-
"@libp2p/interface-compliance-tests": "
|
|
94
|
-
"@libp2p/logger": "
|
|
95
|
-
"@libp2p/peer-id-factory": "
|
|
96
|
-
"@libp2p/peer-store": "
|
|
93
|
+
"@libp2p/interface-compliance-tests": "5.4.2-90cfd25e2",
|
|
94
|
+
"@libp2p/logger": "4.0.11-90cfd25e2",
|
|
95
|
+
"@libp2p/peer-id-factory": "4.1.0-90cfd25e2",
|
|
96
|
+
"@libp2p/peer-store": "10.0.16-90cfd25e2",
|
|
97
97
|
"@types/lodash.random": "^3.2.9",
|
|
98
98
|
"@types/lodash.range": "^3.2.9",
|
|
99
99
|
"@types/sinon": "^17.0.3",
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { CodeError } from '@libp2p/interface'
|
|
2
|
-
import { protocols } from '@multiformats/multiaddr'
|
|
3
|
-
import { equals as uint8ArrayEquals } from 'uint8arrays'
|
|
4
2
|
import { MessageType } from '../../message/dht.js'
|
|
5
3
|
import type { PeerInfoMapper } from '../../index.js'
|
|
6
4
|
import type { Message } from '../../message/dht.js'
|
|
7
5
|
import type { PeerRouting } from '../../peer-routing/index.js'
|
|
8
6
|
import type { DHTMessageHandler } from '../index.js'
|
|
9
7
|
import type { ComponentLogger, Logger, PeerId, PeerInfo } from '@libp2p/interface'
|
|
10
|
-
import type { AddressManager } from '@libp2p/interface-internal'
|
|
11
8
|
|
|
12
9
|
export interface FindNodeHandlerInit {
|
|
13
10
|
peerRouting: PeerRouting
|
|
@@ -17,7 +14,6 @@ export interface FindNodeHandlerInit {
|
|
|
17
14
|
|
|
18
15
|
export interface FindNodeHandlerComponents {
|
|
19
16
|
peerId: PeerId
|
|
20
|
-
addressManager: AddressManager
|
|
21
17
|
logger: ComponentLogger
|
|
22
18
|
}
|
|
23
19
|
|
|
@@ -25,7 +21,6 @@ export class FindNodeHandler implements DHTMessageHandler {
|
|
|
25
21
|
private readonly peerRouting: PeerRouting
|
|
26
22
|
private readonly peerInfoMapper: PeerInfoMapper
|
|
27
23
|
private readonly peerId: PeerId
|
|
28
|
-
private readonly addressManager: AddressManager
|
|
29
24
|
private readonly log: Logger
|
|
30
25
|
|
|
31
26
|
constructor (components: FindNodeHandlerComponents, init: FindNodeHandlerInit) {
|
|
@@ -33,7 +28,6 @@ export class FindNodeHandler implements DHTMessageHandler {
|
|
|
33
28
|
|
|
34
29
|
this.log = components.logger.forComponent(`${logPrefix}:rpc:handlers:find-node`)
|
|
35
30
|
this.peerId = components.peerId
|
|
36
|
-
this.addressManager = components.addressManager
|
|
37
31
|
this.peerRouting = peerRouting
|
|
38
32
|
this.peerInfoMapper = init.peerInfoMapper
|
|
39
33
|
}
|
|
@@ -44,20 +38,11 @@ export class FindNodeHandler implements DHTMessageHandler {
|
|
|
44
38
|
async handle (peerId: PeerId, msg: Message): Promise<Message> {
|
|
45
39
|
this.log('incoming request from %p for peers closer to %b', peerId, msg.key)
|
|
46
40
|
|
|
47
|
-
let closer: PeerInfo[] = []
|
|
48
|
-
|
|
49
41
|
if (msg.key == null) {
|
|
50
42
|
throw new CodeError('Invalid FIND_NODE message received - key was missing', 'ERR_INVALID_MESSAGE')
|
|
51
43
|
}
|
|
52
44
|
|
|
53
|
-
|
|
54
|
-
closer = [{
|
|
55
|
-
id: this.peerId,
|
|
56
|
-
multiaddrs: this.addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code))
|
|
57
|
-
}]
|
|
58
|
-
} else {
|
|
59
|
-
closer = await this.peerRouting.getCloserPeersOffline(msg.key, peerId)
|
|
60
|
-
}
|
|
45
|
+
const closer: PeerInfo[] = await this.peerRouting.getCloserPeersOffline(msg.key, peerId)
|
|
61
46
|
|
|
62
47
|
const response: Message = {
|
|
63
48
|
type: MessageType.FIND_NODE,
|
|
@@ -65,6 +50,7 @@ export class FindNodeHandler implements DHTMessageHandler {
|
|
|
65
50
|
closer: closer
|
|
66
51
|
.map(this.peerInfoMapper)
|
|
67
52
|
.filter(({ multiaddrs }) => multiaddrs.length)
|
|
53
|
+
.filter(({ id }) => !id.equals(this.peerId))
|
|
68
54
|
.map(peerInfo => ({
|
|
69
55
|
id: peerInfo.id.toBytes(),
|
|
70
56
|
multiaddrs: peerInfo.multiaddrs.map(ma => ma.bytes)
|
|
@@ -40,7 +40,7 @@ export class GetProvidersHandler implements DHTMessageHandler {
|
|
|
40
40
|
|
|
41
41
|
async handle (peerId: PeerId, msg: Message): Promise<Message> {
|
|
42
42
|
if (msg.key == null) {
|
|
43
|
-
throw new CodeError('Invalid
|
|
43
|
+
throw new CodeError('Invalid GET_PROVIDERS message received - key was missing', 'ERR_INVALID_MESSAGE')
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
let cid
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,55 +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
|
-
"QueryErrorEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.QueryErrorEvent.html",
|
|
27
|
-
".:QueryErrorEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.QueryErrorEvent.html",
|
|
28
|
-
"RoutingTable": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.RoutingTable.html",
|
|
29
|
-
".:RoutingTable": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.RoutingTable.html",
|
|
30
|
-
"SelectFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SelectFn.html",
|
|
31
|
-
".:SelectFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SelectFn.html",
|
|
32
|
-
"SendQueryEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SendQueryEvent.html",
|
|
33
|
-
".:SendQueryEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SendQueryEvent.html",
|
|
34
|
-
"SingleKadDHT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SingleKadDHT.html",
|
|
35
|
-
".:SingleKadDHT": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.SingleKadDHT.html",
|
|
36
|
-
"ValidateFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ValidateFn.html",
|
|
37
|
-
".:ValidateFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ValidateFn.html",
|
|
38
|
-
"ValueEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ValueEvent.html",
|
|
39
|
-
".:ValueEvent": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_kad_dht.ValueEvent.html",
|
|
40
|
-
"DHTProgressEvents": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.DHTProgressEvents.html",
|
|
41
|
-
".:DHTProgressEvents": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.DHTProgressEvents.html",
|
|
42
|
-
"MessageName": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.MessageName.html",
|
|
43
|
-
".:MessageName": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.MessageName.html",
|
|
44
|
-
"QueryEvent": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.QueryEvent.html",
|
|
45
|
-
".:QueryEvent": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.QueryEvent.html",
|
|
46
|
-
"Selectors": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.Selectors.html",
|
|
47
|
-
".:Selectors": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.Selectors.html",
|
|
48
|
-
"Validators": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.Validators.html",
|
|
49
|
-
".:Validators": "https://libp2p.github.io/js-libp2p/types/_libp2p_kad_dht.Validators.html",
|
|
50
|
-
"kadDHT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.kadDHT-1.html",
|
|
51
|
-
".:kadDHT": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.kadDHT-1.html",
|
|
52
|
-
"passthroughMapper": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.passthroughMapper.html",
|
|
53
|
-
"removePrivateAddressesMapper": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.removePrivateAddressesMapper.html",
|
|
54
|
-
"removePublicAddressesMapper": "https://libp2p.github.io/js-libp2p/functions/_libp2p_kad_dht.removePublicAddressesMapper.html"
|
|
55
|
-
}
|