@libp2p/kad-dht 12.0.13-acef72613 → 12.0.13-c2181f0cf
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
|
@@ -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,SAAS,EAAE,MAAM,mB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E,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.13-
|
|
3
|
+
"version": "12.0.13-c2181f0cf",
|
|
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": "4.0.6-
|
|
61
|
-
"@libp2p/interface": "1.2.0-
|
|
62
|
-
"@libp2p/interface-internal": "1.1.0-
|
|
63
|
-
"@libp2p/peer-collections": "5.1.10-
|
|
64
|
-
"@libp2p/peer-id": "4.0.10-
|
|
65
|
-
"@libp2p/record": "4.0.0-
|
|
66
|
-
"@libp2p/utils": "5.3.1-
|
|
60
|
+
"@libp2p/crypto": "4.0.6-c2181f0cf",
|
|
61
|
+
"@libp2p/interface": "1.2.0-c2181f0cf",
|
|
62
|
+
"@libp2p/interface-internal": "1.1.0-c2181f0cf",
|
|
63
|
+
"@libp2p/peer-collections": "5.1.10-c2181f0cf",
|
|
64
|
+
"@libp2p/peer-id": "4.0.10-c2181f0cf",
|
|
65
|
+
"@libp2p/record": "4.0.0-c2181f0cf",
|
|
66
|
+
"@libp2p/utils": "5.3.1-c2181f0cf",
|
|
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": "5.4.1-
|
|
94
|
-
"@libp2p/logger": "4.0.10-
|
|
95
|
-
"@libp2p/peer-id-factory": "4.0.10-
|
|
96
|
-
"@libp2p/peer-store": "10.0.15-
|
|
93
|
+
"@libp2p/interface-compliance-tests": "5.4.1-c2181f0cf",
|
|
94
|
+
"@libp2p/logger": "4.0.10-c2181f0cf",
|
|
95
|
+
"@libp2p/peer-id-factory": "4.0.10-c2181f0cf",
|
|
96
|
+
"@libp2p/peer-store": "10.0.15-c2181f0cf",
|
|
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
|