@keymetrics/interdb
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -94,6 +94,7 @@ 'use strict' | ||
// Sha sum | ||
getShaSum () { | ||
getShaSum (data) { | ||
try { | ||
const hash = crypto.createHash('sha256') | ||
hash.update(JSON.stringify(this.db.data)) | ||
hash.update(JSON.stringify(data || this.db.data)) | ||
return hash.digest('hex') | ||
@@ -100,0 +101,0 @@ } catch (error) { |
@@ -31,5 +31,3 @@ 'use strict' | ||
this.clients.once('peer:connected', (identity, socket) => { | ||
this.syncDatabase(socket, () => { | ||
this.emit('synced') | ||
}) | ||
this.syncDatabase() | ||
}) | ||
@@ -48,3 +46,3 @@ }) | ||
this.clients.router(cst.DB_SYNC, (reply) => { | ||
reply(null, this.db.getDatabase()) | ||
reply(null, { db: this.db.getDatabase(), shasum: this.db.getShaSum() }) | ||
}) | ||
@@ -68,3 +66,3 @@ | ||
syncDatabase (socket, cb) { | ||
syncDatabase () { | ||
let lastUpdates = [] | ||
@@ -81,8 +79,9 @@ const peersNumber = this.clients.getPeers().length | ||
}) | ||
if (lastUpdates[0].lastUpdate <= this.db.getLastUpdate()) return cb() | ||
if (lastUpdates[0].lastUpdate <= this.db.getLastUpdate()) return this.emit('synced') | ||
this.clients.send(lastUpdates[0].id, cst.DB_SYNC, (err, res, identity) => { | ||
if (err) return console.log(err) | ||
this.db.updateAll(res, () => { | ||
cb() | ||
if (this.db.getShaSum(res.db.data) !== res.shasum) return this.syncDatabase() | ||
this.db.updateAll(res.db, () => { | ||
this.emit('synced') | ||
}) | ||
@@ -89,0 +88,0 @@ }) |
{ | ||
"name": "@keymetrics/interdb", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Shared and discoverable database services", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55187
7
169