Skip to content
Snippets Groups Projects
Commit 8feec8ac authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Apply minimum links count rule to kick members

parent 81e6fc68
No related branches found
No related tags found
No related merge requests found
......@@ -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);
});
async.parallel({
outdistanced: function(callback){
Link.isStillOver3Steps(key.fingerprint, remainingKeys, newLinks, next);
},
function (outdistanced, next) {
enoughLinks: function(callback){
checkHaveEnoughLinks(key.fingerprint, newLinks, function (err) {
callback(null, err);
});
},
}, 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){
async.parallel({
outdistanced: function(callback){
Link.isOver3StepsOfAMember(key, members, next);
},
function (distancedKeys, next){
Key.setKicked(fpr, distancedKeys, next);
enoughLinks: function(callback){
checkHaveEnoughLinks(key.fingerprint, {}, function (err) {
callback(null, err);
});
},
}, next);
},
function (res, next){
var distancedKeys = res.outdistanced;
var notEnoughLinks = res.enoughLinks;
Key.setKicked(fpr, distancedKeys, notEnoughLinks ? true : false, next);
},
], callback);
}, next);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment