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