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

Fix: could not manually add peer which had forked

parent fb05dfcc
No related branches found
No related tags found
No related merge requests found
......@@ -42,24 +42,37 @@ function PeeringService(server, pair, dal) {
done = eraseIfAlreadyRecorded;
eraseIfAlreadyRecorded = false;
}
return that.submitP(peering, eraseIfAlreadyRecorded)
.then((res) => done(null, res))
.catch(done);
};
this.submitP = function(peering, eraseIfAlreadyRecorded, cautious){
let thePeer = new Peer(peering);
let sp = thePeer.block.split('-');
let blockNumber = sp[0];
let blockHash = sp[1];
let sigTime = 0;
let block;
let makeCheckings = cautious || cautious === undefined;
return co(function *() {
if (makeCheckings) {
let goodSignature = localValidator(null).checkPeerSignature(thePeer);
if (!goodSignature) {
throw 'Signature from a peer must match';
}
}
if (thePeer.block == constants.PEER.SPECIAL_BLOCK) {
thePeer.statusTS = 0;
thePeer.status = 'UP';
} else {
block = yield dal.getBlockByNumberAndHashOrNull(blockNumber, blockHash);
if (!block) {
if (!block && makeCheckings) {
throw constants.PEER.UNKNOWN_REFERENCE_BLOCK;
} else if (!block) {
thePeer.block = constants.PEER.SPECIAL_BLOCK;
thePeer.statusTS = 0;
thePeer.status = 'UP';
}
}
sigTime = block ? block.medianTime : 0;
......@@ -84,10 +97,8 @@ function PeeringService(server, pair, dal) {
peerEntity.hash = String(sha1(peerEntity.getRawSigned())).toUpperCase();
yield dal.savePeer(peerEntity);
let res = Peer.statics.peerize(peerEntity);
done(null, res);
return res;
})
.catch(done);
});
};
var peerFifo = async.queue(function (task, callback) {
......
......@@ -156,7 +156,7 @@ program
return Q.nfcall(node.network.peering.get)
.then(function(peering){
logger.info('Apply peering ...');
return Q.nfcall(server.PeeringService.submit, peering, ERASE_IF_ALREADY_RECORDED)
return server.PeeringService.submitP(peering, ERASE_IF_ALREADY_RECORDED, !program.nocautious)
.then(function() {
logger.info('Applied');
return server.dal.getPeer(server.PeeringService.pubkey)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment