Commit 8feec8ac authored by Cédric Moreau's avatar Cédric Moreau

Apply minimum links count rule to kick members

parent 81e6fc68
......@@ -143,9 +143,9 @@ KeySchema.statics.removeMember = function(fingerprint, done){
});
};
KeySchema.statics.setKicked = function(fingerprint, distancedKeys, done){
KeySchema.statics.setKicked = function(fingerprint, distancedKeys, notEnoughLinks, done){
var Key = this.model('Key');
Key.update({ fingerprint: fingerprint }, { kick: distancedKeys.length > 0, distanced: distancedKeys }, function (err) {
Key.update({ fingerprint: fingerprint }, { kick: (distancedKeys.length > 0 || notEnoughLinks), distanced: distancedKeys }, function (err) {
done(err);
});
};
......
......@@ -531,18 +531,34 @@ function KeyService (conn, conf, PublicKeyService) {
key.distanced.forEach(function(m){
remainingKeys.push(m);
});
Link.isStillOver3Steps(key.fingerprint, remainingKeys, newLinks, next);
async.parallel({
outdistanced: function(callback){
Link.isStillOver3Steps(key.fingerprint, remainingKeys, newLinks, next);
},
enoughLinks: function(callback){
checkHaveEnoughLinks(key.fingerprint, newLinks, function (err) {
callback(null, err);
});
},
}, next);
},
function (outdistanced, next) {
function (res, next) {
var outdistanced = res.outdistanced;
var enoughLinksErr = res.enoughLinks;
var isStill = outdistanced.length > 0;
if (isStill && membersChanges.indexOf('-' + key.fingerprint) == -1) {
var isBeingKicked = membersChanges.indexOf('-' + key.fingerprint);
if (isStill && isBeingKicked == -1) {
next('Member ' + key.fingerprint + ' has to lose his member status. Wrong block.');
return;
}
if (!isStill && ~membersChanges.indexOf('-' + key.fingerprint)) {
if (!isStill && ~isBeingKicked) {
next('Member ' + key.fingerprint + ' is no more outdistanced and should not be kicked. Wrong block.');
return;
}
if (enoughLinksErr && isBeingKicked == -1) {
next(enoughLinksErr);
return;
}
// Fine
next();
}
......@@ -716,10 +732,21 @@ function KeyService (conn, conf, PublicKeyService) {
var fpr = key.fingerprint;
async.waterfall([
function (next){
Link.isOver3StepsOfAMember(key, members, next);
async.parallel({
outdistanced: function(callback){
Link.isOver3StepsOfAMember(key, members, next);
},
enoughLinks: function(callback){
checkHaveEnoughLinks(key.fingerprint, {}, function (err) {
callback(null, err);
});
},
}, next);
},
function (distancedKeys, next){
Key.setKicked(fpr, distancedKeys, next);
function (res, next){
var distancedKeys = res.outdistanced;
var notEnoughLinks = res.enoughLinks;
Key.setKicked(fpr, distancedKeys, notEnoughLinks ? true : false, next);
},
], callback);
}, next);
......
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