Mise à jour de GitLab prévue ce samedi 8 mai 2021 à partir de 9h00 CET | GitLab upgrade planned this Saturday May 4th of 2021 from 9:00 AM CET

Commit 9868c668 authored by Cédric Moreau's avatar Cédric Moreau

Refactoring

parent 332514bb
......@@ -33,12 +33,46 @@ function GlobalValidator (dao) {
], done);
};
/**
* Get an identity, using global scope.
* Considers identity collision + existence have already been checked.
**/
function getGlobalIdentity (block, pubkey, done) {
async.waterfall([
function (next){
var localInlineIdty = block.getInlineIdentity(pubkey);
if (localInlineIdty) {
next(null, Identity.fromInline(localInlineIdty));
} else {
dao.getIdentityByPubkey(pubkey, next);
}
},
], done);
}
/**
* Check wether a pubkey is currently a member or not (globally).
**/
function isMember (block, pubkey, done) {
async.waterfall([
function (next){
if (block.isLeaving(pubkey)) {
next(null, false);
} else if (block.isJoining(pubkey)) {
next(null, true);
} else {
dao.isMember(pubkey, next);
}
},
], done);
}
function checkCertificationsAreValid (block, done) {
async.forEach(block.certifications, function(inlineCert, callback){
var cert = Certification.fromInline(inlineCert);
async.waterfall([
function (next){
dao.getIdentityByPubkey(cert.to, next);
getGlobalIdentity(block, cert.to, next);
},
function (idty, next){
var selfCert = idty.selfCert();
......@@ -53,7 +87,7 @@ function GlobalValidator (dao) {
var cert = Certification.fromInline(inlineCert);
async.waterfall([
function (next){
dao.getIdentityByPubkey(cert.from, next);
isMember(block, cert.from, next);
},
function (idty, next){
next(idty ? null : 'Certification from non-member');
......@@ -67,7 +101,7 @@ function GlobalValidator (dao) {
var cert = Certification.fromInline(inlineCert);
async.waterfall([
function (next){
dao.getIdentityByPubkey(cert.to, next);
isMember(block, cert.to, next);
},
function (idty, next){
next(idty ? null : 'Certification to non-member');
......
......@@ -124,6 +124,44 @@ BlockSchema.methods = {
var desc = '#' + this.number + ' (';
desc += this.identities.length + ' newcomers, ' + this.certifications.length + ' certifications)';
return desc;
},
getInlineIdentity: function (pubkey) {
var i = 0;
var found = false;
while (!found && i < this.identities.length) {
if (this.identities[i].match(new RegExp('^' + pubkey)))
found = this.identities[i];
i++;
}
return found;
},
isLeaving: function (pubkey) {
var i = 0;
var found = false;
while (!found && i < this.leavers.length) {
if (this.leavers[i].match(new RegExp('^' + pubkey)))
found = true;
i++;
}
while (!found && i < this.excluded.length) {
if (this.excluded[i].match(new RegExp('^' + pubkey)))
found = true;
i++;
}
return found;
},
isJoining: function (pubkey) {
var i = 0;
var found = false;
while (!found && i < this.joiners.length) {
if (this.joiners[i].match(new RegExp('^' + pubkey)))
found = true;
i++;
}
return found;
}
};
......
......@@ -62,13 +62,12 @@ function validate (raw, callback) {
function BlockCheckerDao (block) {
this.getIdentityByPubkey = function (pubkey, done) {
var i = 0;
var found = false;
while (!found && i < block.identities.length) {
if (block.identities[i].match(new RegExp('^' + pubkey)))
found = Identity.fromInline(block.identities[i]);
i++;
}
done(null, found);
// No existing identity
done(null, null);
}
this.isMember = function (pubkey, done) {
// No existing member
done(null, false);
}
}
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