Commit 2a30e11b authored by Cédric Moreau's avatar Cédric Moreau

Add minimum link quantity constraint

parent c31a52ac
...@@ -20,6 +20,14 @@ LinkSchema.pre('save', function (next) { ...@@ -20,6 +20,14 @@ LinkSchema.pre('save', function (next) {
LinkSchema.methods = { LinkSchema.methods = {
}; };
/**
* Mark as obsolete the links with an age equal to or below a given date
**/
LinkSchema.statics.currentValidLinks = function (fpr, done) {
var Link = this.model('Link');
Link.find({ target: fpr, obsolete: false }, done);
}
/** /**
* Mark as obsolete the links with an age equal to or below a given date * Mark as obsolete the links with an age equal to or below a given date
**/ **/
......
...@@ -406,6 +406,12 @@ function KeyService (conn, conf, PublicKeyService) { ...@@ -406,6 +406,12 @@ function KeyService (conn, conf, PublicKeyService) {
}); });
async.forEachSeries(newcomers, function (newcomer, newcomerTested) { async.forEachSeries(newcomers, function (newcomer, newcomerTested) {
async.waterfall([ async.waterfall([
function (next) {
if (block.number > 0)
checkHaveEnoughLinks(newcomer, newLinks, next);
else
next();
},
function (next) { function (next) {
// Check the newcomer IS RECOGNIZED BY the WoT + other newcomers // Check the newcomer IS RECOGNIZED BY the WoT + other newcomers
// (check we have a path WoT => newcomer) // (check we have a path WoT => newcomer)
...@@ -454,6 +460,20 @@ function KeyService (conn, conf, PublicKeyService) { ...@@ -454,6 +460,20 @@ function KeyService (conn, conf, PublicKeyService) {
} }
} }
function checkHaveEnoughLinks(target, newLinks, done) {
async.waterfall([
function (next){
Link.currentValidLinks(target, next);
},
function (links, next){
var count = links.length;
if (newLinks[target] && newLinks[target].length)
count += newLinks[target].length;
next(count < LINK_QUANTITY_MIN && 'Key ' + target.substring(24) + ' does not have enough links (' + count + '/' + LINK_QUANTITY_MIN + ')');
},
], done);
}
function checkProofOfWork (block, done) { function checkProofOfWork (block, done) {
var powRegexp = new RegExp('^0{' + MINIMUM_ZERO_START + '}'); var powRegexp = new RegExp('^0{' + MINIMUM_ZERO_START + '}');
if (!block.hash.match(powRegexp)) if (!block.hash.match(powRegexp))
......
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