Bug fixes

minor bug fixes
This commit is contained in:
sairajzero 2020-09-20 13:11:07 +05:30
parent 4e9af8060a
commit 65f16fa14b

View File

@ -22,7 +22,7 @@
fee: 0.0005, fee: 0.0005,
//Required for Supernode operations //Required for Supernode operations
SNStorageID: "FEzk75EGMPEQMrCuPosGiwuK162hcEu49E", SNStorageID: "FR876VRTna3DremwQKZ421xPGMTREzctRB",
supernodes: {}, //each supnernode must be stored as floID : {uri:<uri>,pubKey:<publicKey>} supernodes: {}, //each supnernode must be stored as floID : {uri:<uri>,pubKey:<publicKey>}
//for cloud apps //for cloud apps
@ -7915,7 +7915,7 @@ Bitcoin.Util = {
closestOf: function (floID, n, KB) { closestOf: function (floID, n, KB) {
let decodedId = this.decodeID(floID); let decodedId = this.decodeID(floID);
return KB.closest(flo_addr, n) return KB.closest(decodedId, n)
}, },
constructKB: function (list, refID) { constructKB: function (list, refID) {
@ -7940,8 +7940,6 @@ Bitcoin.Util = {
]) ])
.sort((a, b) => a[0] - b[0]) .sort((a, b) => a[0] - b[0])
.map(a => a[1]) .map(a => a[1])
console.log(this.SNCO)
console.log(this.SNKB)
resolve('Supernode KBucket formed'); resolve('Supernode KBucket formed');
} catch (error) { } catch (error) {
reject(error); reject(error);
@ -7973,10 +7971,10 @@ Bitcoin.Util = {
return oNodes return oNodes
}, },
prevNode: function (id, n = 1) { prevNode: function (id, N = 1) {
let n = N || this.SNCO.length;
if (!this.SNCO.includes(id)) if (!this.SNCO.includes(id))
throw Error('Given node is not supernode'); throw Error('Given node is not supernode');
if (!n) n = this.SNCO.length;
let pNodes = [] let pNodes = []
for (let i = 0, j = this.SNCO.indexOf(id) - 1; i < n; j--) { for (let i = 0, j = this.SNCO.indexOf(id) - 1; i < n; j--) {
if (j == this.SNCO.indexOf(id)) if (j == this.SNCO.indexOf(id))
@ -7985,10 +7983,11 @@ Bitcoin.Util = {
pNodes[i++] = this.SNCO[j] pNodes[i++] = this.SNCO[j]
else j = this.SNCO.length else j = this.SNCO.length
} }
return (n == 1 ? pNodes[0] : pNodes) return (N == 1 ? pNodes[0] : pNodes)
}, },
nextNode: function (id, n = 1) { nextNode: function (id, N = 1) {
let n = N || this.SNCO.length;
if (!this.SNCO.includes(id)) if (!this.SNCO.includes(id))
throw Error('Given node is not supernode'); throw Error('Given node is not supernode');
if (!n) n = this.SNCO.length; if (!n) n = this.SNCO.length;
@ -8000,12 +7999,15 @@ Bitcoin.Util = {
nNodes[i++] = this.SNCO[j] nNodes[i++] = this.SNCO[j]
else j = -1 else j = -1
} }
return (n == 1 ? nNodes[0] : nNodes) return (N == 1 ? nNodes[0] : nNodes)
}, },
closestNode: function (id, n = 1) { closestNode: function (id, N = 1) {
let cNodes = this.util.closestOf(id, n).map(k => k.floID) let decodedId = this.util.decodeID(id);
return (n == 1 ? cNodes[0] : cNodes) let n = N || this.SNCO.length;
let cNodes = this.SNKB.closest(decodedId, n)
.map(k => k.floID)
return (N == 1 ? cNodes[0] : cNodes)
} }
}, },
@ -8055,7 +8057,7 @@ Bitcoin.Util = {
let data = JSON.parse(evt.data.substring(42)) let data = JSON.parse(evt.data.substring(42))
resolve(data) resolve(data)
} catch (error) { } catch (error) {
reject(error) reject(evt.data.substring(42))
} finally { } finally {
node.close() node.close()
} }
@ -8065,9 +8067,9 @@ Bitcoin.Util = {
}); });
}, },
liveRequest: function (floID, request, callback) { liveRequest: function (floID, datareq, callback) {
request = { request = {
...request ...datareq.request
}; };
const checkFilter = (v, d, r) => const checkFilter = (v, d, r) =>
(!r.atVectorClock || r.atVectorClock == v) && (!r.atVectorClock || r.atVectorClock == v) &&
@ -8081,7 +8083,7 @@ Bitcoin.Util = {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.connectActive(floID).then(node => { this.connectActive(floID).then(node => {
let randID = floCrypto.randString(5); let randID = floCrypto.randString(5);
node.send(`${floID}|${randID}:${JSON.stringify({request})}`); node.send(`${floID}|${randID}:${JSON.stringify(datareq)}`);
node.onmessage = (evt) => { node.onmessage = (evt) => {
if (evt.data.startsWith(randID, 1)) if (evt.data.startsWith(randID, 1))
var i = 42 var i = 42
@ -8115,7 +8117,7 @@ Bitcoin.Util = {
}, },
filterKey: function (type, options) { filterKey: function (type, options) {
return type + (comment ? ':' + comment : '') + return type + (options.comment ? ':' + options.comment : '') +
'|' + (options.receiverID || floGlobals.adminID) + '|' + (options.receiverID || floGlobals.adminID) +
'|' + (options.application || floGlobals.application); '|' + (options.application || floGlobals.application);
}, },
@ -8212,19 +8214,21 @@ Bitcoin.Util = {
atVectorClock: options.atVectorClock || undefined, atVectorClock: options.atVectorClock || undefined,
mostRecent: options.mostRecent || undefined, mostRecent: options.mostRecent || undefined,
} }
var datareq = {
time: Date.now(),
request
}
if (options.callback instanceof Function) { if (options.callback instanceof Function) {
let callback = (d, e) => { let callback = (d, e) => {
for (let v in d) for (let v in d)
d[v].message = this.util.decodeMessage(d[v].message) d[v].message = this.util.decodeMessage(d[v].message)
options.callback(d, e) options.callback(d, e)
} }
this.util.liveRequest(request.receiverID, request, callback) this.util.liveRequest(request.receiverID, datareq, callback)
.then(result => resolve(result)) .then(result => resolve(result))
.catch(error => reject(error)) .catch(error => reject(error))
} else { } else {
this.util.singleRequest(request.receiverID, { this.util.singleRequest(request.receiverID, datareq).then(data => {
request
}).then(data => {
for (let v in data) for (let v in data)
data[v].message = this.util.decodeMessage(data[v].message) data[v].message = this.util.decodeMessage(data[v].message)
resolve(data) resolve(data)
@ -8248,8 +8252,8 @@ Bitcoin.Util = {
this.util.singleRequest(delreq.requestorID, delreq).then(result => { this.util.singleRequest(delreq.requestorID, delreq).then(result => {
let success = [], let success = [],
failed = []; failed = [];
for (let i in result) result.forEach(r => r.status === 'fulfilled' ?
(result[i] ? success : failed).push(delreq.delete[i]) success.push(r.value): failed.push(r.reason));
resolve({ resolve({
success, success,
failed failed