*Update dist
This commit is contained in:
parent
a7a3ac1d03
commit
eb57f87eb4
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"DHTDataBase.d.ts","sourceRoot":"","sources":["../src/DHTDataBase.ts"],"names":[],"mappings":";;AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAiBlC,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,YAAY;IACnD,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;IACrB,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,KAAK,CAAM;IACnB,OAAO,CAAC,WAAW,CAAW;gBAElB,EAAE,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,GAAE;QAAE,KAAK,CAAC,EAAE,GAAG,CAAA;KAAO;IAavD,OAAO,CAAC,KAAK,CAAK;IAElB,IAAI,IAAI,IAAI,EAAE,CAEb;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,EAAE,EAcjB;IAED,OAAO,CAAC,OAAO,CAAW;IAE1B,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAED,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM;IAIjC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;IAI9B,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM;IAI/C,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;IAG/B,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;IAIpC,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;IAIpC,SAAS,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM;IAqC9B,SAAS,CAAC,YAAY,CAAC,EAAE,EAAE,MAAM;IAiBjC,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAqDpD,OAAO,CAAC,cAAc;IAmBtB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E,EAAE,MAAM;IAqC9B,SAAS,CAAC,YAAY,CAAC,EAAE,EAAE,MAAM;IAiBjC,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IA2DpD,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,QAAQ;IAahB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,qBAAqB;IAa7B,OAAO,CAAC,cAAc;IAgDtB,OAAO,CAAC,iBAAiB;IAgBzB,OAAO,CAAC,YAAY;IAwBpB,OAAO,CAAC,YAAY;CAOrB"}
|
|
@ -113,6 +113,10 @@ class DHTDataBase extends events_1.default {
|
||||||
const { data: rawData, timestamp, signature } = decoded;
|
const { data: rawData, timestamp, signature } = decoded;
|
||||||
if (signature &&
|
if (signature &&
|
||||||
hypercore_crypto_1.default.verify(b4a_1.default.from(`${timestamp}${rawData}`), signature, id)) {
|
hypercore_crypto_1.default.verify(b4a_1.default.from(`${timestamp}${rawData}`), signature, id)) {
|
||||||
|
if ((timestamp || 0) <= this.getPeerTimestamp(id)) {
|
||||||
|
(0, debug_1.default)(`Received old data for peer ${id}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const data = rawData ? ordered_json_1.default.parse(rawData) : null;
|
const data = rawData ? ordered_json_1.default.parse(rawData) : null;
|
||||||
this._setPeer(id, data, timestamp, signature);
|
this._setPeer(id, data, timestamp, signature);
|
||||||
this.emit("peer-data", data, id);
|
this.emit("peer-data", data, id);
|
||||||
|
@ -201,17 +205,23 @@ class DHTDataBase extends events_1.default {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (signature &&
|
if (signature &&
|
||||||
hypercore_crypto_1.default.verify(b4a_1.default.from(`${timestamp}${data}`), signature, b4a_1.default.from(id))) {
|
hypercore_crypto_1.default.verify(b4a_1.default.from(`${timestamp}${data}`), signature, b4a_1.default.from(id, "hex"))) {
|
||||||
const parsedData = data ? ordered_json_1.default.parse(data) : null;
|
const parsedData = data ? ordered_json_1.default.parse(data) : null;
|
||||||
let peerData = parsedData || {};
|
let peerData = parsedData || {};
|
||||||
// If we're already tracking them
|
// If we're already tracking them
|
||||||
if (this._hasSeenPeer(id)) {
|
if (this._hasSeenPeer(id)) {
|
||||||
|
// Ensure we don't have old data
|
||||||
|
if ((timestamp || 0) > this.getPeerTimestamp(id)) {
|
||||||
// See what data we already have for them
|
// See what data we already have for them
|
||||||
// Add their existing data to what we got from the bootstrap
|
// Add their existing data to what we got from the bootstrap
|
||||||
const existingPeerData = this.getPeerData(id);
|
const existingPeerData = this.getPeerData(id);
|
||||||
peerData = { ...existingPeerData, ...peerData };
|
peerData = { ...existingPeerData, ...peerData };
|
||||||
this._setPeer(id, peerData, timestamp, signature);
|
this._setPeer(id, peerData, timestamp, signature);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
(0, debug_1.default)(`Received old data for peer ${id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
(0, debug_1.default)(`Invalid signature received for peer ${id}`);
|
(0, debug_1.default)(`Invalid signature received for peer ${id}`);
|
||||||
|
|
Loading…
Reference in New Issue