Mise à jour effectuée, merci de nous signaler tout dysfonctionnement ! | Upgrade done, please let us know about any dysfunction!

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

`ucoind sync` command working again

parent 2dc4e55b
......@@ -147,6 +147,32 @@ module.exports.database = {
}
};
module.exports.openpgp = {
init: function (currency, conf, done) {
// Import PGP key
openpgp.keyring.importPrivateKey(conf.pgpkey, conf.pgppasswd);
if (!module.exports.fingerprint()) {
pgplogger.error("Wrong PGP key password.");
process.exit(1);
return;
}
done();
}
};
function initServices (currency, conf, done) {
// Init ALL services
service.init(openpgp, currency, conf);
// Load services contexts
service.load(done);
}
module.exports.services = {
init: initServices
};
module.exports.express = {
app: function (currency, conf, onLoaded) {
......@@ -166,16 +192,19 @@ module.exports.express = {
app.use(express.cookieParser('your secret here'));
app.use(express.session());
// Import PGP key
openpgp.keyring.importPrivateKey(conf.pgpkey, conf.pgppasswd);
if (!module.exports.fingerprint()) {
pgplogger.error("Wrong PGP key password.");
process.exit(1);
return;
}
// HTTP Signatures
httpgp(app, conf, function (err) {
async.series([
function (next) {
// OpenPGP functions
module.exports.openpgp.init(currency, conf, next);
},
function (next){
initServices(currency, conf, next);
},
function (next){
// HTTP Signatures
httpgp(app, conf, next);
},
], function(err) {
// HTTPGP OK?
if (err) {
......@@ -192,9 +221,6 @@ module.exports.express = {
app.use(express.errorHandler());
}
// Init ALL services
service.init(openpgp, currency, conf);
// Init Daemon
var daemon = require('./daemon');
daemon.init(conf, module.exports.fingerprint());
......@@ -273,6 +299,25 @@ module.exports.express = {
var SyncService = service.Sync;
async.waterfall([
function (next) {
if(conf.ipv4){
logger.info('Connecting on interface %s...', conf.ipv4);
http.createServer(app).listen(conf.port, conf.ipv4, function(){
logger.info('uCoin server listening on ' + conf.ipv4 + ' port ' + conf.port);
next();
});
}
else next();
},
function (next) {
if(conf.ipv6){
logger.info('Connecting on interface %s...', conf.ipv6);
http.createServer(app).listen(conf.port, conf.ipv6, function(){
logger.info('uCoin server listening on ' + conf.ipv6 + ' port ' + conf.port);
});
}
else next();
},
function (next) {
mongoose.model('Peer').find({ fingerprint: module.exports.fingerprint() }, next);
},
......@@ -311,7 +356,7 @@ module.exports.express = {
},
function (signature, next) {
signature = signature.substring(signature.indexOf('-----BEGIN PGP SIGNATURE'));
PeeringService.persistPeering(raw2 + signature, module.exports.publicKey(), next);
PeeringService.submit(raw2 + signature, module.exports.fingerprint(), next);
},
], function (err) {
next(err);
......@@ -321,11 +366,11 @@ module.exports.express = {
}
},
function (next){
// Load services contexts
service.load(next);
mongoose.model('Peer').getTheOne(module.exports.fingerprint(), next);
},
function (next){
function (peer, next){
// Set peer's statut to UP
PeeringService.peer(peer);
PeeringService.peer().status = 'UP';
PeeringService.peer().save(function (err) {
// Update it in memory
......@@ -333,25 +378,6 @@ module.exports.express = {
next(err);
});
},
function (next) {
if(conf.ipv4){
logger.debug('Connecting on interface %s...', conf.ipv4);
http.createServer(app).listen(conf.port, conf.ipv4, function(){
logger.debug('uCoin server listening on ' + conf.ipv4 + ' port ' + conf.port);
next();
});
}
else next();
},
function (next) {
if(conf.ipv6){
logger.debug('Connecting on interface %s...', conf.ipv6);
http.createServer(app).listen(conf.port, conf.ipv6, function(){
logger.debug('uCoin server listening on ' + conf.ipv6 + ' port ' + conf.port);
});
}
else next();
},
function (next) {
// Initialize managed keys
PeeringService.initKeys(next);
......@@ -370,12 +396,18 @@ module.exports.express = {
logger.info('Broadcasting UP/NEW signals...');
PeeringService.sendUpSignal(next);
},
function (next) {
// Create AM0 proposal if not existing
mongoose.model('Amendment').getTheOneToBeVoted(0, function (err, am) {
function (next){
mongoose.model('Amendment').current(function (err, am) {
next(null, am);
});
},
function (currentAM, next) {
var nextAMNumber = currentAM && currentAM.number + 1 || 0;
// Create NEXT AM proposal if not existing
mongoose.model('Amendment').getTheOneToBeVoted(nextAMNumber, function (err, am) {
if (err || !am) {
logger.info('Creating root AM proposal...');
SyncService.createNext(null, next);
logger.info('Creating next AM (#%d) proposal...', nextAMNumber);
SyncService.createNext(currentAM, next);
return;
}
next();
......
This diff is collapsed.
......@@ -209,23 +209,15 @@ AmendmentSchema.statics.nextNumber = function (done) {
AmendmentSchema.statics.current = function (done) {
this.find({ promoted: true }, function (err, amends) {
this.find({ promoted: true }).sort({ number: -1 }).limit(1).exec(function (err, amends) {
if(amends && amends.length == 1){
done(err, amends[0]);
return;
}
if(!amends || amends.length == 0){
else {
done('No current amendment');
return;
}
if(amends || amends.length > 1){
var current = undefined;
amends.forEach(function (am) {
if(!current || (current && current.number < am.number))
current = am;
});
done(err, current);
}
});
};
......
......@@ -64,10 +64,13 @@ function PeeringService(pgp, currency, conf) {
dbPeers.forEach(function(peer){
that.addPeer(peer);
});
Peer.getTheOne(that.cert.fingerprint, next);
Peer.getTheOne(that.cert.fingerprint, function (err, selfPeer) {
if (selfPeer)
peer = selfPeer;
next();
});
},
function (selfPeer, next){
peer = selfPeer;
function (next){
logger.debug('Loaded service: Peering');
next();
},
......@@ -105,7 +108,7 @@ function PeeringService(pgp, currency, conf) {
next(null, pubkey.raw);
},
function (pubkey, next){
that.persistPeering(signedPR, pubkey, next);
persistPeering(signedPR, pubkey, next);
}
], callback);
}
......@@ -149,14 +152,14 @@ function PeeringService(pgp, currency, conf) {
wasStatus = peer.status;
peer.setStatus(status.status, next);
peer.statusSigDate = status.sigDate;
peers[peer.fingerprint].status = status;
}
], function (err) {
peers[peer.fingerprint].status = status;
callback(err, status, peer, wasStatus);
});
}
this.persistPeering = function (signedPR, pubkey, done) {
function persistPeering (signedPR, pubkey, done) {
var peer = new Peer();
async.waterfall([
function (next){
......@@ -679,7 +682,7 @@ function PeeringService(pgp, currency, conf) {
function getForwardPeers (done) {
async.waterfall([
async.apply(Forward.find.bind(Forward), { to: this.cert.fingerprint }),
async.apply(Forward.find.bind(Forward), { to: that.cert.fingerprint }),
function (fwds, next) {
var fingerprints = _(fwds).map(function(fwd){ return fwd.fingerprint; });
Peer.getList(fingerprints, next);
......
......@@ -101,7 +101,55 @@ module.exports.get = function (pgp, currency, conf) {
}, next);
},
function (next){
SyncService.createNext(am, next);
Key.getMembers(next);
},
function (members, next){
// Update Merkle of proposed members
async.waterfall([
function (next){
Merkle.proposedMembers(next);
},
function (merkle, next){
var fingerprints = [];
members.forEach(function(m){
fingerprints.push(m.fingerprint);
});
fingerprints.sort();
merkle.initialize(fingerprints);
merkle.save(function (err) {
next(err);
});
},
], next);
},
function (next){
Key.getVoters(next);
},
function (voters, next){
// Update Merkle of proposed voters
async.waterfall([
function (next){
Merkle.proposedVoters(next);
},
function (merkle, next){
var fingerprints = [];
voters.forEach(function(v){
fingerprints.push(v.fingerprint);
});
fingerprints.sort();
merkle.initialize(fingerprints);
merkle.save(function (err) {
next(err);
});
},
], next);
},
function (next){
if (conf.createNext) {
SyncService.createNext(am, next);
} else {
next();
}
},
], cb);
}, done);
......
......@@ -454,9 +454,9 @@ module.exports.get = function (pgp, currency, conf) {
}
function updateUniversalDividend (amNext, amCurrent, done) {
// Time for Universal Dividend
// Time for Universal Dividend (and we have members)
var delayPassedSinceRootAM = (amNext.generated - conf.sync.AMStart);
if (delayPassedSinceRootAM > 0 && delayPassedSinceRootAM % conf.sync.UDFreq == 0) {
if (delayPassedSinceRootAM > 0 && delayPassedSinceRootAM % conf.sync.UDFreq == 0 && amNext.membersCount > 0) {
async.waterfall([
function (next) {
Amendment.getPreviouslyPromotedWithDividend(next);
......@@ -799,11 +799,11 @@ module.exports.get = function (pgp, currency, conf) {
var stateFunc = async.apply(whatToDo.state[lastKeyState.toString()][statusTo.toString()] || doNothingWithState, key, statusTo);
if ((lastKeyState == 0 && statusTo == 1) || (lastKeyState == -1 && statusTo == 0)) {
// Make positive change
console.log('> +%s', key);
mathlog.info('VT +%s', key);
actionForVoters(merkleFunc, keysFunc, stateFunc, amNext, next);
} else if ((lastKeyState == 1 && statusTo == 0) || (lastKeyState == 0 && statusTo == -1)) {
// Make negative change
console.log('> -%s', key);
mathlog.info('VT -%s', key);
actionForVoters(merkleFunc, keysFunc, stateFunc, amNext, next);
} else {
// Do nothing!
......
......@@ -46,23 +46,28 @@ program
.description('Tries to synchronise data with remote uCoin node')
.action(connect(function (host, port, conf) {
// Init server
server.express.app(program.currency, conf, function (err, app) {
// Disable daemon
conf.sync.AMDaemon = "OFF";
// Synchronize
var Synchroniser = require('../app/lib/sync');
var remote = new Synchroniser(host, port, false, server.pgp, program.currency, conf);
async.waterfall([
function (next){
remote.sync(next);
},
], function (err) {
if(err){
logger.error('Error during sync:', err);
}
server.database.disconnect();
process.exit();
});
async.series([
function (next){
server.openpgp.init(program.currency, conf, next);
},
function (next){
server.services.init(program.currency, conf, next);
},
function (next){
// Synchronize
var Synchroniser = require('../app/lib/sync');
var remote = new Synchroniser(host, port, false, program.currency, conf);
remote.sync(next);
},
], function (err) {
if(err){
logger.error('Error during sync:', err);
}
server.database.disconnect();
process.exit();
});
}));
......@@ -301,6 +306,9 @@ function overrideConf(conf) {
MSExpires: config.sync.MSExpires || conf.sync.MSExpires || 3600*24*30.4375*6, // 6 months
UCSBlockFreq: config.sync.UCSBlockFreq || conf.sync.UCSBlockFreq || 3600 // hourly
};
// Specific internal settings
conf.createNext = true;
return conf;
}
......
......@@ -36,7 +36,7 @@
"hdc": "~0.5.0",
"connect-pgp": "~0.2.1",
"underscore": "~1.5.2",
"vucoin": "~0.10.0",
"vucoin": "~0.12.0",
"request": "~2.31.0",
"log4js": "~0.6.9"
},
......
......@@ -67,7 +67,8 @@ var conf = {
UDPercent: 0.5, // So it can be tested under 4 UD - this ultra high value of UD growth
Consensus: 2/3,
MSExpires: 3600*24*30 // 30 days
}
},
createNext: true
};
var amendments = {
......
......@@ -76,7 +76,8 @@ var conf = {
UDPercent: 0.5, // So it can be tested under 4 UD - this ultra high value of UD growth
Consensus: 2/3,
MSExpires: 3600*24*30 // 30 days
}
},
createNext: true
};
var amendments = {
......
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