@libp2p/kad-dht 15.1.6-d2dc12c7d → 15.1.7
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/dist/index.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/dist/src/query/query-path.d.ts.map +1 -1
- package/dist/src/query/query-path.js +95 -89
- package/dist/src/query/query-path.js.map +1 -1
- package/dist/typedoc-urls.json +65 -0
- package/package.json +12 -12
- package/src/query/query-path.ts +103 -97
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-path.d.ts","sourceRoot":"","sources":["../../../src/query/query-path.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAA0B,MAAM,mBAAmB,CAAA;AAC/F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAEnD,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACtD;;OAEG;IACH,GAAG,EAAE,UAAU,CAAA;IAEf;;OAEG;IACH,aAAa,EAAE,MAAM,EAAE,CAAA;IAEvB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,KAAK,EAAE,SAAS,CAAA;IAEhB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IAEX;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,iBAAiB,EAAE,iBAAiB,CAAA;IAEpC;;OAEG;IACH,MAAM,EAAE,WAAW,CAAA;CACpB;AAMD;;;GAGG;AACH,wBAAwB,SAAS,CAAE,OAAO,EAAE,gBAAgB,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"query-path.d.ts","sourceRoot":"","sources":["../../../src/query/query-path.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAA0B,MAAM,mBAAmB,CAAA;AAC/F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAEnD,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACtD;;OAEG;IACH,GAAG,EAAE,UAAU,CAAA;IAEf;;OAEG;IACH,aAAa,EAAE,MAAM,EAAE,CAAA;IAEvB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,KAAK,EAAE,SAAS,CAAA;IAEhB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IAEX;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,iBAAiB,EAAE,iBAAiB,CAAA;IAEpC;;OAEG;IACH,MAAM,EAAE,WAAW,CAAA;CACpB;AAMD;;;GAGG;AACH,wBAAwB,SAAS,CAAE,OAAO,EAAE,gBAAgB,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC,CAoJzG"}
|
|
@@ -34,105 +34,111 @@ export async function* queryPath(options) {
|
|
|
34
34
|
queue.addEventListener('error', (evt) => {
|
|
35
35
|
log.error('error during query - %e', evt.detail);
|
|
36
36
|
});
|
|
37
|
-
|
|
37
|
+
const onAbort = () => {
|
|
38
38
|
queue.abort();
|
|
39
39
|
events.end(new AbortError());
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
40
|
+
};
|
|
41
|
+
signal.addEventListener('abort', onAbort);
|
|
42
|
+
try {
|
|
43
|
+
// perform lookups on kadId, not the actual value
|
|
44
|
+
const kadId = await convertBuffer(key, {
|
|
45
|
+
signal
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* Adds the passed peer to the query queue if it's not us and no other path
|
|
49
|
+
* has passed through this peer
|
|
50
|
+
*/
|
|
51
|
+
function queryPeer(peer, peerKadId) {
|
|
52
|
+
if (peer == null) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
peersSeen.add(peer.id.toMultihash().bytes);
|
|
56
|
+
const peerXor = uint8ArrayXor(peerKadId, kadId);
|
|
57
|
+
queue.add(async () => {
|
|
58
|
+
try {
|
|
59
|
+
for await (const event of query({
|
|
60
|
+
...options,
|
|
61
|
+
key,
|
|
62
|
+
peer,
|
|
63
|
+
path: {
|
|
64
|
+
index: path,
|
|
65
|
+
queued: queue.queued,
|
|
66
|
+
running: queue.running,
|
|
67
|
+
total: queue.size
|
|
68
|
+
},
|
|
69
|
+
numPaths,
|
|
70
|
+
peerKadId,
|
|
71
|
+
signal
|
|
72
|
+
})) {
|
|
73
|
+
// if there are closer peers and the query has not completed, continue the query
|
|
74
|
+
if (event.name === 'PEER_RESPONSE') {
|
|
75
|
+
for (const closerPeer of event.closer) {
|
|
76
|
+
if (peersSeen.has(closerPeer.id.toMultihash().bytes)) { // eslint-disable-line max-depth
|
|
77
|
+
log('already seen %p in query', closerPeer.id);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (ourPeerId.equals(closerPeer.id)) { // eslint-disable-line max-depth
|
|
81
|
+
log('not querying ourselves');
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (!(await connectionManager.isDialable(closerPeer.multiaddrs))) { // eslint-disable-line max-depth
|
|
85
|
+
log('not querying undialable peer');
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const closerPeerKadId = await convertPeerId(closerPeer.id, {
|
|
89
|
+
signal
|
|
90
|
+
});
|
|
91
|
+
const closerPeerXor = uint8ArrayXor(closerPeerKadId, kadId);
|
|
92
|
+
// only continue query if closer peer is actually closer
|
|
93
|
+
if (uint8ArrayXorCompare(closerPeerXor, peerXor) !== -1) { // eslint-disable-line max-depth
|
|
94
|
+
log('skipping %p as they are not closer to %b than %p', closerPeer.id, key, peer);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
log('querying closer peer %p', closerPeer.id);
|
|
98
|
+
queryPeer(closerPeer, closerPeerKadId);
|
|
94
99
|
}
|
|
95
|
-
log('querying closer peer %p', closerPeer.id);
|
|
96
|
-
queryPeer(closerPeer, closerPeerKadId);
|
|
97
100
|
}
|
|
101
|
+
events.push({
|
|
102
|
+
...event,
|
|
103
|
+
path: {
|
|
104
|
+
index: path,
|
|
105
|
+
queued: queue.queued,
|
|
106
|
+
running: queue.running,
|
|
107
|
+
total: queue.size
|
|
108
|
+
}
|
|
109
|
+
});
|
|
98
110
|
}
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
// yield error event if query is continuing
|
|
114
|
+
events.push(queryErrorEvent({
|
|
115
|
+
from: peer.id,
|
|
116
|
+
error: err,
|
|
101
117
|
path: {
|
|
102
118
|
index: path,
|
|
103
119
|
queued: queue.queued,
|
|
104
|
-
running: queue.running,
|
|
105
|
-
total: queue.size
|
|
120
|
+
running: queue.running - 1,
|
|
121
|
+
total: queue.size - 1
|
|
106
122
|
}
|
|
107
|
-
});
|
|
123
|
+
}, options));
|
|
108
124
|
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
}, options));
|
|
122
|
-
}
|
|
123
|
-
}, {
|
|
124
|
-
distance: peerXor
|
|
125
|
-
}).catch(err => {
|
|
126
|
-
log.error('error during query - %e', err);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
// begin the query with the starting peers
|
|
130
|
-
await Promise.all(startingPeers.map(async (startingPeer) => {
|
|
131
|
-
queryPeer({ id: startingPeer, multiaddrs: [] }, await convertPeerId(startingPeer, {
|
|
132
|
-
signal
|
|
125
|
+
}, {
|
|
126
|
+
distance: peerXor
|
|
127
|
+
}).catch(err => {
|
|
128
|
+
log.error('error during query - %e', err);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
// begin the query with the starting peers
|
|
132
|
+
await Promise.all(startingPeers.map(async (startingPeer) => {
|
|
133
|
+
queryPeer({ id: startingPeer, multiaddrs: [] }, await convertPeerId(startingPeer, {
|
|
134
|
+
signal
|
|
135
|
+
}));
|
|
133
136
|
}));
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
+
// yield results as they come in
|
|
138
|
+
yield* events;
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
signal.removeEventListener('abort', onAbort);
|
|
142
|
+
}
|
|
137
143
|
}
|
|
138
144
|
//# sourceMappingURL=query-path.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-path.js","sourceRoot":"","sources":["../../../src/query/query-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,GAAG,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAoE7D;;;GAGG;AACH,MAAM,CAAC,KAAK,SAAU,CAAC,CAAC,SAAS,CAAE,OAAyB;IAC1D,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAC1H,MAAM,MAAM,GAAG,QAAQ,CAAa;QAClC,UAAU,EAAE,IAAI;KACjB,CAAC,CAAA;IAEF,+EAA+E;IAC/E,yFAAyF;IACzF,MAAM,KAAK,GAAG,IAAI,KAAK,CAA+B;QACpD,WAAW,EAAE,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;4BACJ,KAAK,EAAE,IAAI;4BACX,MAAM,EAAE,KAAK,CAAC,MAAM;4BACpB,OAAO,EAAE,KAAK,CAAC,OAAO,GAAG,CAAC;4BAC1B,KAAK,EAAE,KAAK,CAAC,IAAI,GAAG,CAAC;yBACtB;qBACF,EAAE,OAAO,CAAC,CAAC,CAAA;gBACd,CAAC;YACH,CAAC,EAAE;gBACD,QAAQ,EAAE,OAAO;aAClB,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;gBACb,GAAG,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAA;YAC3C,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,0CAA0C;QAC1C,MAAM,OAAO,CAAC,GAAG,CACf,aAAa,CAAC,GAAG,CAAC,KAAK,EAAC,YAAY,EAAC,EAAE;YACrC,SAAS,CAAC,EAAE,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC,YAAY,EAAE;gBAChF,MAAM;aACP,CAAC,CAAC,CAAA;QACL,CAAC,CAAC,CACH,CAAA;QAED,gCAAgC;QAChC,KAAM,CAAC,CAAC,MAAM,CAAA;IAChB,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC9C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/kad-dht",
|
|
3
|
-
"version": "15.1.
|
|
3
|
+
"version": "15.1.7",
|
|
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",
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
"doc-check": "aegir doc-check"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@libp2p/crypto": "5.1.
|
|
51
|
-
"@libp2p/interface": "2.10.
|
|
52
|
-
"@libp2p/interface-internal": "2.3.
|
|
53
|
-
"@libp2p/peer-collections": "6.0.
|
|
54
|
-
"@libp2p/peer-id": "5.1.
|
|
55
|
-
"@libp2p/ping": "2.0.
|
|
56
|
-
"@libp2p/record": "4.0.7
|
|
57
|
-
"@libp2p/utils": "6.7.
|
|
50
|
+
"@libp2p/crypto": "^5.1.7",
|
|
51
|
+
"@libp2p/interface": "^2.10.5",
|
|
52
|
+
"@libp2p/interface-internal": "^2.3.18",
|
|
53
|
+
"@libp2p/peer-collections": "^6.0.34",
|
|
54
|
+
"@libp2p/peer-id": "^5.1.8",
|
|
55
|
+
"@libp2p/ping": "^2.0.36",
|
|
56
|
+
"@libp2p/record": "^4.0.7",
|
|
57
|
+
"@libp2p/utils": "^6.7.1",
|
|
58
58
|
"@multiformats/multiaddr": "^12.4.4",
|
|
59
59
|
"any-signal": "^4.1.1",
|
|
60
60
|
"interface-datastore": "^8.3.1",
|
|
@@ -80,9 +80,9 @@
|
|
|
80
80
|
"uint8arrays": "^5.1.0"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
|
-
"@libp2p/interface-compliance-tests": "6.4.
|
|
84
|
-
"@libp2p/logger": "5.1.
|
|
85
|
-
"@libp2p/peer-store": "11.2.
|
|
83
|
+
"@libp2p/interface-compliance-tests": "^6.4.13",
|
|
84
|
+
"@libp2p/logger": "^5.1.21",
|
|
85
|
+
"@libp2p/peer-store": "^11.2.6",
|
|
86
86
|
"@types/lodash.random": "^3.2.9",
|
|
87
87
|
"@types/lodash.range": "^3.2.9",
|
|
88
88
|
"@types/sinon": "^17.0.4",
|
package/src/query/query-path.ts
CHANGED
|
@@ -104,118 +104,124 @@ export async function * queryPath (options: QueryPathOptions): AsyncGenerator<Qu
|
|
|
104
104
|
log.error('error during query - %e', evt.detail)
|
|
105
105
|
})
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
const onAbort = (): void => {
|
|
108
108
|
queue.abort()
|
|
109
109
|
events.end(new AbortError())
|
|
110
|
-
}
|
|
110
|
+
}
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
const kadId = await convertBuffer(key, {
|
|
114
|
-
signal
|
|
115
|
-
})
|
|
112
|
+
signal.addEventListener('abort', onAbort)
|
|
116
113
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (peer == null) {
|
|
123
|
-
return
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
peersSeen.add(peer.id.toMultihash().bytes)
|
|
127
|
-
|
|
128
|
-
const peerXor = uint8ArrayXor(peerKadId, kadId)
|
|
129
|
-
|
|
130
|
-
queue.add(async () => {
|
|
131
|
-
try {
|
|
132
|
-
for await (const event of query({
|
|
133
|
-
...options,
|
|
134
|
-
key,
|
|
135
|
-
peer,
|
|
136
|
-
path: {
|
|
137
|
-
index: path,
|
|
138
|
-
queued: queue.queued,
|
|
139
|
-
running: queue.running,
|
|
140
|
-
total: queue.size
|
|
141
|
-
},
|
|
142
|
-
numPaths,
|
|
143
|
-
peerKadId,
|
|
144
|
-
signal
|
|
145
|
-
})) {
|
|
146
|
-
// if there are closer peers and the query has not completed, continue the query
|
|
147
|
-
if (event.name === 'PEER_RESPONSE') {
|
|
148
|
-
for (const closerPeer of event.closer) {
|
|
149
|
-
if (peersSeen.has(closerPeer.id.toMultihash().bytes)) { // eslint-disable-line max-depth
|
|
150
|
-
log('already seen %p in query', closerPeer.id)
|
|
151
|
-
continue
|
|
152
|
-
}
|
|
114
|
+
try {
|
|
115
|
+
// perform lookups on kadId, not the actual value
|
|
116
|
+
const kadId = await convertBuffer(key, {
|
|
117
|
+
signal
|
|
118
|
+
})
|
|
153
119
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Adds the passed peer to the query queue if it's not us and no other path
|
|
122
|
+
* has passed through this peer
|
|
123
|
+
*/
|
|
124
|
+
function queryPeer (peer: PeerInfo, peerKadId: Uint8Array): void {
|
|
125
|
+
if (peer == null) {
|
|
126
|
+
return
|
|
127
|
+
}
|
|
158
128
|
|
|
159
|
-
|
|
160
|
-
log('not querying undialable peer')
|
|
161
|
-
continue
|
|
162
|
-
}
|
|
129
|
+
peersSeen.add(peer.id.toMultihash().bytes)
|
|
163
130
|
|
|
164
|
-
|
|
165
|
-
signal
|
|
166
|
-
})
|
|
167
|
-
const closerPeerXor = uint8ArrayXor(closerPeerKadId, kadId)
|
|
131
|
+
const peerXor = uint8ArrayXor(peerKadId, kadId)
|
|
168
132
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
133
|
+
queue.add(async () => {
|
|
134
|
+
try {
|
|
135
|
+
for await (const event of query({
|
|
136
|
+
...options,
|
|
137
|
+
key,
|
|
138
|
+
peer,
|
|
139
|
+
path: {
|
|
140
|
+
index: path,
|
|
141
|
+
queued: queue.queued,
|
|
142
|
+
running: queue.running,
|
|
143
|
+
total: queue.size
|
|
144
|
+
},
|
|
145
|
+
numPaths,
|
|
146
|
+
peerKadId,
|
|
147
|
+
signal
|
|
148
|
+
})) {
|
|
149
|
+
// if there are closer peers and the query has not completed, continue the query
|
|
150
|
+
if (event.name === 'PEER_RESPONSE') {
|
|
151
|
+
for (const closerPeer of event.closer) {
|
|
152
|
+
if (peersSeen.has(closerPeer.id.toMultihash().bytes)) { // eslint-disable-line max-depth
|
|
153
|
+
log('already seen %p in query', closerPeer.id)
|
|
154
|
+
continue
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (ourPeerId.equals(closerPeer.id)) { // eslint-disable-line max-depth
|
|
158
|
+
log('not querying ourselves')
|
|
159
|
+
continue
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (!(await connectionManager.isDialable(closerPeer.multiaddrs))) { // eslint-disable-line max-depth
|
|
163
|
+
log('not querying undialable peer')
|
|
164
|
+
continue
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const closerPeerKadId = await convertPeerId(closerPeer.id, {
|
|
168
|
+
signal
|
|
169
|
+
})
|
|
170
|
+
const closerPeerXor = uint8ArrayXor(closerPeerKadId, kadId)
|
|
171
|
+
|
|
172
|
+
// only continue query if closer peer is actually closer
|
|
173
|
+
if (uint8ArrayXorCompare(closerPeerXor, peerXor) !== -1) { // eslint-disable-line max-depth
|
|
174
|
+
log('skipping %p as they are not closer to %b than %p', closerPeer.id, key, peer)
|
|
175
|
+
continue
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
log('querying closer peer %p', closerPeer.id)
|
|
179
|
+
queryPeer(closerPeer, closerPeerKadId)
|
|
173
180
|
}
|
|
174
|
-
|
|
175
|
-
log('querying closer peer %p', closerPeer.id)
|
|
176
|
-
queryPeer(closerPeer, closerPeerKadId)
|
|
177
181
|
}
|
|
178
|
-
}
|
|
179
182
|
|
|
180
|
-
|
|
181
|
-
|
|
183
|
+
events.push({
|
|
184
|
+
...event,
|
|
185
|
+
path: {
|
|
186
|
+
index: path,
|
|
187
|
+
queued: queue.queued,
|
|
188
|
+
running: queue.running,
|
|
189
|
+
total: queue.size
|
|
190
|
+
}
|
|
191
|
+
})
|
|
192
|
+
}
|
|
193
|
+
} catch (err: any) {
|
|
194
|
+
// yield error event if query is continuing
|
|
195
|
+
events.push(queryErrorEvent({
|
|
196
|
+
from: peer.id,
|
|
197
|
+
error: err,
|
|
182
198
|
path: {
|
|
183
199
|
index: path,
|
|
184
200
|
queued: queue.queued,
|
|
185
|
-
running: queue.running,
|
|
186
|
-
total: queue.size
|
|
201
|
+
running: queue.running - 1,
|
|
202
|
+
total: queue.size - 1
|
|
187
203
|
}
|
|
188
|
-
})
|
|
204
|
+
}, options))
|
|
189
205
|
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
index: path,
|
|
197
|
-
queued: queue.queued,
|
|
198
|
-
running: queue.running - 1,
|
|
199
|
-
total: queue.size - 1
|
|
200
|
-
}
|
|
201
|
-
}, options))
|
|
202
|
-
}
|
|
203
|
-
}, {
|
|
204
|
-
distance: peerXor
|
|
205
|
-
}).catch(err => {
|
|
206
|
-
log.error('error during query - %e', err)
|
|
207
|
-
})
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// begin the query with the starting peers
|
|
211
|
-
await Promise.all(
|
|
212
|
-
startingPeers.map(async startingPeer => {
|
|
213
|
-
queryPeer({ id: startingPeer, multiaddrs: [] }, await convertPeerId(startingPeer, {
|
|
214
|
-
signal
|
|
215
|
-
}))
|
|
216
|
-
})
|
|
217
|
-
)
|
|
206
|
+
}, {
|
|
207
|
+
distance: peerXor
|
|
208
|
+
}).catch(err => {
|
|
209
|
+
log.error('error during query - %e', err)
|
|
210
|
+
})
|
|
211
|
+
}
|
|
218
212
|
|
|
219
|
-
|
|
220
|
-
|
|
213
|
+
// begin the query with the starting peers
|
|
214
|
+
await Promise.all(
|
|
215
|
+
startingPeers.map(async startingPeer => {
|
|
216
|
+
queryPeer({ id: startingPeer, multiaddrs: [] }, await convertPeerId(startingPeer, {
|
|
217
|
+
signal
|
|
218
|
+
}))
|
|
219
|
+
})
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
// yield results as they come in
|
|
223
|
+
yield * events
|
|
224
|
+
} finally {
|
|
225
|
+
signal.removeEventListener('abort', onAbort)
|
|
226
|
+
}
|
|
221
227
|
}
|