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) {
|
||||
|
||||
const decodeID = function (floID) {
|
||||
if (floID.startsWith("0x") || floID.length === '40')
|
||||
if (floID.startsWith("0x") || floID.length === 40)
|
||||
floID = proxyID(floID);
|
||||
let k = bitjs.Base58.decode(floID);
|
||||
k.shift();
|
||||
k.splice(-4, 4);
|
||||
const decodedId = Crypto.util.bytesToHex(k);
|
||||
const nodeIdBigInt = new BigInteger(decodedId, 16);
|
||||
const nodeIdBytes = nodeIdBigInt.toByteArrayUnsigned();
|
||||
const nodeIdNewInt8Array = new Uint8Array(nodeIdBytes);
|
||||
return nodeIdNewInt8Array;
|
||||
const bytes = bitjs.Base58.decode(floID);
|
||||
bytes.shift();
|
||||
bytes.splice(-4, 4);
|
||||
return new Uint8Array(bytes);
|
||||
};
|
||||
|
||||
|
||||
const _KB = new BuildKBucket({
|
||||
localNodeId: decodeID(masterID)
|
||||
});
|
||||
@ -22,10 +19,13 @@ function K_Bucket(masterID, nodeList) {
|
||||
id: decodeID(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])
|
||||
.map(a => a[1]);
|
||||
|
||||
|
||||
const self = this;
|
||||
|
||||
Object.defineProperty(self, 'order', {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user