Commit 4ba69926 authored by Cédric Moreau's avatar Cédric Moreau

Add simple unique command gen-next

parent 1c4170a5
...@@ -756,6 +756,22 @@ function KeyService (conn, conf, PublicKeyService) { ...@@ -756,6 +756,22 @@ function KeyService (conn, conf, PublicKeyService) {
* Generate a "newcomers" keyblock * Generate a "newcomers" keyblock
*/ */
this.generateUpdates = function (done) { this.generateUpdates = function (done) {
async.waterfall([
function (next){
findUpdates(next);
},
function (updates, subupdates, next){
KeyBlock.current(function (err, current) {
next(null, current || null, updates, subupdates);
});
},
function (current, updates, subupdates, next){
createNewcomerBlock(current, null, {}, updates, subupdates, next);
},
], done);
}
function findUpdates (done) {
var updates = {}; var updates = {};
var subupdates = {}; var subupdates = {};
async.waterfall([ async.waterfall([
...@@ -802,15 +818,9 @@ function KeyService (conn, conf, PublicKeyService) { ...@@ -802,15 +818,9 @@ function KeyService (conn, conf, PublicKeyService) {
], callback); ], callback);
}, next); }, next);
}, },
function (next){ ], function (err) {
KeyBlock.current(function (err, current) { done(err, updates, subupdates);
next(null, current || null); });
});
},
function (current, next){
createNewcomerBlock(current, null, {}, updates, subupdates, next);
},
], done);
} }
/** /**
...@@ -860,39 +870,81 @@ function KeyService (conn, conf, PublicKeyService) { ...@@ -860,39 +870,81 @@ function KeyService (conn, conf, PublicKeyService) {
* Generate a "newcomers" keyblock * Generate a "newcomers" keyblock
*/ */
this.generateNewcomersAuto = function (done) { this.generateNewcomersAuto = function (done) {
var filtering = function (preJoinData, next) { KeychainService.generateNewcomersBlock(noFiltering, iteratedChecking, done);
// No manual filtering, takes all }
next(null, preJoinData);
};
var checking = function (newcomers, checkWoTForNewcomers, done) { function noFiltering(preJoinData, next) {
var passingNewcomers = []; // No manual filtering, takes all
async.forEachSeries(newcomers, function(newcomer, callback){ next(null, preJoinData);
checkWoTForNewcomers(passingNewcomers.concat(newcomer), function (err) { }
// If success, add this newcomer to the valid newcomers. Otherwise, reject him.
if (!err) function iteratedChecking(newcomers, checkWoTForNewcomers, done) {
passingNewcomers.push(newcomer); var passingNewcomers = [];
callback(); async.forEachSeries(newcomers, function(newcomer, callback){
}); checkWoTForNewcomers(passingNewcomers.concat(newcomer), function (err) {
}, function(){ // If success, add this newcomer to the valid newcomers. Otherwise, reject him.
console.log(passingNewcomers); if (!err)
done(null, passingNewcomers); passingNewcomers.push(newcomer);
callback();
}); });
} }, function(){
KeychainService.generateNewcomersBlock(filtering, checking, done); console.log(passingNewcomers);
done(null, passingNewcomers);
});
} }
this.generateNext = function (done) {
KeychainService.generateNextBlock(findUpdates, noFiltering, iteratedChecking, done);
};
/** /**
* Generate a "newcomers" keyblock * Generate a "newcomers" keyblock
*/ */
this.generateNewcomersBlock = function (filteringFunc, checkingWoTFunc, done) { this.generateNewcomersBlock = function (filteringFunc, checkingWoTFunc, done) {
// 1. See available keychanges var withoutUpdates = function(updates) { updates(null, {}, {}); };
KeychainService.generateNextBlock(withoutUpdates, filteringFunc, checkingWoTFunc, done);
};
/**
* Generate next keyblock, gathering both updates & newcomers
*/
this.generateNextBlock = function (findUpdateFunc, filteringFunc, checkingWoTFunc, done) {
var updates = {};
var subupdates = {};
async.waterfall([
function (next) {
// First, check for members' key updates
findUpdateFunc(next);
},
function (theUpdates, theSubupdates, next) {
updates = theUpdates;
subupdates = theSubupdates;
findNewcomers(filteringFunc, checkingWoTFunc, next);
},
function (current, newWoT, joinData, otherUpdates, next){
// Merges updates
_(otherUpdates).keys().forEach(function(fpr){
if (!updates[fpr])
updates[fpr] = otherUpdates[fpr];
else
updates[fpr].concat(otherUpdates[fpr]);
});
// Create the block
createNewcomerBlock(current, newWoT, joinData, updates, subupdates, next);
},
], done);
};
function findNewcomers (filteringFunc, checkingWoTFunc, done) {
var wotMembers = []; var wotMembers = [];
var preJoinData = {}; var preJoinData = {};
var joinData = {}; var joinData = {};
var updates = {}; var updates = {};
var current; var current;
async.waterfall([ async.waterfall([
function (next) { function (next){
// Second, check for newcomers
KeyBlock.current(function (err, currentBlock) { KeyBlock.current(function (err, currentBlock) {
current = currentBlock; current = currentBlock;
next(); next();
...@@ -1009,11 +1061,11 @@ function KeyService (conn, conf, PublicKeyService) { ...@@ -1009,11 +1061,11 @@ function KeyService (conn, conf, PublicKeyService) {
}); });
updates[signedFPR] = keptCertifs; updates[signedFPR] = keptCertifs;
}); });
// Create the block // Send back the new WoT, the joining data and key updates for newcomers' signature of WoT
createNewcomerBlock(current, wotMembers.concat(realNewcomers), finalJoinData, updates, {}, next); next(null, current, wotMembers.concat(realNewcomers), finalJoinData, updates);
}, }
], done); ], done);
}; }
function computeNewLinks (theNewcomers, joinData, updates, members) { function computeNewLinks (theNewcomers, joinData, updates, members) {
var newLinks = {}; var newLinks = {};
......
...@@ -221,6 +221,11 @@ function handleKey (server, key, isManaged, message) { ...@@ -221,6 +221,11 @@ function handleKey (server, key, isManaged, message) {
}); });
} }
program
.command('gen-next [host] [port] [difficulty]')
.description('Tries to generate the next keyblock of the keychain, with both updates & newcomers')
.action(service(DO_NOT_LISTEN_HTTP, ucoin.createWOTServer, generateAndSend("generateNext")));
program program
.command('gen-empty-next [host] [port] [difficulty]') .command('gen-empty-next [host] [port] [difficulty]')
.description('Tries to generate the next keyblock of the keychain without any changes') .description('Tries to generate the next keyblock of the keychain without any changes')
......
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