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

Now able to generate empty keyblock + accept it

parent 371ef48f
......@@ -553,8 +553,7 @@ function KeyService (conn, conf, PublicKeyService) {
},
function (next){
// Compute obsolete links
next();
// computeObsoleteLinks(block, next);
computeObsoleteLinks(block, next);
},
], function (err) {
done(err, block);
......@@ -827,6 +826,56 @@ function KeyService (conn, conf, PublicKeyService) {
done(null, block);
}
this.generateEmptyNext = function (done) {
var staying = [];
var kicked = [];
var current;
async.waterfall([
function (next) {
KeyBlock.current(function (err, currentBlock) {
current = currentBlock;
next(err && 'No root block: cannot generate an empty block');
});
},
function (next){
Key.getMembers(next);
},
function (memberKeys, next){
memberKeys.forEach(function(mKey){
if (!mKey.kick) {
// Member that stays
staying.push(mKey.fingerprint);
} else {
// Member that leaves (kicked)
kicked.push(mKey.fingerprint);
}
});
createNextEmptyBlock(current, staying, kicked, next);
},
], done);
};
function createNextEmptyBlock (current, members, leaving, done) {
var block = new KeyBlock();
block.version = 1;
block.currency = current.currency;
block.number = current.number + 1;
// Members merkle
var stayers = members.slice(); // copy
var leavers = leaving.slice(); // copy
stayers.sort();
leavers.sort();
var tree = merkle(stayers, 'sha1').process();
block.membersCount = stayers.length;
block.membersRoot = tree.root();
block.membersChanges = [];
leavers.forEach(function(fpr){
block.membersChanges.push('-' + fpr);
});
block.keysChanges = [];
done(null, block);
}
this.prove = function (block, sigFunc, nbZeros, done) {
var powRegexp = new RegExp('^0{' + nbZeros + '}');
var pow = "", sig = "", raw = "";
......
......@@ -275,16 +275,42 @@ program
signature(conf.pgpkey, conf.pgppasswd, conf.openpgpjs, next);
},
function (sigFunc, next){
KeychainService.prove(root, sigFunc, difficulty, next);
proveAndSend(server, root, sigFunc, difficulty, host, port, next);
},
function (block, next){
var Peer = server.conn.model('Peer');
var peer = new Peer({
endpoints: [['BASIC_MERKLED_API', host, port].join(' ')]
});
// console.log(block.getRaw());
// console.log(block.signature);
multicaster().sendKeyblock(peer, block, next);
], next);
},
], function (err) {
if (err) {
logger.error(err);
}
server.disconnect();
process.exit();
});
}));
program
.command('gen-empty-next [host] [port] [difficulty]')
.description('Tries to generate the next keyblock of the keychain without any keychange')
.action(service(DO_NOT_LISTEN_HTTP, ucoin.createWOTServer, function (host, port, difficulty, server, conf) {
var KeychainService = server.KeychainService;
async.waterfall([
function (next){
KeychainService.generateEmptyNext(next);
},
function (block, next){
var wiz = wizard(server);
async.waterfall([
function (next){
wiz.configOpenpgp(conf, next);
},
function (next){
wiz.configKey(conf, next);
},
function (next){
signature(conf.pgpkey, conf.pgppasswd, conf.openpgpjs, next);
},
function (sigFunc, next){
proveAndSend(server, block, sigFunc, difficulty, host, port, next);
},
], next);
},
......@@ -297,6 +323,24 @@ program
});
}));
function proveAndSend (server, block, sigFunc, difficulty, host, port, done) {
var KeychainService = server.KeychainService;
async.waterfall([
function (next){
KeychainService.prove(block, sigFunc, difficulty, next);
},
function (block, next){
var Peer = server.conn.model('Peer');
var peer = new Peer({
endpoints: [['BASIC_MERKLED_API', host, port].join(' ')]
});
// console.log(block.getRaw());
// console.log(block.signature);
multicaster().sendKeyblock(peer, block, next);
},
], done);
}
program
.command('check-config')
.description('Checks the node\'s configuration')
......
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