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

udid2 format no more active by default - may be activated through --udid2 option

parent 47a700a3
No related branches found
No related tags found
No related merge requests found
var META_TS = "META:TS:[1-9][0-9]*";
var UDID2 = "udid2;c;([A-Z-]*);([A-Z-]*);(\\d{4}-\\d{2}-\\d{2});(e\\+\\d{2}\\.\\d{2}(\\+|-)\\d{3}\\.\\d{2});(\\d+)(;?)";
var USER_ID = "[^: ]*";
var BASE58 = "[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+";
var PUBKEY = "[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{43,44}";
var TIMESTAMP = "[1-9][0-9]*";
......@@ -20,13 +21,14 @@ module.exports = {
INTEGER: /^\d+$/,
TIMESTAMP: exact(TIMESTAMP),
USER_ID: exact(USER_ID), // Any format, by default
UDID2_FORMAT: exact(UDID2),
BASE58: exact(BASE58),
PUBLIC_KEY: exact(PUBKEY),
SIG: exact(SIGNATURE),
CERT: {
SELF: {
UID: exact("UID:" + UDID2),
UID: exact("UID:" + USER_ID),
META: exact(META_TS)
},
OTHER: {
......@@ -35,7 +37,7 @@ module.exports = {
}
},
IDENTITY: {
INLINE: exact(PUBKEY + ":" + SIGNATURE + ":" + TIMESTAMP + ":" + UDID2)
INLINE: exact(PUBKEY + ":" + SIGNATURE + ":" + TIMESTAMP + ":" + USER_ID)
},
BLOCK: {
JOINER: exact(PUBKEY + ":" + SIGNATURE + ":" + TIMESTAMP),
......
......@@ -64,7 +64,7 @@ function IdentityParser (onError) {
return "No pubkey found";
}
if (!obj.uid) {
return "Cannot extract udid2";
return "Wrong user id format";
}
if (!obj.time) {
return "Cannot extract signature time";
......
......@@ -56,7 +56,7 @@ function MembershipParser (onError) {
err = {code: codes['BAD_DATE'], message: "Incorrect Date field: must be a positive or zero integer"};
}
if(!err){
if(obj.userid && !obj.userid.match(constants.UDID2_FORMAT))
if(obj.userid && !obj.userid.match(constants.USER_ID))
err = {code: codes['BAD_USERID'], message: "UserID must match udid2 format"};
}
if(!err){
......
......@@ -26,6 +26,7 @@ var ConfigurationSchema = new Schema({
powDelay: {"type": Number, "default": 0}, // Delay before starting computation of a new block
participate: {"type": Boolean, "default": true}, // Participate to writing the keychain
tsInterval: {"type": Number, "default": 30},
udid2: {"type": Boolean, "default": false},
});
ConfigurationSchema.virtual('createNext').get(function () {
......
......@@ -14,6 +14,7 @@ var logger = require('../app/lib/logger')('ucoind');
var signature = require('../app/lib/signature');
var crypto = require('../app/lib/crypto');
var base58 = require('../app/lib/base58');
var constants = require('../app/lib/constants');
var ucoin = require('./..');
function keys (val) {
......@@ -52,6 +53,7 @@ program
.option('--growth <number>', 'Universal Dividend %growth. Aka. \'c\' parameter in RMT')
.option('--ud0 <number>', 'Universal Dividend initial value')
.option('--dt <number>', 'Number of seconds between two UD')
.option('--udid2', 'Enable udid2 format for user id')
;
program
......@@ -412,6 +414,11 @@ program
.description('Start uCoin server using given --currency')
.action(service(ucoin.createPeerServer, function (server, conf) {
if (conf.udid2) {
// UserID must match udid2 format
constants.USER_ID = constants.UDID2_FORMAT;
}
// server
// .pipe(router(server.PeeringService.cert.fingerprint, server.conn))
// .pipe(multicaster());
......@@ -491,7 +498,8 @@ function overrideConf(conf) {
tsInterval: program.tsInterval,
ud0: program.ud0,
c: program.growth,
dt: program.dt
dt: program.dt,
udid2: program.udid2
}
};
......@@ -519,6 +527,7 @@ function overrideConf(conf) {
if (cli.ucp.dt) conf.dt = cli.ucp.dt;
if (cli.ucp.c) conf.c = cli.ucp.c;
if (cli.ucp.ud0) conf.ud0 = cli.ucp.ud0;
if (cli.ucp.udid2) conf.udid2 = cli.ucp.udid2;
// Specific internal settings
conf.createNext = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment