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

Add simple unique command gen-next

parent 1c4170a5
Branches
Tags
No related merge requests found
...@@ -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,11 +870,16 @@ function KeyService (conn, conf, PublicKeyService) { ...@@ -860,11 +870,16 @@ 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);
}
function noFiltering(preJoinData, next) {
// No manual filtering, takes all // No manual filtering, takes all
next(null, preJoinData); next(null, preJoinData);
}; }
var checking = function (newcomers, checkWoTForNewcomers, done) {
function iteratedChecking(newcomers, checkWoTForNewcomers, done) {
var passingNewcomers = []; var passingNewcomers = [];
async.forEachSeries(newcomers, function(newcomer, callback){ async.forEachSeries(newcomers, function(newcomer, callback){
checkWoTForNewcomers(passingNewcomers.concat(newcomer), function (err) { checkWoTForNewcomers(passingNewcomers.concat(newcomer), function (err) {
...@@ -878,14 +893,50 @@ function KeyService (conn, conf, PublicKeyService) { ...@@ -878,14 +893,50 @@ function KeyService (conn, conf, PublicKeyService) {
done(null, passingNewcomers); done(null, passingNewcomers);
}); });
} }
KeychainService.generateNewcomersBlock(filtering, checking, done);
} 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 = {};
...@@ -893,6 +944,7 @@ function KeyService (conn, conf, PublicKeyService) { ...@@ -893,6 +944,7 @@ function KeyService (conn, conf, PublicKeyService) {
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')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment