Commit 0ed0158d authored by Cédric Moreau's avatar Cédric Moreau

Add compute-distances command

parent b57929be
......@@ -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;
......@@ -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
**/
......
......@@ -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 = "";
......
......@@ -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([
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment