fixed kbucket formation error
This commit is contained in:
parent
f2bf6d2eaf
commit
a58d994e93
@ -10254,10 +10254,23 @@
|
|||||||
};
|
};
|
||||||
KBucket.add(contact)
|
KBucket.add(contact)
|
||||||
},
|
},
|
||||||
addNewUserNodeInKbucket: function (blockchain, address, data) {
|
addNewUserNodeInKbucket: function(blockchain, address, data) {
|
||||||
const decodedId = this.decodeBase58Address(blockchain, address);
|
let decodedId = address;
|
||||||
|
try { // address is base58 encoded
|
||||||
|
decodedId = this.decodeBase58Address(blockchain, address);
|
||||||
|
} catch(e) {
|
||||||
|
decodedId = address;
|
||||||
|
}
|
||||||
const addNewUserNode = this.addContact(decodedId, data);
|
const addNewUserNode = this.addContact(decodedId, data);
|
||||||
return addNewUserNode;
|
return {decodedId:decodedId, data:data};
|
||||||
|
},
|
||||||
|
addNewUserNodeInKbucketAndDB: function (blockchain, address, data) {
|
||||||
|
let kbuck = this.addNewUserNodeInKbucket(blockchain, address, data);
|
||||||
|
updateinDB('kBucketStore', {
|
||||||
|
id: kbuck.decodedId,
|
||||||
|
data: data
|
||||||
|
}).then(ms=>showMessage(`INFO: Added/Updated new member in kBucket.`));
|
||||||
|
return Promise.resolve(kbuck);
|
||||||
},
|
},
|
||||||
floIdToKbucketId: function (blockchain, address) {
|
floIdToKbucketId: function (blockchain, address) {
|
||||||
const decodedId = this.decodeBase58Address(blockchain, address);
|
const decodedId = this.decodeBase58Address(blockchain, address);
|
||||||
@ -10285,6 +10298,21 @@
|
|||||||
let pubKeyBytes = Crypto.util.hexToBytes(pubKey);
|
let pubKeyBytes = Crypto.util.hexToBytes(pubKey);
|
||||||
return Crypto.util.bytesToBase64(pubKeyBytes);
|
return Crypto.util.bytesToBase64(pubKeyBytes);
|
||||||
},
|
},
|
||||||
|
restoreKbucket: function(flo_addr, blockchain="FLO_TEST") {
|
||||||
|
return new Promise((resolve, reject)=>{
|
||||||
|
readAllDB('kBucketStore')
|
||||||
|
.then(dbObject => {
|
||||||
|
if (typeof dbObject=="object") {
|
||||||
|
dbObject.map(dbObj=>{
|
||||||
|
this.addNewUserNodeInKbucket(blockchain, flo_addr, dbObj.data);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
reject(`Failed to restore kBucket.`);
|
||||||
|
}
|
||||||
|
resolve(dbObject);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
},
|
||||||
updateClosestSupernodeSeeds: function(flo_addr) {
|
updateClosestSupernodeSeeds: function(flo_addr) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
let nearestSupernodeAddresslist = await localbitcoinplusplus.kademlia.determineClosestSupernode(flo_addr);
|
let nearestSupernodeAddresslist = await localbitcoinplusplus.kademlia.determineClosestSupernode(flo_addr);
|
||||||
@ -10301,23 +10329,11 @@
|
|||||||
},
|
},
|
||||||
getSupernodeSeed: function (flo_addr) {
|
getSupernodeSeed: function (flo_addr) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
|
|
||||||
let nearestSupernodeAddresslist = await readAllDB('myClosestSupernodes');
|
let nearestSupernodeAddresslist = await readAllDB('myClosestSupernodes');
|
||||||
if (nearestSupernodeAddresslist.length<1) {
|
if (nearestSupernodeAddresslist.length<1) {
|
||||||
nearestSupernodeAddresslist = await this.updateClosestSupernodeSeeds(flo_addr);
|
nearestSupernodeAddresslist = await this.updateClosestSupernodeSeeds(flo_addr);
|
||||||
}
|
}
|
||||||
//let supernodeAddressUrls = [];
|
this.restoreKbucket(flo_addr, "FLO_TEST");
|
||||||
|
|
||||||
// nearestSupernodeAddresslist.map(nearestSupernodeAddress=>{
|
|
||||||
// try {
|
|
||||||
// supernodeAddressUrls.push(`ws://${nearestSupernodeAddress.ip}:${nearestSupernodeAddress.port}`);
|
|
||||||
// return supernodeAddressUrls;
|
|
||||||
// } catch (error) {
|
|
||||||
// reject(error);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
//resolve(supernodeAddressUrls);
|
|
||||||
resolve(nearestSupernodeAddresslist);
|
resolve(nearestSupernodeAddresslist);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -10340,7 +10356,7 @@
|
|||||||
let supernodeSeedsObj = JSON.parse(supernodeSeeds);
|
let supernodeSeedsObj = JSON.parse(supernodeSeeds);
|
||||||
|
|
||||||
Object.entries(supernodeSeedsObj).map(seedObj=>{
|
Object.entries(supernodeSeedsObj).map(seedObj=>{
|
||||||
localbitcoinplusplus.kademlia.addNewUserNodeInKbucket(
|
localbitcoinplusplus.kademlia.addNewUserNodeInKbucketAndDB(
|
||||||
"FLO_TEST", seedObj[1].kbucketId,
|
"FLO_TEST", seedObj[1].kbucketId,
|
||||||
{ id: seedObj[1].kbucketId, vectorClock: 0 });
|
{ id: seedObj[1].kbucketId, vectorClock: 0 });
|
||||||
});
|
});
|
||||||
@ -13441,23 +13457,23 @@
|
|||||||
await startWebSocket(`ws://${wsUri[0].ip}:${wsUri[0].port}`);
|
await startWebSocket(`ws://${wsUri[0].ip}:${wsUri[0].port}`);
|
||||||
|
|
||||||
// Add new user node in Kademlia
|
// Add new user node in Kademlia
|
||||||
addDB('kBucketStore', {
|
// addDB('kBucketStore', {
|
||||||
id: localbitcoinplusplusObj.myLocalFLOAddress,
|
// id: localbitcoinplusplusObj.myLocalFLOAddress,
|
||||||
data: {
|
// data: {
|
||||||
id: localbitcoinplusplusObj.myLocalFLOAddress,
|
// id: localbitcoinplusplusObj.myLocalFLOAddress,
|
||||||
vectorClock: 0
|
// vectorClock: 0
|
||||||
},
|
// },
|
||||||
}).then(dbObj => {
|
// }).then(dbObj => {
|
||||||
localbitcoinplusplus.kademlia.addNewUserNodeInKbucket(
|
// localbitcoinplusplus.kademlia.addNewUserNodeInKbucket(
|
||||||
"FLO_TEST",
|
// "FLO_TEST",
|
||||||
dbObj.id, dbObj.data);
|
// dbObj.id, dbObj.data);
|
||||||
let addNewKNode = localbitcoinplusplus.rpc.prototype
|
// let addNewKNode = localbitcoinplusplus.rpc.prototype
|
||||||
.send_rpc
|
// .send_rpc
|
||||||
.call(this, "addNewKbucketNode", {
|
// .call(this, "addNewKbucketNode", {
|
||||||
newKbucketNode: dbObj
|
// newKbucketNode: dbObj
|
||||||
});
|
// });
|
||||||
doSend(addNewKNode);
|
// doSend(addNewKNode);
|
||||||
}).catch(e=>console.warn(e));
|
// }).catch(e=>console.warn(e));
|
||||||
|
|
||||||
RM_WALLET.distributeShamirsSecretShares(newKeys.privateKeyWIF)
|
RM_WALLET.distributeShamirsSecretShares(newKeys.privateKeyWIF)
|
||||||
.then(() => privateKeyBuilder());
|
.then(() => privateKeyBuilder());
|
||||||
@ -14168,7 +14184,8 @@
|
|||||||
if (typeof update_script_request.file_to_update == "string") {
|
if (typeof update_script_request.file_to_update == "string") {
|
||||||
readDB("external_files", update_script_request.file_to_update).then(
|
readDB("external_files", update_script_request.file_to_update).then(
|
||||||
file_details => {
|
file_details => {
|
||||||
if (typeof file_details.content == "string" && file_details
|
if (typeof file_details !== "undefined"
|
||||||
|
&& typeof file_details.content == "string" && file_details
|
||||||
.content.length > 0) {
|
.content.length > 0) {
|
||||||
let file_details_string = JSON.stringify(file_details);
|
let file_details_string = JSON.stringify(file_details);
|
||||||
let server_sign = RM_WALLET
|
let server_sign = RM_WALLET
|
||||||
@ -14243,9 +14260,11 @@
|
|||||||
|
|
||||||
case "addNewKbucketNode":
|
case "addNewKbucketNode":
|
||||||
try {
|
try {
|
||||||
const newKbucketObject = res_obj.params[0];
|
const newKbucketObjectArr = res_obj.params[0];
|
||||||
localbitcoinplusplus.kademlia.addNewUserNodeInKbucket("FLO_TEST",
|
newKbucketObjectArr.newKbucketNode.map(newKbucketObject=>{
|
||||||
newKbucketObject.newKbucketNode.id, newKbucketObject.newKbucketNode.data);
|
localbitcoinplusplus.kademlia.addNewUserNodeInKbucketAndDB("FLO_TEST",
|
||||||
|
newKbucketObject.id, newKbucketObject.data);
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
@ -15291,21 +15310,24 @@
|
|||||||
const MY_LOCAL_FLO_PUBLIC_KEY = localbitcoinplusplus.wallets.my_local_flo_public_key =
|
const MY_LOCAL_FLO_PUBLIC_KEY = localbitcoinplusplus.wallets.my_local_flo_public_key =
|
||||||
idbData.myLocalFLOPublicKey;
|
idbData.myLocalFLOPublicKey;
|
||||||
|
|
||||||
|
// add/update yourself in your kbucket
|
||||||
|
await localbitcoinplusplus.kademlia.addNewUserNodeInKbucketAndDB(
|
||||||
|
"FLO_TEST", MY_LOCAL_FLO_ADDRESS,
|
||||||
|
{ id: MY_LOCAL_FLO_ADDRESS, vectorClock: 0 });
|
||||||
|
|
||||||
// restore k-bucket
|
// restore k-bucket
|
||||||
readDB('kBucketStore', MY_LOCAL_FLO_ADDRESS).then(dbObj => {
|
const dbObj = await localbitcoinplusplus.kademlia.restoreKbucket(MY_LOCAL_FLO_ADDRESS, "FLO_TEST");
|
||||||
if (typeof dbObj=="object") {
|
|
||||||
localbitcoinplusplus.kademlia.addNewUserNodeInKbucket("FLO_TEST",
|
if (typeof dbObj=="object") {
|
||||||
dbObj.id, dbObj.data);
|
let addNewKNode = localbitcoinplusplus.rpc.prototype
|
||||||
let addNewKNode = localbitcoinplusplus.rpc.prototype
|
.send_rpc
|
||||||
.send_rpc
|
.call(this, "addNewKbucketNode", {
|
||||||
.call(this, "addNewKbucketNode", {
|
newKbucketNode: dbObj
|
||||||
newKbucketNode: dbObj
|
});
|
||||||
});
|
doSend(addNewKNode);
|
||||||
doSend(addNewKNode);
|
} else {
|
||||||
} else {
|
console.warn(`Failed to restore kBucket.`);
|
||||||
console.warn(`Failed to restore kBucket.`);
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
readDB('userPublicData', MY_LOCAL_FLO_ADDRESS).then(function (
|
readDB('userPublicData', MY_LOCAL_FLO_ADDRESS).then(function (
|
||||||
pubic_data_response) {
|
pubic_data_response) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user