added code for adding user data from handle_backup_request and backup to backup sync
This commit is contained in:
parent
77435c2b2d
commit
6b5565f806
@ -10075,12 +10075,13 @@
|
|||||||
#!#MaxBackups=2
|
#!#MaxBackups=2
|
||||||
#!#supernodesPubKeys=0315C3A20FE7096CC2E0F81A80D5F1A687B8F9EFA65242A0B0881E1BA3EE7D7D53,
|
#!#supernodesPubKeys=0315C3A20FE7096CC2E0F81A80D5F1A687B8F9EFA65242A0B0881E1BA3EE7D7D53,
|
||||||
03F7493F11B8E44B9798CD434D20FBE7FA34B9779D144984889D11A17C56A18742,039B4AA00DBFC0A6631DE6DA83526611A0E6B857D3579DF840BBDEAE8B6898E3B6,
|
03F7493F11B8E44B9798CD434D20FBE7FA34B9779D144984889D11A17C56A18742,039B4AA00DBFC0A6631DE6DA83526611A0E6B857D3579DF840BBDEAE8B6898E3B6,
|
||||||
03C8E3836C9A77E2AF03D4265D034BA85732738919708EAF6A16382195AE796EDF
|
03C8E3836C9A77E2AF03D4265D034BA85732738919708EAF6A16382195AE796EDF,0349B08AA1ABDCFFB6D78CD7C949665AD2FF065EA02B3C6C47A5E9592C9A1C6BCB
|
||||||
#!#externalFiles={"d3js":"58f54395efa8346e8e94d12609770f66b916897e7f4e05f6c98780cffa5c70a3"},
|
#!#externalFiles={"d3js":"58f54395efa8346e8e94d12609770f66b916897e7f4e05f6c98780cffa5c70a3"},
|
||||||
#!#ShamirsMaxShares=8#!#supernodeSeeds={"ranchimall1":{"ip":"127.0.0.1","port":"9001","kbucketId":"oZxHcbSf1JC8t5GjutopWYXs7C6Fe9p7ps"},
|
#!#ShamirsMaxShares=8#!#supernodeSeeds={"ranchimall1":{"ip":"127.0.0.1","port":"9001","kbucketId":"oZxHcbSf1JC8t5GjutopWYXs7C6Fe9p7ps"},
|
||||||
"ranchimall2":{"ip":"127.0.0.1","port":"9002","kbucketId":"oTWjPupy3Z7uMdPcu5uXd521HBkcsLuSuM"},
|
"ranchimall2":{"ip":"127.0.0.1","port":"9002","kbucketId":"oTWjPupy3Z7uMdPcu5uXd521HBkcsLuSuM"},
|
||||||
"ranchimall3":{"ip":"127.0.0.1","port":"9003","kbucketId":"odYA6KagmbokSh9GY7yAfeTUZRtZLwecY1"},
|
"ranchimall3":{"ip":"127.0.0.1","port":"9003","kbucketId":"odYA6KagmbokSh9GY7yAfeTUZRtZLwecY1"},
|
||||||
"ranchimall4":{"ip":"127.0.0.1","port":"9004","kbucketId":"oJosrve9dBv2Hj2bfncxv2oEpTysg3Wejv"}}`;
|
"ranchimall4":{"ip":"127.0.0.1","port":"9004","kbucketId":"oJosrve9dBv2Hj2bfncxv2oEpTysg3Wejv"},
|
||||||
|
"ranchimall5":{"ip":"127.0.0.1","port":"9005","kbucketId":"oMhv5sAzqg77sYHxmUGZWKRrVo4P4JQduS"}}`;
|
||||||
|
|
||||||
// RMAssets =
|
// RMAssets =
|
||||||
// `masterFLOPubKey=029EF7838D4D103E62262394B5417E8ABFD75539D19E61CA5FD0C2051B69B29910
|
// `masterFLOPubKey=029EF7838D4D103E62262394B5417E8ABFD75539D19E61CA5FD0C2051B69B29910
|
||||||
@ -10175,7 +10176,7 @@
|
|||||||
"job": "SYNC_BACKUP_SUPERNODE_DB_WITH_BACKUP_SUPERNODE_DB",
|
"job": "SYNC_BACKUP_SUPERNODE_DB_WITH_BACKUP_SUPERNODE_DB",
|
||||||
"receiver_flo_address": receiver,
|
"receiver_flo_address": receiver,
|
||||||
"requester_flo_id": requester
|
"requester_flo_id": requester
|
||||||
}).then(sync_request=>doSend(sync_request, receiver));
|
}).then(sync_request=>doSend(sync_request, receiver));
|
||||||
},
|
},
|
||||||
|
|
||||||
get_sharable_db_data: async function (dbTableNamesArray, backup_db="") {
|
get_sharable_db_data: async function (dbTableNamesArray, backup_db="") {
|
||||||
@ -15179,19 +15180,19 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Connect with backup supernodes
|
// Connect with backup supernodes
|
||||||
wsUri.filter((uri, index)=>{
|
wsUri.map((uri, index)=>{
|
||||||
if(index>0 && index<=localbitcoinplusplus.master_configurations.MaxBackups
|
if(index>0 && index<=localbitcoinplusplus.master_configurations.MaxBackups
|
||||||
&& localbitcoinplusplus.master_configurations.supernodesPubKeys
|
&& localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||||
.includes(localbitcoinplusplusObj.myLocalFLOPublicKey)) {
|
.includes(idbData.myLocalFLOPublicKey)) {
|
||||||
return uri;
|
backUpSupernodesWS[uri.trader_flo_address] = new backupSupernodesWebSocketObject(`ws://${uri.ip}:${uri.port}`);
|
||||||
|
backUpSupernodesWS[uri.trader_flo_address].connectWS();
|
||||||
|
}
|
||||||
|
if (index>0 && localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||||
|
.includes(idbData.myLocalFLOPublicKey)) {
|
||||||
|
let dbname = `su_backup_${uri.trader_flo_address}`;
|
||||||
|
BACKUP_DB[uri.trader_flo_address] = new newBackupDB(dbname);
|
||||||
|
BACKUP_DB[uri.trader_flo_address].createNewDB();
|
||||||
}
|
}
|
||||||
}).map((uri, index)=>{
|
|
||||||
backUpSupernodesWS[uri.trader_flo_address] = new backupSupernodesWebSocketObject(`ws://${uri.ip}:${uri.port}`);
|
|
||||||
backUpSupernodesWS[uri.trader_flo_address].connectWS();
|
|
||||||
|
|
||||||
let dbname = `su_backup_${uri.trader_flo_address}`;
|
|
||||||
BACKUP_DB[uri.trader_flo_address] = new newBackupDB(dbname);
|
|
||||||
BACKUP_DB[uri.trader_flo_address].createNewDB();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS = wsUri[0].trader_flo_address;
|
localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS = wsUri[0].trader_flo_address;
|
||||||
@ -15257,7 +15258,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update backup db as well for all supernodes you're serving as backup
|
// Update backup db as well for all supernodes you're serving as backup
|
||||||
for (let index = 1; index <= closestSuNodes.length-1; index++) {
|
for (let index = closestSuNodes.length; index > closestSuNodes.length-localbitcoinplusplus.master_configurations.MaxBackups; index--) {
|
||||||
let firstAliveBackupFloIdForBackupSupernode;
|
let firstAliveBackupFloIdForBackupSupernode;
|
||||||
if (closestSuNodes[index].is_live==true && typeof firstAliveBackupFloIdForBackupSupernode !== "string") {
|
if (closestSuNodes[index].is_live==true && typeof firstAliveBackupFloIdForBackupSupernode !== "string") {
|
||||||
firstAliveBackupFloIdForBackupSupernode = closestSuNodes[index].trader_flo_address;
|
firstAliveBackupFloIdForBackupSupernode = closestSuNodes[index].trader_flo_address;
|
||||||
@ -15266,9 +15267,19 @@
|
|||||||
firstAliveBackupFloIdForBackupSupernode, closestSuNodes[index].trader_flo_address);
|
firstAliveBackupFloIdForBackupSupernode, closestSuNodes[index].trader_flo_address);
|
||||||
} else {
|
} else {
|
||||||
// it will ask backup from backup su next closest
|
// it will ask backup from backup su next closest
|
||||||
console.info(`da daa`);
|
for (let j = index; j <= index+localbitcoinplusplus.master_configurations.MaxBackups; j++) {
|
||||||
|
const nextBKSu = closestSuNodes[j].trader_flo_address;
|
||||||
|
if (nextBKSu !== idbData.myLocalFLOAddress
|
||||||
|
&& closestSuNodes[index].is_live==true
|
||||||
|
&& typeof firstAliveBackupFloIdForBackupSupernode !== "string") {
|
||||||
|
localbitcoinplusplus.actions
|
||||||
|
.sync_backup_supernode_from_backup_supernode(closestSuNodes[0].trader_flo_address,
|
||||||
|
firstAliveBackupFloIdForBackupSupernode, closestSuNodes[j].trader_flo_address);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15292,26 +15303,19 @@
|
|||||||
localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS = wsUri[0].trader_flo_address;
|
localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS = wsUri[0].trader_flo_address;
|
||||||
|
|
||||||
// Connect with backup supernodes
|
// Connect with backup supernodes
|
||||||
wsUri.filter((uri, index)=>{
|
wsUri.map((uri, index)=>{
|
||||||
if(index>0 && index<=localbitcoinplusplus.master_configurations.MaxBackups
|
if(index>0 && index<=localbitcoinplusplus.master_configurations.MaxBackups
|
||||||
&& localbitcoinplusplus.master_configurations.supernodesPubKeys
|
&& localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||||
.includes(idbData.myLocalFLOPublicKey)) {
|
.includes(idbData.myLocalFLOPublicKey)) {
|
||||||
return uri;
|
backUpSupernodesWS[uri.trader_flo_address] = new backupSupernodesWebSocketObject(`ws://${uri.ip}:${uri.port}`);
|
||||||
|
backUpSupernodesWS[uri.trader_flo_address].connectWS();
|
||||||
|
}
|
||||||
|
if (index>0 && localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||||
|
.includes(idbData.myLocalFLOPublicKey)) {
|
||||||
|
let dbname = `su_backup_${uri.trader_flo_address}`;
|
||||||
|
BACKUP_DB[uri.trader_flo_address] = new newBackupDB(dbname);
|
||||||
|
BACKUP_DB[uri.trader_flo_address].createNewDB();
|
||||||
}
|
}
|
||||||
}).map((uri, index)=>{
|
|
||||||
console.log(uri);
|
|
||||||
backUpSupernodesWS[uri.trader_flo_address] = new backupSupernodesWebSocketObject(`ws://${uri.ip}:${uri.port}`);
|
|
||||||
backUpSupernodesWS[uri.trader_flo_address].connectWS();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Init backup db for rest supernodes
|
|
||||||
localbitcoinplusplus.master_configurations.supernodesPubKeys
|
|
||||||
.map(p=>bitjs.FLO_TEST.pubkey2address(p))
|
|
||||||
.filter(f=>f!==localbitcoinplusplus.wallets.my_local_flo_address)
|
|
||||||
.map(m=>{
|
|
||||||
let dbname = `su_backup_${m}`;
|
|
||||||
BACKUP_DB[m] = new newBackupDB(dbname);
|
|
||||||
BACKUP_DB[m].createNewDB();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
resolve(true);
|
resolve(true);
|
||||||
@ -15359,7 +15363,6 @@
|
|||||||
reactor.dispatchEvent('backup_supernode_down');
|
reactor.dispatchEvent('backup_supernode_down');
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
this.ws_connection.onmessage = function (evt) {
|
this.ws_connection.onmessage = function (evt) {
|
||||||
//this.handle_backup_server_messages(evt);
|
|
||||||
let response = evt.data;
|
let response = evt.data;
|
||||||
let isRequestToLinkIp = response.search("linkMyLocalIPToMyFloId");
|
let isRequestToLinkIp = response.search("linkMyLocalIPToMyFloId");
|
||||||
let isRequestToLinkOthersIp = response.search("link_Others_Local_IP_To_Their_Flo_Id");
|
let isRequestToLinkOthersIp = response.search("link_Others_Local_IP_To_Their_Flo_Id");
|
||||||
@ -15367,6 +15370,22 @@
|
|||||||
if (isRequestToLinkIp>=0 || isRequestToLinkOthersIp>=0) {
|
if (isRequestToLinkIp>=0 || isRequestToLinkOthersIp>=0) {
|
||||||
handle_backup_server_messages(response);
|
handle_backup_server_messages(response);
|
||||||
}
|
}
|
||||||
|
var res_pos = response.indexOf('{');
|
||||||
|
if (res_pos >= 0) {
|
||||||
|
var res = response.substr(res_pos);
|
||||||
|
let res_obj = JSON.parse(res);
|
||||||
|
if (res_obj.method==="add_user_public_data") {
|
||||||
|
handle_backup_server_messages(response);
|
||||||
|
}
|
||||||
|
if (res_obj.method==="sync_backup_supernode_from_backup_supernode") {
|
||||||
|
// if (localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||||
|
// .includes(localbitcoinplusplus.wallets.my_local_flo_public_key)) {
|
||||||
|
// response_from_sever = RM_RPC.backup_receive_rpc_response.call(this,
|
||||||
|
// JSON.stringify(res_obj));
|
||||||
|
// }
|
||||||
|
onMessage(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
this.ws_connection.onerror = function (evt) {
|
this.ws_connection.onerror = function (evt) {
|
||||||
console.error(evt);
|
console.error(evt);
|
||||||
@ -16154,7 +16173,7 @@
|
|||||||
const RM_RPC = new localbitcoinplusplus.rpc;
|
const RM_RPC = new localbitcoinplusplus.rpc;
|
||||||
RM_RPC
|
RM_RPC
|
||||||
.send_rpc
|
.send_rpc
|
||||||
.call(this, "add_user_public_data", public_req_object)
|
.call(this, "add_user_public_data_inBackup_db", public_req_object)
|
||||||
.then(add_user_public_data_req=>doSend(add_user_public_data_req));
|
.then(add_user_public_data_req=>doSend(add_user_public_data_req));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -17983,7 +18002,10 @@
|
|||||||
|
|
||||||
case "sync_backup_supernode_from_backup_supernode":
|
case "sync_backup_supernode_from_backup_supernode":
|
||||||
if (localbitcoinplusplus.master_configurations.supernodesPubKeys
|
if (localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||||
.includes(localbitcoinplusplus.wallets.my_local_flo_public_key)) {
|
.includes(localbitcoinplusplus.wallets.my_local_flo_public_key)
|
||||||
|
&& typeof res_obj.globalParams.receiverFloId == "string"
|
||||||
|
&& localbitcoinplusplus.wallets.my_local_flo_address == res_obj.globalParams.receiverFloId
|
||||||
|
) {
|
||||||
response_from_sever = RM_RPC.backup_receive_rpc_response.call(this,
|
response_from_sever = RM_RPC.backup_receive_rpc_response.call(this,
|
||||||
JSON.stringify(res_obj));
|
JSON.stringify(res_obj));
|
||||||
}
|
}
|
||||||
@ -18585,9 +18607,55 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "add_user_public_data_inBackup_db":
|
||||||
|
RM_RPC.filter_legit_backup_requests(res_obj.params[0].trader_flo_address,
|
||||||
|
function (is_valid_request) {
|
||||||
|
if (is_valid_request !== true) return false;
|
||||||
|
|
||||||
|
let supernode_flo_public_key = localbitcoinplusplus.wallets.my_local_flo_public_key;
|
||||||
|
|
||||||
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
|
let req_data = res_obj.params[0];
|
||||||
|
try {
|
||||||
|
let flo_address = bitjs.FLO_TEST.pubkey2address(req_data.trader_flo_pubKey);
|
||||||
|
|
||||||
|
if (flo_address == req_data.trader_flo_address && req_data.trader_flo_address
|
||||||
|
.length > 0) {
|
||||||
|
|
||||||
|
let public_req_object = {
|
||||||
|
trader_flo_address: req_data.trader_flo_address,
|
||||||
|
trader_flo_pubKey: req_data.trader_flo_pubKey,
|
||||||
|
supernode_flo_public_key: supernode_flo_public_key,
|
||||||
|
trader_status: 0,
|
||||||
|
timestamp: +new Date()
|
||||||
|
}
|
||||||
|
|
||||||
|
addDB('userPublicData', public_req_object);
|
||||||
|
|
||||||
|
localbitcoinplusplus.kademlia.determineClosestSupernode(req_data.trader_flo_address)
|
||||||
|
.then(my_closest_su_list=>{
|
||||||
|
const primarySupernodeOfThisUser = my_closest_su_list[0].data.id;
|
||||||
|
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[primarySupernodeOfThisUser];
|
||||||
|
|
||||||
|
if(typeof backup_server_db_instance !== "object") {
|
||||||
|
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
||||||
|
showMessage(backup_db_error_msg);
|
||||||
|
throw new Error(backup_db_error_msg);
|
||||||
|
};
|
||||||
|
backup_server_db_instance.backup_addDB('userPublicData', public_req_object);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error('Invalid public key and flo address combination.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
case "send_back_shamirs_secret_btc_pvtkey":
|
case "send_back_shamirs_secret_btc_pvtkey":
|
||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
|
|
||||||
if(typeof res_obj.globalParams.senderFloId !="string") return;
|
if(typeof res_obj.globalParams.senderFloId !="string") return;
|
||||||
localbitcoinplusplus.kademlia.determineClosestSupernode(res_obj.globalParams.senderFloId)
|
localbitcoinplusplus.kademlia.determineClosestSupernode(res_obj.globalParams.senderFloId)
|
||||||
@ -20559,7 +20627,7 @@
|
|||||||
reactor.registerEvent('fireNodeWelcomeBackEvent');
|
reactor.registerEvent('fireNodeWelcomeBackEvent');
|
||||||
reactor.registerEvent('fireNodeGoodByeEvent');
|
reactor.registerEvent('fireNodeGoodByeEvent');
|
||||||
reactor.registerEvent('primarySupernodeUpdatingLatestDataForItsUserFromOtherSupernodes');
|
reactor.registerEvent('primarySupernodeUpdatingLatestDataForItsUserFromOtherSupernodes');
|
||||||
|
|
||||||
reactor.addEventListener('fireNodeWelcomeBackEvent', function(evt) {
|
reactor.addEventListener('fireNodeWelcomeBackEvent', function(evt) {
|
||||||
let getFLOId = bitjs.FLO_TEST.pubkey2address(evt.flo_public_key);
|
let getFLOId = bitjs.FLO_TEST.pubkey2address(evt.flo_public_key);
|
||||||
if(localbitcoinplusplus.master_configurations.supernodesPubKeys
|
if(localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user