formation of kbucket from various participating node happenning
This commit is contained in:
parent
c54dfb2322
commit
8352094bf3
@ -9144,8 +9144,8 @@
|
|||||||
const incumbent = node.contacts[index]
|
const incumbent = node.contacts[index]
|
||||||
|
|
||||||
/***************Change made by Abhishek*************/
|
/***************Change made by Abhishek*************/
|
||||||
//const selection = this.arbiter(incumbent, contact)
|
const selection = this.arbiter(incumbent, contact)
|
||||||
const selection = localbitcoinplusplus.kademlia.arbiter(incumbent, contact);
|
//const selection = localbitcoinplusplus.kademlia.arbiter(incumbent, contact);
|
||||||
// if the selection is our old contact and the candidate is some new
|
// if the selection is our old contact and the candidate is some new
|
||||||
// contact, then there is nothing to do
|
// contact, then there is nothing to do
|
||||||
if (selection === incumbent && incumbent !== contact) return
|
if (selection === incumbent && incumbent !== contact) return
|
||||||
@ -34683,9 +34683,9 @@ exports.createContext = Script.createContext = function (context) {
|
|||||||
`tradableAsset1=BTC,FLO,BTC_TEST,FLO_TEST#!#tradableAsset2=INR,USD,BTC,FLO,BTC_TEST,FLO_TEST,
|
`tradableAsset1=BTC,FLO,BTC_TEST,FLO_TEST#!#tradableAsset2=INR,USD,BTC,FLO,BTC_TEST,FLO_TEST,
|
||||||
#!#supernodes=127.0.0.1,212.88.88.2#!#MASTER_NODE=023B9F60692A17FAC805D012C5C8ADA3DD19A980A3C5F0D8A5B3500CC54D6E8B75
|
#!#supernodes=127.0.0.1,212.88.88.2#!#MASTER_NODE=023B9F60692A17FAC805D012C5C8ADA3DD19A980A3C5F0D8A5B3500CC54D6E8B75
|
||||||
#!#MASTER_RECEIVING_ADDRESS=oVRq2nka1GtALQT8pbuLHAGjqAQ7PAo6uy#!#validTradingAmount=10000,50000,100000,#!#btcTradeMargin=5000
|
#!#MASTER_RECEIVING_ADDRESS=oVRq2nka1GtALQT8pbuLHAGjqAQ7PAo6uy#!#validTradingAmount=10000,50000,100000,#!#btcTradeMargin=5000
|
||||||
#!#supernodesPubKeys=021E444E83530F0D6DB1D2121EE0696BAF5775F2BDD0D8F0301C63974816D91929,
|
#!#supernodesPubKeys=02B2D2F40EC5BC9D336BAF14017D629B3A96892D5E86095923A50A734E2364FB34,
|
||||||
#!#externalFiles={"d3js":"58f54395efa8346e8e94d12609770f66b916897e7f4e05f6c98780cffa5c70a3","testjs":"5b10c1e79b9a7f3b2fb94f1d0f4c6219918f7d4bc5e9eee97deac888d248e7e2"},
|
#!#externalFiles={"d3js":"58f54395efa8346e8e94d12609770f66b916897e7f4e05f6c98780cffa5c70a3"},
|
||||||
#!#ShamirsMaxShares=8`;
|
#!#ShamirsMaxShares=8#!#supernodeSeeds={"ranchimall1":{"ip":"167.99.5.116","port":"9002"}}`;
|
||||||
let floAssetsArray = RMAssets.split('#!#');
|
let floAssetsArray = RMAssets.split('#!#');
|
||||||
|
|
||||||
if (floAssetsArray.length > 0 && typeof floAssetsArray[0] !== undefined &&
|
if (floAssetsArray.length > 0 && typeof floAssetsArray[0] !== undefined &&
|
||||||
@ -34864,7 +34864,16 @@ exports.createContext = Script.createContext = function (context) {
|
|||||||
|
|
||||||
return merged;
|
return merged;
|
||||||
},
|
},
|
||||||
|
newBase64DiscoverId: function(pubKey) {
|
||||||
|
let pubKeyBytes = Crypto.util.hexToBytes(pubKey);
|
||||||
|
return Crypto.util.bytesToBase64(pubKeyBytes);
|
||||||
|
},
|
||||||
|
getSupernodeSeed: function() {
|
||||||
|
const su_seeds = localbitcoinplusplus.master_configurations.supernodeSeeds;
|
||||||
|
const su_seeds_obj = JSON.parse(su_seeds);
|
||||||
|
const su_addr = `ws://${su_seeds_obj.ranchimall1.ip}:${su_seeds_obj.ranchimall1.port}/`;
|
||||||
|
return su_addr;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -37089,18 +37098,17 @@ exports.createContext = Script.createContext = function (context) {
|
|||||||
|
|
||||||
/* Websocket Code Starts here */
|
/* Websocket Code Starts here */
|
||||||
|
|
||||||
//var wsUri = "ws://localhost:9000/";
|
|
||||||
//var wsUri = "ws://ranchimall.duckdns.org:9000/";
|
|
||||||
var wsUri = "ws://ranchimall1.duckdns.org:9002/";
|
|
||||||
//var wsUri = "ws://167.99.5.116:9000/";
|
|
||||||
var output;
|
var output;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
output = document.getElementById("output_div");
|
output = document.getElementById("output_div");
|
||||||
startWebSocket();
|
return new Promise(resolve=>{
|
||||||
|
wsUri = localbitcoinplusplus.kademlia.getSupernodeSeed();
|
||||||
|
resolve(startWebSocket(wsUri));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function startWebSocket() {
|
function startWebSocket(wsUri) {
|
||||||
websocket = new WebSocket(wsUri);
|
websocket = new WebSocket(wsUri);
|
||||||
websocket.onopen = function (evt) {
|
websocket.onopen = function (evt) {
|
||||||
onOpen(evt)
|
onOpen(evt)
|
||||||
@ -37117,7 +37125,9 @@ exports.createContext = Script.createContext = function (context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onOpen(evt) {
|
function onOpen(evt) {
|
||||||
doShreeGanesh();
|
//doShreeGanesh();
|
||||||
|
loadExternalFiles();
|
||||||
|
dataBaseUIOperations();
|
||||||
writeToScreen("CONNECTED");
|
writeToScreen("CONNECTED");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37707,6 +37717,16 @@ exports.createContext = Script.createContext = function (context) {
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "addNewKbucketNode":
|
||||||
|
try {
|
||||||
|
const newKbucketObject = res_obj.params[0];
|
||||||
|
localbitcoinplusplus.kademlia.addNewUserNodeInKbucket("FLO_TEST",
|
||||||
|
newKbucketObject.newKbucketNode.id, newKbucketObject.newKbucketNode.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case "testMessageBroadcasting":
|
case "testMessageBroadcasting":
|
||||||
console.log(res_obj);
|
console.log(res_obj);
|
||||||
try {
|
try {
|
||||||
@ -37750,8 +37770,6 @@ exports.createContext = Script.createContext = function (context) {
|
|||||||
output.appendChild(pre);
|
output.appendChild(pre);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("load", init, false);
|
|
||||||
|
|
||||||
/* Websocket Code Ends Here*/
|
/* Websocket Code Ends Here*/
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -37868,7 +37886,7 @@ exports.createContext = Script.createContext = function (context) {
|
|||||||
|
|
||||||
var db;
|
var db;
|
||||||
const DBName = "localbitcoinDB";
|
const DBName = "localbitcoinDB";
|
||||||
var request = window.indexedDB.open(DBName, 2);
|
var request = window.indexedDB.open(DBName, 1);
|
||||||
|
|
||||||
request.onerror = function (event) {
|
request.onerror = function (event) {
|
||||||
//https://stackoverflow.com/questions/13972385/invalidstateerror-while-opening-indexeddb-in-firefox
|
//https://stackoverflow.com/questions/13972385/invalidstateerror-while-opening-indexeddb-in-firefox
|
||||||
@ -38154,8 +38172,7 @@ exports.createContext = Script.createContext = function (context) {
|
|||||||
const doShreeGanesh = () => {
|
const doShreeGanesh = () => {
|
||||||
try {
|
try {
|
||||||
var rm_configs = localbitcoinplusplus.actions.fetch_configs(async function (...fetch_configs_res) {
|
var rm_configs = localbitcoinplusplus.actions.fetch_configs(async function (...fetch_configs_res) {
|
||||||
await loadExternalFiles();
|
await init();
|
||||||
await dataBaseUIOperations();
|
|
||||||
window.bitjs = []; // Launch bitjs
|
window.bitjs = []; // Launch bitjs
|
||||||
await localbitcoinplusplus.master_configurations.tradableAsset1.map(asset=>bitjslib(asset));
|
await localbitcoinplusplus.master_configurations.tradableAsset1.map(asset=>bitjslib(asset));
|
||||||
});
|
});
|
||||||
@ -38163,6 +38180,7 @@ exports.createContext = Script.createContext = function (context) {
|
|||||||
throw new Error(`Failed to fetch configurations: ${error}`);
|
throw new Error(`Failed to fetch configurations: ${error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
doShreeGanesh();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -38270,10 +38288,16 @@ exports.createContext = Script.createContext = function (context) {
|
|||||||
// Add new user node in Kademlia
|
// Add new user node in Kademlia
|
||||||
addDB('kBucketStore', {
|
addDB('kBucketStore', {
|
||||||
id: localbitcoinplusplusObj.myLocalFLOAddress,
|
id: localbitcoinplusplusObj.myLocalFLOAddress,
|
||||||
data: {"trader_flo_address": localbitcoinplusplusObj.myLocalFLOAddress},
|
data: {id: localbitcoinplusplusObj.myLocalFLOAddress, vectorClock: 0},
|
||||||
}).then(dbObj=>{
|
}).then(dbObj=>{
|
||||||
// localbitcoinplusplus.kademlia.addNewUserNodeInKbucket("FLO_TEST",
|
localbitcoinplusplus.kademlia.addNewUserNodeInKbucket("FLO_TEST",
|
||||||
// dbObj.id, dbObj.data);
|
dbObj.id, dbObj.data);
|
||||||
|
let addNewKNode = localbitcoinplusplus.rpc.prototype
|
||||||
|
.send_rpc
|
||||||
|
.call(this, "addNewKbucketNode",
|
||||||
|
{newKbucketNode:dbObj});
|
||||||
|
console.log(addNewKNode);
|
||||||
|
doSend(addNewKNode);
|
||||||
});
|
});
|
||||||
|
|
||||||
RM_WALLET.distributeShamirsSecretShares(newKeys.privateKeyWIF)
|
RM_WALLET.distributeShamirsSecretShares(newKeys.privateKeyWIF)
|
||||||
@ -38287,6 +38311,17 @@ exports.createContext = Script.createContext = function (context) {
|
|||||||
const MY_LOCAL_FLO_ADDRESS = localbitcoinplusplus.wallets.my_local_flo_address = idbData.myLocalFLOAddress;
|
const MY_LOCAL_FLO_ADDRESS = localbitcoinplusplus.wallets.my_local_flo_address = idbData.myLocalFLOAddress;
|
||||||
const MY_LOCAL_FLO_PUBLIC_KEY = localbitcoinplusplus.wallets.my_local_flo_public_key = idbData.myLocalFLOPublicKey;
|
const MY_LOCAL_FLO_PUBLIC_KEY = localbitcoinplusplus.wallets.my_local_flo_public_key = idbData.myLocalFLOPublicKey;
|
||||||
|
|
||||||
|
// restore k-bucket
|
||||||
|
readDB('kBucketStore', MY_LOCAL_FLO_ADDRESS).then(dbObj=>{
|
||||||
|
localbitcoinplusplus.kademlia.addNewUserNodeInKbucket("FLO_TEST",
|
||||||
|
dbObj.id, dbObj.data);
|
||||||
|
let addNewKNode = localbitcoinplusplus.rpc.prototype
|
||||||
|
.send_rpc
|
||||||
|
.call(this, "addNewKbucketNode",
|
||||||
|
{newKbucketNode:dbObj});
|
||||||
|
doSend(addNewKNode);
|
||||||
|
});
|
||||||
|
|
||||||
readDB('userPublicData', MY_LOCAL_FLO_ADDRESS).then(function(pubic_data_response) {
|
readDB('userPublicData', MY_LOCAL_FLO_ADDRESS).then(function(pubic_data_response) {
|
||||||
if (typeof pubic_data_response !== "object") {
|
if (typeof pubic_data_response !== "object") {
|
||||||
let user_public_data_object = {
|
let user_public_data_object = {
|
||||||
@ -38950,22 +38985,22 @@ exports.createContext = Script.createContext = function (context) {
|
|||||||
const RM_WALLET = new localbitcoinplusplus.wallets;
|
const RM_WALLET = new localbitcoinplusplus.wallets;
|
||||||
for (let index = 0; index < count; index++) {
|
for (let index = 0; index < count; index++) {
|
||||||
let genAddr = RM_WALLET.generateFloKeys();
|
let genAddr = RM_WALLET.generateFloKeys();
|
||||||
let data = {
|
// let data = {
|
||||||
trader_flo_address: genAddr.address,
|
// trader_flo_address: genAddr.address,
|
||||||
crypto_balances: {
|
// crypto_balances: {
|
||||||
crypto_balance: rand(1,100,100),
|
// crypto_balance: rand(1,100,100),
|
||||||
crypto_currency: "FLO_TEST",
|
// crypto_currency: "FLO_TEST",
|
||||||
id: genAddr.address+"_FLO_TEST",
|
// id: genAddr.address+"_FLO_TEST",
|
||||||
trader_flo_address: genAddr.address
|
// trader_flo_address: genAddr.address
|
||||||
},
|
// },
|
||||||
cash_balances: {
|
// cash_balances: {
|
||||||
id: genAddr.address+"_USD",
|
// id: genAddr.address+"_USD",
|
||||||
trader_flo_address: genAddr.address,
|
// trader_flo_address: genAddr.address,
|
||||||
cash_balance: rand(10000, 1000000, 1000000),
|
// cash_balance: rand(10000, 1000000, 1000000),
|
||||||
currency: "USD"
|
// currency: "USD"
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
//let data = {id: rand(10000, 100000000, 100000000)}
|
let data = {id: genAddr.address, vectorClock: 0}
|
||||||
localbitcoinplusplus.kademlia
|
localbitcoinplusplus.kademlia
|
||||||
.addNewUserNodeInKbucket("FLO_TEST", genAddr.address, data);
|
.addNewUserNodeInKbucket("FLO_TEST", genAddr.address, data);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user