Commit 18826c39 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Protocol 0.2: added msWindow parameter

parent 4dbfc20b
......@@ -135,7 +135,8 @@ function WebAdmin (dbConf, overConf) {
stepMax: conf.stepMax,
ud0: conf.ud0,
xpercent: conf.xpercent,
idtyWindow: conf.idtyWindow
idtyWindow: conf.idtyWindow,
msWindow: conf.msWindow
});
pluggedConfP = co(function *() {
yield bmapi.closeConnections();
......
......@@ -349,16 +349,17 @@ function BlockGenerator(mainContext, prover) {
async.forEach(mss, function(ms, callback){
async.waterfall([
function(nextOne) {
if (current) {
dal.getBlockOrNull(ms.number, nextOne);
} else {
nextOne(null, {});
}
return co(function *() {
if (ms.block != constants.BLOCK.SPECIAL_BLOCK) {
let msBasedBlock = yield dal.getBlock(ms.block);
let age = current.medianTime - msBasedBlock.medianTime;
if (age > conf.msWindow) {
throw 'Too old membership';
}
}
}).then(() => nextOne()).catch(nextOne);
},
function(block, nextOne) {
if (!block) {
return nextOne('Block not found for membership');
}
function(nextOne) {
var idtyHash = (hashf(ms.userid + ms.certts + ms.issuer) + "").toUpperCase();
getSinglePreJoinData(current, idtyHash, nextOne, joiners);
},
......@@ -540,7 +541,7 @@ function BlockGenerator(mainContext, prover) {
block.parameters = block.number > 0 ? '' : [
conf.c, conf.dt, conf.ud0,
conf.sigPeriod, conf.sigStock, conf.sigWindow, conf.sigValidity,
conf.sigQty, conf.idtyWindow, conf.xpercent, conf.msValidity,
conf.sigQty, conf.idtyWindow, conf.msWindow, conf.xpercent, conf.msValidity,
conf.stepMax, conf.medianTimeBlocks, conf.avgGenTime, conf.dtDiffEval,
conf.blocksRot, (conf.percentRot == 1 ? "1.0" : conf.percentRot)
].join(':');
......
......@@ -475,14 +475,15 @@ function BlockchainContext() {
conf.sigValidity = parseInt(sp[6]);
conf.sigQty = parseInt(sp[7]);
conf.idtyWindow = parseInt(sp[8]);
conf.xpercent = parseFloat(sp[9]);
conf.msValidity = parseInt(sp[10]);
conf.stepMax = parseInt(sp[11]);
conf.medianTimeBlocks = parseInt(sp[12]);
conf.avgGenTime = parseInt(sp[13]);
conf.dtDiffEval = parseInt(sp[14]);
conf.blocksRot = parseInt(sp[15]);
conf.percentRot = parseFloat(sp[16]);
conf.msWindow = parseInt(sp[9]);
conf.xpercent = parseFloat(sp[10]);
conf.msValidity = parseInt(sp[11]);
conf.stepMax = parseInt(sp[12]);
conf.medianTimeBlocks = parseInt(sp[13]);
conf.avgGenTime = parseInt(sp[14]);
conf.dtDiffEval = parseInt(sp[15]);
conf.blocksRot = parseInt(sp[16]);
conf.percentRot = parseFloat(sp[17]);
conf.currency = block.currency;
return dal.saveConf(conf).then(done).catch(done);
}
......
......@@ -167,7 +167,7 @@ module.exports = {
PREV_ISSUER: find("PreviousIssuer: (" + PUBKEY + ")"),
MEMBERS_COUNT:find("MembersCount: (" + ZERO_OR_POSITIVE_INT + ")"),
BLOCK_ISSUER:find('Issuer: (' + PUBKEY + ')'),
PARAMETERS: find("Parameters: (" + FLOAT + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + FLOAT + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + FLOAT + ")"),
PARAMETERS: find("Parameters: (" + FLOAT + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + FLOAT + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + INTEGER + ":" + FLOAT + ")"),
JOINER: exact(PUBKEY + ":" + SIGNATURE + ":" + BLOCK_UID + ":" + BLOCK_UID + ":" + USER_ID),
ACTIVE: exact(PUBKEY + ":" + SIGNATURE + ":" + BLOCK_UID + ":" + BLOCK_UID + ":" + USER_ID),
LEAVER: exact(PUBKEY + ":" + SIGNATURE + ":" + BLOCK_UID + ":" + BLOCK_UID + ":" + USER_ID),
......@@ -273,7 +273,8 @@ module.exports = {
AVGGENTIME: 16 * 60,
DTDIFFEVAL: 10,
MEDIANTIMEBLOCKS: 20,
IDTYWINDOW: 3600 * 24 * 7 // a week
IDTYWINDOW: 3600 * 24 * 7, // a week
MSWINDOW: 3600 * 24 * 7 // a week
},
DSEN_P: 1.2 // dSen proportional factor
......
......@@ -34,6 +34,7 @@ function ConfDAL(rootPath, qioFS, parentCore, localDAL, AbstractStorage) {
"sigValidity": parseInt(conf.sigValidity,10),
"sigQty": parseInt(conf.sigQty,10),
"idtyWindow": parseInt(conf.idtyWindow,10),
"msWindow": parseInt(conf.msWindow,10),
"xpercent": parseFloat(conf.xpercent,10),
"msValidity": parseInt(conf.msValidity,10),
"stepMax": parseInt(3,10), // uCoin only handles 3 step currencies for now
......
......@@ -249,6 +249,25 @@ rules.FUNCTIONS = {
return true;
}),
checkMembershipsAreWritable: (block, conf, dal) => co(function *() {
let current = yield dal.getCurrent();
let fields = ['joiners', 'actives', 'leavers'];
for (let m = 0, len2 = fields.length; m < len2; m++) {
let field = fields[m];
for (let i = 0, len = block[field].length; i < len; i++) {
let ms = Membership.statics.fromInline(block[field][i]);
if (ms.block != constants.BLOCK.SPECIAL_BLOCK) {
let msBasedBlock = yield dal.getBlock(ms.block);
let age = current.medianTime - msBasedBlock.medianTime;
if (age > conf.msWindow) {
throw 'Too old membership';
}
}
}
}
return true;
}),
checkIdentityUnicity: (block, conf, dal) => co(function *() {
for (let i = 0, len = block.identities.length; i < len; i++) {
let idty = Identity.statics.fromInline(block.identities[i]);
......
......@@ -79,6 +79,7 @@ rules.ALIAS = {
yield rules.GLOBAL.checkIdentityUnicity(block, conf, dal);
yield rules.GLOBAL.checkPubkeyUnicity(block, conf, dal);
yield rules.GLOBAL.checkIdentitiesAreWritable(block, conf, dal);
yield rules.GLOBAL.checkMembershipsAreWritable(block, conf, dal);
yield rules.GLOBAL.checkJoiners(block, conf, dal);
yield rules.GLOBAL.checkJoinersHaveEnoughCertifications(block, conf, dal);
yield rules.GLOBAL.checkJoinersAreNotOudistanced(block, conf, dal);
......@@ -112,6 +113,7 @@ rules.ALIAS = {
yield rules.GLOBAL.checkIdentityUnicity(block, conf, dal);
yield rules.GLOBAL.checkPubkeyUnicity(block, conf, dal);
yield rules.GLOBAL.checkIdentitiesAreWritable(block, conf, dal);
yield rules.GLOBAL.checkMembershipsAreWritable(block, conf, dal);
yield rules.GLOBAL.checkJoiners(block, conf, dal);
yield rules.GLOBAL.checkJoinersHaveEnoughCertifications(block, conf, dal);
yield rules.GLOBAL.checkJoinersAreNotOudistanced(block, conf, dal);
......
......@@ -23,6 +23,7 @@ dtos.Parameters = {
sigValidity: Number,
sigQty: Number,
idtyWindow: Number,
msWindow: Number,
xpercent: Number,
msValidity: Number,
stepMax: Number,
......
......@@ -158,6 +158,7 @@ var tasks = {
async.apply(simpleInteger, "Certification validity duration", "sigValidity", conf),
async.apply(simpleInteger, "Number of valid certifications required to be a member", "sigQty", conf),
async.apply(simpleInteger, "Maximum age of a non-written identity", "idtyWindow", conf),
async.apply(simpleInteger, "Maximum age of a non-written membership", "msWindow", conf),
async.apply(simpleFloat, "Percentage of sentries to be reached to match WoT distance rule", "xpercent", conf),
async.apply(simpleInteger, "Membership validity duration", "msValidity", conf),
async.apply(simpleInteger, "Number of blocks on which is computed median time", "medianTimeBlocks", conf),
......
......@@ -418,15 +418,16 @@ function BlockchainService () {
theConf.sigWindow = parseInt(sp[5]);
theConf.sigValidity = parseInt(sp[6]);
theConf.sigQty = parseInt(sp[7]);
theConf.idtyWindow = parseFloat(sp[8]);
theConf.xpercent = parseFloat(sp[9]);
theConf.msValidity = parseInt(sp[10]);
theConf.stepMax = parseInt(sp[11]);
theConf.medianTimeBlocks = parseInt(sp[12]);
theConf.avgGenTime = parseInt(sp[13]);
theConf.dtDiffEval = parseInt(sp[14]);
theConf.blocksRot = parseInt(sp[15]);
theConf.percentRot = parseFloat(sp[16]);
theConf.idtyWindow = parseInt(sp[8]);
theConf.msWindow = parseInt(sp[9]);
theConf.xpercent = parseFloat(sp[10]);
theConf.msValidity = parseInt(sp[11]);
theConf.stepMax = parseInt(sp[12]);
theConf.medianTimeBlocks = parseInt(sp[13]);
theConf.avgGenTime = parseInt(sp[14]);
theConf.dtDiffEval = parseInt(sp[15]);
theConf.blocksRot = parseInt(sp[16]);
theConf.percentRot = parseFloat(sp[17]);
theConf.currency = block.currency;
return theConf;
}
......
......@@ -602,6 +602,7 @@ function commandLineConf(conf) {
sigStock: program.sigStock,
sigWindow: program.sigWindow,
idtyWindow: program.idtyWindow,
msWindow: program.msWindow,
sigValidity: program.sigValidity,
sigQty: program.sigQty,
msValidity: program.msValidity,
......@@ -639,6 +640,7 @@ function commandLineConf(conf) {
if (cli.ucp.sigStock) conf.sigStock = cli.ucp.sigStock;
if (cli.ucp.sigWindow) conf.sigWindow = cli.ucp.sigWindow;
if (cli.ucp.idtyWindow) conf.idtyWindow = cli.ucp.idtyWindow;
if (cli.ucp.msWindow) conf.msWindow = cli.ucp.msWindow;
if (cli.ucp.sigValidity) conf.sigValidity = cli.ucp.sigValidity;
if (cli.ucp.msValidity) conf.msValidity = cli.ucp.msValidity;
if (cli.ucp.sigQty) conf.sigQty = cli.ucp.sigQty;
......
......@@ -630,6 +630,7 @@ The synchronization parameters.
sigValidity: 2629800,
sigQty: 3,
idtyWindow: 604800,
msWindow: 604800,
xpercent: 5,
msValidity: 2629800,
stepMax: 3,
......
......@@ -822,7 +822,7 @@ To be a valid, a block must match the following rules:
* `Transactions` is a multiline field composed of [compact transactions](#compact-format)
* `Parameters` is a simple line field, composed of 1 float, 12 integers and 1 last float all separated by a colon `:`, and representing [currency parameters](#protocol-parameters) (a.k.a Protocol parameters, but valued for a given currency) :
c:dt:ud0:sigPeriod:sigStock:sigWindow:sigValidity:sigQty:idtyWindow:xpercent:msValidity:stepMax:medianTimeBlocks:avgGenTime:dtDiffEval:blocksRot:percentRot
c:dt:ud0:sigPeriod:sigStock:sigWindow:sigValidity:sigQty:idtyWindow:msWindow:xpercent:msValidity:stepMax:medianTimeBlocks:avgGenTime:dtDiffEval:blocksRot:percentRot
The document must be ended with a `BOTTOM_SIGNATURE` [Signature](#signature).
......@@ -925,6 +925,7 @@ sigWindow | Maximum delay a certification can wait before being expired for no
sigValidity | Maximum age of a active signature (in seconds)
sigQty | Minimum quantity of signatures to be part of the WoT
idtyWindow | Maximum delay an identity can wait before being expired for non-writing.
msWindow | Maximum delay a membership can wait before being expired for non-writing.
xpercent | Minimum percent of sentries to reach to match the distance rule
msValidity | Maximum age of an active membership (in seconds)
stepMax | Maximum distance between each WoT member and a newcomer
......@@ -1081,6 +1082,12 @@ An identity is to be considered *non-writable* if its age is less or equal to `[
VALID = AGE <= [idtyWindow]
EXPIRED = AGE > [idtyWindow]
###### Membership writability
A membership is to be considered *non-writable* if its age is less or equal to `[msWindow]`:
VALID = AGE <= [msWindow]
EXPIRED = AGE > [msWindow]
###### Certification writability
A certification is to be considered *non-writable* if its age is less or equal to `[sigWindow]`:
......
......@@ -81,6 +81,7 @@ function Server (dbConf, overrideConf) {
msValidity: constants.CONTRACT.DEFAULT.MSVALIDITY,
sigQty: constants.CONTRACT.DEFAULT.SIGQTY,
idtyWindow: constants.CONTRACT.DEFAULT.IDTYWINDOW,
msWindow: constants.CONTRACT.DEFAULT.MSWINDOW,
xpercent: constants.CONTRACT.DEFAULT.X_PERCENT,
percentRot: constants.CONTRACT.DEFAULT.PERCENTROT,
blocksRot: constants.CONTRACT.DEFAULT.BLOCKSROT,
......
......@@ -39,31 +39,31 @@ module.exports = {
"Currency: bb\n" +
"Number: 0\n" +
"PoWMin: 0\n" +
"Time: 1458828976\n" +
"MedianTime: 1458828976\n" +
"Time: 1458831706\n" +
"MedianTime: 1458831706\n" +
"Issuer: HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd\n" +
"Parameters: 0.007376575:2629800:100:0:40:604800:31536000:1:604800:0.9:31536000:3:20:960:10:20:0.6666666666666666\n" +
"Parameters: 0.007376575:2629800:100:0:40:604800:31536000:1:604800:604800:0.9:31536000:3:20:960:10:20:0.6666666666666666\n" +
"MembersCount: 3\n" +
"Identities:\n" +
"HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd:5PmGBvNj8AZ1T75Fe1rDLKy8lygwTFbrSwLYfMZS8eASxig5uHxx7P9l/hVgjIx7byPAkAsmrZIbYp/DEdnnDA==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:cat\n" +
"DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV:/FZ6zVzAw0qZ9qD67CesQTRSp5glmooF37Dxs6kRHOOGZnh4ICykG07/FB76Z3C4H9tq1Qq5Hwbxw96+9Qj1CA==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:tic\n" +
"DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo:bQAaenbeQk89bcKHHi7XsJGyo3mOZXNIphFqSjcJxp/a85k9vOF+yS4T18ZYV3rShI2QV6W7JlLPc4q+YdWhDw==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:toc\n" +
"Joiners:\n" +
"DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo:RkJsHDZdz++fFjr7+Qfv0pkSsTxkpD0TKW410XXVCNrPqHOPMaPVGauy6f1V0LuzVOJIRYPhDVekQLIcyEbjDw==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:toc\n" +
"HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd:ICfYCQvs33HQhusMRswIFljGRjUIcmZPu+pt9qTcGEUf8/wZlIbiY/dwV6RUa4tI6TbvGcg2HUlmKLhFg9AKBQ==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:cat\n" +
"DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV:njph4Y7Kn6vmycTp/rJplRj7PZVFiXv7YjZlC3mrSyXzvQNtX4JFAwXivsRDL6HcWnDesBqwEdrDAmiD28DNDQ==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:tic\n" +
"DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo:RkJsHDZdz++fFjr7+Qfv0pkSsTxkpD0TKW410XXVCNrPqHOPMaPVGauy6f1V0LuzVOJIRYPhDVekQLIcyEbjDw==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:toc\n" +
"Actives:\n" +
"Leavers:\n" +
"Revoked:\n" +
"Excluded:\n" +
"Certifications:\n" +
"HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd:DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo:0:X8P6NZNWq9qTmobhoFB4ITrSZQbEqAxkPt2wRpXC8JVniP3LvQi1h8DyiRvE6SbF1pyUsgRHiVKq1iB32YAGAA==\n" +
"DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo:HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd:0:BXksBR6BU3b694HuLoyUzoDd5xjdaJfYOY4EO7xSD/UkktW5oKy709RL/nCHY5vfPA0HrwPyi8vXAVKNzmGUCQ==\n" +
"HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd:DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV:0:CStF7zf3SShRaW+E3YlU7iJNlMt78m/DDn2eoZZNfHLMwd0hqkBmjQWdVKcnJS3oHqiiFCnVIRAbF03cDlafCA==\n" +
"HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd:DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo:0:X8P6NZNWq9qTmobhoFB4ITrSZQbEqAxkPt2wRpXC8JVniP3LvQi1h8DyiRvE6SbF1pyUsgRHiVKq1iB32YAGAA==\n" +
"Transactions:\n" +
"InnerHash: C88A6F36959002E64ECA3612B4E2BE5350FE845204F0B49BFE59ABA666AF0FC3\n" +
"InnerHash: F737136314618CCB94C41F66EB464CBDA89BD30BB7B346ACCB99C22F75F6B986\n" +
"Nonce: 1\n" +
"+iDt5V9pGg6OI9qfeUh9fgsoZgsgRO/uHjz4jaKPU72xK9hoAL8NH+SrMsfD2m0yweJh8gQV4k1nPDEBrHs2Aw==\n",
"Rj8FJ2Cr2XUVcfzdIpRqbBr0/tqOhZmjrgweKAkAPVN915Lj/LT4QZc8WJ80dmb4a15UXwoWphBMfrAJ+o88CQ==\n",
WRONG_PROOF_OF_WORK:
"Version: 2\n" +
......@@ -120,7 +120,7 @@ module.exports = {
"Time: 1411776000\n" +
"MedianTime: 1411776000\n" +
"Issuer: HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd\n" +
"Parameters: 0.7376575:100:157680000:0:40:7200:31536000:1:1000:0.9:31536000:3:1:60:10:20:0.67\n" +
"Parameters: 0.7376575:100:157680000:0:40:7200:31536000:1:1000:1000:0.9:31536000:3:1:60:10:20:0.67\n" +
"MembersCount: 3\n" +
"Identities:\n" +
"Joiners:\n" +
......
......@@ -18,7 +18,7 @@ var expectHttpCode = httpTest.expectHttpCode;
let WebSocket = require('ws');
// require('../../app/lib/logger')().mute();
require('../../app/lib/logger')().mute();
var MEMORY_MODE = true;
var commonConf = {
......
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