Update cloud.js
1. Fixing the leading 00 byte routing problem by removing bigInteger step in decodeID 2. Optimization of decodeID while building buckets
This commit is contained in:
parent
36d15bd7f8
commit
0a7927d5ca
20
src/cloud.js
20
src/cloud.js
@ -3,18 +3,15 @@
|
|||||||
function K_Bucket(masterID, nodeList) {
|
function K_Bucket(masterID, nodeList) {
|
||||||
|
|
||||||
const decodeID = function (floID) {
|
const decodeID = function (floID) {
|
||||||
if (floID.startsWith("0x") || floID.length === '40')
|
if (floID.startsWith("0x") || floID.length === 40)
|
||||||
floID = proxyID(floID);
|
floID = proxyID(floID);
|
||||||
let k = bitjs.Base58.decode(floID);
|
const bytes = bitjs.Base58.decode(floID);
|
||||||
k.shift();
|
bytes.shift();
|
||||||
k.splice(-4, 4);
|
bytes.splice(-4, 4);
|
||||||
const decodedId = Crypto.util.bytesToHex(k);
|
return new Uint8Array(bytes);
|
||||||
const nodeIdBigInt = new BigInteger(decodedId, 16);
|
|
||||||
const nodeIdBytes = nodeIdBigInt.toByteArrayUnsigned();
|
|
||||||
const nodeIdNewInt8Array = new Uint8Array(nodeIdBytes);
|
|
||||||
return nodeIdNewInt8Array;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const _KB = new BuildKBucket({
|
const _KB = new BuildKBucket({
|
||||||
localNodeId: decodeID(masterID)
|
localNodeId: decodeID(masterID)
|
||||||
});
|
});
|
||||||
@ -22,10 +19,13 @@ function K_Bucket(masterID, nodeList) {
|
|||||||
id: decodeID(id),
|
id: decodeID(id),
|
||||||
floID: id
|
floID: id
|
||||||
}));
|
}));
|
||||||
const _CO = nodeList.map(sn => [_KB.distance(decodeID(masterID), decodeID(sn)), sn])
|
const localId = _KB.localNodeId;
|
||||||
|
const _CO = nodeList
|
||||||
|
.map(sn => [_KB.distance(localId, decodeID(sn)), sn])
|
||||||
.sort((a, b) => a[0] - b[0])
|
.sort((a, b) => a[0] - b[0])
|
||||||
.map(a => a[1]);
|
.map(a => a[1]);
|
||||||
|
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
Object.defineProperty(self, 'order', {
|
Object.defineProperty(self, 'order', {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user