Commit fad2f6c1 authored by Cédric Moreau's avatar Cédric Moreau

Now handle algorithms via --algorithm option

parent 7cac14de
......@@ -105,14 +105,18 @@ function Daemon (regServer) {
Key.wasVoter(selfFingerprint, current.number, function (err, wasVoter) {
if (!err && wasVoter) {
logger.debug("Asking Statement for SELF peer");
async.waterfall([
function (next){
SyncService.getStatement(current.number + 1, Algorithm, next);
},
function (statement, next){
regServer.submit(statement, false, next);
},
], callback);
async.forEach(Algorithm, function(algo, callback){
async.waterfall([
function (next){
SyncService.getStatement(current.number + 1, algo, next);
},
function (statement, next){
regServer.submit(statement, false, next);
},
], callback);
}, function(err){
next(err);
});
return;
}
callback(err);
......@@ -141,21 +145,6 @@ function Daemon (regServer) {
});
}
function askCF (current, peer, done) {
async.auto({
connect: function (cb){
vucoin(peer.getIPv4(), peer.getPort(), true, cb);
},
vote: ['connect', function (cb, results) {
var node = results.connect;
// Ask for peer's vote
node.registry.amendment.statement(current.number + 1, Algorithm, cb);
}]
}, function (err, results) {
done(err, results.vote);
});
}
this.stop = function () {
clearTimeout(timeoutID);
};
......
......@@ -17,8 +17,9 @@ function PubkeyParser (onError) {
GenericParser.call(this, captures, multilineFields, rawer.getPubkey, onError);
this._parse = function (str, obj) {
obj.raw = str;
obj.hash = sha1(str).toUpperCase();
var dosStr = unix2dos(str);
obj.raw = dosStr;
obj.hash = sha1(dosStr).toUpperCase();
var k = jpgp().certificate(obj.raw);
// Extract udid2
obj.udid2s = getSignedUdid2s(k.key);
......
......@@ -302,7 +302,19 @@ var tasks = {
async.apply(simpleInteger, "Dividend frequency", "UDFreq", conf.sync),
async.apply(simpleFloat, "Consensus %required", "Consensus", conf.sync),
async.apply(simpleInteger, "Initial dividend", "UD0", conf.sync),
async.apply(simpleFloat, "Universal Dividend %growth", "UDPercent", conf.sync)
async.apply(simpleFloat, "Universal Dividend %growth", "UDPercent", conf.sync),
function (next) {
inquirer.prompt([{
type: "checkbox",
name: "Algorithm",
message: "Community you want to vote for",
choices: ["AnyKey", "1Sig"],
default: conf.sync.Algorithm,
}], function (answers) {
conf.sync.Algorithm = answers.Algorithm;
done();
});
}
], done);
},
function disabled () {
......
var mongoose = require('mongoose');
var _ = require('underscore');
var Schema = mongoose.Schema;
var logger = require('../lib/logger')();
......@@ -24,7 +25,7 @@ var ConfigurationSchema = new Schema({
UD0: 100,
UDPercent: 0.007376575, // 0.73%
Consensus: 2/3,
Algorithm: 'AnyKey'
Algorithm: ['AnyKey', '1Sig'],
}}
});
......@@ -43,10 +44,14 @@ ConfigurationSchema.virtual('createNext').set(function (create) {
// - UD(0): 100 unities
// - UD % (aka 'c'): 9.22% a year <=> 0.7376575% a month
// - UD Minimal Coin: none
// - Voting % threshold: 2/3 of votes
// - Membership max. delay: 6 months
ConfigurationSchema.pre('save', function (next) {
// Force sync saving
var sync = _({}).extend(this.sync);
this.sync = {};
this.sync = sync;
if(!this.kmanagement || !this.kmanagement.match(/^(ALL|KEYS)$/)){
logger.error('Incorrect --kmanagement value, reset to default `KEYS` value');
this.kmanagement = 'KEYS';
......
......@@ -4,6 +4,7 @@ var async = require('async');
var sha1 = require('sha1');
var _ = require('underscore');
var Schema = mongoose.Schema;
var unix2dos = require('../lib/unix2dos');
var parsers = require('../lib/streams/parsers/doc');
var logger = require('../lib/logger')('pubkey');
......@@ -185,7 +186,7 @@ PublicKeySchema.statics.persist = function (pubkey, done) {
var now = new Date();
var comingKey = jpgp().certificate(pubkey.raw).key;
that.find({ fingerprint: pubkey.fingerprint }, function (err, foundKeys) {
var comingArmored = comingKey.armor();
var comingArmored = unix2dos(comingKey.armor());
var comingHash = comingArmored.hash();
// Create if not exists
if (foundKeys.length == 0) {
......@@ -208,12 +209,13 @@ PublicKeySchema.statics.persist = function (pubkey, done) {
// Merges packets
storedKey.update(comingKey);
var mergedCert = jpgp().certificate(storedKey.armor());
var raw = unix2dos(storedKey.armor());
foundKeys[0].subkeys = mergedCert.subkeys;
foundKeys[0].raw = storedKey.armor();
foundKeys[0].raw = raw;
foundKeys[0].email = pubkey.email;
foundKeys[0].name = pubkey.name;
foundKeys[0].comment = pubkey.comment;
foundKeys[0].hash = storedKey.armor().hash();
foundKeys[0].hash = raw.hash();
foundKeys[0].save(function (err) {
next(err);
});
......
......@@ -198,8 +198,8 @@ function SyncService (conn, conf, signsDetached, ContractService, PeeringService
fifoStatement.push(function (cb) {
async.waterfall([
function (next) {
if (['AnyKey', '1Sig'].indexOf(entry.algorithm) == -1) {
next('Algorithm must be either AnyKey or 1Sig');
if (conf.sync.Algorithm.indexOf(entry.algorithm) == -1) {
next('Algorithm not managed by this node');
return;
}
Statement.getByIssuerAlgoAmendmentHashAndNumber(entry.issuer, entry.algorithm, entry.amendmentHash, entry.amendmentNumber, next);
......@@ -731,8 +731,6 @@ function SyncService (conn, conf, signsDetached, ContractService, PeeringService
}
function computeLocalMSandVTChanges (basis, algo, done) {
if (['1Sig', 'AnyKey'].indexOf(algo) == -1)
done('Algorithm \'' + algo + '\' not managed');
var isMember = function (fpr, done) {
if (basis == -1)
done(null, true);
......@@ -740,7 +738,16 @@ function SyncService (conn, conf, signsDetached, ContractService, PeeringService
Key.wasMember(fpr, basis, done);
};
var getPubkey = PublicKey.getTheOne.bind(PublicKey);
var algoFunc = algo == "1Sig" ? require('../lib/algos/community/1Sig')(isMember, getPubkey) : require('../lib/algos/community/AnyKey');
var algos = {
"1Sig": require('../lib/algos/community/1Sig')(isMember, getPubkey),
"AnyKey": require('../lib/algos/community/AnyKey')
};
var algoFunc = algos[algo];
if (!algoFunc) {
var err = "Unsupported algo '" + algo + "'";
done(new Error(err));
return;
}
var members = [];
var voters = [];
var membersJoining = [];
......
......@@ -51,7 +51,7 @@ program
.option('--msvalidity <timestamp>', 'Duration of a valid membership, in seconds', parseInt)
.option('--vtvalidity <timestamp>', 'Duration of a valid voter, in seconds', parseInt)
.option('--openpgpjs', 'Prefer using embedded Openpgpjs implementation for signing requests')
.option('--algorithm <AnyKey|1Sig>', 'Algorithm to use for membership')
.option('--algorithm <AnyKey:1Sig>', 'Algorithms to use for community changes. Use \':\' to give multiple values', splitColon)
;
program
......@@ -432,4 +432,8 @@ function parseMoment (d) {
}
}
function splitColon (str) {
return str.split(':');
}
program.parse(process.argv);
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