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

Now allow to sync with an existing keychain

parent 65f69d44
...@@ -260,6 +260,17 @@ function KeyHelper (packetList) { ...@@ -260,6 +260,17 @@ function KeyHelper (packetList) {
return this.getHashedPackets(subkeys); return this.getHashedPackets(subkeys);
}; };
this.hasSubkey = function (keyID){
var matched = false;
(key.subKeys || []).forEach(function(subkeyWrapper){
if (subkeyWrapper.isValidSigningKey(key.primaryKey) || subkeyWrapper.isValidEncryptionKey(key.primaryKey)) {
if (subkeyWrapper.subKey.getFingerprint().toUpperCase().match(new RegExp(keyID + '$')))
matched = true;
}
});
return matched;
};
this.getHashedCertifPackets = function (){ this.getHashedCertifPackets = function (){
var certifs = this.getBase64primaryUserOtherCertifications(); // Array of 1 packet lists (signature) var certifs = this.getBase64primaryUserOtherCertifications(); // Array of 1 packet lists (signature)
return this.getHashedPackets(certifs); return this.getHashedPackets(certifs);
......
This diff is collapsed.
...@@ -64,7 +64,7 @@ KeyBlockSchema.methods = { ...@@ -64,7 +64,7 @@ KeyBlockSchema.methods = {
[ [
"membersChanges", "membersChanges",
].forEach(function(field){ ].forEach(function(field){
json[field] = json[field] || []; json[field] = that[field] || [];
}); });
[ [
"keysChanges", "keysChanges",
......
...@@ -37,6 +37,10 @@ function KeyService (conn, conf, PublicKeyService, PeeringService) { ...@@ -37,6 +37,10 @@ function KeyService (conn, conf, PublicKeyService, PeeringService) {
var Link = conn.model('Link'); var Link = conn.model('Link');
var Key = conn.model('Key'); var Key = conn.model('Key');
// Flag to say wether timestamp of received keyblocks should be tested
// Useful for synchronisation of old blocks
this.checkWithLocalTimestamp = true;
this.load = function (done) { this.load = function (done) {
done(); done();
}; };
...@@ -141,7 +145,7 @@ function KeyService (conn, conf, PublicKeyService, PeeringService) { ...@@ -141,7 +145,7 @@ function KeyService (conn, conf, PublicKeyService, PeeringService) {
return; return;
} }
// Test timestamp // Test timestamp
if (Math.abs(block.timestamp - now.utcZero().timestamp()) > conf.tsInterval) { if (KeychainService.checkWithLocalTimestamp && Math.abs(block.timestamp - now.utcZero().timestamp()) > conf.tsInterval) {
next('Timestamp does not match this node\'s time'); next('Timestamp does not match this node\'s time');
return; return;
} }
...@@ -1472,6 +1476,7 @@ function KeyService (conn, conf, PublicKeyService, PeeringService) { ...@@ -1472,6 +1476,7 @@ function KeyService (conn, conf, PublicKeyService, PeeringService) {
}; };
this.startGeneration = function (done) { this.startGeneration = function (done) {
if (!conf.participate) return;
if (!PeeringService) { if (!PeeringService) {
done('Needed peering service activated.'); done('Needed peering service activated.');
return; return;
......
...@@ -141,13 +141,15 @@ program ...@@ -141,13 +141,15 @@ program
program program
.command('sync [host] [port]') .command('sync [host] [port]')
.description('Tries to synchronise data with remote uCoin node') .description('Tries to synchronise data with remote uCoin node')
.action(service(DO_NOT_LISTEN_HTTP, ucoin.createRegistryServer, function (host, port, server, conf) { .action(service(DO_NOT_LISTEN_HTTP, ucoin.createPeerServer, function (host, port, server, conf) {
// Disable daemon // Stop keyblock generation
conf.sync.AMDaemon = "OFF"; conf.participate = false;
conf.createNext = false;
async.series([ async.series([
function (next) {
server.once('peerInited', next);
},
function (next){ function (next){
// Synchronize // Synchronize
var Synchroniser = require('../app/lib/sync'); var Synchroniser = require('../app/lib/sync');
......
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