diff --git a/app/models/key.js b/app/models/key.js index 4c0bae5fe2fe7152281523b7eeba3be276fff106..814da9dbf0bcfe1a7ea24b1ce7f37bd63c420342 100644 --- a/app/models/key.js +++ b/app/models/key.js @@ -146,4 +146,11 @@ KeySchema.statics.unsetKicked = function(fingerprint, done){ }); }; +KeySchema.statics.undistanceEveryKey = function(done){ + var Key = this.model('Key'); + Key.update({}, { kick: false, distanced: [] }, function (err) { + done(err); + }); +}; + module.exports = KeySchema; diff --git a/app/models/link.js b/app/models/link.js index 174daa474ea90c2dd4e62ba3c01685b5e868bf5f..ba17beb1f577f3498da4d01d9d575557ea4acfbe 100644 --- a/app/models/link.js +++ b/app/models/link.js @@ -30,6 +30,16 @@ LinkSchema.statics.obsoletes = function (minTimestamp, done) { }); } +/** +* Unmark obsolete from all the links +**/ +LinkSchema.statics.unobsoletesAllLinks = function (done) { + var Link = this.model('Link'); + Link.update({}, { obsolete: false }, function (err) { + done(err); + }); +} + /** * Mark as obsolete the links with an age equal to or below a given date **/ diff --git a/app/service/KeychainService.js b/app/service/KeychainService.js index 71fb8a37a4387d9cf401d3bdb661967763240906..08fe9eb827c0101f39fc53d6022fccea18940947 100644 --- a/app/service/KeychainService.js +++ b/app/service/KeychainService.js @@ -1065,6 +1065,25 @@ function KeyService (conn, conf, PublicKeyService) { done(null, block); } + this.computeDistances = function (done) { + var current; + async.waterfall([ + function (next) { + KeyBlock.current(next); + }, + function (currentBlock, next) { + current = currentBlock; + Link.unobsoletesAllLinks(next); + }, + function (next) { + Key.undistanceEveryKey(next); + }, + function (next) { + computeObsoleteLinks(current, next); + } + ], done); + } + this.prove = function (block, sigFunc, nbZeros, done) { var powRegexp = new RegExp('^0{' + nbZeros + '}'); var pow = "", sig = "", raw = ""; diff --git a/bin/ucoind b/bin/ucoind index e2f4166f72e7118e1411af2b5418cd6ed15cf263..6b15fdee6c1228c9f39978534ae4d6d2eccca4ad 100755 --- a/bin/ucoind +++ b/bin/ucoind @@ -303,6 +303,17 @@ program .description('Tries to generate a newcomers (#2+) keyblock, containing only newcomers changes') .action(service(DO_NOT_LISTEN_HTTP, ucoin.createWOTServer, generateAndSend("generateNewcomers"))); +program + .command('compute-distances') + .description('Recompute distance between each member and the whole WoT and mark outdistanced ones as kicked') + .action(service(DO_NOT_LISTEN_HTTP, ucoin.createWOTServer, function (server, conf) { + server.KeychainService.computeDistances(function (err) { + if (err) logger.error(err); + server.disconnect(); + process.exit(); + }); + })); + function generateAndSend (generationMethod) { return function (host, port, difficulty, server, conf) { async.waterfall([