From 988cf543b5439e46d1d0b7911e9689c4d28f50fc Mon Sep 17 00:00:00 2001 From: librelois Date: Fri, 13 Oct 2017 16:32:59 +0200 Subject: [PATCH 01/72] [mod] add more typage in some tests --- app/lib/dto/ConfDTO.ts | 19 +++++++------- test/integration/documents-currency.ts | 36 ++++++++++++++------------ test/integration/server-shutdown.ts | 4 ++- test/integration/tools/toolbox.ts | 8 +++--- 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/app/lib/dto/ConfDTO.ts b/app/lib/dto/ConfDTO.ts index 361eb49c..7c0339f0 100644 --- a/app/lib/dto/ConfDTO.ts +++ b/app/lib/dto/ConfDTO.ts @@ -61,9 +61,9 @@ export interface NetworkConfDTO { export interface WS2PConfDTO { ws2p?: { - privateAccess: boolean - publicAccess: boolean - uuid: string + privateAccess?: boolean + publicAccess?: boolean + uuid?: string upnp?: boolean remotehost?: string|null remoteport?: number|null @@ -135,9 +135,9 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, public memory: boolean, public nobma: boolean, public ws2p?: { - privateAccess: boolean - publicAccess: boolean - uuid: string + privateAccess?: boolean + publicAccess?: boolean + uuid?: string upnp?: boolean remotehost?: string|null remoteport?: number|null @@ -156,7 +156,8 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, } static defaultConf() { - return { + return new ConfDTO("", "", [], [], 0, 3600 * 1000, constants.CONTRACT.DEFAULT.C, 1, 1, 0, 0, constants.CONTRACT.DEFAULT.C, constants.CONTRACT.DEFAULT.DT, constants.CONTRACT.DEFAULT.DT_REEVAL, 0, constants.CONTRACT.DEFAULT.UD0, 0, 0, constants.CONTRACT.DEFAULT.STEPMAX, constants.CONTRACT.DEFAULT.SIGPERIOD, 0, constants.CONTRACT.DEFAULT.SIGVALIDITY, constants.CONTRACT.DEFAULT.MSVALIDITY, constants.CONTRACT.DEFAULT.SIGQTY, constants.CONTRACT.DEFAULT.SIGSTOCK, constants.CONTRACT.DEFAULT.X_PERCENT, constants.CONTRACT.DEFAULT.PERCENTROT, constants.CONTRACT.DEFAULT.POWDELAY, constants.CONTRACT.DEFAULT.AVGGENTIME, constants.CONTRACT.DEFAULT.MEDIANTIMEBLOCKS, false, 3000, false, constants.BRANCHES.DEFAULT_WINDOW_SIZE, constants.CONTRACT.DEFAULT_IDTYWINDOW, constants.CONTRACT.DEFAULT.MSWINDOW, constants.CONTRACT.DEFAULT.SIGWINDOW, 0, { pub:'', sec:'' }, null, "", "", 0, "", "", "", 0, "", "", null, false, "", true, true) + /*return { "currency": null, "endpoints": [], "rmEndpoints": [], @@ -182,10 +183,10 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, "isolate": false, "forksize": constants.BRANCHES.DEFAULT_WINDOW_SIZE, "switchOnHeadAdvance": CommonConstants.SWITCH_ON_BRANCH_AHEAD_BY_X_BLOCKS - }; + };*/ } - static complete(conf:any) { + static complete(conf:ConfDTO) { return _(ConfDTO.defaultConf()).extend(conf); } } \ No newline at end of file diff --git a/test/integration/documents-currency.ts b/test/integration/documents-currency.ts index e18173af..370b96ab 100644 --- a/test/integration/documents-currency.ts +++ b/test/integration/documents-currency.ts @@ -1,30 +1,34 @@ -import {NewTestingServer} from "./tools/toolbox" +import { NewTestingServer, TestingServer } from './tools/toolbox'; +import { unlock } from '../../app/lib/common-libs/txunlock'; +import { ConfDTO, CurrencyConfDTO } from '../../app/lib/dto/ConfDTO'; +import { Server } from '../../server'; const co = require('co'); const should = require('should'); const user = require('./tools/user'); const commit = require('./tools/commit'); -let s1:any, s2:any, cat1:any, tac1:any, toc2:any, tic2:any; +let s1:TestingServer, s2:TestingServer, s1Conf:ConfDTO, s2Conf:ConfDTO, cat1:any, tac1:any, toc2:any, tic2:any; describe("Document pool currency", function() { before(() => co(function*() { - s1 = NewTestingServer({ - currency: 'currency_one', - pair: { - pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', - sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' - } - }); - s2 = NewTestingServer({ - currency: 'currency_two', - pair: { - pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', - sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' - } - }); + s1Conf = ConfDTO.defaultConf(); + s1Conf.currency = 'currency_one' + s1Conf.pair = { + pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', + sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' + } + s1 = NewTestingServer(s1Conf) + + s2Conf = ConfDTO.defaultConf(); + s2Conf.currency = 'currency_one' + s2Conf.pair = { + pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', + sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' + } + s2 = NewTestingServer(s2Conf); cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); diff --git a/test/integration/server-shutdown.ts b/test/integration/server-shutdown.ts index 854e20ea..48af2191 100644 --- a/test/integration/server-shutdown.ts +++ b/test/integration/server-shutdown.ts @@ -1,3 +1,5 @@ +import { ConfDTO } from '../../app/lib/dto/ConfDTO'; +import { setTimeout } from 'timers'; import {NewTestingServer} from "./tools/toolbox" const should = require('should') @@ -6,7 +8,7 @@ const querablep = require('querablep') describe("Server shutdown", () => { it('should not interrupt a task in the documents FIFO', async () => { - const s1 = NewTestingServer({}) + const s1 = NewTestingServer(ConfDTO.defaultConf()) const fifo = s1._server.getDocumentsFIFO() const ops:any[] = [] diff --git a/test/integration/tools/toolbox.ts b/test/integration/tools/toolbox.ts index fcf1e967..7b68c60a 100644 --- a/test/integration/tools/toolbox.ts +++ b/test/integration/tools/toolbox.ts @@ -218,11 +218,11 @@ export const fakeSyncServer = async (readBlocksMethod:any, readParticularBlockMe * Creates a new memory duniter server for Unit Test purposes. * @param conf */ -export const server = (conf:any) => NewTestingServer(conf) -export const simpleTestingServer = (conf:any) => NewTestingServer(conf) +export const server = (conf:ConfDTO) => NewTestingServer(conf) +export const simpleTestingServer = (conf:ConfDTO) => NewTestingServer(conf) -export const NewTestingServer = (conf:any) => { - const host = conf.host || HOST +export const NewTestingServer = (conf:ConfDTO) => { + const host = conf.remotehost || HOST const port = conf.port || PORT++ const commonConf = { nobma: false, -- GitLab From cb1b2abe00dfca87ffdd678e0044867491cc7f0f Mon Sep 17 00:00:00 2001 From: librelois Date: Fri, 13 Oct 2017 20:55:06 +0200 Subject: [PATCH 02/72] [mod] rename prover/Constants -> ProverConstants --- app/modules/prover/index.ts | 10 +++++----- app/modules/prover/lib/blockProver.ts | 4 ++-- app/modules/prover/lib/constants.ts | 2 +- app/modules/prover/lib/engine.ts | 4 ++-- app/modules/prover/lib/powCluster.ts | 4 ++-- app/modules/prover/lib/proof.ts | 10 +++++----- app/modules/ws2p/lib/WS2PCluster.ts | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/modules/prover/index.ts b/app/modules/prover/index.ts index 7bdd8346..a6016eaf 100644 --- a/app/modules/prover/index.ts +++ b/app/modules/prover/index.ts @@ -1,6 +1,6 @@ import {ConfDTO} from "../../lib/dto/ConfDTO" import {BlockGenerator, BlockGeneratorWhichProves} from "./lib/blockGenerator" -import {Constants} from "./lib/constants" +import {ProverConstants} from "./lib/constants" import {BlockProver} from "./lib/blockProver" import {Prover} from "./lib/prover" import {Contacter} from "../crawler/lib/contacter" @@ -19,13 +19,13 @@ export const ProverDependency = { config: { onLoading: async (conf:ConfDTO) => { if (conf.cpu === null || conf.cpu === undefined) { - conf.cpu = Constants.DEFAULT_CPU; + conf.cpu = ProverConstants.DEFAULT_CPU; } if (conf.prefix === null || conf.prefix === undefined) { - conf.prefix = Constants.DEFAULT_PEER_ID; + conf.prefix = ProverConstants.DEFAULT_PEER_ID; } - conf.powSecurityRetryDelay = Constants.POW_SECURITY_RETRY_DELAY; - conf.powMaxHandicap = Constants.POW_MAXIMUM_ACCEPTABLE_HANDICAP; + conf.powSecurityRetryDelay = ProverConstants.POW_SECURITY_RETRY_DELAY; + conf.powMaxHandicap = ProverConstants.POW_MAXIMUM_ACCEPTABLE_HANDICAP; }, beforeSave: async (conf:ConfDTO) => { delete conf.powSecurityRetryDelay; diff --git a/app/modules/prover/lib/blockProver.ts b/app/modules/prover/lib/blockProver.ts index 1c68518f..9cd215d9 100644 --- a/app/modules/prover/lib/blockProver.ts +++ b/app/modules/prover/lib/blockProver.ts @@ -1,4 +1,4 @@ -import {Constants} from "./constants" +import {ProverConstants} from "./constants" import {Server} from "../../../../server" import {PowEngine} from "./engine" import {DBBlock} from "../../../lib/db/DBBlock" @@ -165,7 +165,7 @@ export class BlockProver { // Start powFarm.setOnAlmostPoW((pow:any, matches:any, aBlock:any, found:boolean) => { this.powEvent(found, pow); - if (matches && matches[1].length >= Constants.MINIMAL_ZEROS_TO_SHOW_IN_LOGS) { + if (matches && matches[1].length >= ProverConstants.MINIMAL_ZEROS_TO_SHOW_IN_LOGS) { this.logger.info('Matched %s zeros %s with Nonce = %s for block#%s by %s', matches[1].length, pow, aBlock.nonce, aBlock.number, aBlock.issuer.slice(0,6)); } }); diff --git a/app/modules/prover/lib/constants.ts b/app/modules/prover/lib/constants.ts index 0602e7de..0a454d38 100644 --- a/app/modules/prover/lib/constants.ts +++ b/app/modules/prover/lib/constants.ts @@ -1,4 +1,4 @@ -export const Constants = { +export const ProverConstants = { CORES_MAXIMUM_USE_IN_PARALLEL: 8, diff --git a/app/modules/prover/lib/engine.ts b/app/modules/prover/lib/engine.ts index 12d2751d..2be351a9 100644 --- a/app/modules/prover/lib/engine.ts +++ b/app/modules/prover/lib/engine.ts @@ -1,4 +1,4 @@ -import {Constants} from "./constants" +import {ProverConstants} from "./constants" import {Master as PowCluster} from "./powCluster" import {ConfDTO} from "../../../lib/dto/ConfDTO" @@ -20,7 +20,7 @@ export class PowEngine { constructor(private conf:ConfDTO, logger:any) { // We use as much cores as available, but not more than CORES_MAXIMUM_USE_IN_PARALLEL - this.nbWorkers = (conf && conf.nbCores) || Math.min(Constants.CORES_MAXIMUM_USE_IN_PARALLEL, require('os').cpus().length) + this.nbWorkers = (conf && conf.nbCores) || Math.min(ProverConstants.CORES_MAXIMUM_USE_IN_PARALLEL, require('os').cpus().length) this.cluster = new PowCluster(this.nbWorkers, logger) this.id = this.cluster.clusterId } diff --git a/app/modules/prover/lib/powCluster.ts b/app/modules/prover/lib/powCluster.ts index 1e1a6ad3..4d482077 100644 --- a/app/modules/prover/lib/powCluster.ts +++ b/app/modules/prover/lib/powCluster.ts @@ -1,5 +1,5 @@ import {ConfDTO} from "../../../lib/dto/ConfDTO" -import {Constants} from "./constants" +import {ProverConstants} from "./constants" const _ = require('underscore') const nuuid = require('node-uuid'); @@ -84,7 +84,7 @@ export class Master { })(), // Each worker has his own chunk of possible nonces - nonceBeginning: this.nbCores === 1 ? 0 : (index + 1) * Constants.NONCE_RANGE + nonceBeginning: this.nbCores === 1 ? 0 : (index + 1) * ProverConstants.NONCE_RANGE } return this.slavesMap[worker.id] }) diff --git a/app/modules/prover/lib/proof.ts b/app/modules/prover/lib/proof.ts index cc60a584..9b15c0be 100644 --- a/app/modules/prover/lib/proof.ts +++ b/app/modules/prover/lib/proof.ts @@ -2,7 +2,7 @@ import {LOCAL_RULES_HELPERS} from "../../../lib/rules/local_rules" import {hashf} from "../../../lib/common" import {DBBlock} from "../../../lib/db/DBBlock" import {ConfDTO} from "../../../lib/dto/ConfDTO" -import {Constants} from "./constants" +import {ProverConstants} from "./constants" import {KeyGen} from "../../../lib/common-libs/crypto/keyring" import {dos2unix} from "../../../lib/common-libs/dos2unix" import {rawer} from "../../../lib/common-libs/index" @@ -84,10 +84,10 @@ function beginNewProofOfWork(stuff:any) { const nbZeros = stuff.zeros; const pair = stuff.pair; const forcedTime = stuff.forcedTime; - currentCPU = conf.cpu || Constants.DEFAULT_CPU; + currentCPU = conf.cpu || ProverConstants.DEFAULT_CPU; prefix = parseInt(conf.prefix || prefix) - if (prefix && prefix < Constants.NONCE_RANGE) { - prefix *= 100 * Constants.NONCE_RANGE + if (prefix && prefix < ProverConstants.NONCE_RANGE) { + prefix *= 100 * ProverConstants.NONCE_RANGE } const highMark = stuff.highMark; const turnDuration = stuff.turnDuration || TURN_DURATION_IN_MILLISEC @@ -184,7 +184,7 @@ function beginNewProofOfWork(stuff:any) { if (charOK) { found = !!(pow[nbZeros].match(new RegExp('[0-' + highMark + ']'))) } - if (!found && nbZeros > 0 && j - 1 >= Constants.POW_MINIMAL_TO_SHOW) { + if (!found && nbZeros > 0 && j - 1 >= ProverConstants.POW_MINIMAL_TO_SHOW) { pSend({ pow: { pow: pow, block: block, nbZeros: nbZeros }}); } diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 4c991070..766e83ee 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -15,7 +15,7 @@ import {WS2PServerMessageHandler} from "./interface/WS2PServerMessageHandler" import {WS2PMessageHandler} from "./impl/WS2PMessageHandler" import { CommonConstants } from "../../../lib/common-libs/constants"; import { Package } from "../../../lib/common/package"; -import { Constants } from "../../prover/lib/constants"; +import { ProverConstants } from "../../prover/lib/constants"; const es = require('event-stream') const nuuid = require('node-uuid') @@ -426,7 +426,7 @@ export class WS2PCluster { const software = 'duniter' const softVersion = Package.getInstance().version const ws2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) || '00000000' - const prefix = this.server.conf.prefix || Constants.DEFAULT_PEER_ID + const prefix = this.server.conf.prefix || ProverConstants.DEFAULT_PEER_ID const message = `WS2P:HEAD:1:${pub}:${number}-${hash}:${ws2pId}:${software}:${softVersion}:${prefix}` const sig = key.signSync(message) return { sig, message, pub } -- GitLab From a1c224907e9c8f0b929bef59aff032df53990840 Mon Sep 17 00:00:00 2001 From: librelois Date: Fri, 13 Oct 2017 20:55:48 +0200 Subject: [PATCH 03/72] [fix] ConfDTO typing errors --- app/lib/constants.ts | 7 ++++++- app/lib/dto/ConfDTO.ts | 7 ++++--- test/integration/documents-currency.ts | 29 +++++++++++++------------- test/integration/tools/toolbox.ts | 2 +- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/app/lib/constants.ts b/app/lib/constants.ts index cac2f7a0..3641d935 100644 --- a/app/lib/constants.ts +++ b/app/lib/constants.ts @@ -1,6 +1,7 @@ "use strict"; import {CommonConstants} from "./common-libs/constants" import {OtherConstants} from "./other_constants" +import { ProverConstants } from '../modules/prover/lib/constants'; const UDID2 = "udid2;c;([A-Z-]*);([A-Z-]*);(\\d{4}-\\d{2}-\\d{2});(e\\+\\d{2}\\.\\d{2}(\\+|-)\\d{3}\\.\\d{2});(\\d+)(;?)"; const PUBKEY = CommonConstants.FORMATS.PUBKEY @@ -113,7 +114,11 @@ module.exports = { }, PROOF_OF_WORK: { EVALUATION: 1000, - UPPER_BOUND: CommonConstants.PROOF_OF_WORK.UPPER_BOUND.slice() + UPPER_BOUND: CommonConstants.PROOF_OF_WORK.UPPER_BOUND.slice(), + DEFAULT: { + CPU: ProverConstants.DEFAULT_CPU, + PREFIX: ProverConstants.DEFAULT_PEER_ID + } }, DEFAULT_CURRENCY_NAME: "no_currency", diff --git a/app/lib/dto/ConfDTO.ts b/app/lib/dto/ConfDTO.ts index 7c0339f0..3c14e480 100644 --- a/app/lib/dto/ConfDTO.ts +++ b/app/lib/dto/ConfDTO.ts @@ -126,6 +126,7 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, public remotehost: string|null, public remoteipv4: string|null, public remoteipv6: string|null, + public host: string, public port: number, public ipv4: string, public ipv6: string, @@ -152,11 +153,11 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, ) {} static mock() { - return new ConfDTO("", "", [], [], 0, 0, 0.6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false, 0, false, 0, 0, 0, 0, 0, { pub:'', sec:'' }, null, "", "", 0, "", "", "", 0, "", "", null, false, "", true, true) + return new ConfDTO("", "", [], [], 0, 3600 * 1000, constants.PROOF_OF_WORK.DEFAULT.CPU, 1, constants.PROOF_OF_WORK.DEFAULT.PREFIX, 0, 0, constants.CONTRACT.DEFAULT.C, constants.CONTRACT.DEFAULT.DT, constants.CONTRACT.DEFAULT.DT_REEVAL, 0, constants.CONTRACT.DEFAULT.UD0, 0, 0, constants.CONTRACT.DEFAULT.STEPMAX, constants.CONTRACT.DEFAULT.SIGPERIOD, 0, constants.CONTRACT.DEFAULT.SIGVALIDITY, constants.CONTRACT.DEFAULT.MSVALIDITY, constants.CONTRACT.DEFAULT.SIGQTY, constants.CONTRACT.DEFAULT.SIGSTOCK, constants.CONTRACT.DEFAULT.X_PERCENT, constants.CONTRACT.DEFAULT.PERCENTROT, constants.CONTRACT.DEFAULT.POWDELAY, constants.CONTRACT.DEFAULT.AVGGENTIME, constants.CONTRACT.DEFAULT.MEDIANTIMEBLOCKS, false, 3000, false, constants.BRANCHES.DEFAULT_WINDOW_SIZE, constants.CONTRACT.DEFAULT.IDTYWINDOW, constants.CONTRACT.DEFAULT.MSWINDOW, constants.CONTRACT.DEFAULT.SIGWINDOW, 0, { pub:'', sec:'' }, null, "", "", 0, "", "", "", "", 0, "", "", null, false, "", true, true) } static defaultConf() { - return new ConfDTO("", "", [], [], 0, 3600 * 1000, constants.CONTRACT.DEFAULT.C, 1, 1, 0, 0, constants.CONTRACT.DEFAULT.C, constants.CONTRACT.DEFAULT.DT, constants.CONTRACT.DEFAULT.DT_REEVAL, 0, constants.CONTRACT.DEFAULT.UD0, 0, 0, constants.CONTRACT.DEFAULT.STEPMAX, constants.CONTRACT.DEFAULT.SIGPERIOD, 0, constants.CONTRACT.DEFAULT.SIGVALIDITY, constants.CONTRACT.DEFAULT.MSVALIDITY, constants.CONTRACT.DEFAULT.SIGQTY, constants.CONTRACT.DEFAULT.SIGSTOCK, constants.CONTRACT.DEFAULT.X_PERCENT, constants.CONTRACT.DEFAULT.PERCENTROT, constants.CONTRACT.DEFAULT.POWDELAY, constants.CONTRACT.DEFAULT.AVGGENTIME, constants.CONTRACT.DEFAULT.MEDIANTIMEBLOCKS, false, 3000, false, constants.BRANCHES.DEFAULT_WINDOW_SIZE, constants.CONTRACT.DEFAULT_IDTYWINDOW, constants.CONTRACT.DEFAULT.MSWINDOW, constants.CONTRACT.DEFAULT.SIGWINDOW, 0, { pub:'', sec:'' }, null, "", "", 0, "", "", "", 0, "", "", null, false, "", true, true) + return new ConfDTO("", "", [], [], 0, 3600 * 1000, constants.PROOF_OF_WORK.DEFAULT.CPU, 1, constants.PROOF_OF_WORK.DEFAULT.PREFIX, 0, 0, constants.CONTRACT.DEFAULT.C, constants.CONTRACT.DEFAULT.DT, constants.CONTRACT.DEFAULT.DT_REEVAL, 0, constants.CONTRACT.DEFAULT.UD0, 0, 0, constants.CONTRACT.DEFAULT.STEPMAX, constants.CONTRACT.DEFAULT.SIGPERIOD, 0, constants.CONTRACT.DEFAULT.SIGVALIDITY, constants.CONTRACT.DEFAULT.MSVALIDITY, constants.CONTRACT.DEFAULT.SIGQTY, constants.CONTRACT.DEFAULT.SIGSTOCK, constants.CONTRACT.DEFAULT.X_PERCENT, constants.CONTRACT.DEFAULT.PERCENTROT, constants.CONTRACT.DEFAULT.POWDELAY, constants.CONTRACT.DEFAULT.AVGGENTIME, constants.CONTRACT.DEFAULT.MEDIANTIMEBLOCKS, false, 3000, false, constants.BRANCHES.DEFAULT_WINDOW_SIZE, constants.CONTRACT.DEFAULT.IDTYWINDOW, constants.CONTRACT.DEFAULT.MSWINDOW, constants.CONTRACT.DEFAULT.SIGWINDOW, 0, { pub:'', sec:'' }, null, "", "", 0, "", "", "", "", 0, "", "", null, false, "", true, true) /*return { "currency": null, "endpoints": [], @@ -186,7 +187,7 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, };*/ } - static complete(conf:ConfDTO) { + static complete(conf:any) { return _(ConfDTO.defaultConf()).extend(conf); } } \ No newline at end of file diff --git a/test/integration/documents-currency.ts b/test/integration/documents-currency.ts index 370b96ab..36c5e767 100644 --- a/test/integration/documents-currency.ts +++ b/test/integration/documents-currency.ts @@ -14,21 +14,20 @@ describe("Document pool currency", function() { before(() => co(function*() { - s1Conf = ConfDTO.defaultConf(); - s1Conf.currency = 'currency_one' - s1Conf.pair = { - pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', - sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' - } - s1 = NewTestingServer(s1Conf) - - s2Conf = ConfDTO.defaultConf(); - s2Conf.currency = 'currency_one' - s2Conf.pair = { - pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', - sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' - } - s2 = NewTestingServer(s2Conf); + s1 = NewTestingServer(ConfDTO.complete({ + currency: 'currency_one', + pair: { + pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', + sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' + } + })); + s2 = NewTestingServer(ConfDTO.complete({ + currency: 'currency_two', + pair: { + pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', + sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' + } + })); cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); diff --git a/test/integration/tools/toolbox.ts b/test/integration/tools/toolbox.ts index 7b68c60a..a9e1249a 100644 --- a/test/integration/tools/toolbox.ts +++ b/test/integration/tools/toolbox.ts @@ -222,7 +222,7 @@ export const server = (conf:ConfDTO) => NewTestingServer(conf) export const simpleTestingServer = (conf:ConfDTO) => NewTestingServer(conf) export const NewTestingServer = (conf:ConfDTO) => { - const host = conf.remotehost || HOST + const host = conf.host || HOST const port = conf.port || PORT++ const commonConf = { nobma: false, -- GitLab From ba478e8351e591866b73604f6fc2363a5428127d Mon Sep 17 00:00:00 2001 From: librelois Date: Fri, 13 Oct 2017 20:56:17 +0200 Subject: [PATCH 04/72] rename ProverConstants --- index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index 3c6b04bc..97b9f681 100644 --- a/index.ts +++ b/index.ts @@ -7,7 +7,7 @@ import {KeypairDependency} from "./app/modules/keypair/index" import {CrawlerDependency} from "./app/modules/crawler/index" import {BmaDependency} from "./app/modules/bma/index" import {WS2PDependency} from "./app/modules/ws2p/index" -import {Constants} from "./app/modules/prover/lib/constants" +import {ProverConstants} from "./app/modules/prover/lib/constants" const path = require('path'); const _ = require('underscore'); @@ -469,7 +469,7 @@ function commandLineConf(program:any, conf:any = {}) { if (cli.currency) conf.currency = cli.currency; if (cli.server.port) conf.port = cli.server.port; if (cli.cpu) conf.cpu = Math.max(0.01, Math.min(1.0, cli.cpu)); - if (cli.prefix) conf.prefix = Math.max(Constants.MIN_PEER_ID, Math.min(Constants.MAX_PEER_ID, cli.prefix)); + if (cli.prefix) conf.prefix = Math.max(ProverConstants.MIN_PEER_ID, Math.min(ProverConstants.MAX_PEER_ID, cli.prefix)); if (cli.logs.http) conf.httplogs = true; if (cli.logs.nohttp) conf.httplogs = false; if (cli.db.mport) conf.mport = cli.db.mport; -- GitLab From 314c83fd900649d61b77b2e97cc00b9f0060d0fc Mon Sep 17 00:00:00 2001 From: librelois Date: Fri, 13 Oct 2017 22:01:14 +0200 Subject: [PATCH 05/72] [typage] create type sandboxDocument --- app/lib/dal/fileDAL.ts | 2 +- app/lib/dal/sqliteDAL/CertDAL.ts | 4 ++-- app/lib/dal/sqliteDAL/IdentityDAL.ts | 4 ++-- app/lib/dal/sqliteDAL/MembershipDAL.ts | 4 ++-- app/lib/dal/sqliteDAL/SandBox.ts | 10 +++++++--- app/lib/dal/sqliteDAL/TxsDAL.ts | 5 ++--- app/service/IdentityService.ts | 1 + app/service/MembershipService.ts | 1 + app/service/TransactionsService.ts | 2 +- 9 files changed, 19 insertions(+), 14 deletions(-) diff --git a/app/lib/dal/fileDAL.ts b/app/lib/dal/fileDAL.ts index 6281d83f..43f4952c 100644 --- a/app/lib/dal/fileDAL.ts +++ b/app/lib/dal/fileDAL.ts @@ -754,7 +754,7 @@ export class FileDAL { } saveTransaction(tx:DBTx) { - return this.txsDAL.addPending(TransactionDTO.fromJSONObject(tx)) + return this.txsDAL.addPending(tx) } async getTransactionsHistory(pubkey:string) { diff --git a/app/lib/dal/sqliteDAL/CertDAL.ts b/app/lib/dal/sqliteDAL/CertDAL.ts index d854ef16..0efb58f2 100644 --- a/app/lib/dal/sqliteDAL/CertDAL.ts +++ b/app/lib/dal/sqliteDAL/CertDAL.ts @@ -1,10 +1,10 @@ import {SQLiteDriver} from "../drivers/SQLiteDriver" import {AbstractSQLite} from "./AbstractSQLite" -import {SandBox} from "./SandBox" +import { SandBox, sandboxDocument } from './SandBox'; const constants = require('../../constants'); -export interface DBCert { +export interface DBCert extends sandboxDocument { linked:boolean written:boolean written_block:null diff --git a/app/lib/dal/sqliteDAL/IdentityDAL.ts b/app/lib/dal/sqliteDAL/IdentityDAL.ts index c23f6be9..1445fb35 100644 --- a/app/lib/dal/sqliteDAL/IdentityDAL.ts +++ b/app/lib/dal/sqliteDAL/IdentityDAL.ts @@ -1,6 +1,6 @@ import {AbstractSQLite} from "./AbstractSQLite" import {SQLiteDriver} from "../drivers/SQLiteDriver" -import {SandBox} from "./SandBox" +import { SandBox, sandboxDocument } from './SandBox'; import {IdentityDTO} from "../../dto/IdentityDTO" import {Cloneable} from "../../dto/Cloneable"; const constants = require('../../constants'); @@ -143,7 +143,7 @@ export class ExistingDBIdentity extends DBIdentity { } } -export interface DBSandboxIdentity extends DBIdentity { +export interface DBSandboxIdentity extends DBIdentity,sandboxDocument { certsCount: number ref_block: number } diff --git a/app/lib/dal/sqliteDAL/MembershipDAL.ts b/app/lib/dal/sqliteDAL/MembershipDAL.ts index 61ce346e..41557cf8 100644 --- a/app/lib/dal/sqliteDAL/MembershipDAL.ts +++ b/app/lib/dal/sqliteDAL/MembershipDAL.ts @@ -1,10 +1,10 @@ import {SQLiteDriver} from "../drivers/SQLiteDriver"; import {AbstractSQLite} from "./AbstractSQLite"; -import {SandBox} from "./SandBox"; +import { SandBox, sandboxDocument } from './SandBox'; const _ = require('underscore'); const constants = require('../../constants'); -export interface DBMembership { +export interface DBMembership extends sandboxDocument { membership: string issuer: string number: number diff --git a/app/lib/dal/sqliteDAL/SandBox.ts b/app/lib/dal/sqliteDAL/SandBox.ts index c84f9a87..48d736dc 100644 --- a/app/lib/dal/sqliteDAL/SandBox.ts +++ b/app/lib/dal/sqliteDAL/SandBox.ts @@ -1,4 +1,8 @@ -export class SandBox { +export interface sandboxDocument { + issuers: string[]; +} + +export class SandBox { maxSize:number @@ -10,8 +14,8 @@ export class SandBox { this.maxSize = maxSize || 10 } - async acceptNewSandBoxEntry(element:any, pubkey:string) { - if (element.pubkey === pubkey) { + async acceptNewSandBoxEntry(element:T, pubkey:string) { + if (element.issuers.indexOf(pubkey) !== -1) { return true; } const elements = await this.findElements() diff --git a/app/lib/dal/sqliteDAL/TxsDAL.ts b/app/lib/dal/sqliteDAL/TxsDAL.ts index b6330cb9..204ae827 100644 --- a/app/lib/dal/sqliteDAL/TxsDAL.ts +++ b/app/lib/dal/sqliteDAL/TxsDAL.ts @@ -169,12 +169,11 @@ export class TxsDAL extends AbstractSQLite { return this.saveEntity(dbTx) } - addPending(tx:TransactionDTO) { - const dbTx = DBTx.fromTransactionDTO(tx) + addPending(dbTx:DBTx) { dbTx.received = moment().unix() dbTx.written = false dbTx.removed = false - dbTx.hash = tx.getHash() + //dbTx.hash = tx.getHash() return this.saveEntity(dbTx) } diff --git a/app/service/IdentityService.ts b/app/service/IdentityService.ts index 81288451..7dc41224 100644 --- a/app/service/IdentityService.ts +++ b/app/service/IdentityService.ts @@ -166,6 +166,7 @@ export class IdentityService extends FIFOService { }; } const mCert:DBCert = { + issuers: [cert.from], from: cert.from, sig: cert.sig, block_number: cert.block_number, diff --git a/app/service/MembershipService.ts b/app/service/MembershipService.ts index fd27d3d2..5612493d 100644 --- a/app/service/MembershipService.ts +++ b/app/service/MembershipService.ts @@ -63,6 +63,7 @@ export class MembershipService extends FIFOService { } // Saves entry await this.dal.savePendingMembership({ + issuers: [entry.issuer], membership: entry.membership, issuer: entry.issuer, number: entry.number, diff --git a/app/service/TransactionsService.ts b/app/service/TransactionsService.ts index ab144b24..e6ddf126 100644 --- a/app/service/TransactionsService.ts +++ b/app/service/TransactionsService.ts @@ -46,7 +46,7 @@ export class TransactionService extends FIFOService { await GLOBAL_RULES_HELPERS.checkSingleTransaction(dto, nextBlockWithFakeTimeVariation, this.conf, this.dal, CHECK_PENDING_TRANSACTIONS); const server_pubkey = this.conf.pair && this.conf.pair.pub; if (!(await this.dal.txsDAL.sandbox.acceptNewSandBoxEntry({ - pubkey: tx.issuers.indexOf(server_pubkey) !== -1 ? server_pubkey : '', + issuers: tx.issuers, output_base: tx.output_base, output_amount: tx.output_amount }, server_pubkey))) { -- GitLab From 88172f5357cd0d8d43f60a4878e6d5da6c4aa0eb Mon Sep 17 00:00:00 2001 From: librelois Date: Fri, 13 Oct 2017 22:06:42 +0200 Subject: [PATCH 06/72] [fix] ProverConstant incomplete renaming --- test/integration/branches_revert2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/branches_revert2.js b/test/integration/branches_revert2.js index 9800c3ad..4d5d38a3 100644 --- a/test/integration/branches_revert2.js +++ b/test/integration/branches_revert2.js @@ -10,7 +10,7 @@ const httpTest = require('./tools/http'); const commit = require('./tools/commit'); const shutDownEngine = require('./tools/shutDownEngine'); -require('../../app/modules/prover/lib/constants').Constants.CORES_MAXIMUM_USE_IN_PARALLEL = 1 +require('../../app/modules/prover/lib/constants').ProverConstants.CORES_MAXIMUM_USE_IN_PARALLEL = 1 require('../../app/modules/bma').BmaDependency.duniter.methods.noLimit(); // Disables the HTTP limiter const expectJSON = httpTest.expectJSON; -- GitLab From 813fc1a3e016163ad57aeac1b30430bbb31cf761 Mon Sep 17 00:00:00 2001 From: librelois Date: Fri, 13 Oct 2017 22:22:22 +0200 Subject: [PATCH 07/72] [fix] ProverConstant incomplete renaming --- test/integration/http_api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/http_api.js b/test/integration/http_api.js index 43e8733a..3e3bab9f 100644 --- a/test/integration/http_api.js +++ b/test/integration/http_api.js @@ -13,7 +13,7 @@ const shutDownEngine = require('./tools/shutDownEngine'); const rp = require('request-promise'); const ws = require('ws'); -require('../../app/modules/prover/lib/constants').Constants.CORES_MAXIMUM_USE_IN_PARALLEL = 1 +require('../../app/modules/prover/lib/constants').ProverConstants.CORES_MAXIMUM_USE_IN_PARALLEL = 1 let server, server2, cat, toc -- GitLab From e322fa4a91566e764eb98e99e7b71bf3976661a6 Mon Sep 17 00:00:00 2001 From: librelois Date: Sat, 14 Oct 2017 00:08:29 +0200 Subject: [PATCH 08/72] update yarn.lock --- yarn.lock | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/yarn.lock b/yarn.lock index 1eb4771b..e31a5cf3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -51,6 +51,10 @@ acorn@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.1.1.tgz#53fe161111f912ab999ee887a90a0bc52822fd75" +adm-zip@0.4.7: + version "0.4.7" + resolved "https://registry.yarnpkg.com/adm-zip/-/adm-zip-0.4.7.tgz#8606c2cbf1c426ce8c8ec00174447fd49b6eafc1" + ajv-keywords@^1.0.0: version "1.5.1" resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-1.5.1.tgz#314dd0a4b3368fad3dfcdc54ede6171b886daf3c" @@ -902,6 +906,28 @@ doctrine@^1.2.2: esutils "^2.0.2" isarray "^1.0.0" +duniter-ui@^1.6.13: + version "1.6.13" + resolved "https://registry.yarnpkg.com/duniter-ui/-/duniter-ui-1.6.13.tgz#3f203152fc0e3e1cbae74c1a0353a620c82d72ee" + dependencies: + adm-zip "0.4.7" + body-parser "1.17.1" + co "4.6.0" + cors "2.8.2" + event-stream "3.3.4" + express "4.15.2" + express-fileupload "0.0.5" + fs-extra "2.1.2" + materialize-css "0.98.1" + moment "2.18.1" + node-pre-gyp "0.6.34" + q "1.5.0" + request "2.81.0" + request-promise "4.2.0" + rimraf "2.6.1" + tmp "0.0.31" + underscore "1.8.3" + duplexer@~0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1" @@ -1410,6 +1436,13 @@ from@~0: version "0.1.7" resolved "https://registry.yarnpkg.com/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe" +fs-extra@2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-2.1.2.tgz#046c70163cef9aad46b0e4a7fa467fb22d71de35" + dependencies: + graceful-fs "^4.1.2" + jsonfile "^2.1.0" + fs-extra@^0.22.1: version "0.22.1" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-0.22.1.tgz#5fd6f8049dc976ca19eb2355d658173cabcce056" @@ -1577,6 +1610,10 @@ growl@1.9.2: version "1.9.2" resolved "https://registry.yarnpkg.com/growl/-/growl-1.9.2.tgz#0ea7743715db8d8de2c5ede1775e1b45ac85c02f" +hammerjs@^2.0.4: + version "2.0.8" + resolved "https://registry.yarnpkg.com/hammerjs/-/hammerjs-2.0.8.tgz#04ef77862cff2bb79d30f7692095930222bf60f1" + handlebars@^4.0.3: version "4.0.10" resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.10.tgz#3d30c718b09a3d96f23ea4cc1f403c4d3ba9ff4f" @@ -1997,6 +2034,10 @@ jison@0.4.17: lex-parser "~0.1.3" nomnom "1.5.2" +jquery@^2.1.4: + version "2.2.4" + resolved "https://registry.yarnpkg.com/jquery/-/jquery-2.2.4.tgz#2c89d6889b5eac522a7eea32c14521559c6cbf02" + js-tokens@^3.0.0: version "3.0.2" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" @@ -2254,6 +2295,14 @@ map-stream@~0.1.0: buffers "~0.1.1" readable-stream "~1.0.0" +materialize-css@0.98.1: + version "0.98.1" + resolved "https://registry.yarnpkg.com/materialize-css/-/materialize-css-0.98.1.tgz#7276895b2c998b53e26deaa0c23a0484c0851d99" + dependencies: + hammerjs "^2.0.4" + jquery "^2.1.4" + node-archiver "^0.3.0" + md5-hex@^1.2.0: version "1.3.0" resolved "https://registry.yarnpkg.com/md5-hex/-/md5-hex-1.3.0.tgz#d2c4afe983c4370662179b8cad145219135046c4" @@ -2482,6 +2531,13 @@ nnupnp@1.0.2: request "2.10.0" xml2js "0.1.14" +node-archiver@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/node-archiver/-/node-archiver-0.3.0.tgz#b9f1afe5006d0bdf29260181833a070978bc6947" + dependencies: + fstream "^1.0.10" + tar "^2.2.1" + node-pre-gyp@0.6.23: version "0.6.23" resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.6.23.tgz#155bf3683abcfcde008aedab1248891a0773db95" @@ -2899,7 +2955,7 @@ q-io@1.13.2: qs "^1.2.1" url2 "^0.0.0" -q@^1.0.1: +q@1.5.0, q@^1.0.1: version "1.5.0" resolved "https://registry.yarnpkg.com/q/-/q-1.5.0.tgz#dd01bac9d06d30e6f219aecb8253ee9ebdc308f1" @@ -3204,7 +3260,7 @@ right-align@^0.1.1: dependencies: align-text "^0.1.1" -rimraf@2, rimraf@^2.2.8, rimraf@^2.3.3, rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1: +rimraf@2, rimraf@2.6.1, rimraf@^2.2.8, rimraf@^2.3.3, rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1: version "2.6.1" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.1.tgz#c2338ec643df7a1b7fe5c54fa86f57428a55f33d" dependencies: @@ -3311,7 +3367,7 @@ setprototypeof@1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.0.3.tgz#66567e37043eeb4f04d91bd658c0cbefb55b8e04" -sha1@: +sha1@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/sha1/-/sha1-1.1.1.tgz#addaa7a93168f393f19eb2b15091618e2700f848" dependencies: @@ -3714,7 +3770,7 @@ tmp@0.0.29: dependencies: os-tmpdir "~1.0.1" -tmp@^0.0.31: +tmp@0.0.31, tmp@^0.0.31: version "0.0.31" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.31.tgz#8f38ab9438e17315e5dbd8b3657e8bfb277ae4a7" dependencies: -- GitLab From 0c895de1ab39aeb5a7b39fc4b78414dabd00281e Mon Sep 17 00:00:00 2001 From: librelois Date: Sat, 14 Oct 2017 14:58:43 +0200 Subject: [PATCH 09/72] [mod] sandox change pubkey -> issuers[0] --- app/lib/dal/sqliteDAL/SandBox.ts | 2 +- app/service/IdentityService.ts | 4 ++-- app/service/MembershipService.ts | 4 ++-- test/dal/triming.js | 4 ---- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/lib/dal/sqliteDAL/SandBox.ts b/app/lib/dal/sqliteDAL/SandBox.ts index 48d736dc..bdf3c427 100644 --- a/app/lib/dal/sqliteDAL/SandBox.ts +++ b/app/lib/dal/sqliteDAL/SandBox.ts @@ -15,7 +15,7 @@ export class SandBox { } async acceptNewSandBoxEntry(element:T, pubkey:string) { - if (element.issuers.indexOf(pubkey) !== -1) { + if (element.issuers !== undefined && element.issuers.indexOf(pubkey) !== -1) { return true; } const elements = await this.findElements() diff --git a/app/service/IdentityService.ts b/app/service/IdentityService.ts index 7dc41224..e052aa29 100644 --- a/app/service/IdentityService.ts +++ b/app/service/IdentityService.ts @@ -115,7 +115,7 @@ export class IdentityService extends FIFOService { await GLOBAL_RULES_FUNCTIONS.checkIdentitiesAreWritable({ identities: [idtyObj.inline()], version: (current && current.version) || constants.BLOCK_GENERATED_VERSION }, this.conf, this.dal); if (byAbsorption !== BY_ABSORPTION) { if (!(await this.dal.idtyDAL.sandbox.acceptNewSandBoxEntry({ - pubkey: idty.pubkey, + issuers: [idty.pubkey], ref_block: parseInt(idty.buid.split('-')[0]) }, this.conf.pair && this.conf.pair.pub))) { throw constants.ERRORS.SANDBOX_FOR_IDENTITY_IS_FULL; @@ -240,7 +240,7 @@ export class IdentityService extends FIFOService { const idty = IdentityDTO.fromRevocation(revoc); idty.revocation_sig = revoc.revocation; if (!(await this.dal.idtyDAL.sandbox.acceptNewSandBoxEntry({ - pubkey: idty.pubkey, + issuers: [idty.pubkey], ref_block: parseInt(idty.buid.split('-')[0]), certsCount: 0 }, this.conf.pair && this.conf.pair.pub))) { diff --git a/app/service/MembershipService.ts b/app/service/MembershipService.ts index 5612493d..1cbb2d73 100644 --- a/app/service/MembershipService.ts +++ b/app/service/MembershipService.ts @@ -56,14 +56,14 @@ export class MembershipService extends FIFOService { const current = await this.dal.getCurrentBlockOrNull(); const basedBlock = await GLOBAL_RULES_HELPERS.checkMembershipBlock(entry, current, this.conf, this.dal); if (!(await this.dal.msDAL.sandbox.acceptNewSandBoxEntry({ - pubkey: entry.pubkey, + issuers: [entry.pubkey], block_number: entry.block_number }, this.conf.pair && this.conf.pair.pub))) { throw constants.ERRORS.SANDBOX_FOR_MEMERSHIP_IS_FULL; } // Saves entry await this.dal.savePendingMembership({ - issuers: [entry.issuer], + issuers: [entry.pubkey], membership: entry.membership, issuer: entry.issuer, number: entry.number, diff --git a/test/dal/triming.js b/test/dal/triming.js index db2c0cb8..501ec550 100644 --- a/test/dal/triming.js +++ b/test/dal/triming.js @@ -124,10 +124,6 @@ describe("Triming", function(){ it('should be able to trim the bindex', () => co(function *() { // Triming const server = (yield toolbox.simpleNodeWith2Users({ - pair: { - pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', - sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' - }, forksize: 9, sigQty: 1, dtDiffEval: 2, -- GitLab From 2a95620ca88e46b97c1b5e61b5fc2a1b2f827067 Mon Sep 17 00:00:00 2001 From: librelois Date: Sat, 14 Oct 2017 15:14:14 +0200 Subject: [PATCH 10/72] Uppercase sandboxDocument -> SandboxDocument --- app/lib/dal/sqliteDAL/CertDAL.ts | 4 ++-- app/lib/dal/sqliteDAL/IdentityDAL.ts | 4 ++-- app/lib/dal/sqliteDAL/MembershipDAL.ts | 4 ++-- app/lib/dal/sqliteDAL/SandBox.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/lib/dal/sqliteDAL/CertDAL.ts b/app/lib/dal/sqliteDAL/CertDAL.ts index 0efb58f2..e940ef3d 100644 --- a/app/lib/dal/sqliteDAL/CertDAL.ts +++ b/app/lib/dal/sqliteDAL/CertDAL.ts @@ -1,10 +1,10 @@ import {SQLiteDriver} from "../drivers/SQLiteDriver" import {AbstractSQLite} from "./AbstractSQLite" -import { SandBox, sandboxDocument } from './SandBox'; +import { SandBox, SandboxDocument } from './SandBox'; const constants = require('../../constants'); -export interface DBCert extends sandboxDocument { +export interface DBCert extends SandboxDocument { linked:boolean written:boolean written_block:null diff --git a/app/lib/dal/sqliteDAL/IdentityDAL.ts b/app/lib/dal/sqliteDAL/IdentityDAL.ts index 1445fb35..883db802 100644 --- a/app/lib/dal/sqliteDAL/IdentityDAL.ts +++ b/app/lib/dal/sqliteDAL/IdentityDAL.ts @@ -1,6 +1,6 @@ import {AbstractSQLite} from "./AbstractSQLite" import {SQLiteDriver} from "../drivers/SQLiteDriver" -import { SandBox, sandboxDocument } from './SandBox'; +import { SandBox, SandboxDocument } from './SandBox'; import {IdentityDTO} from "../../dto/IdentityDTO" import {Cloneable} from "../../dto/Cloneable"; const constants = require('../../constants'); @@ -143,7 +143,7 @@ export class ExistingDBIdentity extends DBIdentity { } } -export interface DBSandboxIdentity extends DBIdentity,sandboxDocument { +export interface DBSandboxIdentity extends DBIdentity,SandboxDocument { certsCount: number ref_block: number } diff --git a/app/lib/dal/sqliteDAL/MembershipDAL.ts b/app/lib/dal/sqliteDAL/MembershipDAL.ts index 41557cf8..d35caf01 100644 --- a/app/lib/dal/sqliteDAL/MembershipDAL.ts +++ b/app/lib/dal/sqliteDAL/MembershipDAL.ts @@ -1,10 +1,10 @@ import {SQLiteDriver} from "../drivers/SQLiteDriver"; import {AbstractSQLite} from "./AbstractSQLite"; -import { SandBox, sandboxDocument } from './SandBox'; +import { SandBox, SandboxDocument } from './SandBox'; const _ = require('underscore'); const constants = require('../../constants'); -export interface DBMembership extends sandboxDocument { +export interface DBMembership extends SandboxDocument { membership: string issuer: string number: number diff --git a/app/lib/dal/sqliteDAL/SandBox.ts b/app/lib/dal/sqliteDAL/SandBox.ts index bdf3c427..652db540 100644 --- a/app/lib/dal/sqliteDAL/SandBox.ts +++ b/app/lib/dal/sqliteDAL/SandBox.ts @@ -1,8 +1,8 @@ -export interface sandboxDocument { +export interface SandboxDocument { issuers: string[]; } -export class SandBox { +export class SandBox { maxSize:number -- GitLab From 1b7f0a83a72b431f501861a309474b2542038371 Mon Sep 17 00:00:00 2001 From: librelois Date: Sat, 14 Oct 2017 16:21:43 +0200 Subject: [PATCH 11/72] revert test typing (I will type only the product code in a first step) --- test/integration/documents-currency.ts | 26 +++++++++++++------------- test/integration/server-shutdown.ts | 2 +- test/integration/tools/toolbox.ts | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/test/integration/documents-currency.ts b/test/integration/documents-currency.ts index 36c5e767..36da15e8 100644 --- a/test/integration/documents-currency.ts +++ b/test/integration/documents-currency.ts @@ -8,26 +8,26 @@ const should = require('should'); const user = require('./tools/user'); const commit = require('./tools/commit'); -let s1:TestingServer, s2:TestingServer, s1Conf:ConfDTO, s2Conf:ConfDTO, cat1:any, tac1:any, toc2:any, tic2:any; +let s1:any, s2:any, cat1:any, tac1:any, toc2:any, tic2:any; describe("Document pool currency", function() { before(() => co(function*() { - s1 = NewTestingServer(ConfDTO.complete({ + s1 = NewTestingServer({ currency: 'currency_one', pair: { - pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', - sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' - } - })); - s2 = NewTestingServer(ConfDTO.complete({ - currency: 'currency_two', - pair: { - pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', - sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' - } - })); + pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', + sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' + } + }); + s2 = NewTestingServer({ + currency: 'currency_two', + pair: { + pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', + sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' + } + }); cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); diff --git a/test/integration/server-shutdown.ts b/test/integration/server-shutdown.ts index 48af2191..033ef307 100644 --- a/test/integration/server-shutdown.ts +++ b/test/integration/server-shutdown.ts @@ -8,7 +8,7 @@ const querablep = require('querablep') describe("Server shutdown", () => { it('should not interrupt a task in the documents FIFO', async () => { - const s1 = NewTestingServer(ConfDTO.defaultConf()) + const s1 = NewTestingServer({}) const fifo = s1._server.getDocumentsFIFO() const ops:any[] = [] diff --git a/test/integration/tools/toolbox.ts b/test/integration/tools/toolbox.ts index a9e1249a..fcf1e967 100644 --- a/test/integration/tools/toolbox.ts +++ b/test/integration/tools/toolbox.ts @@ -218,10 +218,10 @@ export const fakeSyncServer = async (readBlocksMethod:any, readParticularBlockMe * Creates a new memory duniter server for Unit Test purposes. * @param conf */ -export const server = (conf:ConfDTO) => NewTestingServer(conf) -export const simpleTestingServer = (conf:ConfDTO) => NewTestingServer(conf) +export const server = (conf:any) => NewTestingServer(conf) +export const simpleTestingServer = (conf:any) => NewTestingServer(conf) -export const NewTestingServer = (conf:ConfDTO) => { +export const NewTestingServer = (conf:any) => { const host = conf.host || HOST const port = conf.port || PORT++ const commonConf = { -- GitLab From 955f16256668fcf1300058abf99d5b49f7375a24 Mon Sep 17 00:00:00 2001 From: librelois Date: Sat, 14 Oct 2017 16:35:48 +0200 Subject: [PATCH 12/72] move SandboxDocument -> DBDocument --- app/lib/dal/sqliteDAL/CertDAL.ts | 5 +++-- app/lib/dal/sqliteDAL/DocumentDAL.ts | 3 +++ app/lib/dal/sqliteDAL/IdentityDAL.ts | 5 +++-- app/lib/dal/sqliteDAL/MembershipDAL.ts | 5 +++-- app/lib/dal/sqliteDAL/SandBox.ts | 6 ++---- 5 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 app/lib/dal/sqliteDAL/DocumentDAL.ts diff --git a/app/lib/dal/sqliteDAL/CertDAL.ts b/app/lib/dal/sqliteDAL/CertDAL.ts index e940ef3d..d12774e5 100644 --- a/app/lib/dal/sqliteDAL/CertDAL.ts +++ b/app/lib/dal/sqliteDAL/CertDAL.ts @@ -1,10 +1,11 @@ import {SQLiteDriver} from "../drivers/SQLiteDriver" import {AbstractSQLite} from "./AbstractSQLite" -import { SandBox, SandboxDocument } from './SandBox'; +import { SandBox } from './SandBox'; +import { DBDocument } from './DocumentDAL'; const constants = require('../../constants'); -export interface DBCert extends SandboxDocument { +export interface DBCert extends DBDocument { linked:boolean written:boolean written_block:null diff --git a/app/lib/dal/sqliteDAL/DocumentDAL.ts b/app/lib/dal/sqliteDAL/DocumentDAL.ts new file mode 100644 index 00000000..d427e3e5 --- /dev/null +++ b/app/lib/dal/sqliteDAL/DocumentDAL.ts @@ -0,0 +1,3 @@ +export interface DBDocument { + issuers: string[]; +} \ No newline at end of file diff --git a/app/lib/dal/sqliteDAL/IdentityDAL.ts b/app/lib/dal/sqliteDAL/IdentityDAL.ts index 883db802..364eb00c 100644 --- a/app/lib/dal/sqliteDAL/IdentityDAL.ts +++ b/app/lib/dal/sqliteDAL/IdentityDAL.ts @@ -1,8 +1,9 @@ import {AbstractSQLite} from "./AbstractSQLite" import {SQLiteDriver} from "../drivers/SQLiteDriver" -import { SandBox, SandboxDocument } from './SandBox'; +import { SandBox } from './SandBox'; import {IdentityDTO} from "../../dto/IdentityDTO" import {Cloneable} from "../../dto/Cloneable"; +import { DBDocument } from './DocumentDAL'; const constants = require('../../constants'); export abstract class DBIdentity implements Cloneable { @@ -143,7 +144,7 @@ export class ExistingDBIdentity extends DBIdentity { } } -export interface DBSandboxIdentity extends DBIdentity,SandboxDocument { +export interface DBSandboxIdentity extends DBIdentity,DBDocument { certsCount: number ref_block: number } diff --git a/app/lib/dal/sqliteDAL/MembershipDAL.ts b/app/lib/dal/sqliteDAL/MembershipDAL.ts index d35caf01..110ed142 100644 --- a/app/lib/dal/sqliteDAL/MembershipDAL.ts +++ b/app/lib/dal/sqliteDAL/MembershipDAL.ts @@ -1,10 +1,11 @@ import {SQLiteDriver} from "../drivers/SQLiteDriver"; import {AbstractSQLite} from "./AbstractSQLite"; -import { SandBox, SandboxDocument } from './SandBox'; +import { SandBox } from './SandBox'; +import { DBDocument } from './DocumentDAL'; const _ = require('underscore'); const constants = require('../../constants'); -export interface DBMembership extends SandboxDocument { +export interface DBMembership extends DBDocument { membership: string issuer: string number: number diff --git a/app/lib/dal/sqliteDAL/SandBox.ts b/app/lib/dal/sqliteDAL/SandBox.ts index 652db540..8a0d3077 100644 --- a/app/lib/dal/sqliteDAL/SandBox.ts +++ b/app/lib/dal/sqliteDAL/SandBox.ts @@ -1,8 +1,6 @@ -export interface SandboxDocument { - issuers: string[]; -} +import { DBDocument } from './DocumentDAL'; -export class SandBox { +export class SandBox { maxSize:number -- GitLab From 5f8f3b784b35dc00ecb60ec793f2a407852b9bfd Mon Sep 17 00:00:00 2001 From: librelois Date: Sat, 14 Oct 2017 20:33:47 +0200 Subject: [PATCH 13/72] {fix] try to repair integration tests --- app/lib/dto/ConfDTO.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/lib/dto/ConfDTO.ts b/app/lib/dto/ConfDTO.ts index 3c14e480..a1729fe9 100644 --- a/app/lib/dto/ConfDTO.ts +++ b/app/lib/dto/ConfDTO.ts @@ -157,8 +157,8 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, } static defaultConf() { - return new ConfDTO("", "", [], [], 0, 3600 * 1000, constants.PROOF_OF_WORK.DEFAULT.CPU, 1, constants.PROOF_OF_WORK.DEFAULT.PREFIX, 0, 0, constants.CONTRACT.DEFAULT.C, constants.CONTRACT.DEFAULT.DT, constants.CONTRACT.DEFAULT.DT_REEVAL, 0, constants.CONTRACT.DEFAULT.UD0, 0, 0, constants.CONTRACT.DEFAULT.STEPMAX, constants.CONTRACT.DEFAULT.SIGPERIOD, 0, constants.CONTRACT.DEFAULT.SIGVALIDITY, constants.CONTRACT.DEFAULT.MSVALIDITY, constants.CONTRACT.DEFAULT.SIGQTY, constants.CONTRACT.DEFAULT.SIGSTOCK, constants.CONTRACT.DEFAULT.X_PERCENT, constants.CONTRACT.DEFAULT.PERCENTROT, constants.CONTRACT.DEFAULT.POWDELAY, constants.CONTRACT.DEFAULT.AVGGENTIME, constants.CONTRACT.DEFAULT.MEDIANTIMEBLOCKS, false, 3000, false, constants.BRANCHES.DEFAULT_WINDOW_SIZE, constants.CONTRACT.DEFAULT.IDTYWINDOW, constants.CONTRACT.DEFAULT.MSWINDOW, constants.CONTRACT.DEFAULT.SIGWINDOW, 0, { pub:'', sec:'' }, null, "", "", 0, "", "", "", "", 0, "", "", null, false, "", true, true) - /*return { + /*return new ConfDTO("", "", [], [], 0, 3600 * 1000, constants.PROOF_OF_WORK.DEFAULT.CPU, 1, constants.PROOF_OF_WORK.DEFAULT.PREFIX, 0, 0, constants.CONTRACT.DEFAULT.C, constants.CONTRACT.DEFAULT.DT, constants.CONTRACT.DEFAULT.DT_REEVAL, 0, constants.CONTRACT.DEFAULT.UD0, 0, 0, constants.CONTRACT.DEFAULT.STEPMAX, constants.CONTRACT.DEFAULT.SIGPERIOD, 0, constants.CONTRACT.DEFAULT.SIGVALIDITY, constants.CONTRACT.DEFAULT.MSVALIDITY, constants.CONTRACT.DEFAULT.SIGQTY, constants.CONTRACT.DEFAULT.SIGSTOCK, constants.CONTRACT.DEFAULT.X_PERCENT, constants.CONTRACT.DEFAULT.PERCENTROT, constants.CONTRACT.DEFAULT.POWDELAY, constants.CONTRACT.DEFAULT.AVGGENTIME, constants.CONTRACT.DEFAULT.MEDIANTIMEBLOCKS, false, 3000, false, constants.BRANCHES.DEFAULT_WINDOW_SIZE, constants.CONTRACT.DEFAULT.IDTYWINDOW, constants.CONTRACT.DEFAULT.MSWINDOW, constants.CONTRACT.DEFAULT.SIGWINDOW, 0, { pub:'', sec:'' }, null, "", "", 0, "", "", "", "", 0, "", "", null, false, "", true, true)*/ + return { "currency": null, "endpoints": [], "rmEndpoints": [], @@ -184,7 +184,7 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, "isolate": false, "forksize": constants.BRANCHES.DEFAULT_WINDOW_SIZE, "switchOnHeadAdvance": CommonConstants.SWITCH_ON_BRANCH_AHEAD_BY_X_BLOCKS - };*/ + }; } static complete(conf:any) { -- GitLab From 0aa96db2e531b48857d2d152dc08b29f7bcee660 Mon Sep 17 00:00:00 2001 From: cgeek Date: Tue, 7 Nov 2017 18:54:28 +0100 Subject: [PATCH 14/72] [fix] #1168 Quick sync does not updates correctly the index --- app/lib/computation/QuickSync.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/lib/computation/QuickSync.ts b/app/lib/computation/QuickSync.ts index ccdeac10..db385418 100644 --- a/app/lib/computation/QuickSync.ts +++ b/app/lib/computation/QuickSync.ts @@ -126,8 +126,11 @@ export class QuickSynchronizer { // Remember expiration dates for (const entry of index) { - if (entry.expires_on || entry.revokes_on) { - sync_expires.push(entry.expires_on || entry.revokes_on); + if (entry.expires_on) { + sync_expires.push(entry.expires_on) + } + if (entry.revokes_on) { + sync_expires.push(entry.revokes_on) } } sync_expires = _.uniq(sync_expires); @@ -151,8 +154,8 @@ export class QuickSynchronizer { i--; } } - let currentNextExpiring = sync_nextExpiring - sync_nextExpiring = sync_expires.reduce((max, value) => max ? Math.min(max, value) : value, sync_nextExpiring); + const currentNextExpiring = sync_nextExpiring + sync_nextExpiring = sync_expires.reduce((max, value) => max ? Math.min(max, value) : value, 9007199254740991); // Far far away date const nextExpiringChanged = currentNextExpiring !== sync_nextExpiring // Fills in correctly the SINDEX -- GitLab From 1d251881986b87ec1f2770054fbda1c96148d357 Mon Sep 17 00:00:00 2001 From: librelois Date: Wed, 8 Nov 2017 01:58:55 +0100 Subject: [PATCH 15/72] [mod] refactoring ws2p connetion priorities #1184 #1185 --- app/modules/ws2p/lib/WS2PClient.ts | 5 +- app/modules/ws2p/lib/WS2PCluster.ts | 107 +++++++++++++++---------- app/modules/ws2p/lib/WS2PConnection.ts | 12 ++- app/modules/ws2p/lib/WS2PServer.ts | 56 +++++-------- app/modules/ws2p/lib/constants.ts | 1 + 5 files changed, 95 insertions(+), 86 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PClient.ts b/app/modules/ws2p/lib/WS2PClient.ts index 569609f6..0bc7bc11 100644 --- a/app/modules/ws2p/lib/WS2PClient.ts +++ b/app/modules/ws2p/lib/WS2PClient.ts @@ -13,7 +13,7 @@ export class WS2PClient { private constructor(public connection:WS2PConnection) {} - static async connectTo(server:Server, fullEndpointAddress:string, uuid:string, messageHandler:WS2PMessageHandler, expectedPub:string, allowKey:(pub:string)=>Promise ) { + static async connectTo(server:Server, fullEndpointAddress:string, expectedWS2PUID:string, messageHandler:WS2PMessageHandler, expectedPub:string, allowKey:(pub:string)=>Promise ) { const k2 = new Key(server.conf.pair.pub, server.conf.pair.sec) const c = WS2PConnection.newConnectionToAddress( fullEndpointAddress, @@ -25,7 +25,8 @@ export class WS2PClient { connectionTimeout: WS2PConstants.REQUEST_TIMEOUT, requestTimeout: WS2PConstants.REQUEST_TIMEOUT }, - expectedPub + expectedPub, + expectedWS2PUID ) const singleWriteProtection = new WS2PSingleWriteStream() const streamer = new WS2PStreamer(c) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index f41ad9cb..b8940819 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -267,7 +267,7 @@ export class WS2PCluster { } this.ws2pServer = await WS2PServer.bindOn(this.server, host, port, this.fifo, (pubkey:string, connectedPubkeys:string[]) => { const privilegedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[] - return this.acceptPubkey(pubkey, connectedPubkeys, () => this.servedCount(), this.maxLevel2Peers, privilegedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.privilegedOnly || false)) + return this.acceptPubkey(pubkey, connectedPubkeys, [], () => this.servedCount(), this.maxLevel2Peers, privilegedNodes, (this.server.conf.ws2p !== undefined && this.server.conf.ws2p.privilegedOnly)) }, this.messageHandler) this.host = host this.port = port @@ -298,8 +298,9 @@ export class WS2PCluster { const fullEndpointAddress = WS2PCluster.getFullAddress(host, port, path) const ws2pc = await WS2PClient.connectTo(this.server, fullEndpointAddress, ws2pEndpointUUID, messageHandler, expectedPub, (pub:string) => { const connectedPubkeys = this.getConnectedPubkeys() + const connectedWS2PUID = this.getConnectedWS2PUID() const preferedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[] - return this.acceptPubkey(expectedPub, connectedPubkeys, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEndpointUUID) + return this.acceptPubkey(expectedPub, connectedPubkeys, connectedWS2PUID, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEndpointUUID) }) this.ws2pClients[uuid] = ws2pc pub = ws2pc.connection.pubkey @@ -403,10 +404,11 @@ export class WS2PCluster { if (ws2pEnpoint) { // Check if already connected to the pubkey (in any way: server or client) const connectedPubkeys = this.getConnectedPubkeys() + const connectedWS2PUID = this.getConnectedWS2PUID() const preferedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[] - const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEnpoint.uuid) + const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, connectedWS2PUID, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEnpoint.uuid) if (shouldAccept && (!this.server.conf.ws2p || ws2pEnpoint.uuid !== this.server.conf.ws2p.uuid || peer.pubkey !== this.server.conf.pair.pub || ws2pEnpoint.uuid === '11111111')) { - await this.connectToRemoteWS(ws2pEnpoint.host, ws2pEnpoint.port, ws2pEnpoint.path, this.messageHandler, peer.pubkey) + await this.connectToRemoteWS(ws2pEnpoint.host, ws2pEnpoint.port, ws2pEnpoint.path, this.messageHandler, peer.pubkey, ws2pEnpoint.uuid) await this.trimClientConnections() } } @@ -573,64 +575,75 @@ export class WS2PCluster { protected async acceptPubkey( pub:string, connectedPubkeys:string[], + connectedWS2PUID:string[], getConcurrentConnexionsCount:()=>number, maxConcurrentConnexionsSize:number, priorityKeys:string[], priorityKeysOnly:boolean, targetWS2PUID = "" ) { + // We need ws2pServer instance + if (!this.ws2pServer) { + return false + } + + // We do not accept oneself connetion + if (this.server.conf.pair.pub === pub && this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID) { + return false + } + // We do not accept banned keys if (this.banned[pub]) { this.server.logger.warn('Connection to %s refused, reason: %s', pub.slice(0, 8), this.banned[pub]) return false } - let accept = priorityKeys.indexOf(pub) !== -1 - if (!accept && !priorityKeysOnly && connectedPubkeys.indexOf(pub) === -1) { - // Do we have room? - if (this.server.conf.pair.pub === pub && this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID) { - accept = false - } - else if (getConcurrentConnexionsCount() < maxConcurrentConnexionsSize) { - // Yes: just connect to it - accept = true - } - else { - // No: let's verify some peer has a lower priority - if (connectedPubkeys.indexOf(this.server.conf.pair.pub) !== -1) { - // Yes, we are connected to ourself. Let's replace this connexion - accept = true - } - else { - // Does this node have the priority over at least one node? - const isMemberPeer = await this.server.dal.isMember(pub) - if (isMemberPeer) { - // The node may have the priority over at least 1 other node - let i = 0, existsOneNonMemberNode = false - while (!existsOneNonMemberNode && i < connectedPubkeys.length) { - const isAlsoAMemberPeer = await this.server.dal.isMember(connectedPubkeys[i]) - existsOneNonMemberNode = !isAlsoAMemberPeer - i++ - } - if (existsOneNonMemberNode) { - // The node has the priority over a non-member peer: try to connect - accept = true - } - } + + // Is priority key ? + let isPriorityKey = priorityKeys.indexOf(pub) !== -1 + + // We do not accept forbidden keys + if (priorityKeysOnly && !isPriorityKey && this.server.conf.pair.pub !== pub) { + return false + } + + // Is member key ? + const isMemberPeer = await this.server.dal.isMember(pub) + + // Do we have room? + if (getConcurrentConnexionsCount() < maxConcurrentConnexionsSize) { + // Yes: just connect to it + return true + } else if (this.server.conf.pair.pub === pub) { + // We always accept self nodes, and they have a supreme priority (these are siblings) + if (targetWS2PUID !== "") { + if (this.isNewSiblingNode(pub, targetWS2PUID, connectedWS2PUID)) { + return true } } - } else { - // The pubkey is already connected: we accept only self nodes, and they have a supreme priority (these are siblings) - if (targetWS2PUID) { - if (this.isSiblingNode(pub, targetWS2PUID)) { - accept = true + } + else if (connectedPubkeys.indexOf(pub) === -1) + { + let minPriorityLevel = WS2PConstants.MAX_PRIORITY_LEVEL + for (const connectedPubkey of connectedPubkeys) { + let connectedPubkeyPriorityLevel = this.ws2pServer.keyPriorityLevel(connectedPubkey, priorityKeys) + if (connectedPubkeyPriorityLevel < minPriorityLevel) { + minPriorityLevel = connectedPubkeyPriorityLevel } } + if (this.ws2pServer.keyPriorityLevel(pub, priorityKeys) > minPriorityLevel) { + return true + } } - return accept + return false } - isSiblingNode(pub:string, uuid:string) { - return !!(this.server.conf.pair.pub === pub && this.server.conf.ws2p && this.server.conf.ws2p.uuid !== uuid) + isNewSiblingNode(pub:string, targetWS2PUID:string, connectedWS2PUID:string[]) { + for (const uuid of connectedWS2PUID) { + if (uuid === targetWS2PUID) { + return false + } + } + return true } async getLevel1Connections() { @@ -742,6 +755,12 @@ export class WS2PCluster { return clients.concat(served) } + getConnectedWS2PUID() { + const clients = Object.keys(this.ws2pClients).map(k => this.ws2pClients[k].connection.uuid) + const served = this.ws2pServer ? this.ws2pServer.getConnexions().map(c => c.uuid) : [] + return clients.concat(served) + } + banConnection(c:WS2PConnection, reason:string) { this.server.logger.warn('Banning connections of %s for %ss, reason: %s', c.pubkey.slice(0, 8), WS2PConstants.BAN_DURATION_IN_SECONDS, reason) if (c.pubkey) { diff --git a/app/modules/ws2p/lib/WS2PConnection.ts b/app/modules/ws2p/lib/WS2PConnection.ts index 0595e562..eed3dfff 100644 --- a/app/modules/ws2p/lib/WS2PConnection.ts +++ b/app/modules/ws2p/lib/WS2PConnection.ts @@ -256,7 +256,8 @@ export class WS2PConnection { connectionTimeout: REQUEST_TIMEOUT_VALUE, requestTimeout: REQUEST_TIMEOUT_VALUE }, - private expectedPub:string = "" + private expectedPub:string = "", + private expectedWS2PUID:string = "" ) { this.connectedp = new Promise((resolve, reject) => { this.connectedResolve = resolve @@ -277,7 +278,8 @@ export class WS2PConnection { connectionTimeout: REQUEST_TIMEOUT_VALUE, requestTimeout: REQUEST_TIMEOUT_VALUE }, - expectedPub:string = "") { + expectedPub:string = "", + expectedWS2PUID:string = "") { if (address.match(WS2PConstants.FULL_ADDRESS_ONION_REGEX)) { options = { connectionTimeout: WS2PConstants.CONNEXION_TOR_TIMEOUT, @@ -292,7 +294,7 @@ export class WS2PConnection { websocket.on('close', () => res()) }) websocket.on('error', () => websocket.close()) - return new WS2PConnection(websocket, onWsOpened, onWsClosed, messageHandler, localAuth, remoteAuth, options, expectedPub) + return new WS2PConnection(websocket, onWsOpened, onWsClosed, messageHandler, localAuth, remoteAuth, options, expectedPub, expectedWS2PUID) } static newConnectionFromWebSocketServer( @@ -319,6 +321,10 @@ export class WS2PConnection { return this.remoteAuth.getPubkey() } + get uuid() { + return this.expectedWS2PUID + } + get nbRequests() { return this.nbRequestsCount } diff --git a/app/modules/ws2p/lib/WS2PServer.ts b/app/modules/ws2p/lib/WS2PServer.ts index ae79815f..d11c3298 100644 --- a/app/modules/ws2p/lib/WS2PServer.ts +++ b/app/modules/ws2p/lib/WS2PServer.ts @@ -116,8 +116,8 @@ export class WS2PServer extends events.EventEmitter { } }) }) - - await this.trimConnections() + let privilegedKeys = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[] + await this.removeLowPriorityConnection(privilegedKeys) await this.server.dal.setPeerUP(c.pubkey) @@ -128,44 +128,26 @@ export class WS2PServer extends events.EventEmitter { }) } - async trimConnections() { - /*** OVERFLOW TRIMMING ***/ - let disconnectedOne = true - // Disconnect non-members - while (disconnectedOne && this.connections.length > this.maxLevel2Size) { - disconnectedOne = false - for (const c of this.connections) { - const isMember = await this.server.dal.isMember(c.pubkey) - if (!isMember && !disconnectedOne) { - c.close() - this.removeConnection(c) - disconnectedOne = true - } - } - } - // Disconnect members - while (this.connections.length > this.maxLevel2Size) { - for (const c of this.connections) { - c.close() - this.removeConnection(c) - } - } - /*** DUPLICATES TRIMMING ***/ - disconnectedOne = true - while (disconnectedOne) { - disconnectedOne = false - const pubkeysFound = [] - for (const c of this.connections) { - if (pubkeysFound.indexOf(c.pubkey) !== -1) { - c.close() - this.removeConnection(c) - disconnectedOne = true - } - else if (c.pubkey !== this.server.conf.pair.pub) { - pubkeysFound.push(c.pubkey) + async removeLowPriorityConnection(privilegedKeys:string[]) { + let lowPriorityConnection:WS2PConnection = this.connections[0] + let minPriorityLevel = this.keyPriorityLevel(lowPriorityConnection.pubkey, privilegedKeys) + for (const c of this.connections) { + if (c !== lowPriorityConnection) { + let cPriorityLevel = this.keyPriorityLevel(c.pubkey, privilegedKeys) + if (cPriorityLevel < minPriorityLevel) { + lowPriorityConnection = c + minPriorityLevel = cPriorityLevel } } } + this.removeConnection(lowPriorityConnection) + } + + keyPriorityLevel(pubkey:string, privilegedKeys:string[]) { + let priorityLevel = (this.server.dal.isMember(pubkey)) ? 1:0 + priorityLevel += (privilegedKeys.indexOf(pubkey) !== -1) ? 2:0 + priorityLevel += (this.server.conf.pair.pub === pubkey) ? 4:0 + return priorityLevel } private removeConnection(c:WS2PConnection) { diff --git a/app/modules/ws2p/lib/constants.ts b/app/modules/ws2p/lib/constants.ts index 51972d7f..cc75af03 100644 --- a/app/modules/ws2p/lib/constants.ts +++ b/app/modules/ws2p/lib/constants.ts @@ -19,6 +19,7 @@ export const WS2PConstants = { MAX_LEVEL_1_PEERS: 10, MAX_LEVEL_2_PEERS: 10, CONNECTIONS_LOW_LEVEL: 3, + MAX_PRIORITY_LEVEL: 7, BAN_DURATION_IN_SECONDS: 120, BAN_ON_REPEAT_THRESHOLD: 5, -- GitLab From 4a173cfc7849760717a7d4fa11c36866847f1882 Mon Sep 17 00:00:00 2001 From: librelois Date: Wed, 8 Nov 2017 22:36:15 +0100 Subject: [PATCH 16/72] [enh] prepare the management of several ws2p versions + continuation of refactoring ws2p connetions priority --- app/lib/common-libs/constants.ts | 4 + app/lib/dto/PeerDTO.ts | 77 ++++++++++++---- app/modules/ws2p/lib/WS2PCluster.ts | 132 ++++++++++++++++++++++------ app/modules/ws2p/lib/WS2PServer.ts | 15 ++-- app/modules/ws2p/lib/constants.ts | 10 ++- 5 files changed, 183 insertions(+), 55 deletions(-) diff --git a/app/lib/common-libs/constants.ts b/app/lib/common-libs/constants.ts index f9cda71f..637bc0e0 100644 --- a/app/lib/common-libs/constants.ts +++ b/app/lib/common-libs/constants.ts @@ -33,7 +33,9 @@ const CONDITIONS = "(&&|\\|\\|| |[()]|(SIG\\(" + PUBKEY + "\\)|(XHX\\([A-F0-9] const BMA_REGEXP = /^BASIC_MERKLED_API( ([a-z_][a-z0-9-_.]*))?( ([0-9.]+))?( ([0-9a-f:]+))?( ([0-9]+))$/ const BMATOR_REGEXP = /^BMATOR( ([a-z0-9]{16})\.onion)( ([0-9.]+))?( ([0-9a-f:]+))?( ([0-9]+))$/ const WS2P_REGEXP = /^WS2P ([a-f0-9]{8}) ([a-z_][a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+) ([0-9]+)(?: (.+))?$/ +const WS2P_V2_REGEXP = /^WS2P ([0-9]+) ([a-f0-9]{8}) ([a-z_][a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+) ([0-9]+)(?: (.+))?$/ const WS2PTOR_REGEXP = /^WS2PTOR ([a-f0-9]{8}) ([a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+.onion) ([0-9]+)(?: (.+))?$/ +const WS2PTOR_V2_REGEXP = /^WS2PTOR ([0-9]+) ([a-f0-9]{8}) ([a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+.onion) ([0-9]+)(?: (.+))?$/ const WS_FULL_ADDRESS_ONION_REGEX = /^(?:wss?:\/\/)(?:www\.)?([0-9a-z]{16}\.onion)(:[0-9]+)?$/ const IPV4_REGEXP = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/; const IPV6_REGEXP = /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|(([0-9A-Fa-f]{1,4}:){0,5}:((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|(::([0-9A-Fa-f]{1,4}:){0,5}((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/; @@ -95,7 +97,9 @@ export const CommonConstants = { BMA_REGEXP, BMATOR_REGEXP, WS2P_REGEXP, + WS2P_V2_REGEXP, WS2PTOR_REGEXP, + WS2PTOR_V2_REGEXP, WS_FULL_ADDRESS_ONION_REGEX, IPV4_REGEXP, IPV6_REGEXP, diff --git a/app/lib/dto/PeerDTO.ts b/app/lib/dto/PeerDTO.ts index dc5754b6..0704fe14 100644 --- a/app/lib/dto/PeerDTO.ts +++ b/app/lib/dto/PeerDTO.ts @@ -2,6 +2,7 @@ import {DBPeer} from "../dal/sqliteDAL/PeerDAL" import {hashf} from "../common" import {CommonConstants} from "../common-libs/constants" import {Cloneable} from "./Cloneable" +import { WS2PConstants } from '../../modules/ws2p/lib/constants'; export interface WS2PEndpoint { uuid:string @@ -94,29 +95,59 @@ export class PeerDTO implements Cloneable { return bma || {}; } - getWS2P(canReachTorEp:boolean, canReachClearEp:boolean) { - let api:{ uuid:string, host:string, port:number, path:string }|null = null - const endpointRegexp = (canReachTorEp) ? CommonConstants.WS2PTOR_REGEXP:CommonConstants.WS2P_REGEXP + getOnceWS2PEndpoint(canReachTorEp:boolean, canReachClearEp:boolean, uuidExcluded:string[] = []) { + let api:{ version:number, uuid:string, host:string, port:number, path:string }|null = null + let bestWS2PVersionAvailable:number = 0 + let bestWS2PTORVersionAvailable:number = 0 for (const ep of this.endpoints) { if (canReachTorEp) { - const matches:any = ep.match(CommonConstants.WS2PTOR_REGEXP) - if (matches) { - return { - uuid: matches[1], - host: matches[2] || '', - port: parseInt(matches[3]) || 0, - path: matches[4] + let matches:any = ep.match(CommonConstants.WS2PTOR_V2_REGEXP) + if (matches && parseInt(matches[1]) > bestWS2PTORVersionAvailable && (uuidExcluded.indexOf(matches[2]) === -1)) { + bestWS2PTORVersionAvailable = matches[1] + api = { + version: parseInt(matches[1]), + uuid: matches[2], + host: matches[3] || '', + port: parseInt(matches[4]) || 0, + path: matches[5] + } + } else { + matches = ep.match(CommonConstants.WS2PTOR_REGEXP) + if (matches && bestWS2PTORVersionAvailable == 0 && (uuidExcluded.indexOf(matches[1]) === -1)) { + bestWS2PTORVersionAvailable = 1 + api = { + version: 1, + uuid: matches[1], + host: matches[2] || '', + port: parseInt(matches[3]) || 0, + path: matches[4] + } } } } - if (canReachClearEp) { - const matches:any = !api && ep.match(CommonConstants.WS2P_REGEXP) - if (matches) { + // If can reach clear endpoint and not found tor endpoint + if (canReachClearEp && bestWS2PTORVersionAvailable == 0) { + let matches:any = ep.match(CommonConstants.WS2P_V2_REGEXP) + if (matches && parseInt(matches[1]) > bestWS2PVersionAvailable && (uuidExcluded.indexOf(matches[2]) === -1)) { + bestWS2PVersionAvailable = parseInt(matches[1]) api = { - uuid: matches[1], - host: matches[2] || '', - port: parseInt(matches[3]) || 0, - path: matches[4] + version: parseInt(matches[1]), + uuid: matches[2], + host: matches[3] || '', + port: parseInt(matches[4]) || 0, + path: matches[5] + } + } else { + matches = ep.match(CommonConstants.WS2P_REGEXP) + if (matches && bestWS2PVersionAvailable == 0 && (uuidExcluded.indexOf(matches[1]) === -1)) { + bestWS2PVersionAvailable = 1 + api = { + version: 1, + uuid: matches[1], + host: matches[2] || '', + port: parseInt(matches[3]) || 0, + path: matches[4] + } } } } @@ -124,6 +155,18 @@ export class PeerDTO implements Cloneable { return api || null } + getAllWS2PEndpoints(canReachTorEp:boolean, canReachClearEp:boolean, myUUID:string) { + let apis:{ uuid:string, host:string, port:number, path:string }[] = [] + let uuidExcluded:string[] = [myUUID] + let api = this.getOnceWS2PEndpoint(canReachTorEp, canReachClearEp, uuidExcluded) + while (api !== null) { + uuidExcluded.push(api.uuid) + apis.push(api) + api = this.getOnceWS2PEndpoint(canReachTorEp, canReachClearEp, uuidExcluded) + } + return apis + } + getDns() { const bma = this.getBMA(); return bma.dns ? bma.dns : null; diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index b8940819..fdd829af 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -17,6 +17,7 @@ import { CommonConstants } from '../../../lib/common-libs/constants'; import { Package } from "../../../lib/common/package"; import { Constants } from "../../prover/lib/constants"; import { ProxiesConf } from '../../../lib/proxy'; +import { Keypair } from '../../../lib/dto/ConfDTO'; const es = require('event-stream') const nuuid = require('node-uuid') @@ -268,7 +269,7 @@ export class WS2PCluster { this.ws2pServer = await WS2PServer.bindOn(this.server, host, port, this.fifo, (pubkey:string, connectedPubkeys:string[]) => { const privilegedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[] return this.acceptPubkey(pubkey, connectedPubkeys, [], () => this.servedCount(), this.maxLevel2Peers, privilegedNodes, (this.server.conf.ws2p !== undefined && this.server.conf.ws2p.privilegedOnly)) - }, this.messageHandler) + }, this.keyPriorityLevel, this.messageHandler) this.host = host this.port = port return this.ws2pServer @@ -330,13 +331,20 @@ export class WS2PCluster { } async connectToWS2Peers() { + const myUUID = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) ? this.server.conf.ws2p.uuid:"" const potentials = await this.server.dal.getWS2Peers() const peers:PeerDTO[] = potentials.map((p:any) => PeerDTO.fromJSONObject(p)) const prefered = ((this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) || []).slice() // Copy // Our key is also a prefered one, so we connect to our siblings - prefered.push(this.server.conf.pair.pub) const canReachTorEndpoint = ProxiesConf.canReachTorEndpoint(this.server.conf.proxiesConf) peers.sort((a, b) => { + // Top priority at our own nodes + if (a.pubkey === this.server.conf.pair.pub && b.pubkey !== this.server.conf.pair.pub) { + return -1 + } else if (a.pubkey !== this.server.conf.pair.pub && b.pubkey === this.server.conf.pair.pub) { + return 1 + } + const aIsPrefered = prefered.indexOf(a.pubkey) !== -1 const bIsPrefered = prefered.indexOf(b.pubkey) !== -1 @@ -373,20 +381,34 @@ export class WS2PCluster { const canReachClearEndpoint = ProxiesConf.canReachClearEndpoint(this.server.conf.proxiesConf) while (i < peers.length && this.clientsCount() < this.maxLevel1Size) { const p = peers[i] - const api = p.getWS2P(canReachTorEndpoint, canReachClearEndpoint) - if (api) { - try { - // We do not connect to local host - if (!this.server.conf.ws2p || api.uuid !== this.server.conf.ws2p.uuid || p.pubkey !== this.server.conf.pair.pub || api.uuid === '11111111') { - await this.connectToRemoteWS(api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) + if (p.pubkey === this.server.conf.pair.pub) { + const apis = p.getAllWS2PEndpoints(canReachTorEndpoint, canReachClearEndpoint, myUUID) + for (const api of apis) { + try { + // We do not connect to local host + if (api.uuid !== myUUID || api.uuid === '11111111') { + await this.connectToRemoteWS(api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) + } + } catch (e) { + this.server.logger.debug('WS2P: init: failed connection') + } + } + } else { + const api = p.getOnceWS2PEndpoint(canReachTorEndpoint, canReachClearEndpoint) + if (api) { + try { + // We do not connect to local host + if (api.uuid !== myUUID || api.uuid === '11111111') { + await this.connectToRemoteWS(api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) + } + } catch (e) { + this.server.logger.debug('WS2P: init: failed connection') } - } catch (e) { - this.server.logger.debug('WS2P: init: failed connection') } } i++ // Trim the eventual extra connections - setTimeout(() => this.trimClientConnections(), WS2PConstants.CONNEXION_TIMEOUT) + setTimeout(() => this.trimClientConnections(prefered), WS2PConstants.CONNEXION_TIMEOUT) } } @@ -400,16 +422,16 @@ export class WS2PCluster { // New peer if (data.endpoints) { const peer = PeerDTO.fromJSONObject(data) - const ws2pEnpoint = peer.getWS2P(ProxiesConf.canReachTorEndpoint(this.server.conf.proxiesConf), ProxiesConf.canReachClearEndpoint(this.server.conf.proxiesConf)) + const ws2pEnpoint = peer.getOnceWS2PEndpoint(ProxiesConf.canReachTorEndpoint(this.server.conf.proxiesConf), ProxiesConf.canReachClearEndpoint(this.server.conf.proxiesConf)) if (ws2pEnpoint) { // Check if already connected to the pubkey (in any way: server or client) const connectedPubkeys = this.getConnectedPubkeys() const connectedWS2PUID = this.getConnectedWS2PUID() - const preferedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[] - const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, connectedWS2PUID, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEnpoint.uuid) + const preferedKeys = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[] + const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, connectedWS2PUID, () => this.clientsCount(), this.maxLevel1Size, preferedKeys, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEnpoint.uuid) if (shouldAccept && (!this.server.conf.ws2p || ws2pEnpoint.uuid !== this.server.conf.ws2p.uuid || peer.pubkey !== this.server.conf.pair.pub || ws2pEnpoint.uuid === '11111111')) { await this.connectToRemoteWS(ws2pEnpoint.host, ws2pEnpoint.port, ws2pEnpoint.path, this.messageHandler, peer.pubkey, ws2pEnpoint.uuid) - await this.trimClientConnections() + await this.trimClientConnections(preferedKeys) } } } @@ -480,7 +502,60 @@ export class WS2PCluster { return { sig, message, pub } } - async trimClientConnections() { + async removeLowPriorityConnections(privilegedKeys:string[]) { + let serverPubkeys:string[] = [] + if (this.ws2pServer) { + serverPubkeys = this.ws2pServer.getConnexions().map(c => c.pubkey) + } + let disconnectedOne = true + // Disconnect Private connexions already present under Public + while (disconnectedOne) { + disconnectedOne = false + let uuids = Object.keys(this.ws2pClients) + uuids = _.shuffle(uuids) + for (const uuid of uuids) { + const client = this.ws2pClients[uuid] + const pub = client.connection.pubkey + const isNotOurself = pub !== this.server.conf.pair.pub + const isAlreadyInPublic = serverPubkeys.indexOf(pub) !== -1 + if (isNotOurself && isAlreadyInPublic) { + client.connection.close() + await client.connection.closed + disconnectedOne = true + if (this.ws2pClients[uuid]) { + delete this.ws2pClients[uuid] + } + } + } + } + // Disconnect Private connexions until the maximum size is respected + while (disconnectedOne && this.clientsCount() > this.maxLevel1Size) { + let uuids = Object.keys(this.ws2pClients) + uuids = _.shuffle(uuids) + let lowPriorityConnectionUUID:string = uuids[0] + let minPriorityLevel = this.keyPriorityLevel(this.ws2pClients[lowPriorityConnectionUUID].connection.pubkey, privilegedKeys) + for (const uuid of uuids) { + const client = this.ws2pClients[uuid] + if (uuid !== lowPriorityConnectionUUID) { + let uuidPriorityLevel = this.keyPriorityLevel(client.connection.pubkey, privilegedKeys) + if (uuidPriorityLevel < minPriorityLevel) { + lowPriorityConnectionUUID = uuid + minPriorityLevel = uuidPriorityLevel + } + } + delete this.ws2pClients[lowPriorityConnectionUUID] + } + } + } + + keyPriorityLevel(pubkey:string, preferedOrPrivilegedKeys:string[]) { + let priorityLevel = (this.server.dal.isMember(pubkey)) ? WS2PConstants.CONNECTIONS_PRIORITY.MEMBER_KEY_LEVEL:0 + priorityLevel += (preferedOrPrivilegedKeys.indexOf(pubkey) !== -1) ? WS2PConstants.CONNECTIONS_PRIORITY.PREFERED_PRIVILEGED_KEY_LEVEL:0 + priorityLevel += (this.server.conf.pair.pub === pubkey) ? WS2PConstants.CONNECTIONS_PRIORITY.SELF_KEY_LEVEL:0 + return priorityLevel + } + + async trimClientConnections(preferedKeys:string[]) { let serverPubkeys:string[] = [] if (this.ws2pServer) { serverPubkeys = this.ws2pServer.getConnexions().map(c => c.pubkey) @@ -587,9 +662,19 @@ export class WS2PCluster { return false } - // We do not accept oneself connetion - if (this.server.conf.pair.pub === pub && this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID) { - return false + if (this.server.conf.pair.pub === pub) { + // We do not accept oneself connetion + if (this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID) { + return false + } else { + // We always accept self nodes, and they have a supreme priority (these are siblings) + if (targetWS2PUID === "" || this.isNewSiblingNode(pub, targetWS2PUID, connectedWS2PUID) ) { + return true + } else { + // We are already connected to this self node (same WS2PUID) + return false + } + } } // We do not accept banned keys @@ -613,17 +698,10 @@ export class WS2PCluster { if (getConcurrentConnexionsCount() < maxConcurrentConnexionsSize) { // Yes: just connect to it return true - } else if (this.server.conf.pair.pub === pub) { - // We always accept self nodes, and they have a supreme priority (these are siblings) - if (targetWS2PUID !== "") { - if (this.isNewSiblingNode(pub, targetWS2PUID, connectedWS2PUID)) { - return true - } - } } else if (connectedPubkeys.indexOf(pub) === -1) { - let minPriorityLevel = WS2PConstants.MAX_PRIORITY_LEVEL + let minPriorityLevel = WS2PConstants.CONNECTIONS_PRIORITY.MAX_PRIORITY_LEVEL for (const connectedPubkey of connectedPubkeys) { let connectedPubkeyPriorityLevel = this.ws2pServer.keyPriorityLevel(connectedPubkey, priorityKeys) if (connectedPubkeyPriorityLevel < minPriorityLevel) { diff --git a/app/modules/ws2p/lib/WS2PServer.ts b/app/modules/ws2p/lib/WS2PServer.ts index d11c3298..85bed337 100644 --- a/app/modules/ws2p/lib/WS2PServer.ts +++ b/app/modules/ws2p/lib/WS2PServer.ts @@ -7,6 +7,7 @@ import {WS2PConstants} from "./constants" import {WS2PMessageHandler} from "./impl/WS2PMessageHandler" import {WS2PStreamer} from "./WS2PStreamer" import {WS2PSingleWriteStream} from "./WS2PSingleWriteStream" +import { WS2PCluster } from './WS2PCluster'; const WebSocketServer = require('ws').Server @@ -21,7 +22,8 @@ export class WS2PServer extends events.EventEmitter { private host:string, private port:number, private fifo:GlobalFifoPromise, - private shouldAcceptConnection:(pubkey:string, connectedPubkeys:string[])=>Promise) { + private shouldAcceptConnection:(pubkey:string, connectedPubkeys:string[])=>Promise, + public keyPriorityLevel:(pubkey:string, privilegedKeys:string[])=>number) { super() // Conf: max public connections if (this.server.conf.ws2p && this.server.conf.ws2p.maxPublic !== undefined) { @@ -143,13 +145,6 @@ export class WS2PServer extends events.EventEmitter { this.removeConnection(lowPriorityConnection) } - keyPriorityLevel(pubkey:string, privilegedKeys:string[]) { - let priorityLevel = (this.server.dal.isMember(pubkey)) ? 1:0 - priorityLevel += (privilegedKeys.indexOf(pubkey) !== -1) ? 2:0 - priorityLevel += (this.server.conf.pair.pub === pubkey) ? 4:0 - return priorityLevel - } - private removeConnection(c:WS2PConnection) { const index = this.connections.indexOf(c) if (index !== -1) { @@ -183,8 +178,8 @@ export class WS2PServer extends events.EventEmitter { })) } - static async bindOn(server:Server, host:string, port:number, fifo:GlobalFifoPromise, shouldAcceptConnection:(pubkey:string, connectedPubkeys:string[])=>Promise, messageHandler:WS2PMessageHandler) { - const ws2ps = new WS2PServer(server, host, port, fifo, shouldAcceptConnection) + static async bindOn(server:Server, host:string, port:number, fifo:GlobalFifoPromise, shouldAcceptConnection:(pubkey:string, connectedPubkeys:string[])=>Promise, keyPriorityLevel:(pubkey:string, privilegedKeys:string[])=>number, messageHandler:WS2PMessageHandler) { + const ws2ps = new WS2PServer(server, host, port, fifo, shouldAcceptConnection, keyPriorityLevel) await ws2ps.listenToWebSocketConnections(messageHandler) server.logger.info('WS2P server %s listening on %s:%s', server.conf.pair.pub, host, port) return ws2ps diff --git a/app/modules/ws2p/lib/constants.ts b/app/modules/ws2p/lib/constants.ts index cc75af03..080db10c 100644 --- a/app/modules/ws2p/lib/constants.ts +++ b/app/modules/ws2p/lib/constants.ts @@ -1,6 +1,8 @@ import {CommonConstants} from "../../../lib/common-libs/constants" export const WS2PConstants = { + WS2P_VERSION: 2, + WS2P_UPNP_TTL: 600, WS2P_PORTS_START: 20900, WS2P_PORTS_END: 20999, @@ -19,7 +21,13 @@ export const WS2PConstants = { MAX_LEVEL_1_PEERS: 10, MAX_LEVEL_2_PEERS: 10, CONNECTIONS_LOW_LEVEL: 3, - MAX_PRIORITY_LEVEL: 7, + + CONNECTIONS_PRIORITY: { + MEMBER_KEY_LEVEL: 1, + PREFERED_PRIVILEGED_KEY_LEVEL: 2, + SELF_KEY_LEVEL: 4, + MAX_PRIORITY_LEVEL: 7, + }, BAN_DURATION_IN_SECONDS: 120, BAN_ON_REPEAT_THRESHOLD: 5, -- GitLab From d752c1cdddc8c2e8d851f3c73aac773d2c321887 Mon Sep 17 00:00:00 2001 From: cgeek Date: Fri, 10 Nov 2017 09:03:18 +0100 Subject: [PATCH 17/72] [fix] #1190 Revoked identity inclusion in a block [test] --- test/integration/revoked_pubkey_replay.ts | 68 +++++++++++++++++++++++ test/integration/tools/toolbox.ts | 4 +- test/integration/tools/user.js | 10 ++-- 3 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 test/integration/revoked_pubkey_replay.ts diff --git a/test/integration/revoked_pubkey_replay.ts b/test/integration/revoked_pubkey_replay.ts new file mode 100644 index 00000000..dbaddc9a --- /dev/null +++ b/test/integration/revoked_pubkey_replay.ts @@ -0,0 +1,68 @@ +import {simpleNodeWith2Users, TestingServer} from "./tools/toolbox" + +const _ = require('underscore') +const user = require('./tools/user') + +describe("Revoked pubkey replay", function() { + + const now = 1500000000 + const DONT_WAIT_FOR_BLOCKCHAIN_CHANGE = true + let s1:TestingServer, cat:any, tic:any + + const conf = { nbCores: 1, sigQty: 1 } + + before(async () => { + const res1 = await simpleNodeWith2Users(conf) + s1 = res1.s1 + cat = res1.cat + tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }) + await s1.commit({ time: now }) + await s1.commit({ time: now }) + // Create the tested identity « tic » + await tic.createIdentity() + }) + + it('should exist tic as pending identity', () => s1.expect('/wot/lookup/tic', (res:any) => { + res.should.have.property('results').length(1) + res.results[0].should.have.property('uids').length(1) + res.results[0].uids[0].should.have.property('uid').equal('tic') + })) + + it('should be able to make tic become a member', async () => { + await tic.join() + await cat.cert(tic) + await s1.commit() + await s1.expect('/wot/members', (res:any) => { + res.should.have.property('results').length(3) + const ticEntries = _.filter(res.results, (entry:any) => entry.uid === 'tic') + ticEntries.should.have.length(1) + }) + }) + + it('should be able to revoke tic', async () => { + await tic.revoke() + await s1.expect('/wot/lookup/tic', (res:any) => { + res.should.have.property('results').length(1) + res.results[0].should.have.property('uids').length(1) + res.results[0].uids[0].should.have.property('uid').equal('tic') + res.results[0].uids[0].should.have.property('revocation_sig').not.equal(null) + }) + await s1.commit() + await s1.expect('/wot/members', (res:any) => { + res.should.have.property('results').length(2) + const ticEntries = _.filter(res.results, (entry:any) => entry.uid === 'tic') + ticEntries.should.have.length(0) + }) + }) + + it('should not try to include tic2 in a new block', async () => { + await s1.commit() + await tic.join() + const block = await s1.commit(null, DONT_WAIT_FOR_BLOCKCHAIN_CHANGE) + block.should.have.property('joiners').length(0) + }) + + after(async () => { + await s1.closeCluster() + }) +}) diff --git a/test/integration/tools/toolbox.ts b/test/integration/tools/toolbox.ts index cbbe1d15..0bb986b7 100644 --- a/test/integration/tools/toolbox.ts +++ b/test/integration/tools/toolbox.ts @@ -476,8 +476,8 @@ export class TestingServer { return until(this.server, type, count); } - async commit(options:any = null) { - const raw = await commit(this.server)(options); + async commit(options:any = null, noWait = false) { + const raw = await commit(this.server, null, noWait)(options); return JSON.parse(raw); } diff --git a/test/integration/tools/user.js b/test/integration/tools/user.js index 9e82326e..1f910f88 100644 --- a/test/integration/tools/user.js +++ b/test/integration/tools/user.js @@ -26,6 +26,7 @@ function User (uid, options, node) { var pub, sec; var createdIdentity = ""; that.node = node; + that.uid = uid // For sync code if (options.pub && options.sec) { @@ -68,7 +69,7 @@ function User (uid, options, node) { this.makeCert = (user, fromServer, overrideProps) => co(function*() { const lookup = yield that.lookup(user.pub, fromServer); const current = yield node.server.BlockchainService.current(); - const idty = lookup.results[0].uids[0]; + const idty = _.filter(lookup.results[0].uids, (uidEntry) => uidEntry.uid === user.uid)[0] let buid = current ? ucp.format.buid(current.number, current.hash) : ucp.format.buid(); const cert = { "version": constants.DOCUMENTS_VERSION, @@ -103,10 +104,11 @@ function User (uid, options, node) { this.makeRevocation = (givenLookupIdty, overrideProps) => co(function*() { const res = givenLookupIdty || (yield that.lookup(pub)); + const matchingResult = _.filter(res.results[0].uids, (uidEntry) => uidEntry.uid === uid)[0] const idty = { - uid: res.results[0].uids[0].uid, - buid: res.results[0].uids[0].meta.timestamp, - sig: res.results[0].uids[0].self + uid: matchingResult.uid, + buid: matchingResult.meta.timestamp, + sig: matchingResult.self } const revocation = { "currency": node.server.conf.currency, -- GitLab From 1591749bb14c3e151cf791357fa5a965a390f9fe Mon Sep 17 00:00:00 2001 From: librelois Date: Sat, 11 Nov 2017 18:46:24 +0100 Subject: [PATCH 18/72] Revert "[enh] prepare the management of several ws2p versions + continuation of refactoring ws2p connetions priority" This reverts commit 4a173cfc7849760717a7d4fa11c36866847f1882. --- app/lib/common-libs/constants.ts | 4 - app/lib/dto/PeerDTO.ts | 77 ++++------------ app/modules/ws2p/lib/WS2PCluster.ts | 132 ++++++---------------------- app/modules/ws2p/lib/WS2PServer.ts | 15 ++-- app/modules/ws2p/lib/constants.ts | 10 +-- 5 files changed, 55 insertions(+), 183 deletions(-) diff --git a/app/lib/common-libs/constants.ts b/app/lib/common-libs/constants.ts index 637bc0e0..f9cda71f 100644 --- a/app/lib/common-libs/constants.ts +++ b/app/lib/common-libs/constants.ts @@ -33,9 +33,7 @@ const CONDITIONS = "(&&|\\|\\|| |[()]|(SIG\\(" + PUBKEY + "\\)|(XHX\\([A-F0-9] const BMA_REGEXP = /^BASIC_MERKLED_API( ([a-z_][a-z0-9-_.]*))?( ([0-9.]+))?( ([0-9a-f:]+))?( ([0-9]+))$/ const BMATOR_REGEXP = /^BMATOR( ([a-z0-9]{16})\.onion)( ([0-9.]+))?( ([0-9a-f:]+))?( ([0-9]+))$/ const WS2P_REGEXP = /^WS2P ([a-f0-9]{8}) ([a-z_][a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+) ([0-9]+)(?: (.+))?$/ -const WS2P_V2_REGEXP = /^WS2P ([0-9]+) ([a-f0-9]{8}) ([a-z_][a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+) ([0-9]+)(?: (.+))?$/ const WS2PTOR_REGEXP = /^WS2PTOR ([a-f0-9]{8}) ([a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+.onion) ([0-9]+)(?: (.+))?$/ -const WS2PTOR_V2_REGEXP = /^WS2PTOR ([0-9]+) ([a-f0-9]{8}) ([a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+.onion) ([0-9]+)(?: (.+))?$/ const WS_FULL_ADDRESS_ONION_REGEX = /^(?:wss?:\/\/)(?:www\.)?([0-9a-z]{16}\.onion)(:[0-9]+)?$/ const IPV4_REGEXP = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/; const IPV6_REGEXP = /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|(([0-9A-Fa-f]{1,4}:){0,5}:((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|(::([0-9A-Fa-f]{1,4}:){0,5}((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/; @@ -97,9 +95,7 @@ export const CommonConstants = { BMA_REGEXP, BMATOR_REGEXP, WS2P_REGEXP, - WS2P_V2_REGEXP, WS2PTOR_REGEXP, - WS2PTOR_V2_REGEXP, WS_FULL_ADDRESS_ONION_REGEX, IPV4_REGEXP, IPV6_REGEXP, diff --git a/app/lib/dto/PeerDTO.ts b/app/lib/dto/PeerDTO.ts index 0704fe14..dc5754b6 100644 --- a/app/lib/dto/PeerDTO.ts +++ b/app/lib/dto/PeerDTO.ts @@ -2,7 +2,6 @@ import {DBPeer} from "../dal/sqliteDAL/PeerDAL" import {hashf} from "../common" import {CommonConstants} from "../common-libs/constants" import {Cloneable} from "./Cloneable" -import { WS2PConstants } from '../../modules/ws2p/lib/constants'; export interface WS2PEndpoint { uuid:string @@ -95,59 +94,29 @@ export class PeerDTO implements Cloneable { return bma || {}; } - getOnceWS2PEndpoint(canReachTorEp:boolean, canReachClearEp:boolean, uuidExcluded:string[] = []) { - let api:{ version:number, uuid:string, host:string, port:number, path:string }|null = null - let bestWS2PVersionAvailable:number = 0 - let bestWS2PTORVersionAvailable:number = 0 + getWS2P(canReachTorEp:boolean, canReachClearEp:boolean) { + let api:{ uuid:string, host:string, port:number, path:string }|null = null + const endpointRegexp = (canReachTorEp) ? CommonConstants.WS2PTOR_REGEXP:CommonConstants.WS2P_REGEXP for (const ep of this.endpoints) { if (canReachTorEp) { - let matches:any = ep.match(CommonConstants.WS2PTOR_V2_REGEXP) - if (matches && parseInt(matches[1]) > bestWS2PTORVersionAvailable && (uuidExcluded.indexOf(matches[2]) === -1)) { - bestWS2PTORVersionAvailable = matches[1] - api = { - version: parseInt(matches[1]), - uuid: matches[2], - host: matches[3] || '', - port: parseInt(matches[4]) || 0, - path: matches[5] - } - } else { - matches = ep.match(CommonConstants.WS2PTOR_REGEXP) - if (matches && bestWS2PTORVersionAvailable == 0 && (uuidExcluded.indexOf(matches[1]) === -1)) { - bestWS2PTORVersionAvailable = 1 - api = { - version: 1, - uuid: matches[1], - host: matches[2] || '', - port: parseInt(matches[3]) || 0, - path: matches[4] - } + const matches:any = ep.match(CommonConstants.WS2PTOR_REGEXP) + if (matches) { + return { + uuid: matches[1], + host: matches[2] || '', + port: parseInt(matches[3]) || 0, + path: matches[4] } } } - // If can reach clear endpoint and not found tor endpoint - if (canReachClearEp && bestWS2PTORVersionAvailable == 0) { - let matches:any = ep.match(CommonConstants.WS2P_V2_REGEXP) - if (matches && parseInt(matches[1]) > bestWS2PVersionAvailable && (uuidExcluded.indexOf(matches[2]) === -1)) { - bestWS2PVersionAvailable = parseInt(matches[1]) + if (canReachClearEp) { + const matches:any = !api && ep.match(CommonConstants.WS2P_REGEXP) + if (matches) { api = { - version: parseInt(matches[1]), - uuid: matches[2], - host: matches[3] || '', - port: parseInt(matches[4]) || 0, - path: matches[5] - } - } else { - matches = ep.match(CommonConstants.WS2P_REGEXP) - if (matches && bestWS2PVersionAvailable == 0 && (uuidExcluded.indexOf(matches[1]) === -1)) { - bestWS2PVersionAvailable = 1 - api = { - version: 1, - uuid: matches[1], - host: matches[2] || '', - port: parseInt(matches[3]) || 0, - path: matches[4] - } + uuid: matches[1], + host: matches[2] || '', + port: parseInt(matches[3]) || 0, + path: matches[4] } } } @@ -155,18 +124,6 @@ export class PeerDTO implements Cloneable { return api || null } - getAllWS2PEndpoints(canReachTorEp:boolean, canReachClearEp:boolean, myUUID:string) { - let apis:{ uuid:string, host:string, port:number, path:string }[] = [] - let uuidExcluded:string[] = [myUUID] - let api = this.getOnceWS2PEndpoint(canReachTorEp, canReachClearEp, uuidExcluded) - while (api !== null) { - uuidExcluded.push(api.uuid) - apis.push(api) - api = this.getOnceWS2PEndpoint(canReachTorEp, canReachClearEp, uuidExcluded) - } - return apis - } - getDns() { const bma = this.getBMA(); return bma.dns ? bma.dns : null; diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index fdd829af..b8940819 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -17,7 +17,6 @@ import { CommonConstants } from '../../../lib/common-libs/constants'; import { Package } from "../../../lib/common/package"; import { Constants } from "../../prover/lib/constants"; import { ProxiesConf } from '../../../lib/proxy'; -import { Keypair } from '../../../lib/dto/ConfDTO'; const es = require('event-stream') const nuuid = require('node-uuid') @@ -269,7 +268,7 @@ export class WS2PCluster { this.ws2pServer = await WS2PServer.bindOn(this.server, host, port, this.fifo, (pubkey:string, connectedPubkeys:string[]) => { const privilegedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[] return this.acceptPubkey(pubkey, connectedPubkeys, [], () => this.servedCount(), this.maxLevel2Peers, privilegedNodes, (this.server.conf.ws2p !== undefined && this.server.conf.ws2p.privilegedOnly)) - }, this.keyPriorityLevel, this.messageHandler) + }, this.messageHandler) this.host = host this.port = port return this.ws2pServer @@ -331,20 +330,13 @@ export class WS2PCluster { } async connectToWS2Peers() { - const myUUID = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) ? this.server.conf.ws2p.uuid:"" const potentials = await this.server.dal.getWS2Peers() const peers:PeerDTO[] = potentials.map((p:any) => PeerDTO.fromJSONObject(p)) const prefered = ((this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) || []).slice() // Copy // Our key is also a prefered one, so we connect to our siblings + prefered.push(this.server.conf.pair.pub) const canReachTorEndpoint = ProxiesConf.canReachTorEndpoint(this.server.conf.proxiesConf) peers.sort((a, b) => { - // Top priority at our own nodes - if (a.pubkey === this.server.conf.pair.pub && b.pubkey !== this.server.conf.pair.pub) { - return -1 - } else if (a.pubkey !== this.server.conf.pair.pub && b.pubkey === this.server.conf.pair.pub) { - return 1 - } - const aIsPrefered = prefered.indexOf(a.pubkey) !== -1 const bIsPrefered = prefered.indexOf(b.pubkey) !== -1 @@ -381,34 +373,20 @@ export class WS2PCluster { const canReachClearEndpoint = ProxiesConf.canReachClearEndpoint(this.server.conf.proxiesConf) while (i < peers.length && this.clientsCount() < this.maxLevel1Size) { const p = peers[i] - if (p.pubkey === this.server.conf.pair.pub) { - const apis = p.getAllWS2PEndpoints(canReachTorEndpoint, canReachClearEndpoint, myUUID) - for (const api of apis) { - try { - // We do not connect to local host - if (api.uuid !== myUUID || api.uuid === '11111111') { - await this.connectToRemoteWS(api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) - } - } catch (e) { - this.server.logger.debug('WS2P: init: failed connection') - } - } - } else { - const api = p.getOnceWS2PEndpoint(canReachTorEndpoint, canReachClearEndpoint) - if (api) { - try { - // We do not connect to local host - if (api.uuid !== myUUID || api.uuid === '11111111') { - await this.connectToRemoteWS(api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) - } - } catch (e) { - this.server.logger.debug('WS2P: init: failed connection') + const api = p.getWS2P(canReachTorEndpoint, canReachClearEndpoint) + if (api) { + try { + // We do not connect to local host + if (!this.server.conf.ws2p || api.uuid !== this.server.conf.ws2p.uuid || p.pubkey !== this.server.conf.pair.pub || api.uuid === '11111111') { + await this.connectToRemoteWS(api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) } + } catch (e) { + this.server.logger.debug('WS2P: init: failed connection') } } i++ // Trim the eventual extra connections - setTimeout(() => this.trimClientConnections(prefered), WS2PConstants.CONNEXION_TIMEOUT) + setTimeout(() => this.trimClientConnections(), WS2PConstants.CONNEXION_TIMEOUT) } } @@ -422,16 +400,16 @@ export class WS2PCluster { // New peer if (data.endpoints) { const peer = PeerDTO.fromJSONObject(data) - const ws2pEnpoint = peer.getOnceWS2PEndpoint(ProxiesConf.canReachTorEndpoint(this.server.conf.proxiesConf), ProxiesConf.canReachClearEndpoint(this.server.conf.proxiesConf)) + const ws2pEnpoint = peer.getWS2P(ProxiesConf.canReachTorEndpoint(this.server.conf.proxiesConf), ProxiesConf.canReachClearEndpoint(this.server.conf.proxiesConf)) if (ws2pEnpoint) { // Check if already connected to the pubkey (in any way: server or client) const connectedPubkeys = this.getConnectedPubkeys() const connectedWS2PUID = this.getConnectedWS2PUID() - const preferedKeys = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[] - const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, connectedWS2PUID, () => this.clientsCount(), this.maxLevel1Size, preferedKeys, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEnpoint.uuid) + const preferedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[] + const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, connectedWS2PUID, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEnpoint.uuid) if (shouldAccept && (!this.server.conf.ws2p || ws2pEnpoint.uuid !== this.server.conf.ws2p.uuid || peer.pubkey !== this.server.conf.pair.pub || ws2pEnpoint.uuid === '11111111')) { await this.connectToRemoteWS(ws2pEnpoint.host, ws2pEnpoint.port, ws2pEnpoint.path, this.messageHandler, peer.pubkey, ws2pEnpoint.uuid) - await this.trimClientConnections(preferedKeys) + await this.trimClientConnections() } } } @@ -502,60 +480,7 @@ export class WS2PCluster { return { sig, message, pub } } - async removeLowPriorityConnections(privilegedKeys:string[]) { - let serverPubkeys:string[] = [] - if (this.ws2pServer) { - serverPubkeys = this.ws2pServer.getConnexions().map(c => c.pubkey) - } - let disconnectedOne = true - // Disconnect Private connexions already present under Public - while (disconnectedOne) { - disconnectedOne = false - let uuids = Object.keys(this.ws2pClients) - uuids = _.shuffle(uuids) - for (const uuid of uuids) { - const client = this.ws2pClients[uuid] - const pub = client.connection.pubkey - const isNotOurself = pub !== this.server.conf.pair.pub - const isAlreadyInPublic = serverPubkeys.indexOf(pub) !== -1 - if (isNotOurself && isAlreadyInPublic) { - client.connection.close() - await client.connection.closed - disconnectedOne = true - if (this.ws2pClients[uuid]) { - delete this.ws2pClients[uuid] - } - } - } - } - // Disconnect Private connexions until the maximum size is respected - while (disconnectedOne && this.clientsCount() > this.maxLevel1Size) { - let uuids = Object.keys(this.ws2pClients) - uuids = _.shuffle(uuids) - let lowPriorityConnectionUUID:string = uuids[0] - let minPriorityLevel = this.keyPriorityLevel(this.ws2pClients[lowPriorityConnectionUUID].connection.pubkey, privilegedKeys) - for (const uuid of uuids) { - const client = this.ws2pClients[uuid] - if (uuid !== lowPriorityConnectionUUID) { - let uuidPriorityLevel = this.keyPriorityLevel(client.connection.pubkey, privilegedKeys) - if (uuidPriorityLevel < minPriorityLevel) { - lowPriorityConnectionUUID = uuid - minPriorityLevel = uuidPriorityLevel - } - } - delete this.ws2pClients[lowPriorityConnectionUUID] - } - } - } - - keyPriorityLevel(pubkey:string, preferedOrPrivilegedKeys:string[]) { - let priorityLevel = (this.server.dal.isMember(pubkey)) ? WS2PConstants.CONNECTIONS_PRIORITY.MEMBER_KEY_LEVEL:0 - priorityLevel += (preferedOrPrivilegedKeys.indexOf(pubkey) !== -1) ? WS2PConstants.CONNECTIONS_PRIORITY.PREFERED_PRIVILEGED_KEY_LEVEL:0 - priorityLevel += (this.server.conf.pair.pub === pubkey) ? WS2PConstants.CONNECTIONS_PRIORITY.SELF_KEY_LEVEL:0 - return priorityLevel - } - - async trimClientConnections(preferedKeys:string[]) { + async trimClientConnections() { let serverPubkeys:string[] = [] if (this.ws2pServer) { serverPubkeys = this.ws2pServer.getConnexions().map(c => c.pubkey) @@ -662,19 +587,9 @@ export class WS2PCluster { return false } - if (this.server.conf.pair.pub === pub) { - // We do not accept oneself connetion - if (this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID) { - return false - } else { - // We always accept self nodes, and they have a supreme priority (these are siblings) - if (targetWS2PUID === "" || this.isNewSiblingNode(pub, targetWS2PUID, connectedWS2PUID) ) { - return true - } else { - // We are already connected to this self node (same WS2PUID) - return false - } - } + // We do not accept oneself connetion + if (this.server.conf.pair.pub === pub && this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID) { + return false } // We do not accept banned keys @@ -698,10 +613,17 @@ export class WS2PCluster { if (getConcurrentConnexionsCount() < maxConcurrentConnexionsSize) { // Yes: just connect to it return true + } else if (this.server.conf.pair.pub === pub) { + // We always accept self nodes, and they have a supreme priority (these are siblings) + if (targetWS2PUID !== "") { + if (this.isNewSiblingNode(pub, targetWS2PUID, connectedWS2PUID)) { + return true + } + } } else if (connectedPubkeys.indexOf(pub) === -1) { - let minPriorityLevel = WS2PConstants.CONNECTIONS_PRIORITY.MAX_PRIORITY_LEVEL + let minPriorityLevel = WS2PConstants.MAX_PRIORITY_LEVEL for (const connectedPubkey of connectedPubkeys) { let connectedPubkeyPriorityLevel = this.ws2pServer.keyPriorityLevel(connectedPubkey, priorityKeys) if (connectedPubkeyPriorityLevel < minPriorityLevel) { diff --git a/app/modules/ws2p/lib/WS2PServer.ts b/app/modules/ws2p/lib/WS2PServer.ts index 85bed337..d11c3298 100644 --- a/app/modules/ws2p/lib/WS2PServer.ts +++ b/app/modules/ws2p/lib/WS2PServer.ts @@ -7,7 +7,6 @@ import {WS2PConstants} from "./constants" import {WS2PMessageHandler} from "./impl/WS2PMessageHandler" import {WS2PStreamer} from "./WS2PStreamer" import {WS2PSingleWriteStream} from "./WS2PSingleWriteStream" -import { WS2PCluster } from './WS2PCluster'; const WebSocketServer = require('ws').Server @@ -22,8 +21,7 @@ export class WS2PServer extends events.EventEmitter { private host:string, private port:number, private fifo:GlobalFifoPromise, - private shouldAcceptConnection:(pubkey:string, connectedPubkeys:string[])=>Promise, - public keyPriorityLevel:(pubkey:string, privilegedKeys:string[])=>number) { + private shouldAcceptConnection:(pubkey:string, connectedPubkeys:string[])=>Promise) { super() // Conf: max public connections if (this.server.conf.ws2p && this.server.conf.ws2p.maxPublic !== undefined) { @@ -145,6 +143,13 @@ export class WS2PServer extends events.EventEmitter { this.removeConnection(lowPriorityConnection) } + keyPriorityLevel(pubkey:string, privilegedKeys:string[]) { + let priorityLevel = (this.server.dal.isMember(pubkey)) ? 1:0 + priorityLevel += (privilegedKeys.indexOf(pubkey) !== -1) ? 2:0 + priorityLevel += (this.server.conf.pair.pub === pubkey) ? 4:0 + return priorityLevel + } + private removeConnection(c:WS2PConnection) { const index = this.connections.indexOf(c) if (index !== -1) { @@ -178,8 +183,8 @@ export class WS2PServer extends events.EventEmitter { })) } - static async bindOn(server:Server, host:string, port:number, fifo:GlobalFifoPromise, shouldAcceptConnection:(pubkey:string, connectedPubkeys:string[])=>Promise, keyPriorityLevel:(pubkey:string, privilegedKeys:string[])=>number, messageHandler:WS2PMessageHandler) { - const ws2ps = new WS2PServer(server, host, port, fifo, shouldAcceptConnection, keyPriorityLevel) + static async bindOn(server:Server, host:string, port:number, fifo:GlobalFifoPromise, shouldAcceptConnection:(pubkey:string, connectedPubkeys:string[])=>Promise, messageHandler:WS2PMessageHandler) { + const ws2ps = new WS2PServer(server, host, port, fifo, shouldAcceptConnection) await ws2ps.listenToWebSocketConnections(messageHandler) server.logger.info('WS2P server %s listening on %s:%s', server.conf.pair.pub, host, port) return ws2ps diff --git a/app/modules/ws2p/lib/constants.ts b/app/modules/ws2p/lib/constants.ts index 080db10c..cc75af03 100644 --- a/app/modules/ws2p/lib/constants.ts +++ b/app/modules/ws2p/lib/constants.ts @@ -1,8 +1,6 @@ import {CommonConstants} from "../../../lib/common-libs/constants" export const WS2PConstants = { - WS2P_VERSION: 2, - WS2P_UPNP_TTL: 600, WS2P_PORTS_START: 20900, WS2P_PORTS_END: 20999, @@ -21,13 +19,7 @@ export const WS2PConstants = { MAX_LEVEL_1_PEERS: 10, MAX_LEVEL_2_PEERS: 10, CONNECTIONS_LOW_LEVEL: 3, - - CONNECTIONS_PRIORITY: { - MEMBER_KEY_LEVEL: 1, - PREFERED_PRIVILEGED_KEY_LEVEL: 2, - SELF_KEY_LEVEL: 4, - MAX_PRIORITY_LEVEL: 7, - }, + MAX_PRIORITY_LEVEL: 7, BAN_DURATION_IN_SECONDS: 120, BAN_ON_REPEAT_THRESHOLD: 5, -- GitLab From a36d28929220c6249840058f6dd60a1eff569d45 Mon Sep 17 00:00:00 2001 From: librelois Date: Sat, 11 Nov 2017 18:46:59 +0100 Subject: [PATCH 19/72] Revert "[mod] refactoring ws2p connetion priorities #1184 #1185" This reverts commit 1d251881986b87ec1f2770054fbda1c96148d357. --- app/modules/ws2p/lib/WS2PClient.ts | 5 +- app/modules/ws2p/lib/WS2PCluster.ts | 107 ++++++++++--------------- app/modules/ws2p/lib/WS2PConnection.ts | 12 +-- app/modules/ws2p/lib/WS2PServer.ts | 56 ++++++++----- app/modules/ws2p/lib/constants.ts | 1 - 5 files changed, 86 insertions(+), 95 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PClient.ts b/app/modules/ws2p/lib/WS2PClient.ts index 0bc7bc11..569609f6 100644 --- a/app/modules/ws2p/lib/WS2PClient.ts +++ b/app/modules/ws2p/lib/WS2PClient.ts @@ -13,7 +13,7 @@ export class WS2PClient { private constructor(public connection:WS2PConnection) {} - static async connectTo(server:Server, fullEndpointAddress:string, expectedWS2PUID:string, messageHandler:WS2PMessageHandler, expectedPub:string, allowKey:(pub:string)=>Promise ) { + static async connectTo(server:Server, fullEndpointAddress:string, uuid:string, messageHandler:WS2PMessageHandler, expectedPub:string, allowKey:(pub:string)=>Promise ) { const k2 = new Key(server.conf.pair.pub, server.conf.pair.sec) const c = WS2PConnection.newConnectionToAddress( fullEndpointAddress, @@ -25,8 +25,7 @@ export class WS2PClient { connectionTimeout: WS2PConstants.REQUEST_TIMEOUT, requestTimeout: WS2PConstants.REQUEST_TIMEOUT }, - expectedPub, - expectedWS2PUID + expectedPub ) const singleWriteProtection = new WS2PSingleWriteStream() const streamer = new WS2PStreamer(c) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index b8940819..f41ad9cb 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -267,7 +267,7 @@ export class WS2PCluster { } this.ws2pServer = await WS2PServer.bindOn(this.server, host, port, this.fifo, (pubkey:string, connectedPubkeys:string[]) => { const privilegedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[] - return this.acceptPubkey(pubkey, connectedPubkeys, [], () => this.servedCount(), this.maxLevel2Peers, privilegedNodes, (this.server.conf.ws2p !== undefined && this.server.conf.ws2p.privilegedOnly)) + return this.acceptPubkey(pubkey, connectedPubkeys, () => this.servedCount(), this.maxLevel2Peers, privilegedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.privilegedOnly || false)) }, this.messageHandler) this.host = host this.port = port @@ -298,9 +298,8 @@ export class WS2PCluster { const fullEndpointAddress = WS2PCluster.getFullAddress(host, port, path) const ws2pc = await WS2PClient.connectTo(this.server, fullEndpointAddress, ws2pEndpointUUID, messageHandler, expectedPub, (pub:string) => { const connectedPubkeys = this.getConnectedPubkeys() - const connectedWS2PUID = this.getConnectedWS2PUID() const preferedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[] - return this.acceptPubkey(expectedPub, connectedPubkeys, connectedWS2PUID, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEndpointUUID) + return this.acceptPubkey(expectedPub, connectedPubkeys, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEndpointUUID) }) this.ws2pClients[uuid] = ws2pc pub = ws2pc.connection.pubkey @@ -404,11 +403,10 @@ export class WS2PCluster { if (ws2pEnpoint) { // Check if already connected to the pubkey (in any way: server or client) const connectedPubkeys = this.getConnectedPubkeys() - const connectedWS2PUID = this.getConnectedWS2PUID() const preferedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[] - const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, connectedWS2PUID, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEnpoint.uuid) + const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEnpoint.uuid) if (shouldAccept && (!this.server.conf.ws2p || ws2pEnpoint.uuid !== this.server.conf.ws2p.uuid || peer.pubkey !== this.server.conf.pair.pub || ws2pEnpoint.uuid === '11111111')) { - await this.connectToRemoteWS(ws2pEnpoint.host, ws2pEnpoint.port, ws2pEnpoint.path, this.messageHandler, peer.pubkey, ws2pEnpoint.uuid) + await this.connectToRemoteWS(ws2pEnpoint.host, ws2pEnpoint.port, ws2pEnpoint.path, this.messageHandler, peer.pubkey) await this.trimClientConnections() } } @@ -575,75 +573,64 @@ export class WS2PCluster { protected async acceptPubkey( pub:string, connectedPubkeys:string[], - connectedWS2PUID:string[], getConcurrentConnexionsCount:()=>number, maxConcurrentConnexionsSize:number, priorityKeys:string[], priorityKeysOnly:boolean, targetWS2PUID = "" ) { - // We need ws2pServer instance - if (!this.ws2pServer) { - return false - } - - // We do not accept oneself connetion - if (this.server.conf.pair.pub === pub && this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID) { - return false - } - // We do not accept banned keys if (this.banned[pub]) { this.server.logger.warn('Connection to %s refused, reason: %s', pub.slice(0, 8), this.banned[pub]) return false } - - // Is priority key ? - let isPriorityKey = priorityKeys.indexOf(pub) !== -1 - - // We do not accept forbidden keys - if (priorityKeysOnly && !isPriorityKey && this.server.conf.pair.pub !== pub) { - return false - } - - // Is member key ? - const isMemberPeer = await this.server.dal.isMember(pub) - - // Do we have room? - if (getConcurrentConnexionsCount() < maxConcurrentConnexionsSize) { - // Yes: just connect to it - return true - } else if (this.server.conf.pair.pub === pub) { - // We always accept self nodes, and they have a supreme priority (these are siblings) - if (targetWS2PUID !== "") { - if (this.isNewSiblingNode(pub, targetWS2PUID, connectedWS2PUID)) { - return true - } + let accept = priorityKeys.indexOf(pub) !== -1 + if (!accept && !priorityKeysOnly && connectedPubkeys.indexOf(pub) === -1) { + // Do we have room? + if (this.server.conf.pair.pub === pub && this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID) { + accept = false } - } - else if (connectedPubkeys.indexOf(pub) === -1) - { - let minPriorityLevel = WS2PConstants.MAX_PRIORITY_LEVEL - for (const connectedPubkey of connectedPubkeys) { - let connectedPubkeyPriorityLevel = this.ws2pServer.keyPriorityLevel(connectedPubkey, priorityKeys) - if (connectedPubkeyPriorityLevel < minPriorityLevel) { - minPriorityLevel = connectedPubkeyPriorityLevel + else if (getConcurrentConnexionsCount() < maxConcurrentConnexionsSize) { + // Yes: just connect to it + accept = true + } + else { + // No: let's verify some peer has a lower priority + if (connectedPubkeys.indexOf(this.server.conf.pair.pub) !== -1) { + // Yes, we are connected to ourself. Let's replace this connexion + accept = true + } + else { + // Does this node have the priority over at least one node? + const isMemberPeer = await this.server.dal.isMember(pub) + if (isMemberPeer) { + // The node may have the priority over at least 1 other node + let i = 0, existsOneNonMemberNode = false + while (!existsOneNonMemberNode && i < connectedPubkeys.length) { + const isAlsoAMemberPeer = await this.server.dal.isMember(connectedPubkeys[i]) + existsOneNonMemberNode = !isAlsoAMemberPeer + i++ + } + if (existsOneNonMemberNode) { + // The node has the priority over a non-member peer: try to connect + accept = true + } + } } } - if (this.ws2pServer.keyPriorityLevel(pub, priorityKeys) > minPriorityLevel) { - return true + } else { + // The pubkey is already connected: we accept only self nodes, and they have a supreme priority (these are siblings) + if (targetWS2PUID) { + if (this.isSiblingNode(pub, targetWS2PUID)) { + accept = true + } } } - return false + return accept } - isNewSiblingNode(pub:string, targetWS2PUID:string, connectedWS2PUID:string[]) { - for (const uuid of connectedWS2PUID) { - if (uuid === targetWS2PUID) { - return false - } - } - return true + isSiblingNode(pub:string, uuid:string) { + return !!(this.server.conf.pair.pub === pub && this.server.conf.ws2p && this.server.conf.ws2p.uuid !== uuid) } async getLevel1Connections() { @@ -755,12 +742,6 @@ export class WS2PCluster { return clients.concat(served) } - getConnectedWS2PUID() { - const clients = Object.keys(this.ws2pClients).map(k => this.ws2pClients[k].connection.uuid) - const served = this.ws2pServer ? this.ws2pServer.getConnexions().map(c => c.uuid) : [] - return clients.concat(served) - } - banConnection(c:WS2PConnection, reason:string) { this.server.logger.warn('Banning connections of %s for %ss, reason: %s', c.pubkey.slice(0, 8), WS2PConstants.BAN_DURATION_IN_SECONDS, reason) if (c.pubkey) { diff --git a/app/modules/ws2p/lib/WS2PConnection.ts b/app/modules/ws2p/lib/WS2PConnection.ts index eed3dfff..0595e562 100644 --- a/app/modules/ws2p/lib/WS2PConnection.ts +++ b/app/modules/ws2p/lib/WS2PConnection.ts @@ -256,8 +256,7 @@ export class WS2PConnection { connectionTimeout: REQUEST_TIMEOUT_VALUE, requestTimeout: REQUEST_TIMEOUT_VALUE }, - private expectedPub:string = "", - private expectedWS2PUID:string = "" + private expectedPub:string = "" ) { this.connectedp = new Promise((resolve, reject) => { this.connectedResolve = resolve @@ -278,8 +277,7 @@ export class WS2PConnection { connectionTimeout: REQUEST_TIMEOUT_VALUE, requestTimeout: REQUEST_TIMEOUT_VALUE }, - expectedPub:string = "", - expectedWS2PUID:string = "") { + expectedPub:string = "") { if (address.match(WS2PConstants.FULL_ADDRESS_ONION_REGEX)) { options = { connectionTimeout: WS2PConstants.CONNEXION_TOR_TIMEOUT, @@ -294,7 +292,7 @@ export class WS2PConnection { websocket.on('close', () => res()) }) websocket.on('error', () => websocket.close()) - return new WS2PConnection(websocket, onWsOpened, onWsClosed, messageHandler, localAuth, remoteAuth, options, expectedPub, expectedWS2PUID) + return new WS2PConnection(websocket, onWsOpened, onWsClosed, messageHandler, localAuth, remoteAuth, options, expectedPub) } static newConnectionFromWebSocketServer( @@ -321,10 +319,6 @@ export class WS2PConnection { return this.remoteAuth.getPubkey() } - get uuid() { - return this.expectedWS2PUID - } - get nbRequests() { return this.nbRequestsCount } diff --git a/app/modules/ws2p/lib/WS2PServer.ts b/app/modules/ws2p/lib/WS2PServer.ts index d11c3298..ae79815f 100644 --- a/app/modules/ws2p/lib/WS2PServer.ts +++ b/app/modules/ws2p/lib/WS2PServer.ts @@ -116,8 +116,8 @@ export class WS2PServer extends events.EventEmitter { } }) }) - let privilegedKeys = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[] - await this.removeLowPriorityConnection(privilegedKeys) + + await this.trimConnections() await this.server.dal.setPeerUP(c.pubkey) @@ -128,26 +128,44 @@ export class WS2PServer extends events.EventEmitter { }) } - async removeLowPriorityConnection(privilegedKeys:string[]) { - let lowPriorityConnection:WS2PConnection = this.connections[0] - let minPriorityLevel = this.keyPriorityLevel(lowPriorityConnection.pubkey, privilegedKeys) - for (const c of this.connections) { - if (c !== lowPriorityConnection) { - let cPriorityLevel = this.keyPriorityLevel(c.pubkey, privilegedKeys) - if (cPriorityLevel < minPriorityLevel) { - lowPriorityConnection = c - minPriorityLevel = cPriorityLevel + async trimConnections() { + /*** OVERFLOW TRIMMING ***/ + let disconnectedOne = true + // Disconnect non-members + while (disconnectedOne && this.connections.length > this.maxLevel2Size) { + disconnectedOne = false + for (const c of this.connections) { + const isMember = await this.server.dal.isMember(c.pubkey) + if (!isMember && !disconnectedOne) { + c.close() + this.removeConnection(c) + disconnectedOne = true + } + } + } + // Disconnect members + while (this.connections.length > this.maxLevel2Size) { + for (const c of this.connections) { + c.close() + this.removeConnection(c) + } + } + /*** DUPLICATES TRIMMING ***/ + disconnectedOne = true + while (disconnectedOne) { + disconnectedOne = false + const pubkeysFound = [] + for (const c of this.connections) { + if (pubkeysFound.indexOf(c.pubkey) !== -1) { + c.close() + this.removeConnection(c) + disconnectedOne = true + } + else if (c.pubkey !== this.server.conf.pair.pub) { + pubkeysFound.push(c.pubkey) } } } - this.removeConnection(lowPriorityConnection) - } - - keyPriorityLevel(pubkey:string, privilegedKeys:string[]) { - let priorityLevel = (this.server.dal.isMember(pubkey)) ? 1:0 - priorityLevel += (privilegedKeys.indexOf(pubkey) !== -1) ? 2:0 - priorityLevel += (this.server.conf.pair.pub === pubkey) ? 4:0 - return priorityLevel } private removeConnection(c:WS2PConnection) { diff --git a/app/modules/ws2p/lib/constants.ts b/app/modules/ws2p/lib/constants.ts index cc75af03..51972d7f 100644 --- a/app/modules/ws2p/lib/constants.ts +++ b/app/modules/ws2p/lib/constants.ts @@ -19,7 +19,6 @@ export const WS2PConstants = { MAX_LEVEL_1_PEERS: 10, MAX_LEVEL_2_PEERS: 10, CONNECTIONS_LOW_LEVEL: 3, - MAX_PRIORITY_LEVEL: 7, BAN_DURATION_IN_SECONDS: 120, BAN_ON_REPEAT_THRESHOLD: 5, -- GitLab From 0345d7e5e565f0913c2d70c51f56750ba0b38e51 Mon Sep 17 00:00:00 2001 From: librelois Date: Sat, 11 Nov 2017 20:42:52 +0100 Subject: [PATCH 20/72] Revert "Revert "[mod] refactoring ws2p connetion priorities #1184 #1185"" This reverts commit a36d28929220c6249840058f6dd60a1eff569d45. --- app/modules/ws2p/lib/WS2PClient.ts | 5 +- app/modules/ws2p/lib/WS2PCluster.ts | 107 +++++++++++++++---------- app/modules/ws2p/lib/WS2PConnection.ts | 12 ++- app/modules/ws2p/lib/WS2PServer.ts | 56 +++++-------- app/modules/ws2p/lib/constants.ts | 1 + 5 files changed, 95 insertions(+), 86 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PClient.ts b/app/modules/ws2p/lib/WS2PClient.ts index 569609f6..0bc7bc11 100644 --- a/app/modules/ws2p/lib/WS2PClient.ts +++ b/app/modules/ws2p/lib/WS2PClient.ts @@ -13,7 +13,7 @@ export class WS2PClient { private constructor(public connection:WS2PConnection) {} - static async connectTo(server:Server, fullEndpointAddress:string, uuid:string, messageHandler:WS2PMessageHandler, expectedPub:string, allowKey:(pub:string)=>Promise ) { + static async connectTo(server:Server, fullEndpointAddress:string, expectedWS2PUID:string, messageHandler:WS2PMessageHandler, expectedPub:string, allowKey:(pub:string)=>Promise ) { const k2 = new Key(server.conf.pair.pub, server.conf.pair.sec) const c = WS2PConnection.newConnectionToAddress( fullEndpointAddress, @@ -25,7 +25,8 @@ export class WS2PClient { connectionTimeout: WS2PConstants.REQUEST_TIMEOUT, requestTimeout: WS2PConstants.REQUEST_TIMEOUT }, - expectedPub + expectedPub, + expectedWS2PUID ) const singleWriteProtection = new WS2PSingleWriteStream() const streamer = new WS2PStreamer(c) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index f41ad9cb..b8940819 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -267,7 +267,7 @@ export class WS2PCluster { } this.ws2pServer = await WS2PServer.bindOn(this.server, host, port, this.fifo, (pubkey:string, connectedPubkeys:string[]) => { const privilegedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[] - return this.acceptPubkey(pubkey, connectedPubkeys, () => this.servedCount(), this.maxLevel2Peers, privilegedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.privilegedOnly || false)) + return this.acceptPubkey(pubkey, connectedPubkeys, [], () => this.servedCount(), this.maxLevel2Peers, privilegedNodes, (this.server.conf.ws2p !== undefined && this.server.conf.ws2p.privilegedOnly)) }, this.messageHandler) this.host = host this.port = port @@ -298,8 +298,9 @@ export class WS2PCluster { const fullEndpointAddress = WS2PCluster.getFullAddress(host, port, path) const ws2pc = await WS2PClient.connectTo(this.server, fullEndpointAddress, ws2pEndpointUUID, messageHandler, expectedPub, (pub:string) => { const connectedPubkeys = this.getConnectedPubkeys() + const connectedWS2PUID = this.getConnectedWS2PUID() const preferedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[] - return this.acceptPubkey(expectedPub, connectedPubkeys, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEndpointUUID) + return this.acceptPubkey(expectedPub, connectedPubkeys, connectedWS2PUID, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEndpointUUID) }) this.ws2pClients[uuid] = ws2pc pub = ws2pc.connection.pubkey @@ -403,10 +404,11 @@ export class WS2PCluster { if (ws2pEnpoint) { // Check if already connected to the pubkey (in any way: server or client) const connectedPubkeys = this.getConnectedPubkeys() + const connectedWS2PUID = this.getConnectedWS2PUID() const preferedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[] - const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEnpoint.uuid) + const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, connectedWS2PUID, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEnpoint.uuid) if (shouldAccept && (!this.server.conf.ws2p || ws2pEnpoint.uuid !== this.server.conf.ws2p.uuid || peer.pubkey !== this.server.conf.pair.pub || ws2pEnpoint.uuid === '11111111')) { - await this.connectToRemoteWS(ws2pEnpoint.host, ws2pEnpoint.port, ws2pEnpoint.path, this.messageHandler, peer.pubkey) + await this.connectToRemoteWS(ws2pEnpoint.host, ws2pEnpoint.port, ws2pEnpoint.path, this.messageHandler, peer.pubkey, ws2pEnpoint.uuid) await this.trimClientConnections() } } @@ -573,64 +575,75 @@ export class WS2PCluster { protected async acceptPubkey( pub:string, connectedPubkeys:string[], + connectedWS2PUID:string[], getConcurrentConnexionsCount:()=>number, maxConcurrentConnexionsSize:number, priorityKeys:string[], priorityKeysOnly:boolean, targetWS2PUID = "" ) { + // We need ws2pServer instance + if (!this.ws2pServer) { + return false + } + + // We do not accept oneself connetion + if (this.server.conf.pair.pub === pub && this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID) { + return false + } + // We do not accept banned keys if (this.banned[pub]) { this.server.logger.warn('Connection to %s refused, reason: %s', pub.slice(0, 8), this.banned[pub]) return false } - let accept = priorityKeys.indexOf(pub) !== -1 - if (!accept && !priorityKeysOnly && connectedPubkeys.indexOf(pub) === -1) { - // Do we have room? - if (this.server.conf.pair.pub === pub && this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID) { - accept = false - } - else if (getConcurrentConnexionsCount() < maxConcurrentConnexionsSize) { - // Yes: just connect to it - accept = true - } - else { - // No: let's verify some peer has a lower priority - if (connectedPubkeys.indexOf(this.server.conf.pair.pub) !== -1) { - // Yes, we are connected to ourself. Let's replace this connexion - accept = true - } - else { - // Does this node have the priority over at least one node? - const isMemberPeer = await this.server.dal.isMember(pub) - if (isMemberPeer) { - // The node may have the priority over at least 1 other node - let i = 0, existsOneNonMemberNode = false - while (!existsOneNonMemberNode && i < connectedPubkeys.length) { - const isAlsoAMemberPeer = await this.server.dal.isMember(connectedPubkeys[i]) - existsOneNonMemberNode = !isAlsoAMemberPeer - i++ - } - if (existsOneNonMemberNode) { - // The node has the priority over a non-member peer: try to connect - accept = true - } - } + + // Is priority key ? + let isPriorityKey = priorityKeys.indexOf(pub) !== -1 + + // We do not accept forbidden keys + if (priorityKeysOnly && !isPriorityKey && this.server.conf.pair.pub !== pub) { + return false + } + + // Is member key ? + const isMemberPeer = await this.server.dal.isMember(pub) + + // Do we have room? + if (getConcurrentConnexionsCount() < maxConcurrentConnexionsSize) { + // Yes: just connect to it + return true + } else if (this.server.conf.pair.pub === pub) { + // We always accept self nodes, and they have a supreme priority (these are siblings) + if (targetWS2PUID !== "") { + if (this.isNewSiblingNode(pub, targetWS2PUID, connectedWS2PUID)) { + return true } } - } else { - // The pubkey is already connected: we accept only self nodes, and they have a supreme priority (these are siblings) - if (targetWS2PUID) { - if (this.isSiblingNode(pub, targetWS2PUID)) { - accept = true + } + else if (connectedPubkeys.indexOf(pub) === -1) + { + let minPriorityLevel = WS2PConstants.MAX_PRIORITY_LEVEL + for (const connectedPubkey of connectedPubkeys) { + let connectedPubkeyPriorityLevel = this.ws2pServer.keyPriorityLevel(connectedPubkey, priorityKeys) + if (connectedPubkeyPriorityLevel < minPriorityLevel) { + minPriorityLevel = connectedPubkeyPriorityLevel } } + if (this.ws2pServer.keyPriorityLevel(pub, priorityKeys) > minPriorityLevel) { + return true + } } - return accept + return false } - isSiblingNode(pub:string, uuid:string) { - return !!(this.server.conf.pair.pub === pub && this.server.conf.ws2p && this.server.conf.ws2p.uuid !== uuid) + isNewSiblingNode(pub:string, targetWS2PUID:string, connectedWS2PUID:string[]) { + for (const uuid of connectedWS2PUID) { + if (uuid === targetWS2PUID) { + return false + } + } + return true } async getLevel1Connections() { @@ -742,6 +755,12 @@ export class WS2PCluster { return clients.concat(served) } + getConnectedWS2PUID() { + const clients = Object.keys(this.ws2pClients).map(k => this.ws2pClients[k].connection.uuid) + const served = this.ws2pServer ? this.ws2pServer.getConnexions().map(c => c.uuid) : [] + return clients.concat(served) + } + banConnection(c:WS2PConnection, reason:string) { this.server.logger.warn('Banning connections of %s for %ss, reason: %s', c.pubkey.slice(0, 8), WS2PConstants.BAN_DURATION_IN_SECONDS, reason) if (c.pubkey) { diff --git a/app/modules/ws2p/lib/WS2PConnection.ts b/app/modules/ws2p/lib/WS2PConnection.ts index 0595e562..eed3dfff 100644 --- a/app/modules/ws2p/lib/WS2PConnection.ts +++ b/app/modules/ws2p/lib/WS2PConnection.ts @@ -256,7 +256,8 @@ export class WS2PConnection { connectionTimeout: REQUEST_TIMEOUT_VALUE, requestTimeout: REQUEST_TIMEOUT_VALUE }, - private expectedPub:string = "" + private expectedPub:string = "", + private expectedWS2PUID:string = "" ) { this.connectedp = new Promise((resolve, reject) => { this.connectedResolve = resolve @@ -277,7 +278,8 @@ export class WS2PConnection { connectionTimeout: REQUEST_TIMEOUT_VALUE, requestTimeout: REQUEST_TIMEOUT_VALUE }, - expectedPub:string = "") { + expectedPub:string = "", + expectedWS2PUID:string = "") { if (address.match(WS2PConstants.FULL_ADDRESS_ONION_REGEX)) { options = { connectionTimeout: WS2PConstants.CONNEXION_TOR_TIMEOUT, @@ -292,7 +294,7 @@ export class WS2PConnection { websocket.on('close', () => res()) }) websocket.on('error', () => websocket.close()) - return new WS2PConnection(websocket, onWsOpened, onWsClosed, messageHandler, localAuth, remoteAuth, options, expectedPub) + return new WS2PConnection(websocket, onWsOpened, onWsClosed, messageHandler, localAuth, remoteAuth, options, expectedPub, expectedWS2PUID) } static newConnectionFromWebSocketServer( @@ -319,6 +321,10 @@ export class WS2PConnection { return this.remoteAuth.getPubkey() } + get uuid() { + return this.expectedWS2PUID + } + get nbRequests() { return this.nbRequestsCount } diff --git a/app/modules/ws2p/lib/WS2PServer.ts b/app/modules/ws2p/lib/WS2PServer.ts index ae79815f..d11c3298 100644 --- a/app/modules/ws2p/lib/WS2PServer.ts +++ b/app/modules/ws2p/lib/WS2PServer.ts @@ -116,8 +116,8 @@ export class WS2PServer extends events.EventEmitter { } }) }) - - await this.trimConnections() + let privilegedKeys = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[] + await this.removeLowPriorityConnection(privilegedKeys) await this.server.dal.setPeerUP(c.pubkey) @@ -128,44 +128,26 @@ export class WS2PServer extends events.EventEmitter { }) } - async trimConnections() { - /*** OVERFLOW TRIMMING ***/ - let disconnectedOne = true - // Disconnect non-members - while (disconnectedOne && this.connections.length > this.maxLevel2Size) { - disconnectedOne = false - for (const c of this.connections) { - const isMember = await this.server.dal.isMember(c.pubkey) - if (!isMember && !disconnectedOne) { - c.close() - this.removeConnection(c) - disconnectedOne = true - } - } - } - // Disconnect members - while (this.connections.length > this.maxLevel2Size) { - for (const c of this.connections) { - c.close() - this.removeConnection(c) - } - } - /*** DUPLICATES TRIMMING ***/ - disconnectedOne = true - while (disconnectedOne) { - disconnectedOne = false - const pubkeysFound = [] - for (const c of this.connections) { - if (pubkeysFound.indexOf(c.pubkey) !== -1) { - c.close() - this.removeConnection(c) - disconnectedOne = true - } - else if (c.pubkey !== this.server.conf.pair.pub) { - pubkeysFound.push(c.pubkey) + async removeLowPriorityConnection(privilegedKeys:string[]) { + let lowPriorityConnection:WS2PConnection = this.connections[0] + let minPriorityLevel = this.keyPriorityLevel(lowPriorityConnection.pubkey, privilegedKeys) + for (const c of this.connections) { + if (c !== lowPriorityConnection) { + let cPriorityLevel = this.keyPriorityLevel(c.pubkey, privilegedKeys) + if (cPriorityLevel < minPriorityLevel) { + lowPriorityConnection = c + minPriorityLevel = cPriorityLevel } } } + this.removeConnection(lowPriorityConnection) + } + + keyPriorityLevel(pubkey:string, privilegedKeys:string[]) { + let priorityLevel = (this.server.dal.isMember(pubkey)) ? 1:0 + priorityLevel += (privilegedKeys.indexOf(pubkey) !== -1) ? 2:0 + priorityLevel += (this.server.conf.pair.pub === pubkey) ? 4:0 + return priorityLevel } private removeConnection(c:WS2PConnection) { diff --git a/app/modules/ws2p/lib/constants.ts b/app/modules/ws2p/lib/constants.ts index 51972d7f..cc75af03 100644 --- a/app/modules/ws2p/lib/constants.ts +++ b/app/modules/ws2p/lib/constants.ts @@ -19,6 +19,7 @@ export const WS2PConstants = { MAX_LEVEL_1_PEERS: 10, MAX_LEVEL_2_PEERS: 10, CONNECTIONS_LOW_LEVEL: 3, + MAX_PRIORITY_LEVEL: 7, BAN_DURATION_IN_SECONDS: 120, BAN_ON_REPEAT_THRESHOLD: 5, -- GitLab From be21edfaf3ad6cfda6f47f9efaa74a9399d60ce1 Mon Sep 17 00:00:00 2001 From: librelois Date: Sat, 11 Nov 2017 20:43:05 +0100 Subject: [PATCH 21/72] Revert "Revert "[enh] prepare the management of several ws2p versions + continuation of refactoring ws2p connetions priority"" This reverts commit 1591749bb14c3e151cf791357fa5a965a390f9fe. --- app/lib/common-libs/constants.ts | 4 + app/lib/dto/PeerDTO.ts | 77 ++++++++++++---- app/modules/ws2p/lib/WS2PCluster.ts | 132 ++++++++++++++++++++++------ app/modules/ws2p/lib/WS2PServer.ts | 15 ++-- app/modules/ws2p/lib/constants.ts | 10 ++- 5 files changed, 183 insertions(+), 55 deletions(-) diff --git a/app/lib/common-libs/constants.ts b/app/lib/common-libs/constants.ts index f9cda71f..637bc0e0 100644 --- a/app/lib/common-libs/constants.ts +++ b/app/lib/common-libs/constants.ts @@ -33,7 +33,9 @@ const CONDITIONS = "(&&|\\|\\|| |[()]|(SIG\\(" + PUBKEY + "\\)|(XHX\\([A-F0-9] const BMA_REGEXP = /^BASIC_MERKLED_API( ([a-z_][a-z0-9-_.]*))?( ([0-9.]+))?( ([0-9a-f:]+))?( ([0-9]+))$/ const BMATOR_REGEXP = /^BMATOR( ([a-z0-9]{16})\.onion)( ([0-9.]+))?( ([0-9a-f:]+))?( ([0-9]+))$/ const WS2P_REGEXP = /^WS2P ([a-f0-9]{8}) ([a-z_][a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+) ([0-9]+)(?: (.+))?$/ +const WS2P_V2_REGEXP = /^WS2P ([0-9]+) ([a-f0-9]{8}) ([a-z_][a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+) ([0-9]+)(?: (.+))?$/ const WS2PTOR_REGEXP = /^WS2PTOR ([a-f0-9]{8}) ([a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+.onion) ([0-9]+)(?: (.+))?$/ +const WS2PTOR_V2_REGEXP = /^WS2PTOR ([0-9]+) ([a-f0-9]{8}) ([a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+.onion) ([0-9]+)(?: (.+))?$/ const WS_FULL_ADDRESS_ONION_REGEX = /^(?:wss?:\/\/)(?:www\.)?([0-9a-z]{16}\.onion)(:[0-9]+)?$/ const IPV4_REGEXP = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/; const IPV6_REGEXP = /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|(([0-9A-Fa-f]{1,4}:){0,5}:((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|(::([0-9A-Fa-f]{1,4}:){0,5}((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/; @@ -95,7 +97,9 @@ export const CommonConstants = { BMA_REGEXP, BMATOR_REGEXP, WS2P_REGEXP, + WS2P_V2_REGEXP, WS2PTOR_REGEXP, + WS2PTOR_V2_REGEXP, WS_FULL_ADDRESS_ONION_REGEX, IPV4_REGEXP, IPV6_REGEXP, diff --git a/app/lib/dto/PeerDTO.ts b/app/lib/dto/PeerDTO.ts index dc5754b6..0704fe14 100644 --- a/app/lib/dto/PeerDTO.ts +++ b/app/lib/dto/PeerDTO.ts @@ -2,6 +2,7 @@ import {DBPeer} from "../dal/sqliteDAL/PeerDAL" import {hashf} from "../common" import {CommonConstants} from "../common-libs/constants" import {Cloneable} from "./Cloneable" +import { WS2PConstants } from '../../modules/ws2p/lib/constants'; export interface WS2PEndpoint { uuid:string @@ -94,29 +95,59 @@ export class PeerDTO implements Cloneable { return bma || {}; } - getWS2P(canReachTorEp:boolean, canReachClearEp:boolean) { - let api:{ uuid:string, host:string, port:number, path:string }|null = null - const endpointRegexp = (canReachTorEp) ? CommonConstants.WS2PTOR_REGEXP:CommonConstants.WS2P_REGEXP + getOnceWS2PEndpoint(canReachTorEp:boolean, canReachClearEp:boolean, uuidExcluded:string[] = []) { + let api:{ version:number, uuid:string, host:string, port:number, path:string }|null = null + let bestWS2PVersionAvailable:number = 0 + let bestWS2PTORVersionAvailable:number = 0 for (const ep of this.endpoints) { if (canReachTorEp) { - const matches:any = ep.match(CommonConstants.WS2PTOR_REGEXP) - if (matches) { - return { - uuid: matches[1], - host: matches[2] || '', - port: parseInt(matches[3]) || 0, - path: matches[4] + let matches:any = ep.match(CommonConstants.WS2PTOR_V2_REGEXP) + if (matches && parseInt(matches[1]) > bestWS2PTORVersionAvailable && (uuidExcluded.indexOf(matches[2]) === -1)) { + bestWS2PTORVersionAvailable = matches[1] + api = { + version: parseInt(matches[1]), + uuid: matches[2], + host: matches[3] || '', + port: parseInt(matches[4]) || 0, + path: matches[5] + } + } else { + matches = ep.match(CommonConstants.WS2PTOR_REGEXP) + if (matches && bestWS2PTORVersionAvailable == 0 && (uuidExcluded.indexOf(matches[1]) === -1)) { + bestWS2PTORVersionAvailable = 1 + api = { + version: 1, + uuid: matches[1], + host: matches[2] || '', + port: parseInt(matches[3]) || 0, + path: matches[4] + } } } } - if (canReachClearEp) { - const matches:any = !api && ep.match(CommonConstants.WS2P_REGEXP) - if (matches) { + // If can reach clear endpoint and not found tor endpoint + if (canReachClearEp && bestWS2PTORVersionAvailable == 0) { + let matches:any = ep.match(CommonConstants.WS2P_V2_REGEXP) + if (matches && parseInt(matches[1]) > bestWS2PVersionAvailable && (uuidExcluded.indexOf(matches[2]) === -1)) { + bestWS2PVersionAvailable = parseInt(matches[1]) api = { - uuid: matches[1], - host: matches[2] || '', - port: parseInt(matches[3]) || 0, - path: matches[4] + version: parseInt(matches[1]), + uuid: matches[2], + host: matches[3] || '', + port: parseInt(matches[4]) || 0, + path: matches[5] + } + } else { + matches = ep.match(CommonConstants.WS2P_REGEXP) + if (matches && bestWS2PVersionAvailable == 0 && (uuidExcluded.indexOf(matches[1]) === -1)) { + bestWS2PVersionAvailable = 1 + api = { + version: 1, + uuid: matches[1], + host: matches[2] || '', + port: parseInt(matches[3]) || 0, + path: matches[4] + } } } } @@ -124,6 +155,18 @@ export class PeerDTO implements Cloneable { return api || null } + getAllWS2PEndpoints(canReachTorEp:boolean, canReachClearEp:boolean, myUUID:string) { + let apis:{ uuid:string, host:string, port:number, path:string }[] = [] + let uuidExcluded:string[] = [myUUID] + let api = this.getOnceWS2PEndpoint(canReachTorEp, canReachClearEp, uuidExcluded) + while (api !== null) { + uuidExcluded.push(api.uuid) + apis.push(api) + api = this.getOnceWS2PEndpoint(canReachTorEp, canReachClearEp, uuidExcluded) + } + return apis + } + getDns() { const bma = this.getBMA(); return bma.dns ? bma.dns : null; diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index b8940819..fdd829af 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -17,6 +17,7 @@ import { CommonConstants } from '../../../lib/common-libs/constants'; import { Package } from "../../../lib/common/package"; import { Constants } from "../../prover/lib/constants"; import { ProxiesConf } from '../../../lib/proxy'; +import { Keypair } from '../../../lib/dto/ConfDTO'; const es = require('event-stream') const nuuid = require('node-uuid') @@ -268,7 +269,7 @@ export class WS2PCluster { this.ws2pServer = await WS2PServer.bindOn(this.server, host, port, this.fifo, (pubkey:string, connectedPubkeys:string[]) => { const privilegedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[] return this.acceptPubkey(pubkey, connectedPubkeys, [], () => this.servedCount(), this.maxLevel2Peers, privilegedNodes, (this.server.conf.ws2p !== undefined && this.server.conf.ws2p.privilegedOnly)) - }, this.messageHandler) + }, this.keyPriorityLevel, this.messageHandler) this.host = host this.port = port return this.ws2pServer @@ -330,13 +331,20 @@ export class WS2PCluster { } async connectToWS2Peers() { + const myUUID = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) ? this.server.conf.ws2p.uuid:"" const potentials = await this.server.dal.getWS2Peers() const peers:PeerDTO[] = potentials.map((p:any) => PeerDTO.fromJSONObject(p)) const prefered = ((this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) || []).slice() // Copy // Our key is also a prefered one, so we connect to our siblings - prefered.push(this.server.conf.pair.pub) const canReachTorEndpoint = ProxiesConf.canReachTorEndpoint(this.server.conf.proxiesConf) peers.sort((a, b) => { + // Top priority at our own nodes + if (a.pubkey === this.server.conf.pair.pub && b.pubkey !== this.server.conf.pair.pub) { + return -1 + } else if (a.pubkey !== this.server.conf.pair.pub && b.pubkey === this.server.conf.pair.pub) { + return 1 + } + const aIsPrefered = prefered.indexOf(a.pubkey) !== -1 const bIsPrefered = prefered.indexOf(b.pubkey) !== -1 @@ -373,20 +381,34 @@ export class WS2PCluster { const canReachClearEndpoint = ProxiesConf.canReachClearEndpoint(this.server.conf.proxiesConf) while (i < peers.length && this.clientsCount() < this.maxLevel1Size) { const p = peers[i] - const api = p.getWS2P(canReachTorEndpoint, canReachClearEndpoint) - if (api) { - try { - // We do not connect to local host - if (!this.server.conf.ws2p || api.uuid !== this.server.conf.ws2p.uuid || p.pubkey !== this.server.conf.pair.pub || api.uuid === '11111111') { - await this.connectToRemoteWS(api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) + if (p.pubkey === this.server.conf.pair.pub) { + const apis = p.getAllWS2PEndpoints(canReachTorEndpoint, canReachClearEndpoint, myUUID) + for (const api of apis) { + try { + // We do not connect to local host + if (api.uuid !== myUUID || api.uuid === '11111111') { + await this.connectToRemoteWS(api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) + } + } catch (e) { + this.server.logger.debug('WS2P: init: failed connection') + } + } + } else { + const api = p.getOnceWS2PEndpoint(canReachTorEndpoint, canReachClearEndpoint) + if (api) { + try { + // We do not connect to local host + if (api.uuid !== myUUID || api.uuid === '11111111') { + await this.connectToRemoteWS(api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) + } + } catch (e) { + this.server.logger.debug('WS2P: init: failed connection') } - } catch (e) { - this.server.logger.debug('WS2P: init: failed connection') } } i++ // Trim the eventual extra connections - setTimeout(() => this.trimClientConnections(), WS2PConstants.CONNEXION_TIMEOUT) + setTimeout(() => this.trimClientConnections(prefered), WS2PConstants.CONNEXION_TIMEOUT) } } @@ -400,16 +422,16 @@ export class WS2PCluster { // New peer if (data.endpoints) { const peer = PeerDTO.fromJSONObject(data) - const ws2pEnpoint = peer.getWS2P(ProxiesConf.canReachTorEndpoint(this.server.conf.proxiesConf), ProxiesConf.canReachClearEndpoint(this.server.conf.proxiesConf)) + const ws2pEnpoint = peer.getOnceWS2PEndpoint(ProxiesConf.canReachTorEndpoint(this.server.conf.proxiesConf), ProxiesConf.canReachClearEndpoint(this.server.conf.proxiesConf)) if (ws2pEnpoint) { // Check if already connected to the pubkey (in any way: server or client) const connectedPubkeys = this.getConnectedPubkeys() const connectedWS2PUID = this.getConnectedWS2PUID() - const preferedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[] - const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, connectedWS2PUID, () => this.clientsCount(), this.maxLevel1Size, preferedNodes, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEnpoint.uuid) + const preferedKeys = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[] + const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, connectedWS2PUID, () => this.clientsCount(), this.maxLevel1Size, preferedKeys, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEnpoint.uuid) if (shouldAccept && (!this.server.conf.ws2p || ws2pEnpoint.uuid !== this.server.conf.ws2p.uuid || peer.pubkey !== this.server.conf.pair.pub || ws2pEnpoint.uuid === '11111111')) { await this.connectToRemoteWS(ws2pEnpoint.host, ws2pEnpoint.port, ws2pEnpoint.path, this.messageHandler, peer.pubkey, ws2pEnpoint.uuid) - await this.trimClientConnections() + await this.trimClientConnections(preferedKeys) } } } @@ -480,7 +502,60 @@ export class WS2PCluster { return { sig, message, pub } } - async trimClientConnections() { + async removeLowPriorityConnections(privilegedKeys:string[]) { + let serverPubkeys:string[] = [] + if (this.ws2pServer) { + serverPubkeys = this.ws2pServer.getConnexions().map(c => c.pubkey) + } + let disconnectedOne = true + // Disconnect Private connexions already present under Public + while (disconnectedOne) { + disconnectedOne = false + let uuids = Object.keys(this.ws2pClients) + uuids = _.shuffle(uuids) + for (const uuid of uuids) { + const client = this.ws2pClients[uuid] + const pub = client.connection.pubkey + const isNotOurself = pub !== this.server.conf.pair.pub + const isAlreadyInPublic = serverPubkeys.indexOf(pub) !== -1 + if (isNotOurself && isAlreadyInPublic) { + client.connection.close() + await client.connection.closed + disconnectedOne = true + if (this.ws2pClients[uuid]) { + delete this.ws2pClients[uuid] + } + } + } + } + // Disconnect Private connexions until the maximum size is respected + while (disconnectedOne && this.clientsCount() > this.maxLevel1Size) { + let uuids = Object.keys(this.ws2pClients) + uuids = _.shuffle(uuids) + let lowPriorityConnectionUUID:string = uuids[0] + let minPriorityLevel = this.keyPriorityLevel(this.ws2pClients[lowPriorityConnectionUUID].connection.pubkey, privilegedKeys) + for (const uuid of uuids) { + const client = this.ws2pClients[uuid] + if (uuid !== lowPriorityConnectionUUID) { + let uuidPriorityLevel = this.keyPriorityLevel(client.connection.pubkey, privilegedKeys) + if (uuidPriorityLevel < minPriorityLevel) { + lowPriorityConnectionUUID = uuid + minPriorityLevel = uuidPriorityLevel + } + } + delete this.ws2pClients[lowPriorityConnectionUUID] + } + } + } + + keyPriorityLevel(pubkey:string, preferedOrPrivilegedKeys:string[]) { + let priorityLevel = (this.server.dal.isMember(pubkey)) ? WS2PConstants.CONNECTIONS_PRIORITY.MEMBER_KEY_LEVEL:0 + priorityLevel += (preferedOrPrivilegedKeys.indexOf(pubkey) !== -1) ? WS2PConstants.CONNECTIONS_PRIORITY.PREFERED_PRIVILEGED_KEY_LEVEL:0 + priorityLevel += (this.server.conf.pair.pub === pubkey) ? WS2PConstants.CONNECTIONS_PRIORITY.SELF_KEY_LEVEL:0 + return priorityLevel + } + + async trimClientConnections(preferedKeys:string[]) { let serverPubkeys:string[] = [] if (this.ws2pServer) { serverPubkeys = this.ws2pServer.getConnexions().map(c => c.pubkey) @@ -587,9 +662,19 @@ export class WS2PCluster { return false } - // We do not accept oneself connetion - if (this.server.conf.pair.pub === pub && this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID) { - return false + if (this.server.conf.pair.pub === pub) { + // We do not accept oneself connetion + if (this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID) { + return false + } else { + // We always accept self nodes, and they have a supreme priority (these are siblings) + if (targetWS2PUID === "" || this.isNewSiblingNode(pub, targetWS2PUID, connectedWS2PUID) ) { + return true + } else { + // We are already connected to this self node (same WS2PUID) + return false + } + } } // We do not accept banned keys @@ -613,17 +698,10 @@ export class WS2PCluster { if (getConcurrentConnexionsCount() < maxConcurrentConnexionsSize) { // Yes: just connect to it return true - } else if (this.server.conf.pair.pub === pub) { - // We always accept self nodes, and they have a supreme priority (these are siblings) - if (targetWS2PUID !== "") { - if (this.isNewSiblingNode(pub, targetWS2PUID, connectedWS2PUID)) { - return true - } - } } else if (connectedPubkeys.indexOf(pub) === -1) { - let minPriorityLevel = WS2PConstants.MAX_PRIORITY_LEVEL + let minPriorityLevel = WS2PConstants.CONNECTIONS_PRIORITY.MAX_PRIORITY_LEVEL for (const connectedPubkey of connectedPubkeys) { let connectedPubkeyPriorityLevel = this.ws2pServer.keyPriorityLevel(connectedPubkey, priorityKeys) if (connectedPubkeyPriorityLevel < minPriorityLevel) { diff --git a/app/modules/ws2p/lib/WS2PServer.ts b/app/modules/ws2p/lib/WS2PServer.ts index d11c3298..85bed337 100644 --- a/app/modules/ws2p/lib/WS2PServer.ts +++ b/app/modules/ws2p/lib/WS2PServer.ts @@ -7,6 +7,7 @@ import {WS2PConstants} from "./constants" import {WS2PMessageHandler} from "./impl/WS2PMessageHandler" import {WS2PStreamer} from "./WS2PStreamer" import {WS2PSingleWriteStream} from "./WS2PSingleWriteStream" +import { WS2PCluster } from './WS2PCluster'; const WebSocketServer = require('ws').Server @@ -21,7 +22,8 @@ export class WS2PServer extends events.EventEmitter { private host:string, private port:number, private fifo:GlobalFifoPromise, - private shouldAcceptConnection:(pubkey:string, connectedPubkeys:string[])=>Promise) { + private shouldAcceptConnection:(pubkey:string, connectedPubkeys:string[])=>Promise, + public keyPriorityLevel:(pubkey:string, privilegedKeys:string[])=>number) { super() // Conf: max public connections if (this.server.conf.ws2p && this.server.conf.ws2p.maxPublic !== undefined) { @@ -143,13 +145,6 @@ export class WS2PServer extends events.EventEmitter { this.removeConnection(lowPriorityConnection) } - keyPriorityLevel(pubkey:string, privilegedKeys:string[]) { - let priorityLevel = (this.server.dal.isMember(pubkey)) ? 1:0 - priorityLevel += (privilegedKeys.indexOf(pubkey) !== -1) ? 2:0 - priorityLevel += (this.server.conf.pair.pub === pubkey) ? 4:0 - return priorityLevel - } - private removeConnection(c:WS2PConnection) { const index = this.connections.indexOf(c) if (index !== -1) { @@ -183,8 +178,8 @@ export class WS2PServer extends events.EventEmitter { })) } - static async bindOn(server:Server, host:string, port:number, fifo:GlobalFifoPromise, shouldAcceptConnection:(pubkey:string, connectedPubkeys:string[])=>Promise, messageHandler:WS2PMessageHandler) { - const ws2ps = new WS2PServer(server, host, port, fifo, shouldAcceptConnection) + static async bindOn(server:Server, host:string, port:number, fifo:GlobalFifoPromise, shouldAcceptConnection:(pubkey:string, connectedPubkeys:string[])=>Promise, keyPriorityLevel:(pubkey:string, privilegedKeys:string[])=>number, messageHandler:WS2PMessageHandler) { + const ws2ps = new WS2PServer(server, host, port, fifo, shouldAcceptConnection, keyPriorityLevel) await ws2ps.listenToWebSocketConnections(messageHandler) server.logger.info('WS2P server %s listening on %s:%s', server.conf.pair.pub, host, port) return ws2ps diff --git a/app/modules/ws2p/lib/constants.ts b/app/modules/ws2p/lib/constants.ts index cc75af03..080db10c 100644 --- a/app/modules/ws2p/lib/constants.ts +++ b/app/modules/ws2p/lib/constants.ts @@ -1,6 +1,8 @@ import {CommonConstants} from "../../../lib/common-libs/constants" export const WS2PConstants = { + WS2P_VERSION: 2, + WS2P_UPNP_TTL: 600, WS2P_PORTS_START: 20900, WS2P_PORTS_END: 20999, @@ -19,7 +21,13 @@ export const WS2PConstants = { MAX_LEVEL_1_PEERS: 10, MAX_LEVEL_2_PEERS: 10, CONNECTIONS_LOW_LEVEL: 3, - MAX_PRIORITY_LEVEL: 7, + + CONNECTIONS_PRIORITY: { + MEMBER_KEY_LEVEL: 1, + PREFERED_PRIVILEGED_KEY_LEVEL: 2, + SELF_KEY_LEVEL: 4, + MAX_PRIORITY_LEVEL: 7, + }, BAN_DURATION_IN_SECONDS: 120, BAN_ON_REPEAT_THRESHOLD: 5, -- GitLab From 67247c8ce4bcb321438dfa75af0f72dd38e18b72 Mon Sep 17 00:00:00 2001 From: Moul Date: Sun, 12 Nov 2017 15:17:02 +0100 Subject: [PATCH 22/72] [sec] update 'ws' dependency as a there is a security issue. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f231cd0a..aa910d04 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,7 @@ "unzip2": "0.2.5", "winston": "2.3.1", "wotb": "0.6.x", - "ws": "1.1.1" + "ws": "1.1.5" }, "devDependencies": { "@types/mocha": "^2.2.41", -- GitLab From 02b49ca72eb7652c9987d820dd10756568bb84d2 Mon Sep 17 00:00:00 2001 From: librelois Date: Sun, 12 Nov 2017 15:23:38 +0100 Subject: [PATCH 23/72] [mod] countConnexions : not counting connections with other nodes in your own key --- app/modules/ws2p/lib/WS2PCluster.ts | 12 +++++++++--- app/modules/ws2p/lib/WS2PServer.ts | 24 ++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index fdd829af..5e2eb475 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -52,7 +52,7 @@ export class WS2PCluster { } private ws2pServer:WS2PServer|null = null - private ws2pClients:{[k:string]:WS2PClient} = {} + private ws2pClients:{[ws2puid:string]:WS2PClient} = {} private host:string|null = null private port:number|null = null private syncBlockInterval:NodeJS.Timer @@ -284,11 +284,17 @@ export class WS2PCluster { } clientsCount() { - return Object.keys(this.ws2pClients).length + let count = 0 + for (const ws2pid of Object.keys(this.ws2pClients)) { + if (this.ws2pClients[ws2pid].connection.pubkey != this.server.conf.pair.pub) { + count++ + } + } + return count } servedCount() { - return this.ws2pServer ? this.ws2pServer.getConnexions().length : 0 + return (this.ws2pServer) ? this.ws2pServer.countConnexions():0 } async connectToRemoteWS(host: string, port: number, path:string, messageHandler:WS2PMessageHandler, expectedPub:string, ws2pEndpointUUID:string = ""): Promise { diff --git a/app/modules/ws2p/lib/WS2PServer.ts b/app/modules/ws2p/lib/WS2PServer.ts index 85bed337..0e4d66b4 100644 --- a/app/modules/ws2p/lib/WS2PServer.ts +++ b/app/modules/ws2p/lib/WS2PServer.ts @@ -43,6 +43,17 @@ export class WS2PServer extends events.EventEmitter { return this.connections.slice() } + countConnexions() { + const connections = this.getConnexions() + let count = 0 + for (const c of connections) { + if (c.pubkey != this.server.conf.pair.pub) { + count++ + } + } + return count + } + private listenToWebSocketConnections(messageHandler:WS2PMessageHandler) { const key = new Key(this.server.conf.pair.pub, this.server.conf.pair.sec) this.wss = new WebSocketServer({ host: this.host, port: this.port }) @@ -118,8 +129,9 @@ export class WS2PServer extends events.EventEmitter { } }) }) - let privilegedKeys = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[] - await this.removeLowPriorityConnection(privilegedKeys) + + // Remove excess incoming connections + this.removeExcessIncomingConnections() await this.server.dal.setPeerUP(c.pubkey) @@ -130,6 +142,14 @@ export class WS2PServer extends events.EventEmitter { }) } + async removeExcessIncomingConnections() { + const ws2pPublicMax = (this.server.conf.ws2p && this.server.conf.ws2p.maxPublic) ? this.server.conf.ws2p.maxPublic:10 + let privilegedKeys = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[] + while (this.countConnexions() > ws2pPublicMax) { + await this.removeLowPriorityConnection(privilegedKeys) + } + } + async removeLowPriorityConnection(privilegedKeys:string[]) { let lowPriorityConnection:WS2PConnection = this.connections[0] let minPriorityLevel = this.keyPriorityLevel(lowPriorityConnection.pubkey, privilegedKeys) -- GitLab From ca4d7c468a076d59bd3ef001140b25237b43651f Mon Sep 17 00:00:00 2001 From: cgeek Date: Sun, 12 Nov 2017 16:14:07 +0100 Subject: [PATCH 24/72] [enh] #1193 Refactoring test user.js to TestUser.ts --- .gitignore | 2 + app/lib/common-libs/buid.ts | 4 + app/lib/dto/IdentityDTO.ts | 5 + app/lib/dto/RevocationDTO.ts | 5 + test/fast/modules/bma/ddos-test.js | 2 +- test/fast/modules/bma/limiter-test.js | 4 +- test/integration/branches2.ts | 6 +- test/integration/branches_pending_data.js | 10 +- test/integration/branches_revert.js | 6 +- test/integration/branches_revert2.js | 6 +- .../branches_revert_memberships.js | 8 +- test/integration/branches_switch.js | 6 +- test/integration/branches_switch.ts | 6 +- .../integration/certification_chainability.js | 10 +- test/integration/certifier-is-member.js | 8 +- test/integration/collapse.js | 6 +- test/integration/continuous-proof.js | 6 +- test/integration/crosschain-test.js | 18 +- test/integration/documents-currency.ts | 12 +- test/integration/forwarding.js | 10 +- test/integration/http_api.js | 6 +- test/integration/identity-absorption.js | 6 +- test/integration/identity-clean-test.js | 10 +- test/integration/identity-expiry.js | 10 +- .../identity-implicit-revocation.js | 8 +- test/integration/identity-kicking-by-certs.js | 12 +- test/integration/identity-kicking.js | 8 +- test/integration/identity-pulling.js | 12 +- test/integration/identity-same-pubkey.js | 8 +- test/integration/identity-test.js | 18 +- test/integration/lookup.js | 8 +- test/integration/network-update.js | 6 +- test/integration/newcomers-shuffling.js | 10 +- test/integration/peer-outdated.js | 6 +- test/integration/peerings.js | 8 +- test/integration/peers-same-pubkey.js | 6 +- test/integration/register-fork-blocks.js | 8 +- test/integration/revocation-test.js | 12 +- test/integration/revoked_pubkey_replay.ts | 4 +- test/integration/server-import-export.js | 6 +- test/integration/server-sandbox.js | 36 +- test/integration/single-document-treatment.js | 6 +- test/integration/start_generate_blocks.js | 10 +- test/integration/tests.js | 18 +- test/integration/tools/TestUser.ts | 403 ++++++++++++++++++ test/integration/tools/node.js | 1 - test/integration/tools/toolbox.ts | 18 +- test/integration/tools/user.js | 394 ----------------- test/integration/transactions-chaining.js | 6 +- test/integration/transactions-pruning.js | 6 +- test/integration/transactions-test.js | 10 +- test/integration/v1.1-dividend.js | 8 +- test/integration/wotb.js | 20 +- 53 files changed, 636 insertions(+), 612 deletions(-) create mode 100644 test/integration/tools/TestUser.ts delete mode 100644 test/integration/tools/user.js diff --git a/.gitignore b/.gitignore index 8d7e9c28..58f619a8 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,8 @@ test/integration/membership_chainability.js* test/integration/membership_chainability.d.ts test/integration/tools/toolbox.js* test/integration/tools/toolbox.d.ts +test/integration/tools/TestUser.js* +test/integration/tools/TestUser.d.ts test/integration/documents-currency.js* test/integration/documents-currency.d.ts test/fast/modules/crawler/block_pulling.js* diff --git a/app/lib/common-libs/buid.ts b/app/lib/common-libs/buid.ts index a0cc71b9..3e2be9cb 100644 --- a/app/lib/common-libs/buid.ts +++ b/app/lib/common-libs/buid.ts @@ -28,5 +28,9 @@ export const Buid = { }, buid: buidFunctions + }, + + getBlockstamp: (block:{ number:number, hash:string }) => { + return [block.number, block.hash].join('-') } }; diff --git a/app/lib/dto/IdentityDTO.ts b/app/lib/dto/IdentityDTO.ts index d185d0cc..5bf4a81c 100644 --- a/app/lib/dto/IdentityDTO.ts +++ b/app/lib/dto/IdentityDTO.ts @@ -1,6 +1,7 @@ import {RevocationDTO} from "./RevocationDTO" import {hashf} from "../common" import {DBIdentity, NewDBIdentity} from "../dal/sqliteDAL/IdentityDAL" + const DEFAULT_DOCUMENT_VERSION = 10 export interface HashableIdentity { @@ -50,6 +51,10 @@ export class IdentityDTO { return raw } + getRawUnSigned() { + return this.rawWithoutSig() + } + getRawSigned() { return this.rawWithoutSig() + this.sig + "\n" } diff --git a/app/lib/dto/RevocationDTO.ts b/app/lib/dto/RevocationDTO.ts index ae8801e8..f98d75b6 100644 --- a/app/lib/dto/RevocationDTO.ts +++ b/app/lib/dto/RevocationDTO.ts @@ -1,5 +1,6 @@ import {Cloneable} from "./Cloneable"; import {hashf} from "../common"; + const DEFAULT_DOCUMENT_VERSION = 10 export interface ShortRevocation { @@ -39,6 +40,10 @@ export class RevocationDTO implements ShortRevocation, Cloneable { return this.rawWithoutSig() + this.revocation + "\n" } + getRawUnsigned() { + return this.rawWithoutSig() + } + // TODO: to remove when BMA has been merged in duniter/duniter repo json() { return { diff --git a/test/fast/modules/bma/ddos-test.js b/test/fast/modules/bma/ddos-test.js index c4127c62..5bb0d64f 100644 --- a/test/fast/modules/bma/ddos-test.js +++ b/test/fast/modules/bma/ddos-test.js @@ -3,7 +3,7 @@ // const co = require('co'); // const limiter = require('../../app/lib/system/limiter'); // const toolbox = require('../integration/tools/toolbox'); -// const user = require('../integration/tools/user'); +// const TestUser = require('../integration/tools/TestUser').TestUser // const bma = require('../lib/bma'); // // limiter.noLimit(); diff --git a/test/fast/modules/bma/limiter-test.js b/test/fast/modules/bma/limiter-test.js index 0ba0c025..2ec5db9f 100644 --- a/test/fast/modules/bma/limiter-test.js +++ b/test/fast/modules/bma/limiter-test.js @@ -3,7 +3,7 @@ // const co = require('co'); // const limiter = require('../lib/limiter'); // const toolbox = require('../integration/tools/toolbox'); -// const user = require('../integration/tools/user'); +// const TestUser = require('../integration/tools/TestUser').TestUser // const bma = require('duniter-bma').duniter.methods.bma; // // limiter.noLimit(); @@ -15,7 +15,7 @@ // } // }); // -// const cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); +// const cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); // // let theLimiter; // diff --git a/test/integration/branches2.ts b/test/integration/branches2.ts index 0d4eb63a..6626d061 100644 --- a/test/integration/branches2.ts +++ b/test/integration/branches2.ts @@ -3,12 +3,12 @@ import {NewLogger} from "../../app/lib/logger" import {BmaDependency} from "../../app/modules/bma/index" import {CrawlerDependency} from "../../app/modules/crawler/index" import {waitForkResolution, waitToHaveBlock} from "./tools/toolbox" +import {TestUser} from "./tools/TestUser"; const co = require('co'); const _ = require('underscore'); const duniter = require('../../index'); const bma = BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -69,8 +69,8 @@ describe("SelfFork", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); const commitS1 = commit(s1); const commitS2 = commit(s2, { diff --git a/test/integration/branches_pending_data.js b/test/integration/branches_pending_data.js index e4d4184d..ef60584d 100644 --- a/test/integration/branches_pending_data.js +++ b/test/integration/branches_pending_data.js @@ -4,7 +4,7 @@ const co = require('co'); const _ = require('underscore'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -39,10 +39,10 @@ describe("Pending data", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - tuc = user('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + tuc = new TestUser('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s1 }); const commitS1 = commit(s1); diff --git a/test/integration/branches_revert.js b/test/integration/branches_revert.js index d92ff38d..b2332574 100644 --- a/test/integration/branches_revert.js +++ b/test/integration/branches_revert.js @@ -3,7 +3,7 @@ const co = require('co'); const _ = require('underscore'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const toolbox = require('./tools/toolbox'); const commit = require('./tools/commit'); @@ -32,8 +32,8 @@ describe("Revert root", function() { sigQty: 1, dt: 1, ud0: 120 }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); yield s1.initDalBmaConnections(); yield cat.createIdentity(); diff --git a/test/integration/branches_revert2.js b/test/integration/branches_revert2.js index 9800c3ad..bf78020a 100644 --- a/test/integration/branches_revert2.js +++ b/test/integration/branches_revert2.js @@ -4,7 +4,7 @@ const co = require('co'); const _ = require('underscore'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -49,8 +49,8 @@ describe("Revert two blocks", function() { sigQty: 1, dt: 1, ud0: 120 }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); return co(function *() { yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); diff --git a/test/integration/branches_revert_memberships.js b/test/integration/branches_revert_memberships.js index f1a6df5e..b1b115f2 100644 --- a/test/integration/branches_revert_memberships.js +++ b/test/integration/branches_revert_memberships.js @@ -3,7 +3,7 @@ const co = require('co'); const should = require('should'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); @@ -24,9 +24,9 @@ describe("Revert memberships", function() { } }); - i1 = user('i1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - i2 = user('i2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - i3 = user('i3', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + i1 = new TestUser('i1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + i2 = new TestUser('i2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + i3 = new TestUser('i3', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); yield s1.initDalBmaConnections(); diff --git a/test/integration/branches_switch.js b/test/integration/branches_switch.js index 44839640..353ef811 100644 --- a/test/integration/branches_switch.js +++ b/test/integration/branches_switch.js @@ -6,7 +6,7 @@ const co = require('co'); const _ = require('underscore'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser; const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -43,8 +43,8 @@ describe("Switch", function () { sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' }, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' }, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' }, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' }, { server: s1 }); yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); yield s2.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); s1.addEndpointsDefinitions(() => index_2.BmaDependency.duniter.methods.getMainEndpoint(s1.conf)); diff --git a/test/integration/branches_switch.ts b/test/integration/branches_switch.ts index 862257dc..2eb7fae6 100644 --- a/test/integration/branches_switch.ts +++ b/test/integration/branches_switch.ts @@ -6,7 +6,7 @@ const co = require('co'); const _ = require('underscore'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -57,8 +57,8 @@ describe("Switch", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); yield s1.initWithDAL().then(bma).then((bmapi:any) => bmapi.openConnections()); yield s2.initWithDAL().then(bma).then((bmapi:any) => bmapi.openConnections()); diff --git a/test/integration/certification_chainability.js b/test/integration/certification_chainability.js index f33feec8..3eaf70f9 100644 --- a/test/integration/certification_chainability.js +++ b/test/integration/certification_chainability.js @@ -5,7 +5,7 @@ const co = require('co'); const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const constants = require('../../app/lib/constants'); const rp = require('request-promise'); const httpTest = require('./tools/http'); @@ -41,10 +41,10 @@ describe("Certification chainability", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); const now = 1482220000; diff --git a/test/integration/certifier-is-member.js b/test/integration/certifier-is-member.js index 25287c7b..ffc5ec01 100644 --- a/test/integration/certifier-is-member.js +++ b/test/integration/certifier-is-member.js @@ -6,7 +6,7 @@ const assert = require('assert'); const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const constants = require('../../app/lib/constants'); const toolbox = require('./tools/toolbox'); @@ -29,9 +29,9 @@ describe("Certifier must be a member", function() { medianTimeBlocks: 1 }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); yield s1.initDalBmaConnections(); yield cat.createIdentity(); diff --git a/test/integration/collapse.js b/test/integration/collapse.js index 234e6d93..f343b513 100644 --- a/test/integration/collapse.js +++ b/test/integration/collapse.js @@ -4,7 +4,7 @@ const co = require('co'); const _ = require('underscore'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const httpTest = require('./tools/http'); const shutDownEngine = require('./tools/shutDownEngine'); @@ -40,8 +40,8 @@ describe("Community collapse", function() { sigQty: 1, dt: 100, ud0: 120, sigValidity: 1 }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); return co(function *() { yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); diff --git a/test/integration/continuous-proof.js b/test/integration/continuous-proof.js index 39b4de12..289d5b69 100644 --- a/test/integration/continuous-proof.js +++ b/test/integration/continuous-proof.js @@ -3,7 +3,7 @@ const co = require('co'); const es = require('event-stream'); const should = require('should'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const toolbox = require('./tools/toolbox'); const constants = require('../../app/lib/constants'); @@ -26,8 +26,8 @@ describe("Continous proof-of-work", function() { } }) - i1 = user('i1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - i2 = user('i2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + i1 = new TestUser('i1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + i2 = new TestUser('i2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); yield s1.prepareForNetwork(); yield i1.createIdentity(); diff --git a/test/integration/crosschain-test.js b/test/integration/crosschain-test.js index a0e8f32a..2d232eb0 100644 --- a/test/integration/crosschain-test.js +++ b/test/integration/crosschain-test.js @@ -8,7 +8,7 @@ const rp = require('request-promise'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const unit = require('./tools/unit'); const httpTest = require('./tools/http'); @@ -57,11 +57,11 @@ describe("Crosschain transactions", function() { }, commonConf)); // toc is on 2 currencies - tocB = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sB }); - tocM = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sM }); + tocB = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sB }); + tocM = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sM }); // tic is on 2 currencies - ticB = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sB }); - ticM = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sM }); + ticB = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sB }); + ticM = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sM }); yield sB.initDalBmaConnections(); yield sM.initDalBmaConnections(); @@ -243,11 +243,11 @@ describe("Crosschain transactions", function() { }, commonConf)); // toc is on 2 currencies - tocB = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sB }); - tocM = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sM }); + tocB = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sB }); + tocM = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sM }); // tic is on 2 currencies - ticB = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sB }); - ticM = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sM }); + ticB = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sB }); + ticM = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sM }); yield sB.initDalBmaConnections(); yield sM.initDalBmaConnections() diff --git a/test/integration/documents-currency.ts b/test/integration/documents-currency.ts index 2bffa0b1..c066ab2a 100644 --- a/test/integration/documents-currency.ts +++ b/test/integration/documents-currency.ts @@ -1,8 +1,8 @@ -import { NewTestingServer } from './tools/toolbox'; +import {NewTestingServer} from './tools/toolbox'; const co = require('co'); const should = require('should'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser let s1:any, s2:any, cat1:any, tac1:any, toc2:any, tic2:any; @@ -30,10 +30,10 @@ describe("Document pool currency", function() { } }); - cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - toc2 = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s2 }); - tic2 = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); + cat1 = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac1 = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + toc2 = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s2 }); + tic2 = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); yield s1.prepareForNetwork(); yield s2.prepareForNetwork(); diff --git a/test/integration/forwarding.js b/test/integration/forwarding.js index ba392a69..993247af 100644 --- a/test/integration/forwarding.js +++ b/test/integration/forwarding.js @@ -5,7 +5,7 @@ const async = require('async'); const _ = require('underscore'); const co = require('co'); const node = require('./tools/node'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const jspckg = require('../../package'); const constants = require('../../app/lib/constants'); @@ -24,10 +24,10 @@ describe("Forwarding", function() { const node1 = node('db_1', _({ upnp: false, httplogs: false, port: 9600, remoteport: 9600, pair: { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'} }).extend(common)); const node2 = node('db_2', _({ upnp: false, httplogs: false, port: 9601, remoteport: 9601, pair: { pub: 'G2CBgZBPLe6FSFUgpx2Jf1Aqsgta6iib3vmDRA1yLiqU', sec: '58LDg8QLmF5pv6Dn9h7X4yFKfMTdP8fdAiWVcyDoTRJu454fwRihCLULH4MW37zncsg4ruoTGJPZneWk22QmG1w4'} }).extend(common)); - const cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, node1); - const tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, node1); - const tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, node1); - const toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, node1); + const cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, node1); + const tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, node1); + const tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, node1); + const toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, node1); before(() => co(function*(){ yield [node1, node2].map((theNode) => theNode.startTesting()); diff --git a/test/integration/http_api.js b/test/integration/http_api.js index 43e8733a..088909ec 100644 --- a/test/integration/http_api.js +++ b/test/integration/http_api.js @@ -7,7 +7,7 @@ const assert = require('assert'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; const PeerDTO = require('../../app/lib/dto/PeerDTO').PeerDTO -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const http = require('./tools/http'); const shutDownEngine = require('./tools/shutDownEngine'); const rp = require('request-promise'); @@ -64,8 +64,8 @@ describe("HTTP API", function() { } }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: server }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: server }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: server }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: server }); commit = makeBlockAndPost(server); diff --git a/test/integration/identity-absorption.js b/test/integration/identity-absorption.js index 2c0574f1..2f85059b 100644 --- a/test/integration/identity-absorption.js +++ b/test/integration/identity-absorption.js @@ -4,7 +4,7 @@ const _ = require('underscore'); const co = require('co'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const toolbox = require('./tools/toolbox'); @@ -51,8 +51,8 @@ describe("Identity absorption", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); return co(function *() { yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); diff --git a/test/integration/identity-clean-test.js b/test/integration/identity-clean-test.js index df0606b4..99e5c468 100644 --- a/test/integration/identity-clean-test.js +++ b/test/integration/identity-clean-test.js @@ -4,7 +4,7 @@ const _ = require('underscore'); const co = require('co'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -40,10 +40,10 @@ describe("Identities cleaned", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - toc = user('cat', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + toc = new TestUser('cat', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); const commitS1 = commit(s1); diff --git a/test/integration/identity-expiry.js b/test/integration/identity-expiry.js index c6a80f1a..58ba310c 100644 --- a/test/integration/identity-expiry.js +++ b/test/integration/identity-expiry.js @@ -6,7 +6,7 @@ const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; const prover = require('../../app/modules/prover').ProverDependency.duniter.methods; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const constants = require('../../app/lib/constants'); const rp = require('request-promise'); const httpTest = require('./tools/http'); @@ -50,10 +50,10 @@ describe("Identities expiry", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); prover.hookServer(s1) diff --git a/test/integration/identity-implicit-revocation.js b/test/integration/identity-implicit-revocation.js index 255778f2..ee1475f9 100644 --- a/test/integration/identity-implicit-revocation.js +++ b/test/integration/identity-implicit-revocation.js @@ -6,7 +6,7 @@ const assert = require('assert'); const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const constants = require('../../app/lib/constants'); const toolbox = require('./tools/toolbox'); @@ -29,9 +29,9 @@ describe("Implicit revocation", function() { medianTimeBlocks: 1 }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); yield s1.initDalBmaConnections(); yield cat.createIdentity(); diff --git a/test/integration/identity-kicking-by-certs.js b/test/integration/identity-kicking-by-certs.js index 199bf75e..2d524113 100644 --- a/test/integration/identity-kicking-by-certs.js +++ b/test/integration/identity-kicking-by-certs.js @@ -2,7 +2,7 @@ const co = require('co'); const assert = require('assert'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const toolbox = require('./tools/toolbox'); const now = 1480000000; @@ -25,11 +25,11 @@ describe("Identities kicking by certs", function() { sigQty: 2 }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tuc = user('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tuc = new TestUser('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s1 }); yield s1.initDalBmaConnections(); yield cat.createIdentity(); diff --git a/test/integration/identity-kicking.js b/test/integration/identity-kicking.js index b6e91d65..ac90bc8f 100644 --- a/test/integration/identity-kicking.js +++ b/test/integration/identity-kicking.js @@ -5,7 +5,7 @@ const co = require('co'); const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const constants = require('../../app/lib/constants'); const rp = require('request-promise'); const httpTest = require('./tools/http'); @@ -47,9 +47,9 @@ describe("Identities kicking", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); const now = 1400000000 yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); diff --git a/test/integration/identity-pulling.js b/test/integration/identity-pulling.js index 6cfffb2f..427d792e 100644 --- a/test/integration/identity-pulling.js +++ b/test/integration/identity-pulling.js @@ -3,7 +3,7 @@ const _ = require('underscore'); const co = require('co'); const assert = require('assert'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); @@ -26,11 +26,11 @@ describe("Identity pulling", function() { } }); - cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - toc2 = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s2 }); - tic2 = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); - tuc2 = user('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s2 }); + cat1 = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac1 = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + toc2 = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s2 }); + tic2 = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); + tuc2 = new TestUser('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s2 }); yield s1.prepareForNetwork(); yield s2.prepareForNetwork(); diff --git a/test/integration/identity-same-pubkey.js b/test/integration/identity-same-pubkey.js index 65480a3d..d42dc006 100644 --- a/test/integration/identity-same-pubkey.js +++ b/test/integration/identity-same-pubkey.js @@ -3,7 +3,7 @@ const co = require('co'); const should = require('should'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); @@ -20,9 +20,9 @@ describe("Identities with shared pubkey", function() { } }); - cat1 = user('cat1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - cat2 = user('cat2', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - catb = user('cat1', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + cat1 = new TestUser('cat1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + cat2 = new TestUser('cat2', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + catb = new TestUser('cat1', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); yield s1.initDalBmaConnections(); diff --git a/test/integration/identity-test.js b/test/integration/identity-test.js index 59612a36..de996d07 100644 --- a/test/integration/identity-test.js +++ b/test/integration/identity-test.js @@ -5,7 +5,7 @@ const co = require('co'); const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const constants = require('../../app/lib/constants'); const rp = require('request-promise'); const httpTest = require('./tools/http'); @@ -44,14 +44,14 @@ describe("Identities collision", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - tic2 = user('tic', { pub: '4KEA63RCFF7AXUePPg5Q7JX9RtzXjywai1iKmE7LcoEC', sec: '48vHGE2xkhnC81ChSu7dHaNv8JqnYubyyHRbkmkeAPKNg8Tv2BE7kVi3voh2ZhfVpQhEJLzceufzqpJ2dqnyXNSp'}, { server: s1 }); - man1 = user('man1', { pub: '12AbjvYY5hxV4v2KrN9pnGzgFxogwrzgYyncYHHsyFDK', sec: '2h8UNKE4YRnjmTGQTrgf4DZp2h3F5LqjnecxP8AgU6aH1x4dvbNVirsNeBiSR2UQfExuLAbdXiyM465hb5qUxYC1'}, { server: s1 }); - man2 = user('man2', { pub: 'E44RxG9jKZQsaPLFSw2ZTJgW7AVRqo1NGy6KGLbKgtNm', sec: 'pJRwpaCWshKZNWsbDxAHFQbVjk6X8gz9eBy9jaLnVY9gUZRqotrZLZPZe68ag4vEX1Y8mX77NhPXV2hj9F1UkX3'}, { server: s1 }); - man3 = user('man3', { pub: '5bfpAfZJ4xYspUBYseASJrofhRm6e6JMombt43HBaRzW', sec: '2VFQtEcYZRwjoc8Lxwfzcejtw9VP8VAi47WjwDDjCJCXu7g1tXUAbVZN3QmvG6NJqaSuLCuYP7WDHWkFmTrUEMaE'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + tic2 = new TestUser('tic', { pub: '4KEA63RCFF7AXUePPg5Q7JX9RtzXjywai1iKmE7LcoEC', sec: '48vHGE2xkhnC81ChSu7dHaNv8JqnYubyyHRbkmkeAPKNg8Tv2BE7kVi3voh2ZhfVpQhEJLzceufzqpJ2dqnyXNSp'}, { server: s1 }); + man1 = new TestUser('man1', { pub: '12AbjvYY5hxV4v2KrN9pnGzgFxogwrzgYyncYHHsyFDK', sec: '2h8UNKE4YRnjmTGQTrgf4DZp2h3F5LqjnecxP8AgU6aH1x4dvbNVirsNeBiSR2UQfExuLAbdXiyM465hb5qUxYC1'}, { server: s1 }); + man2 = new TestUser('man2', { pub: 'E44RxG9jKZQsaPLFSw2ZTJgW7AVRqo1NGy6KGLbKgtNm', sec: 'pJRwpaCWshKZNWsbDxAHFQbVjk6X8gz9eBy9jaLnVY9gUZRqotrZLZPZe68ag4vEX1Y8mX77NhPXV2hj9F1UkX3'}, { server: s1 }); + man3 = new TestUser('man3', { pub: '5bfpAfZJ4xYspUBYseASJrofhRm6e6JMombt43HBaRzW', sec: '2VFQtEcYZRwjoc8Lxwfzcejtw9VP8VAi47WjwDDjCJCXu7g1tXUAbVZN3QmvG6NJqaSuLCuYP7WDHWkFmTrUEMaE'}, { server: s1 }); const commitS1 = commit(s1); diff --git a/test/integration/lookup.js b/test/integration/lookup.js index 44de12ff..381ebf67 100644 --- a/test/integration/lookup.js +++ b/test/integration/lookup.js @@ -4,7 +4,7 @@ const _ = require('underscore'); const co = require('co'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const shutDownEngine = require('./tools/shutDownEngine'); @@ -32,9 +32,9 @@ describe("Lookup identity grouping", () => { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tic1 = user('tic1', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - tic2 = user('tic2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tic1 = new TestUser('tic1', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + tic2 = new TestUser('tic2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); // Server initialization yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); diff --git a/test/integration/network-update.js b/test/integration/network-update.js index 7d533a09..44c7ce92 100644 --- a/test/integration/network-update.js +++ b/test/integration/network-update.js @@ -5,7 +5,7 @@ const _ = require('underscore'); const rp = require('request-promise'); const httpTest = require('./tools/http'); const node = require('./tools/node'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const sync = require('./tools/sync'); const until = require('./tools/until'); @@ -51,8 +51,8 @@ describe("Network updating", function() { s1 = toolbox.server(_.clone(catKeyPair)); s2 = toolbox.server(_.clone(tocKeyPair)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); const commitS1 = commit(s1); const commitS2 = commit(s2); diff --git a/test/integration/newcomers-shuffling.js b/test/integration/newcomers-shuffling.js index 6d9e0ffd..0de6bdc1 100644 --- a/test/integration/newcomers-shuffling.js +++ b/test/integration/newcomers-shuffling.js @@ -3,7 +3,7 @@ const _ = require('underscore'); const co = require('co'); const assert = require('assert'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); @@ -20,10 +20,10 @@ describe("Newcomers shuffling", function() { } }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); yield s1.prepareForNetwork(); diff --git a/test/integration/peer-outdated.js b/test/integration/peer-outdated.js index 31af4bc7..3f2cb0e1 100644 --- a/test/integration/peer-outdated.js +++ b/test/integration/peer-outdated.js @@ -5,7 +5,7 @@ const should = require('should'); const es = require('event-stream'); const _ = require('underscore'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const until = require('./tools/until'); const toolbox = require('./tools/toolbox'); @@ -34,8 +34,8 @@ describe("Peer document expiry", function() { } }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); const commitS1 = commit(s1); diff --git a/test/integration/peerings.js b/test/integration/peerings.js index da7f16c6..4b227f63 100644 --- a/test/integration/peerings.js +++ b/test/integration/peerings.js @@ -5,7 +5,7 @@ const _ = require('underscore'); const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const constants = require('../../app/lib/constants'); const rp = require('request-promise'); const httpTest = require('./tools/http'); @@ -74,9 +74,9 @@ describe("Network", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); const commitS1 = commit(s1); const commitS2 = commit(s2); diff --git a/test/integration/peers-same-pubkey.js b/test/integration/peers-same-pubkey.js index 6afed89f..41c4b9c1 100644 --- a/test/integration/peers-same-pubkey.js +++ b/test/integration/peers-same-pubkey.js @@ -3,7 +3,7 @@ const co = require('co'); const _ = require('underscore'); const should = require('should'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const sync = require('./tools/sync'); const until = require('./tools/until'); @@ -27,8 +27,8 @@ describe("Peer document", function() { s2 = toolbox.server(_.clone(catKeyPair)); s3 = toolbox.server(_.clone(catKeyPair)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); const commitS1 = commit(s1); const commitS2 = commit(s2); diff --git a/test/integration/register-fork-blocks.js b/test/integration/register-fork-blocks.js index cf1faf59..a19df022 100644 --- a/test/integration/register-fork-blocks.js +++ b/test/integration/register-fork-blocks.js @@ -3,7 +3,7 @@ const _ = require('underscore'); const co = require('co'); const assert = require('assert'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); const CommonConstants = require('../../app/lib/common-libs/constants').CommonConstants @@ -56,9 +56,9 @@ describe("Fork blocks", function() { } }); - cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - toc1 = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat1 = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac1 = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + toc1 = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); yield s1.prepareForNetwork(); yield s2.prepareForNetwork(); diff --git a/test/integration/revocation-test.js b/test/integration/revocation-test.js index 63300af0..a49dce45 100644 --- a/test/integration/revocation-test.js +++ b/test/integration/revocation-test.js @@ -5,7 +5,7 @@ const co = require('co'); const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -59,11 +59,11 @@ describe("Revocation", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tacOnS1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - tacOnS2 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s2 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tacOnS1 = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + tacOnS2 = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s2 }); const now = 1400000000 yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); diff --git a/test/integration/revoked_pubkey_replay.ts b/test/integration/revoked_pubkey_replay.ts index dbaddc9a..03f4bab6 100644 --- a/test/integration/revoked_pubkey_replay.ts +++ b/test/integration/revoked_pubkey_replay.ts @@ -1,7 +1,7 @@ import {simpleNodeWith2Users, TestingServer} from "./tools/toolbox" const _ = require('underscore') -const user = require('./tools/user') +const TestUser = require('./tools/TestUser').TestUser describe("Revoked pubkey replay", function() { @@ -15,7 +15,7 @@ describe("Revoked pubkey replay", function() { const res1 = await simpleNodeWith2Users(conf) s1 = res1.s1 cat = res1.cat - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }) + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }) await s1.commit({ time: now }) await s1.commit({ time: now }) // Create the tested identity « tic » diff --git a/test/integration/server-import-export.js b/test/integration/server-import-export.js index b4ab2c49..4c568540 100644 --- a/test/integration/server-import-export.js +++ b/test/integration/server-import-export.js @@ -5,7 +5,7 @@ const fs = require('fs'); const co = require('co'); const unzip = require('unzip'); const toolbox = require('../integration/tools/toolbox'); -const user = require('../integration/tools/user'); +const TestUser = require('../integration/tools/TestUser').TestUser const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; const serverConfig = { @@ -26,8 +26,8 @@ describe('Import/Export', () => { s1 = toolbox.server(_.extend({ homename: 'dev_unit_tests1' }, serverConfig)); - const cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - const tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + const cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + const tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); yield s1.initDalBmaConnections(); yield cat.createIdentity(); diff --git a/test/integration/server-sandbox.js b/test/integration/server-sandbox.js index b5052551..e3d438be 100644 --- a/test/integration/server-sandbox.js +++ b/test/integration/server-sandbox.js @@ -3,7 +3,7 @@ const co = require('co'); const should = require('should'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); const constants = require('../../app/lib/constants'); @@ -43,23 +43,23 @@ describe("Sandboxes", function() { } }); - i1 = user('i1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - i2 = user('i2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - i3 = user('i3', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - i4 = user('i4', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - i5 = user('i5', { pub: '91dWdiyf7KaC4GAiKrwU7nGuue1vvmHqjCXbPziJFYtE', sec: '4Zno2b8ZULwBLY3RU5JcZhUf2a5FfXLVUMaYwPEzzN6i4ow9vXPsiCq7u2pEhkgJywqWdj97Hje1fdqnnzHeFgQe'}, { server: s1 }); - i6 = user('i6', { pub: '3C95HniUZsUN55AJy7z4wkz1UwtebbNd63dVAZ6EaUNm', sec: '3iJMz8JKNeU692L7jvug8xVnKvzN9RDee2m6QkMKbWKrvoHhv6apS4LR9hP786PUyFYJWz8bReMrFK8PY3aGxB8m'}, { server: s1 }); - i7 = user('i7', { pub: '4e9QJhJqHfMzEHgt3GtbfCXjqHVaQuJZKrKt8CNKR3AF', sec: 'TqdT99RpPEUjiz8su5QY7AQwharxPeo4ELCmeaFcvBEd3fW7wY7s9i531LMnTrCYBsgkrES494V6KjkhGppyEcF' }, { server: s1 }); - i7onS2 = user('i7', { pub: '4e9QJhJqHfMzEHgt3GtbfCXjqHVaQuJZKrKt8CNKR3AF', sec: 'TqdT99RpPEUjiz8su5QY7AQwharxPeo4ELCmeaFcvBEd3fW7wY7s9i531LMnTrCYBsgkrES494V6KjkhGppyEcF' }, { server: s2 }); - i8 = user('i8', { pub: '6GiiWjJxr29Stc4Ph4J4EipZJCzaQW1j6QXKANTNzRV3', sec: 'Yju625FGz6FHErshRc7jZyJUJ83MG4Zh9TXUNML62rKLXz7VJmwofnhJzeRRensranFJGQMYBLNSAeycAAsp62m' }, { server: s1 }); - i9 = user('i9', { pub: '6v4HnmiGxNzKwEjnBqxicWAmdKo6Bk51GvfQByS5YmiB', sec: '2wXPPDYfM3a8jmpYiFihS9qzdqFZrLWryu4uwpNPRuw5TRW3JCdJPsMa64eAcpshLTnMXkrKL94argk3FGxzzBKh' }, { server: s1 }); - i10 = user('i10', { pub: '6kr9Xr86qmrrwGq3XEjUXRVpHqS63FL52tcutcYGcRiv', sec: '2jCzQx7XUWoxboH67mMMv2z8VcrQabtYWpxS39iF6hNQnSBwN1d9RVauVC52PTRz6mgMzTjrSMETPrrB5N3oC7qQ' }, { server: s1 }); - i11 = user('i11', { pub: '5VLVTp96iX3YAq7NXwZeM2N6RjCkmxaU4G6bwMg1ZNwf', sec: '3BJtyeH1Q8jPcKuzL35m4eVPGuFXpcfRiGSseVawToCWykz1qAic9V2wk31wzEqXjqCq7ZKW4MjtZrzKCGN5K7sT' }, { server: s1 }); - i12 = user('i12', { pub: 'D6zJSPxZqs1bpgGpzJu9MgkCH7UxkG7D5u4xnnSH62wz', sec: '375vhCZdmVx7MaYD4bMZCevRLtebSuNPucfGevyPiPtdqpRzYLLNfd1h25Q59h4bm54dakpZ1RJ45ZofAyBmX4Et' }, { server: s1 }); - i13 = user('i13', { pub: 'BQ1fhCsJGohYKKfCbt58zQ8RpiSy5M8vwzdXzm4rH7mZ', sec: '4bTX2rMeAv8x79xQdFWPgY8zQLbPZ4HE7MWKXoXHyCoYgeCFpiWLdfvXwTbt31UMGrkNp2CViEt68WkjAZAQkjjm' }, { server: s1 }); - i14 = user('i14', { pub: 'H9dtBFmJohAwMNXSbfoL6xfRtmrqMw8WZnjXMHr4vEHX', sec: '2ANWb1qjjYRtT2TPFv1rBWA4EVfY7pqE4WqFUuzEgWG4vzcuvyUxMtyeBSf93M4V3g4MeEkELaj6NjA72jxnb4yF' }, { server: s1 }); -// i15 = user('i15', { pub: '8cHWEmVrdT249w8vJdiBms9mbu6CguQgXx2gRVE8gfnT', sec: '5Fy9GXiLMyhvRLCpoFf35XXNj24WXX29wM6xeCQiy5Uk7ggNhRcZjjp8GcpjRyE94oNR2jRNK4eAGiYUFnvbEnGB' }, { server: s1 }); -// i16 = user('i16', { pub: 'vi8hUTxss825cFCQE4SzmqBaAwLS236NmtrTQZBAAhG', sec: '5dVvAdWKcndQSaR9pzjEriRhGkCjef74HzecqKnydBVHdxXDewpAu3mcSU72PRKcCkTYTJPpgWmwuCyZubDKmoy4' }, { server: s1 }); + i1 = new TestUser('i1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + i2 = new TestUser('i2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + i3 = new TestUser('i3', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + i4 = new TestUser('i4', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + i5 = new TestUser('i5', { pub: '91dWdiyf7KaC4GAiKrwU7nGuue1vvmHqjCXbPziJFYtE', sec: '4Zno2b8ZULwBLY3RU5JcZhUf2a5FfXLVUMaYwPEzzN6i4ow9vXPsiCq7u2pEhkgJywqWdj97Hje1fdqnnzHeFgQe'}, { server: s1 }); + i6 = new TestUser('i6', { pub: '3C95HniUZsUN55AJy7z4wkz1UwtebbNd63dVAZ6EaUNm', sec: '3iJMz8JKNeU692L7jvug8xVnKvzN9RDee2m6QkMKbWKrvoHhv6apS4LR9hP786PUyFYJWz8bReMrFK8PY3aGxB8m'}, { server: s1 }); + i7 = new TestUser('i7', { pub: '4e9QJhJqHfMzEHgt3GtbfCXjqHVaQuJZKrKt8CNKR3AF', sec: 'TqdT99RpPEUjiz8su5QY7AQwharxPeo4ELCmeaFcvBEd3fW7wY7s9i531LMnTrCYBsgkrES494V6KjkhGppyEcF' }, { server: s1 }); + i7onS2 = new TestUser('i7', { pub: '4e9QJhJqHfMzEHgt3GtbfCXjqHVaQuJZKrKt8CNKR3AF', sec: 'TqdT99RpPEUjiz8su5QY7AQwharxPeo4ELCmeaFcvBEd3fW7wY7s9i531LMnTrCYBsgkrES494V6KjkhGppyEcF' }, { server: s2 }); + i8 = new TestUser('i8', { pub: '6GiiWjJxr29Stc4Ph4J4EipZJCzaQW1j6QXKANTNzRV3', sec: 'Yju625FGz6FHErshRc7jZyJUJ83MG4Zh9TXUNML62rKLXz7VJmwofnhJzeRRensranFJGQMYBLNSAeycAAsp62m' }, { server: s1 }); + i9 = new TestUser('i9', { pub: '6v4HnmiGxNzKwEjnBqxicWAmdKo6Bk51GvfQByS5YmiB', sec: '2wXPPDYfM3a8jmpYiFihS9qzdqFZrLWryu4uwpNPRuw5TRW3JCdJPsMa64eAcpshLTnMXkrKL94argk3FGxzzBKh' }, { server: s1 }); + i10 = new TestUser('i10', { pub: '6kr9Xr86qmrrwGq3XEjUXRVpHqS63FL52tcutcYGcRiv', sec: '2jCzQx7XUWoxboH67mMMv2z8VcrQabtYWpxS39iF6hNQnSBwN1d9RVauVC52PTRz6mgMzTjrSMETPrrB5N3oC7qQ' }, { server: s1 }); + i11 = new TestUser('i11', { pub: '5VLVTp96iX3YAq7NXwZeM2N6RjCkmxaU4G6bwMg1ZNwf', sec: '3BJtyeH1Q8jPcKuzL35m4eVPGuFXpcfRiGSseVawToCWykz1qAic9V2wk31wzEqXjqCq7ZKW4MjtZrzKCGN5K7sT' }, { server: s1 }); + i12 = new TestUser('i12', { pub: 'D6zJSPxZqs1bpgGpzJu9MgkCH7UxkG7D5u4xnnSH62wz', sec: '375vhCZdmVx7MaYD4bMZCevRLtebSuNPucfGevyPiPtdqpRzYLLNfd1h25Q59h4bm54dakpZ1RJ45ZofAyBmX4Et' }, { server: s1 }); + i13 = new TestUser('i13', { pub: 'BQ1fhCsJGohYKKfCbt58zQ8RpiSy5M8vwzdXzm4rH7mZ', sec: '4bTX2rMeAv8x79xQdFWPgY8zQLbPZ4HE7MWKXoXHyCoYgeCFpiWLdfvXwTbt31UMGrkNp2CViEt68WkjAZAQkjjm' }, { server: s1 }); + i14 = new TestUser('i14', { pub: 'H9dtBFmJohAwMNXSbfoL6xfRtmrqMw8WZnjXMHr4vEHX', sec: '2ANWb1qjjYRtT2TPFv1rBWA4EVfY7pqE4WqFUuzEgWG4vzcuvyUxMtyeBSf93M4V3g4MeEkELaj6NjA72jxnb4yF' }, { server: s1 }); +// i15 = new TestUser('i15', { pub: '8cHWEmVrdT249w8vJdiBms9mbu6CguQgXx2gRVE8gfnT', sec: '5Fy9GXiLMyhvRLCpoFf35XXNj24WXX29wM6xeCQiy5Uk7ggNhRcZjjp8GcpjRyE94oNR2jRNK4eAGiYUFnvbEnGB' }, { server: s1 }); +// i16 = new TestUser('i16', { pub: 'vi8hUTxss825cFCQE4SzmqBaAwLS236NmtrTQZBAAhG', sec: '5dVvAdWKcndQSaR9pzjEriRhGkCjef74HzecqKnydBVHdxXDewpAu3mcSU72PRKcCkTYTJPpgWmwuCyZubDKmoy4' }, { server: s1 }); yield s1.initDalBmaConnections(); yield s2.initDalBmaConnections(); diff --git a/test/integration/single-document-treatment.js b/test/integration/single-document-treatment.js index a525dd8b..9661f462 100644 --- a/test/integration/single-document-treatment.js +++ b/test/integration/single-document-treatment.js @@ -3,7 +3,7 @@ const _ = require('underscore'); const co = require('co'); const assert = require('assert'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); const CommonConstants = require('../../app/lib/common-libs/constants').CommonConstants @@ -35,8 +35,8 @@ describe("Single document treatment", function() { } }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); yield s1.prepareForNetwork(); yield s2.prepareForNetwork(); diff --git a/test/integration/start_generate_blocks.js b/test/integration/start_generate_blocks.js index c71bd8c8..3c79c483 100644 --- a/test/integration/start_generate_blocks.js +++ b/test/integration/start_generate_blocks.js @@ -4,7 +4,7 @@ const co = require('co'); const _ = require('underscore'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -65,10 +65,10 @@ describe("Generation", function() { const commitS1 = commit(s1); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - tuc = user('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + tuc = new TestUser('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s1 }); let servers = [s1, s2]; for (const server of servers) { diff --git a/test/integration/tests.js b/test/integration/tests.js index 3848b6b9..8f910656 100644 --- a/test/integration/tests.js +++ b/test/integration/tests.js @@ -8,7 +8,7 @@ const bma = require('../../app/modules/bma').BmaDependency.duniter.methods const constants = require('../../app/lib/constants'); const node = require('./tools/node'); const duniter = require('../../index'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const jspckg = require('../../package'); const commit = require('./tools/commit'); const httpTest = require('./tools/http'); @@ -33,10 +33,10 @@ describe("Integration", function() { } }); - const cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, node1); - const tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, node1); - const tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, node1); - const toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, node1); + const cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, node1); + const tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, node1); + const tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, node1); + const toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, node1); before(function(done) { node1.startTesting() @@ -187,10 +187,10 @@ describe("Integration", function() { } }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: node3 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: node3 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: node3 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: node3 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: node3 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: node3 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: node3 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: node3 }); yield node3.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); const now = 1482220000; diff --git a/test/integration/tools/TestUser.ts b/test/integration/tools/TestUser.ts new file mode 100644 index 00000000..f58fd8d5 --- /dev/null +++ b/test/integration/tools/TestUser.ts @@ -0,0 +1,403 @@ +import {KeyGen} from "../../../app/lib/common-libs/crypto/keyring" +import {IdentityDTO} from "../../../app/lib/dto/IdentityDTO"; +import {TestingServer} from "./toolbox" +import {CommonConstants} from "../../../app/lib/common-libs/constants" +import {CertificationDTO} from "../../../app/lib/dto/CertificationDTO" +import {MembershipDTO} from "../../../app/lib/dto/MembershipDTO" +import {RevocationDTO} from "../../../app/lib/dto/RevocationDTO" +import {CrawlerDependency} from "../../../app/modules/crawler/index" +import {Buid} from "../../../app/lib/common-libs/buid" +import {parsers} from "../../../app/lib/common-libs/parsers/index" +import {TransactionDTO} from "../../../app/lib/dto/TransactionDTO" +import {PeerDTO} from "../../../app/lib/dto/PeerDTO" +import {Contacter} from "../../../app/modules/crawler/lib/contacter" + +const request = require('request') +const _ = require('underscore') + +export interface TestInput { + src:string + unlock:string +} + +export interface TestOutput { + qty:number + base:number + lock:string +} + +export class TestUser { + + public pub = "" + public sec = "" + private createdIdentity = "" + + constructor(public uid:string, private options:any, public node:any) { + // For sync code + if (this.options.pub && this.options.sec) { + this.pub = this.options.pub + this.sec = this.options.sec + } + } + + private init(done:()=>void) { + if (this.options.pub && this.options.sec) { + this.pub = this.options.pub + this.sec = this.options.sec + done() + } else { + throw 'Not keypair information given for testing user ' + this.uid + } + } + + public async createIdentity(useRoot?:boolean, fromServer?:any) { + if (!this.pub) { + this.init(() => {}) + } + const current = await this.node.server.BlockchainService.current(); + let buid = !useRoot && current ? Buid.format.buid(current.number, current.hash) : CommonConstants.SPECIAL_BLOCK + this.createdIdentity = IdentityDTO.fromJSONObject({ + buid: buid, + uid: this.uid, + issuer: this.pub, + currency: this.node.server.conf.currency + }).getRawUnSigned() + this.createdIdentity += KeyGen(this.pub, this.sec).signSync(this.createdIdentity) + '\n' + await this.submitIdentity(this.createdIdentity, fromServer); + } + + public submitIdentity(raw:string, fromServer:any) { + return this.doPost('/wot/add', { + "identity": raw + }, fromServer) + } + + public getIdentityRaw() { + return this.createdIdentity + } + + public async makeCert(user:TestUser, fromServer?:TestingServer, overrideProps?:any) { + const lookup = await this.lookup(user.pub, fromServer) + const current = await this.node.server.BlockchainService.current() + const idty = _.filter(lookup.results[0].uids, (uidEntry:{ uid: string }) => uidEntry.uid === user.uid)[0] + let buid = current ? Buid.format.buid(current.number, current.hash) : CommonConstants.SPECIAL_BLOCK + const cert = { + "version": CommonConstants.DOCUMENTS_VERSION, + "currency": this.node.server.conf.currency, + "issuer": this.pub, + "idty_issuer": user.pub, + "idty_uid": idty.uid, + "idty_buid": idty.meta.timestamp, + "idty_sig": idty.self, + "buid": buid, + "sig": "" + } + _.extend(cert, overrideProps || {}); + const rawCert = CertificationDTO.fromJSONObject(cert).getRawUnSigned() + cert.sig = KeyGen(this.pub, this.sec).signSync(rawCert) + return CertificationDTO.fromJSONObject(cert) + } + + public async cert(user:TestUser, fromServer?:TestingServer, toServer?:TestingServer) { + const cert = await this.makeCert(user, fromServer) + await this.doPost('/wot/certify', { + "cert": cert.getRawSigned() + }, toServer); + } + + public async join() { + return await this.sendMembership("IN") + } + + public async leave() { + return await this.sendMembership("OUT") + } + + public async makeRevocation(givenLookupIdty?:any, overrideProps?:any) { + const res = givenLookupIdty || (await this.lookup(this.pub)); + const matchingResult = _.filter(res.results[0].uids, (uidEntry: { uid:string }) => uidEntry.uid === this.uid)[0] + const idty = { + uid: matchingResult.uid, + buid: matchingResult.meta.timestamp, + sig: matchingResult.self + } + const revocation = { + "currency": this.node.server.conf.currency, + "issuer": this.pub, + "uid": idty.uid, + "sig": idty.sig, + "buid": idty.buid, + "revocation": '' + }; + _.extend(revocation, overrideProps || {}); + const rawRevocation = RevocationDTO.fromJSONObject(revocation).getRawUnsigned() + revocation.revocation = KeyGen(this.pub, this.sec).signSync(rawRevocation); + return RevocationDTO.fromJSONObject(revocation) + } + + public async revoke(givenLookupIdty?:any) { + const revocation = await this.makeRevocation(givenLookupIdty) + return this.post('/wot/revoke', { + "revocation": revocation.getRaw() + }) + } + + public async makeMembership(type:string, fromServer?:TestingServer, overrideProps?:any) { + const lookup = await this.lookup(this.pub, fromServer) + const current = await this.node.server.BlockchainService.current(); + const idty = lookup.results[0].uids[0]; + const block = Buid.format.buid(current); + const join = { + "version": CommonConstants.DOCUMENTS_VERSION, + "currency": this.node.server.conf.currency, + "issuer": this.pub, + "block": block, + "membership": type, + "userid": this.uid, + "certts": idty.meta.timestamp, + "signature": "" + }; + _.extend(join, overrideProps || {}); + const rawJoin = MembershipDTO.fromJSONObject(join).getRaw() + join.signature = KeyGen(this.pub, this.sec).signSync(rawJoin) + return MembershipDTO.fromJSONObject(join) + } + + public async sendMembership(type:string) { + const ms = await this.makeMembership(type); + await this.post('/blockchain/membership', { + "membership": ms.getRawSigned() + }) + } + + public send(amount:number, recipient:string, comment?:string) { + const that = this + return async function(done:(e?:any)=>void) { + try { + let raw = await that.prepareITX(amount, recipient, comment) + await that.sendTX(raw) + done() + } catch (e) { + done(e) + } + }; + }; + + public async sendMoney(amount:number, recipient:string, comment?:string) { + const raw = await this.prepareITX(amount, recipient, comment) + await this.sendTX(raw) + } + + public async sendTX(rawTX:string) { + let http = await this.getContacter() + return http.processTransaction(rawTX) + } + + public async prepareUTX(previousTX:string, unlocks:string[], outputs:TestOutput[], opts:any) { + let obj = parsers.parseTransaction.syncWrite(previousTX); + // Unlocks inputs with given "unlocks" strings + let outputsToConsume = obj.outputs; + if (opts.theseOutputsStart !== undefined) { + outputsToConsume = outputsToConsume.slice(opts.theseOutputsStart); + } + let inputs = outputsToConsume.map((out:string, index:number) => { + const output = TransactionDTO.outputStr2Obj(out); + return { + src: [output.amount, output.base, 'T', obj.hash, (opts.theseOutputsStart || 0) + index].join(':'), + unlock: unlocks[index] + } + }) + return this.signed(this.prepareTX(inputs, outputs, opts)) + } + + public async prepareMTX(previousTX:string, user2:TestUser, unlocks:string[], outputs:TestOutput[], opts:any) { + let obj = parsers.parseTransaction.syncWrite(previousTX); + // Unlocks inputs with given "unlocks" strings + let inputs = obj.outputs.map((out:string, index:number) => { + const output = TransactionDTO.outputStr2Obj(out); + return { + src: [output.amount, output.base, 'T', obj.hash, index].join(':'), + unlock: unlocks[index] + } + }) + opts = opts || {} + opts.issuers = [this.pub, user2.pub] + return this.signed(this.prepareTX(inputs, outputs, opts), user2) + } + + public async prepareITX(amount:number, recipient:TestUser|string, comment?:string) { + let sources = [] + if (!amount || !recipient) { + throw 'Amount and recipient are required' + } + let http = await this.getContacter() + let current = await http.getCurrent() + let version = current && Math.min(CommonConstants.LAST_VERSION_FOR_TX, current.version) + let json = await http.getSources(this.pub) + let i = 0 + let cumulated = 0 + let commonbase = 99999999 + while (i < json.sources.length) { + let src = json.sources[i]; + sources.push({ + 'type': src.type, + 'amount': src.amount, + 'base': src.base, + 'noffset': src.noffset, + 'identifier': src.identifier + }) + commonbase = Math.min(commonbase, src.base); + cumulated += src.amount * Math.pow(10, src.base); + i++; + } + if (cumulated < amount) { + throw 'You do not have enough coins! (' + cumulated + ' ' + this.node.server.conf.currency + ' left)'; + } + let sources2 = []; + let total = 0; + for (let j = 0; j < sources.length && total < amount; j++) { + let src = sources[j]; + total += src.amount * Math.pow(10, src.base); + sources2.push(src); + } + let inputSum = 0; + sources2.forEach((src) => inputSum += src.amount * Math.pow(10, src.base)); + let inputs = sources2.map((src) => { + return { + src: [src.amount, src.base].concat([src.type, src.identifier, src.noffset]).join(':'), + unlock: 'SIG(0)' + }; + }); + let outputs = [{ + qty: amount, + base: commonbase, + lock: 'SIG(' + (typeof recipient === 'string' ? recipient : recipient.pub) + ')' + }]; + if (inputSum - amount > 0) { + // Rest back to issuer + outputs.push({ + qty: inputSum - amount, + base: commonbase, + lock: "SIG(" + this.pub + ")" + }); + } + let raw = this.prepareTX(inputs, outputs, { + version: version, + blockstamp: current && [current.number, current.hash].join('-'), + comment: comment + }); + return this.signed(raw) + } + + private signed(raw:string, user2?:TestUser) { + let signatures = [KeyGen(this.pub, this.sec).signSync(raw)]; + if (user2) { + signatures.push(KeyGen(user2.pub, user2.sec).signSync(raw)); + } + return raw + signatures.join('\n') + '\n'; + } + + public makeTX(inputs:TestInput[], outputs:TestOutput[], theOptions:any) { + const raw = this.prepareTX(inputs, outputs, theOptions) + return this.signed(raw) + } + + public prepareTX(inputs:TestInput[], outputs:TestOutput[], theOptions:any) { + let opts = theOptions || {}; + let issuers = opts.issuers || [this.pub]; + let raw = ''; + raw += "Version: " + (opts.version || CommonConstants.TRANSACTION_VERSION) + '\n'; + raw += "Type: Transaction\n"; + raw += "Currency: " + (opts.currency || this.node.server.conf.currency) + '\n'; + raw += "Blockstamp: " + opts.blockstamp + '\n'; + raw += "Locktime: " + (opts.locktime || 0) + '\n'; + raw += "Issuers:\n"; + issuers.forEach((issuer:string) => raw += issuer + '\n'); + raw += "Inputs:\n"; + inputs.forEach(function (input) { + raw += input.src + '\n'; + }); + raw += "Unlocks:\n"; + inputs.forEach(function (input, index) { + if (input.unlock) { + raw += index + ":" + input.unlock + '\n'; + } + }); + raw += "Outputs:\n"; + outputs.forEach(function (output) { + raw += [output.qty, output.base, output.lock].join(':') + '\n'; + }); + raw += "Comment: " + (opts.comment || "") + "\n"; + return raw; + } + + public async makePeer(endpoints:string[], overrideProps:any) { + const peer = PeerDTO.fromJSONObject({ + currency: this.node.server.conf.currency, + pubkey: this.pub, + block: '2-00008DF633FC158F9DB4864ABED696C1AA0FE5D617A7B5F7AB8DE7CA2EFCD4CB', + endpoints: endpoints + }); + _.extend(peer, overrideProps || {}); + const rawPeer = PeerDTO.fromJSONObject(peer).getRawUnsigned() + peer.signature = KeyGen(this.pub, this.sec).signSync(rawPeer) + return PeerDTO.fromJSONObject(peer) + } + + private async post(uri:string, data:any, done?:(e?:any, res?:any, body?:string)=>void) { + return new Promise((resolve, reject) => { + var postReq = request.post({ + "uri": 'http://' + [this.node.server.conf.remoteipv4, this.node.server.conf.remoteport].join(':') + uri, + "timeout": 1000 * 100000 + }, function (err:any, res:any, body:string) { + err = err || (res.statusCode != 200 && body != 'Already up-to-date' && body) || null; + if (err) { + reject(err) + } else { + resolve(res) + } + done && done(err, res, body) + }); + postReq.form(data); + }) + } + + private async doPost(uri:string, data:any, toServer?:TestingServer) { + const ip = toServer ? toServer.conf.ipv4 : this.node.server.conf.remoteipv4; + const port = toServer ? toServer.conf.port : this.node.server.conf.remoteport; + return new Promise((resolve, reject) => { + var postReq = request.post({ + "uri": 'http://' + [ip, port].join(':') + uri, + "timeout": 1000 * 100000 + }, function (err:any, res:any, body:string) { + err = err || (res.statusCode != 200 && body != 'Already up-to-date' && body) || null; + err ? reject(err) : resolve(res); + }); + postReq.form(data); + }); + } + + private async getContacter(fromServer?:TestingServer) { + const that = this + return new Promise(function(resolve){ + let theNode = (fromServer && { server: fromServer }) || that.node + resolve(CrawlerDependency.duniter.methods.contacter(theNode.server.conf.ipv4, theNode.server.conf.port, { + timeout: 1000 * 100000 + })); + }); + } + + public async lookup(pubkey:string, fromServer?:TestingServer) { + const node2 = await this.getContacter(fromServer) + return node2.getLookup(pubkey); + } + + public async sendP(amount:number, userid:string, comment?:string) { + return new Promise((res, rej) => { + this.send(amount, userid, comment)((err) => { + if (err) return rej(err) + res() + }) + }) + } +} diff --git a/test/integration/tools/node.js b/test/integration/tools/node.js index cb65f6ff..2748b3da 100644 --- a/test/integration/tools/node.js +++ b/test/integration/tools/node.js @@ -8,7 +8,6 @@ var duniter = require('../../../index'); var multicaster = require('../../../app/lib/streams/multicaster'); var ConfDTO = require('../../../app/lib/dto/ConfDTO').ConfDTO var PeerDTO = require('../../../app/lib/dto/PeerDTO').PeerDTO -var user = require('./user'); var http = require('./http'); const bma = require('../../../app/modules/bma').BmaDependency.duniter.methods.bma; diff --git a/test/integration/tools/toolbox.ts b/test/integration/tools/toolbox.ts index 0bb986b7..45a7ceb7 100644 --- a/test/integration/tools/toolbox.ts +++ b/test/integration/tools/toolbox.ts @@ -22,6 +22,7 @@ import {WS2PMessageHandler} from "../../../app/modules/ws2p/lib/impl/WS2PMessage import {WS2PCluster} from "../../../app/modules/ws2p/lib/WS2PCluster" import {WS2PServer} from "../../../app/modules/ws2p/lib/WS2PServer" import {WS2PServerMessageHandler} from "../../../app/modules/ws2p/lib/interface/WS2PServerMessageHandler" +import {TestUser} from "./TestUser" const assert = require('assert'); const _ = require('underscore'); @@ -31,7 +32,6 @@ const WebSocketServer = require('ws').Server const httpTest = require('../tools/http'); const sync = require('../tools/sync'); const commit = require('../tools/commit'); -const user = require('../tools/user'); const until = require('../tools/until'); const bma = require('../../../app/modules/bma').BmaDependency.duniter.methods.bma; const logger = require('../../../app/lib/logger').NewLogger('toolbox'); @@ -72,7 +72,7 @@ export const assertThrows = async (promise:Promise, message:string|null = n } export const simpleUser = (uid:string, keyring:{ pub:string, sec:string }, server:TestingServer) => { - return user(uid, keyring, { server }); + return new TestUser(uid, keyring, { server }); } export const simpleNetworkOf2NodesAnd2Users = async (options:any) => { @@ -82,8 +82,8 @@ export const simpleNetworkOf2NodesAnd2Users = async (options:any) => { const s1 = NewTestingServer(_.extend({ pair: catKeyring }, options || {})); const s2 = NewTestingServer(_.extend({ pair: tacKeyring }, options || {})); - const cat = user('cat', catKeyring, { server: s1 }); - const tac = user('tac', tacKeyring, { server: s1 }); + const cat = new TestUser('cat', catKeyring, { server: s1 }); + const tac = new TestUser('tac', tacKeyring, { server: s1 }); await s1.initDalBmaConnections() await s2.initDalBmaConnections() @@ -113,8 +113,8 @@ export const simpleNodeWith2Users = async (options:any) => { const s1 = NewTestingServer(_.extend({ pair: catKeyring }, options || {})); - const cat = user('cat', catKeyring, { server: s1 }); - const tac = user('tac', tacKeyring, { server: s1 }); + const cat = new TestUser('cat', catKeyring, { server: s1 }); + const tac = new TestUser('tac', tacKeyring, { server: s1 }); await s1.initDalBmaConnections() @@ -135,8 +135,8 @@ export const simpleNodeWith2otherUsers = async (options:any) => { const s1 = NewTestingServer(_.extend({ pair: ticKeyring }, options || {})); - const tic = user('cat', ticKeyring, { server: s1 }); - const toc = user('tac', tocKeyring, { server: s1 }); + const tic = new TestUser('cat', ticKeyring, { server: s1 }); + const toc = new TestUser('tac', tocKeyring, { server: s1 }); await s1.initDalBmaConnections() @@ -152,7 +152,7 @@ export const simpleNodeWith2otherUsers = async (options:any) => { export const createUser = async (uid:string, pub:string, sec:string, defaultServer:Server) => { const keyring = { pub: pub, sec: sec }; - return user(uid, keyring, { server: defaultServer }); + return new TestUser(uid, keyring, { server: defaultServer }); } export const fakeSyncServer = async (readBlocksMethod:any, readParticularBlockMethod:any, onPeersRequested:any) => { diff --git a/test/integration/tools/user.js b/test/integration/tools/user.js deleted file mode 100644 index 1f910f88..00000000 --- a/test/integration/tools/user.js +++ /dev/null @@ -1,394 +0,0 @@ -"use strict"; -const co = require('co'); -const _ = require('underscore'); -const async = require('async'); -const request = require('request'); -const contacter = require('../../../app/modules/crawler').CrawlerDependency.duniter.methods.contacter; -const CommonConstants = require('../../../app/lib/common-libs/constants').CommonConstants -const ucp = require('../../../app/lib/common-libs/buid').Buid -const parsers = require('../../../app/lib/common-libs/parsers').parsers -const rawer = require('../../../app/lib/common-libs').rawer -const keyring = require('../../../app/lib/common-libs/crypto/keyring') -const constants = require('../../../app/lib/constants'); -const CertificationDTO = require('../../../app/lib/dto/CertificationDTO').CertificationDTO -const MembershipDTO = require('../../../app/lib/dto/MembershipDTO').MembershipDTO -const RevocationDTO = require('../../../app/lib/dto/RevocationDTO').RevocationDTO -const PeerDTO = require('../../../app/lib/dto/PeerDTO').PeerDTO -const TransactionDTO = require('../../../app/lib/dto/TransactionDTO').TransactionDTO - -module.exports = function (uid, url, node) { - return new User(uid, url, node); -}; - -function User (uid, options, node) { - - var that = this; - var pub, sec; - var createdIdentity = ""; - that.node = node; - that.uid = uid - - // For sync code - if (options.pub && options.sec) { - pub = that.pub = options.pub; - sec = that.sec = options.sec; - } - - function init(done) { - if (options.pub && options.sec) { - pub = that.pub = options.pub; - sec = that.sec = options.sec; - done(); - } else { - throw 'Not keypair information given for testing user ' + uid; - } - } - - this.createIdentity = (useRoot, fromServer) => co(function*() { - if (!pub) { - init(() => {}) - } - const current = yield node.server.BlockchainService.current(); - let buid = !useRoot && current ? ucp.format.buid(current.number, current.hash) : '0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855'; - createdIdentity = rawer.getOfficialIdentity({ - buid: buid, - uid: uid, - issuer: pub, - currency: node.server.conf.currency - }, false); - createdIdentity += keyring.KeyGen(pub, sec).signSync(createdIdentity) + '\n'; - yield that.submitIdentity(createdIdentity, fromServer); - }); - - this.submitIdentity = (raw, fromServer) => doPost('/wot/add', { - "identity": raw - }, fromServer); - - this.getIdentityRaw = () => createdIdentity; - - this.makeCert = (user, fromServer, overrideProps) => co(function*() { - const lookup = yield that.lookup(user.pub, fromServer); - const current = yield node.server.BlockchainService.current(); - const idty = _.filter(lookup.results[0].uids, (uidEntry) => uidEntry.uid === user.uid)[0] - let buid = current ? ucp.format.buid(current.number, current.hash) : ucp.format.buid(); - const cert = { - "version": constants.DOCUMENTS_VERSION, - "currency": node.server.conf.currency, - "issuer": pub, - "idty_issuer": user.pub, - "idty_uid": idty.uid, - "idty_buid": idty.meta.timestamp, - "idty_sig": idty.self, - "buid": buid - }; - _.extend(cert, overrideProps || {}); - const rawCert = rawer.getOfficialCertification(cert); - cert.sig = keyring.KeyGen(pub, sec).signSync(rawCert, sec); - return CertificationDTO.fromJSONObject(cert); - }); - - this.cert = (user, fromServer, toServer) => co(function*() { - const cert = yield that.makeCert(user, fromServer); - yield doPost('/wot/certify', { - "cert": cert.getRawSigned() - }, toServer); - }); - - this.join = () => co(function*() { - return yield that.sendMembership("IN"); - }); - - this.leave = () => co(function*() { - return yield that.sendMembership("OUT"); - }); - - this.makeRevocation = (givenLookupIdty, overrideProps) => co(function*() { - const res = givenLookupIdty || (yield that.lookup(pub)); - const matchingResult = _.filter(res.results[0].uids, (uidEntry) => uidEntry.uid === uid)[0] - const idty = { - uid: matchingResult.uid, - buid: matchingResult.meta.timestamp, - sig: matchingResult.self - } - const revocation = { - "currency": node.server.conf.currency, - "issuer": pub, - "uid": idty.uid, - "sig": idty.sig, - "buid": idty.buid, - "revocation": '' - }; - _.extend(revocation, overrideProps || {}); - const rawRevocation = rawer.getOfficialRevocation(revocation); - revocation.revocation = keyring.KeyGen(pub, sec).signSync(rawRevocation); - return RevocationDTO.fromJSONObject(revocation); - }); - - this.revoke = (givenLookupIdty) => co(function *() { - const revocation = yield that.makeRevocation(givenLookupIdty); - return post('/wot/revoke', { - "revocation": revocation.getRaw() - }) - }); - - this.makeMembership = (type, fromServer, overrideProps) => co(function*() { - const lookup = yield that.lookup(pub, fromServer); - const current = yield node.server.BlockchainService.current(); - const idty = lookup.results[0].uids[0]; - const block = ucp.format.buid(current); - const join = { - "version": constants.DOCUMENTS_VERSION, - "currency": node.server.conf.currency, - "issuer": pub, - "block": block, - "membership": type, - "userid": uid, - "certts": idty.meta.timestamp - }; - _.extend(join, overrideProps || {}); - const rawJoin = rawer.getMembershipWithoutSignature(join); - join.signature = keyring.KeyGen(pub, sec).signSync(rawJoin); - return MembershipDTO.fromJSONObject(join) - }); - - this.sendMembership = (type) => co(function*() { - const ms = yield that.makeMembership(type); - yield post('/blockchain/membership', { - "membership": ms.getRawSigned() - }); - }); - - this.send = function (amount, recipient, comment) { - return function(done) { - return co(function *() { - try { - let raw = yield that.prepareITX(amount, recipient, comment); - yield that.sendTX(raw); - done(); - } catch (e) { - done(e); - } - }); - }; - }; - - this.sendMoney = function (amount, recipient, comment) { - return co(function *() { - let raw = yield that.prepareITX(amount, recipient, comment); - yield that.sendTX(raw); - }) - }; - - this.sendTX = (rawTX) => co(function *() { - let http = yield getContacter(); - return http.processTransaction(rawTX); - }); - - this.prepareUTX = (previousTX, unlocks, outputs, opts) => co(function *() { - let obj = parsers.parseTransaction.syncWrite(previousTX); - // Unlocks inputs with given "unlocks" strings - let outputsToConsume = obj.outputs; - if (opts.theseOutputsStart !== undefined) { - outputsToConsume = outputsToConsume.slice(opts.theseOutputsStart); - } - let inputs = outputsToConsume.map((out, index) => { - const output = TransactionDTO.outputStr2Obj(out); - return { - src: [output.amount, output.base, 'T', obj.hash, (opts.theseOutputsStart || 0) + index].join(':'), - unlock: unlocks[index] - }; - }); - return signed(that.prepareTX(inputs, outputs, opts)); - }); - - this.prepareMTX = (previousTX, user2, unlocks, outputs, opts) => co(function *() { - let obj = parsers.parseTransaction.syncWrite(previousTX); - // Unlocks inputs with given "unlocks" strings - let inputs = obj.outputs.map((out, index) => { - const output = TransactionDTO.outputStr2Obj(out); - return { - src: [output.amount, output.base, 'T', obj.hash, index].join(':'), - unlock: unlocks[index] - }; - }); - opts = opts || {}; - opts.issuers = [pub, user2.pub]; - return signed(that.prepareTX(inputs, outputs, opts), user2); - }); - - this.prepareITX = (amount, recipient, comment) => co(function *() { - let sources = []; - if (!amount || !recipient) { - throw 'Amount and recipient are required'; - } - let http = yield getContacter(); - let current = yield http.getCurrent(); - let version = current && Math.min(CommonConstants.LAST_VERSION_FOR_TX, current.version); - let json = yield http.getSources(pub); - let i = 0; - let cumulated = 0; - let commonbase = null; - while (i < json.sources.length) { - let src = json.sources[i]; - sources.push({ - 'type': src.type, - 'amount': src.amount, - 'base': src.base, - 'noffset': src.noffset, - 'identifier': src.identifier - }); - if (commonbase == null) { - commonbase = src.base; - } - commonbase = Math.min(commonbase, src.base); - cumulated += src.amount * Math.pow(10, src.base); - i++; - } - if (cumulated < amount) { - throw 'You do not have enough coins! (' + cumulated + ' ' + node.server.conf.currency + ' left)'; - } - let sources2 = []; - let total = 0; - for (let j = 0; j < sources.length && total < amount; j++) { - let src = sources[j]; - total += src.amount * Math.pow(10, src.base); - sources2.push(src); - } - let inputSum = 0; - sources2.forEach((src) => inputSum += src.amount * Math.pow(10, src.base)); - let inputs = sources2.map((src) => { - return { - src: [src.amount, src.base].concat([src.type, src.identifier, src.noffset]).join(':'), - unlock: 'SIG(0)' - }; - }); - let outputs = [{ - qty: amount, - base: commonbase, - lock: 'SIG(' + (recipient.pub || recipient) + ')' - }]; - if (inputSum - amount > 0) { - // Rest back to issuer - outputs.push({ - qty: inputSum - amount, - base: commonbase, - lock: "SIG(" + pub + ")" - }); - } - let raw = that.prepareTX(inputs, outputs, { - version: version, - blockstamp: current && [current.number, current.hash].join('-'), - comment: comment - }); - return signed(raw); - }); - - function signed(raw, user2) { - let signatures = [keyring.KeyGen(pub, sec).signSync(raw)]; - if (user2) { - signatures.push(keyring.KeyGen(user2.pub, user2.sec).signSync(raw)); - } - return raw + signatures.join('\n') + '\n'; - } - - this.makeTX = (inputs, outputs, theOptions) => { - const raw = that.prepareTX(inputs, outputs, theOptions); - return signed(raw); - }; - - this.prepareTX = (inputs, outputs, theOptions) => { - let opts = theOptions || {}; - let issuers = opts.issuers || [pub]; - let raw = ''; - raw += "Version: " + (opts.version || constants.TRANSACTION_VERSION) + '\n'; - raw += "Type: Transaction\n"; - raw += "Currency: " + (opts.currency || node.server.conf.currency) + '\n'; - raw += "Blockstamp: " + opts.blockstamp + '\n'; - raw += "Locktime: " + (opts.locktime || 0) + '\n'; - raw += "Issuers:\n"; - issuers.forEach((issuer) => raw += issuer + '\n'); - raw += "Inputs:\n"; - inputs.forEach(function (input) { - raw += input.src + '\n'; - }); - raw += "Unlocks:\n"; - inputs.forEach(function (input, index) { - if (input.unlock) { - raw += index + ":" + input.unlock + '\n'; - } - }); - raw += "Outputs:\n"; - outputs.forEach(function (output) { - raw += [output.qty, output.base, output.lock].join(':') + '\n'; - }); - raw += "Comment: " + (opts.comment || "") + "\n"; - return raw; - }; - - this.makePeer = (endpoints, overrideProps) => co(function*() { - const peer = PeerDTO.fromJSONObject({ - currency: node.server.conf.currency, - pubkey: pub, - block: '2-00008DF633FC158F9DB4864ABED696C1AA0FE5D617A7B5F7AB8DE7CA2EFCD4CB', - endpoints: endpoints - }); - _.extend(peer, overrideProps || {}); - const rawPeer = rawer.getPeerWithoutSignature(peer); - peer.signature = keyring.KeyGen(pub, sec).signSync(rawPeer); - return PeerDTO.fromJSONObject(peer) - }); - - function post(uri, data, done) { - return new Promise((resolve, reject) => { - var postReq = request.post({ - "uri": 'http://' + [node.server.conf.remoteipv4, node.server.conf.remoteport].join(':') + uri, - "timeout": 1000 * 100000 - }, function (err, res, body) { - err = err || (res.statusCode != 200 && body != 'Already up-to-date' && body) || null; - if (err) { - reject(err) - } else { - resolve(res, body) - } - done && done(err, res, body); - }); - postReq.form(data); - }) - } - - function doPost(uri, data, fromServer) { - const ip = fromServer ? fromServer.conf.ipv4 : node.server.conf.remoteipv4; - const port = fromServer ? fromServer.conf.port : node.server.conf.remoteport; - return new Promise((resolve, reject) => { - var postReq = request.post({ - "uri": 'http://' + [ip, port].join(':') + uri, - "timeout": 1000 * 100000 - }, function (err, res, body) { - err = err || (res.statusCode != 200 && body != 'Already up-to-date' && body) || null; - err ? reject(err) : resolve(res); - }); - postReq.form(data); - }); - } - - function getContacter(fromServer) { - return new Promise(function(resolve){ - let theNode = (fromServer && { server: fromServer }) || node; - resolve(contacter(theNode.server.conf.ipv4, theNode.server.conf.port, { - timeout: 1000 * 100000 - })); - }); - } - - this.lookup = (pubkey, fromServer) => co(function*() { - const node2 = yield getContacter(fromServer); - return node2.getLookup(pubkey); - }); - - this.sendP = (amount, userid, comment) => new Promise((res, rej) => { - that.send(amount, userid, comment)((err, data) => { - if (err) return rej(err) - res(data) - }) - }) -} diff --git a/test/integration/transactions-chaining.js b/test/integration/transactions-chaining.js index 600641b7..66a02c1c 100644 --- a/test/integration/transactions-chaining.js +++ b/test/integration/transactions-chaining.js @@ -9,7 +9,7 @@ const bma = require('../../app/modules/bma').BmaDependency.duniter.methods const CommonConstants = require('../../app/lib/common-libs/constants').CommonConstants const toolbox = require('./tools/toolbox'); const node = require('./tools/node'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const unit = require('./tools/unit'); const http = require('./tools/http'); @@ -32,8 +32,8 @@ describe("Transaction chaining", function() { c: 0.1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); yield s1.initDalBmaConnections(); yield tic.createIdentity(); diff --git a/test/integration/transactions-pruning.js b/test/integration/transactions-pruning.js index 13d8c9b1..d5a6f5c3 100644 --- a/test/integration/transactions-pruning.js +++ b/test/integration/transactions-pruning.js @@ -2,7 +2,7 @@ const co = require('co'); const should = require('should'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); const constants = require('../../app/lib/constants'); @@ -23,8 +23,8 @@ describe("Transactions pruning", function() { } }); - cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + cat1 = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac1 = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); yield s1.prepareForNetwork(); diff --git a/test/integration/transactions-test.js b/test/integration/transactions-test.js index ee5cfa15..6b659eb9 100644 --- a/test/integration/transactions-test.js +++ b/test/integration/transactions-test.js @@ -8,7 +8,7 @@ const constants = require('../../app/lib/constants'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; const toolbox = require('./tools/toolbox'); const node = require('./tools/node'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const unit = require('./tools/unit'); const http = require('./tools/http'); @@ -35,8 +35,8 @@ describe("Testing transactions", function() { medianTimeBlocks: 1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); yield s1.initDalBmaConnections(); // Self certifications @@ -193,8 +193,8 @@ describe("Testing transactions", function() { (yield s1.get('/tx/sources/DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV')).should.have.property('sources').length(4); // As well as tic let tx3 = yield tic.prepareUTX(tx2, ['XHX(1872767826647264) SIG(0)'], [{ qty: 1200, base: 0, lock: 'SIG(' + toc.pub + ')' }], { comment: 'wrong', blockstamp: [current.number, current.hash].join('-') }); let tx4 = yield toc.prepareUTX(tx2, ['XHX(1872767826647264) SIG(0)'], [{ qty: 1200, base: 0, lock: 'SIG(' + toc.pub + ')' }], { comment: 'ok', blockstamp: [current.number, current.hash].join('-') }); - let tx5 = yield tic.prepareMTX(tx2, toc, ['XHX(1872767826647264) SIG(1) SIG(0) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789)'], [{ qty: 1200, base: 0, lock: 'SIG(' + toc.pub + ')' }], { comment: 'multi OK', blockstamp: [current.number, current.hash].join('-') }); - let tx6 = yield toc.prepareMTX(tx2, tic, ['XHX(1872767826647264) SIG(1) SIG(0)'], [{ qty: 1200, base: 0, lock: 'SIG(' + toc.pub + ')' }], { comment: 'multi WRONG', blockstamp: [current.number, current.hash].join('-') }); + let tx5 = yield tic.prepareMTX(tx2, toc, ['XHX(1872767826647264) SIG(1) SIG(0)'], [{ qty: 1200, base: 0, lock: 'SIG(' + toc.pub + ')' }], { comment: 'multi OK', blockstamp: [current.number, current.hash].join('-') }); + let tx6 = yield toc.prepareMTX(tx2, tic, ['XHX(1872767826647264) SIG(1) SIG(0) SIG(0) SIG(0)'], [{ qty: 1200, base: 0, lock: 'SIG(' + toc.pub + ')' }], { comment: 'multi WRONG', blockstamp: [current.number, current.hash].join('-') }); // nLocktime let tx7 = yield tic.prepareMTX(tx2, toc, ['XHX(1872767826647264) SIG(1) SIG(0)'], [{ qty: 1200, base: 0, lock: 'SIG(' + toc.pub + ')' }], { comment: 'wrong locktime', locktime: 100, blockstamp: [current.number, current.hash].join('-') }); yield unit.shouldFail(toc.sendTX(tx3), 'Wrong unlocker in transaction'); diff --git a/test/integration/v1.1-dividend.js b/test/integration/v1.1-dividend.js index cc8698c2..2ba9e404 100644 --- a/test/integration/v1.1-dividend.js +++ b/test/integration/v1.1-dividend.js @@ -3,7 +3,7 @@ const co = require('co'); const should = require('should'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); @@ -30,9 +30,9 @@ describe("Protocol 1.1 Dividend", function() { medianTimeBlocks: 1 }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); yield s1.initDalBmaConnections(); diff --git a/test/integration/wotb.js b/test/integration/wotb.js index a9b82f44..d9a7db18 100644 --- a/test/integration/wotb.js +++ b/test/integration/wotb.js @@ -5,7 +5,7 @@ const should = require('should'); const _ = require('underscore'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const shutDownEngine = require('./tools/shutDownEngine'); @@ -79,17 +79,17 @@ describe("WOTB module", function() { sigValidity: 1400, sigPeriod: 0 }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - cat2 = user('cat2', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s2 }); - toc2 = user('toc2', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s2 }); - tic2 = user('tic2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); + cat2 = new TestUser('cat2', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s2 }); + toc2 = new TestUser('toc2', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s2 }); + tic2 = new TestUser('tic2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); - cat3 = user('cat3', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s3 }); - toc3 = user('toc3', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s3 }); - tic3 = user('tic3', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s3 }); + cat3 = new TestUser('cat3', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s3 }); + toc3 = new TestUser('toc3', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s3 }); + tic3 = new TestUser('tic3', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s3 }); /** * cat <==> toc -- GitLab From 4c67e0e84dcc3040c88dd6be9a37d4374d596ed6 Mon Sep 17 00:00:00 2001 From: cgeek Date: Sun, 12 Nov 2017 16:55:15 +0100 Subject: [PATCH 25/72] [fix] #1192 Set version of Node to ">=6 <9" --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aa910d04..ac48cbc4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "duniter", "version": "1.6.13", "engines": { - "node": ">=6.11.1", + "node": ">=6 <9", "npm": ">=3.10" }, "engineStrict": true, -- GitLab From 9c22c5a92377dfd591ac3a188d7d077765a4a76c Mon Sep 17 00:00:00 2001 From: librelois Date: Sun, 12 Nov 2017 18:20:41 +0100 Subject: [PATCH 26/72] ws2p log add details --- app/modules/ws2p/lib/WS2PCluster.ts | 2 +- app/modules/ws2p/lib/WS2PServer.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 5e2eb475..e1c48c43 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -490,7 +490,7 @@ export class WS2PCluster { try { await c.pushHeads(heads) } catch (e) { - this.server.logger.warn('Could not spread new HEAD info to %s WS2P %s %s', c.pubkey) + this.server.logger.warn('Could not spread new HEAD info to %s WS2PID %s', c.pubkey, c.uuid) } })) } diff --git a/app/modules/ws2p/lib/WS2PServer.ts b/app/modules/ws2p/lib/WS2PServer.ts index 0e4d66b4..f104f972 100644 --- a/app/modules/ws2p/lib/WS2PServer.ts +++ b/app/modules/ws2p/lib/WS2PServer.ts @@ -105,7 +105,7 @@ export class WS2PServer extends events.EventEmitter { }) this.connections.push(c) this.emit('newConnection', c) - this.server.logger.info('WS2P: established incoming connection from %s:%s', host, port) + this.server.logger.info('WS2P: established incoming connection from %s %s:%s', c.pubkey.slice(0, 8), host, port) // Broadcasting const singleWriteProtection = new WS2PSingleWriteStream() -- GitLab From 14237631587378154cf10f0e87bb497b6c6f2c81 Mon Sep 17 00:00:00 2001 From: Moul Date: Sun, 12 Nov 2017 15:17:02 +0100 Subject: [PATCH 27/72] [sec] update 'ws' dependency as a there is a security issue. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f231cd0a..aa910d04 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,7 @@ "unzip2": "0.2.5", "winston": "2.3.1", "wotb": "0.6.x", - "ws": "1.1.1" + "ws": "1.1.5" }, "devDependencies": { "@types/mocha": "^2.2.41", -- GitLab From 1edc424daa3e43655b077f2de04ba46c38f80941 Mon Sep 17 00:00:00 2001 From: cgeek Date: Sun, 12 Nov 2017 16:14:07 +0100 Subject: [PATCH 28/72] [enh] #1193 Refactoring test user.js to TestUser.ts --- .gitignore | 2 + app/lib/common-libs/buid.ts | 4 + app/lib/dto/IdentityDTO.ts | 5 + app/lib/dto/RevocationDTO.ts | 5 + test/fast/modules/bma/ddos-test.js | 2 +- test/fast/modules/bma/limiter-test.js | 4 +- test/integration/branches2.ts | 6 +- test/integration/branches_pending_data.js | 10 +- test/integration/branches_revert.js | 6 +- test/integration/branches_revert2.js | 6 +- .../branches_revert_memberships.js | 8 +- test/integration/branches_switch.js | 6 +- test/integration/branches_switch.ts | 6 +- .../integration/certification_chainability.js | 10 +- test/integration/certifier-is-member.js | 8 +- test/integration/collapse.js | 6 +- test/integration/continuous-proof.js | 6 +- test/integration/crosschain-test.js | 18 +- test/integration/documents-currency.ts | 12 +- test/integration/forwarding.js | 10 +- test/integration/http_api.js | 6 +- test/integration/identity-absorption.js | 6 +- test/integration/identity-clean-test.js | 10 +- test/integration/identity-expiry.js | 10 +- .../identity-implicit-revocation.js | 8 +- test/integration/identity-kicking-by-certs.js | 12 +- test/integration/identity-kicking.js | 8 +- test/integration/identity-pulling.js | 12 +- test/integration/identity-same-pubkey.js | 8 +- test/integration/identity-test.js | 18 +- test/integration/lookup.js | 8 +- test/integration/network-update.js | 6 +- test/integration/newcomers-shuffling.js | 10 +- test/integration/peer-outdated.js | 6 +- test/integration/peerings.js | 8 +- test/integration/peers-same-pubkey.js | 6 +- test/integration/register-fork-blocks.js | 8 +- test/integration/revocation-test.js | 12 +- test/integration/revoked_pubkey_replay.ts | 4 +- test/integration/server-import-export.js | 6 +- test/integration/server-sandbox.js | 36 +- test/integration/single-document-treatment.js | 6 +- test/integration/start_generate_blocks.js | 10 +- test/integration/tests.js | 18 +- test/integration/tools/TestUser.ts | 403 ++++++++++++++++++ test/integration/tools/node.js | 1 - test/integration/tools/toolbox.ts | 18 +- test/integration/tools/user.js | 394 ----------------- test/integration/transactions-chaining.js | 6 +- test/integration/transactions-pruning.js | 6 +- test/integration/transactions-test.js | 10 +- test/integration/v1.1-dividend.js | 8 +- test/integration/wotb.js | 20 +- 53 files changed, 636 insertions(+), 612 deletions(-) create mode 100644 test/integration/tools/TestUser.ts delete mode 100644 test/integration/tools/user.js diff --git a/.gitignore b/.gitignore index 8d7e9c28..58f619a8 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,8 @@ test/integration/membership_chainability.js* test/integration/membership_chainability.d.ts test/integration/tools/toolbox.js* test/integration/tools/toolbox.d.ts +test/integration/tools/TestUser.js* +test/integration/tools/TestUser.d.ts test/integration/documents-currency.js* test/integration/documents-currency.d.ts test/fast/modules/crawler/block_pulling.js* diff --git a/app/lib/common-libs/buid.ts b/app/lib/common-libs/buid.ts index a0cc71b9..3e2be9cb 100644 --- a/app/lib/common-libs/buid.ts +++ b/app/lib/common-libs/buid.ts @@ -28,5 +28,9 @@ export const Buid = { }, buid: buidFunctions + }, + + getBlockstamp: (block:{ number:number, hash:string }) => { + return [block.number, block.hash].join('-') } }; diff --git a/app/lib/dto/IdentityDTO.ts b/app/lib/dto/IdentityDTO.ts index d185d0cc..5bf4a81c 100644 --- a/app/lib/dto/IdentityDTO.ts +++ b/app/lib/dto/IdentityDTO.ts @@ -1,6 +1,7 @@ import {RevocationDTO} from "./RevocationDTO" import {hashf} from "../common" import {DBIdentity, NewDBIdentity} from "../dal/sqliteDAL/IdentityDAL" + const DEFAULT_DOCUMENT_VERSION = 10 export interface HashableIdentity { @@ -50,6 +51,10 @@ export class IdentityDTO { return raw } + getRawUnSigned() { + return this.rawWithoutSig() + } + getRawSigned() { return this.rawWithoutSig() + this.sig + "\n" } diff --git a/app/lib/dto/RevocationDTO.ts b/app/lib/dto/RevocationDTO.ts index ae8801e8..f98d75b6 100644 --- a/app/lib/dto/RevocationDTO.ts +++ b/app/lib/dto/RevocationDTO.ts @@ -1,5 +1,6 @@ import {Cloneable} from "./Cloneable"; import {hashf} from "../common"; + const DEFAULT_DOCUMENT_VERSION = 10 export interface ShortRevocation { @@ -39,6 +40,10 @@ export class RevocationDTO implements ShortRevocation, Cloneable { return this.rawWithoutSig() + this.revocation + "\n" } + getRawUnsigned() { + return this.rawWithoutSig() + } + // TODO: to remove when BMA has been merged in duniter/duniter repo json() { return { diff --git a/test/fast/modules/bma/ddos-test.js b/test/fast/modules/bma/ddos-test.js index c4127c62..5bb0d64f 100644 --- a/test/fast/modules/bma/ddos-test.js +++ b/test/fast/modules/bma/ddos-test.js @@ -3,7 +3,7 @@ // const co = require('co'); // const limiter = require('../../app/lib/system/limiter'); // const toolbox = require('../integration/tools/toolbox'); -// const user = require('../integration/tools/user'); +// const TestUser = require('../integration/tools/TestUser').TestUser // const bma = require('../lib/bma'); // // limiter.noLimit(); diff --git a/test/fast/modules/bma/limiter-test.js b/test/fast/modules/bma/limiter-test.js index 0ba0c025..2ec5db9f 100644 --- a/test/fast/modules/bma/limiter-test.js +++ b/test/fast/modules/bma/limiter-test.js @@ -3,7 +3,7 @@ // const co = require('co'); // const limiter = require('../lib/limiter'); // const toolbox = require('../integration/tools/toolbox'); -// const user = require('../integration/tools/user'); +// const TestUser = require('../integration/tools/TestUser').TestUser // const bma = require('duniter-bma').duniter.methods.bma; // // limiter.noLimit(); @@ -15,7 +15,7 @@ // } // }); // -// const cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); +// const cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); // // let theLimiter; // diff --git a/test/integration/branches2.ts b/test/integration/branches2.ts index 0d4eb63a..6626d061 100644 --- a/test/integration/branches2.ts +++ b/test/integration/branches2.ts @@ -3,12 +3,12 @@ import {NewLogger} from "../../app/lib/logger" import {BmaDependency} from "../../app/modules/bma/index" import {CrawlerDependency} from "../../app/modules/crawler/index" import {waitForkResolution, waitToHaveBlock} from "./tools/toolbox" +import {TestUser} from "./tools/TestUser"; const co = require('co'); const _ = require('underscore'); const duniter = require('../../index'); const bma = BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -69,8 +69,8 @@ describe("SelfFork", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); const commitS1 = commit(s1); const commitS2 = commit(s2, { diff --git a/test/integration/branches_pending_data.js b/test/integration/branches_pending_data.js index e4d4184d..ef60584d 100644 --- a/test/integration/branches_pending_data.js +++ b/test/integration/branches_pending_data.js @@ -4,7 +4,7 @@ const co = require('co'); const _ = require('underscore'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -39,10 +39,10 @@ describe("Pending data", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - tuc = user('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + tuc = new TestUser('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s1 }); const commitS1 = commit(s1); diff --git a/test/integration/branches_revert.js b/test/integration/branches_revert.js index d92ff38d..b2332574 100644 --- a/test/integration/branches_revert.js +++ b/test/integration/branches_revert.js @@ -3,7 +3,7 @@ const co = require('co'); const _ = require('underscore'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const toolbox = require('./tools/toolbox'); const commit = require('./tools/commit'); @@ -32,8 +32,8 @@ describe("Revert root", function() { sigQty: 1, dt: 1, ud0: 120 }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); yield s1.initDalBmaConnections(); yield cat.createIdentity(); diff --git a/test/integration/branches_revert2.js b/test/integration/branches_revert2.js index 9800c3ad..bf78020a 100644 --- a/test/integration/branches_revert2.js +++ b/test/integration/branches_revert2.js @@ -4,7 +4,7 @@ const co = require('co'); const _ = require('underscore'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -49,8 +49,8 @@ describe("Revert two blocks", function() { sigQty: 1, dt: 1, ud0: 120 }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); return co(function *() { yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); diff --git a/test/integration/branches_revert_memberships.js b/test/integration/branches_revert_memberships.js index f1a6df5e..b1b115f2 100644 --- a/test/integration/branches_revert_memberships.js +++ b/test/integration/branches_revert_memberships.js @@ -3,7 +3,7 @@ const co = require('co'); const should = require('should'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); @@ -24,9 +24,9 @@ describe("Revert memberships", function() { } }); - i1 = user('i1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - i2 = user('i2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - i3 = user('i3', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + i1 = new TestUser('i1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + i2 = new TestUser('i2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + i3 = new TestUser('i3', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); yield s1.initDalBmaConnections(); diff --git a/test/integration/branches_switch.js b/test/integration/branches_switch.js index 44839640..353ef811 100644 --- a/test/integration/branches_switch.js +++ b/test/integration/branches_switch.js @@ -6,7 +6,7 @@ const co = require('co'); const _ = require('underscore'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser; const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -43,8 +43,8 @@ describe("Switch", function () { sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' }, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' }, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' }, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' }, { server: s1 }); yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); yield s2.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); s1.addEndpointsDefinitions(() => index_2.BmaDependency.duniter.methods.getMainEndpoint(s1.conf)); diff --git a/test/integration/branches_switch.ts b/test/integration/branches_switch.ts index 862257dc..2eb7fae6 100644 --- a/test/integration/branches_switch.ts +++ b/test/integration/branches_switch.ts @@ -6,7 +6,7 @@ const co = require('co'); const _ = require('underscore'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -57,8 +57,8 @@ describe("Switch", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); yield s1.initWithDAL().then(bma).then((bmapi:any) => bmapi.openConnections()); yield s2.initWithDAL().then(bma).then((bmapi:any) => bmapi.openConnections()); diff --git a/test/integration/certification_chainability.js b/test/integration/certification_chainability.js index f33feec8..3eaf70f9 100644 --- a/test/integration/certification_chainability.js +++ b/test/integration/certification_chainability.js @@ -5,7 +5,7 @@ const co = require('co'); const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const constants = require('../../app/lib/constants'); const rp = require('request-promise'); const httpTest = require('./tools/http'); @@ -41,10 +41,10 @@ describe("Certification chainability", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); const now = 1482220000; diff --git a/test/integration/certifier-is-member.js b/test/integration/certifier-is-member.js index 25287c7b..ffc5ec01 100644 --- a/test/integration/certifier-is-member.js +++ b/test/integration/certifier-is-member.js @@ -6,7 +6,7 @@ const assert = require('assert'); const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const constants = require('../../app/lib/constants'); const toolbox = require('./tools/toolbox'); @@ -29,9 +29,9 @@ describe("Certifier must be a member", function() { medianTimeBlocks: 1 }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); yield s1.initDalBmaConnections(); yield cat.createIdentity(); diff --git a/test/integration/collapse.js b/test/integration/collapse.js index 234e6d93..f343b513 100644 --- a/test/integration/collapse.js +++ b/test/integration/collapse.js @@ -4,7 +4,7 @@ const co = require('co'); const _ = require('underscore'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const httpTest = require('./tools/http'); const shutDownEngine = require('./tools/shutDownEngine'); @@ -40,8 +40,8 @@ describe("Community collapse", function() { sigQty: 1, dt: 100, ud0: 120, sigValidity: 1 }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); return co(function *() { yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); diff --git a/test/integration/continuous-proof.js b/test/integration/continuous-proof.js index 39b4de12..289d5b69 100644 --- a/test/integration/continuous-proof.js +++ b/test/integration/continuous-proof.js @@ -3,7 +3,7 @@ const co = require('co'); const es = require('event-stream'); const should = require('should'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const toolbox = require('./tools/toolbox'); const constants = require('../../app/lib/constants'); @@ -26,8 +26,8 @@ describe("Continous proof-of-work", function() { } }) - i1 = user('i1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - i2 = user('i2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + i1 = new TestUser('i1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + i2 = new TestUser('i2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); yield s1.prepareForNetwork(); yield i1.createIdentity(); diff --git a/test/integration/crosschain-test.js b/test/integration/crosschain-test.js index a0e8f32a..2d232eb0 100644 --- a/test/integration/crosschain-test.js +++ b/test/integration/crosschain-test.js @@ -8,7 +8,7 @@ const rp = require('request-promise'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const unit = require('./tools/unit'); const httpTest = require('./tools/http'); @@ -57,11 +57,11 @@ describe("Crosschain transactions", function() { }, commonConf)); // toc is on 2 currencies - tocB = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sB }); - tocM = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sM }); + tocB = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sB }); + tocM = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sM }); // tic is on 2 currencies - ticB = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sB }); - ticM = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sM }); + ticB = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sB }); + ticM = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sM }); yield sB.initDalBmaConnections(); yield sM.initDalBmaConnections(); @@ -243,11 +243,11 @@ describe("Crosschain transactions", function() { }, commonConf)); // toc is on 2 currencies - tocB = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sB }); - tocM = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sM }); + tocB = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sB }); + tocM = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: sM }); // tic is on 2 currencies - ticB = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sB }); - ticM = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sM }); + ticB = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sB }); + ticM = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: sM }); yield sB.initDalBmaConnections(); yield sM.initDalBmaConnections() diff --git a/test/integration/documents-currency.ts b/test/integration/documents-currency.ts index 2bffa0b1..c066ab2a 100644 --- a/test/integration/documents-currency.ts +++ b/test/integration/documents-currency.ts @@ -1,8 +1,8 @@ -import { NewTestingServer } from './tools/toolbox'; +import {NewTestingServer} from './tools/toolbox'; const co = require('co'); const should = require('should'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser let s1:any, s2:any, cat1:any, tac1:any, toc2:any, tic2:any; @@ -30,10 +30,10 @@ describe("Document pool currency", function() { } }); - cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - toc2 = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s2 }); - tic2 = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); + cat1 = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac1 = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + toc2 = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s2 }); + tic2 = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); yield s1.prepareForNetwork(); yield s2.prepareForNetwork(); diff --git a/test/integration/forwarding.js b/test/integration/forwarding.js index ba392a69..993247af 100644 --- a/test/integration/forwarding.js +++ b/test/integration/forwarding.js @@ -5,7 +5,7 @@ const async = require('async'); const _ = require('underscore'); const co = require('co'); const node = require('./tools/node'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const jspckg = require('../../package'); const constants = require('../../app/lib/constants'); @@ -24,10 +24,10 @@ describe("Forwarding", function() { const node1 = node('db_1', _({ upnp: false, httplogs: false, port: 9600, remoteport: 9600, pair: { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'} }).extend(common)); const node2 = node('db_2', _({ upnp: false, httplogs: false, port: 9601, remoteport: 9601, pair: { pub: 'G2CBgZBPLe6FSFUgpx2Jf1Aqsgta6iib3vmDRA1yLiqU', sec: '58LDg8QLmF5pv6Dn9h7X4yFKfMTdP8fdAiWVcyDoTRJu454fwRihCLULH4MW37zncsg4ruoTGJPZneWk22QmG1w4'} }).extend(common)); - const cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, node1); - const tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, node1); - const tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, node1); - const toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, node1); + const cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, node1); + const tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, node1); + const tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, node1); + const toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, node1); before(() => co(function*(){ yield [node1, node2].map((theNode) => theNode.startTesting()); diff --git a/test/integration/http_api.js b/test/integration/http_api.js index 43e8733a..088909ec 100644 --- a/test/integration/http_api.js +++ b/test/integration/http_api.js @@ -7,7 +7,7 @@ const assert = require('assert'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; const PeerDTO = require('../../app/lib/dto/PeerDTO').PeerDTO -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const http = require('./tools/http'); const shutDownEngine = require('./tools/shutDownEngine'); const rp = require('request-promise'); @@ -64,8 +64,8 @@ describe("HTTP API", function() { } }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: server }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: server }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: server }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: server }); commit = makeBlockAndPost(server); diff --git a/test/integration/identity-absorption.js b/test/integration/identity-absorption.js index 2c0574f1..2f85059b 100644 --- a/test/integration/identity-absorption.js +++ b/test/integration/identity-absorption.js @@ -4,7 +4,7 @@ const _ = require('underscore'); const co = require('co'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const toolbox = require('./tools/toolbox'); @@ -51,8 +51,8 @@ describe("Identity absorption", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); return co(function *() { yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); diff --git a/test/integration/identity-clean-test.js b/test/integration/identity-clean-test.js index df0606b4..99e5c468 100644 --- a/test/integration/identity-clean-test.js +++ b/test/integration/identity-clean-test.js @@ -4,7 +4,7 @@ const _ = require('underscore'); const co = require('co'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -40,10 +40,10 @@ describe("Identities cleaned", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - toc = user('cat', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + toc = new TestUser('cat', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); const commitS1 = commit(s1); diff --git a/test/integration/identity-expiry.js b/test/integration/identity-expiry.js index c6a80f1a..58ba310c 100644 --- a/test/integration/identity-expiry.js +++ b/test/integration/identity-expiry.js @@ -6,7 +6,7 @@ const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; const prover = require('../../app/modules/prover').ProverDependency.duniter.methods; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const constants = require('../../app/lib/constants'); const rp = require('request-promise'); const httpTest = require('./tools/http'); @@ -50,10 +50,10 @@ describe("Identities expiry", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); prover.hookServer(s1) diff --git a/test/integration/identity-implicit-revocation.js b/test/integration/identity-implicit-revocation.js index 255778f2..ee1475f9 100644 --- a/test/integration/identity-implicit-revocation.js +++ b/test/integration/identity-implicit-revocation.js @@ -6,7 +6,7 @@ const assert = require('assert'); const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const constants = require('../../app/lib/constants'); const toolbox = require('./tools/toolbox'); @@ -29,9 +29,9 @@ describe("Implicit revocation", function() { medianTimeBlocks: 1 }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); yield s1.initDalBmaConnections(); yield cat.createIdentity(); diff --git a/test/integration/identity-kicking-by-certs.js b/test/integration/identity-kicking-by-certs.js index 199bf75e..2d524113 100644 --- a/test/integration/identity-kicking-by-certs.js +++ b/test/integration/identity-kicking-by-certs.js @@ -2,7 +2,7 @@ const co = require('co'); const assert = require('assert'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const toolbox = require('./tools/toolbox'); const now = 1480000000; @@ -25,11 +25,11 @@ describe("Identities kicking by certs", function() { sigQty: 2 }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tuc = user('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tuc = new TestUser('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s1 }); yield s1.initDalBmaConnections(); yield cat.createIdentity(); diff --git a/test/integration/identity-kicking.js b/test/integration/identity-kicking.js index b6e91d65..ac90bc8f 100644 --- a/test/integration/identity-kicking.js +++ b/test/integration/identity-kicking.js @@ -5,7 +5,7 @@ const co = require('co'); const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const constants = require('../../app/lib/constants'); const rp = require('request-promise'); const httpTest = require('./tools/http'); @@ -47,9 +47,9 @@ describe("Identities kicking", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); const now = 1400000000 yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); diff --git a/test/integration/identity-pulling.js b/test/integration/identity-pulling.js index 6cfffb2f..427d792e 100644 --- a/test/integration/identity-pulling.js +++ b/test/integration/identity-pulling.js @@ -3,7 +3,7 @@ const _ = require('underscore'); const co = require('co'); const assert = require('assert'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); @@ -26,11 +26,11 @@ describe("Identity pulling", function() { } }); - cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - toc2 = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s2 }); - tic2 = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); - tuc2 = user('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s2 }); + cat1 = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac1 = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + toc2 = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s2 }); + tic2 = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); + tuc2 = new TestUser('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s2 }); yield s1.prepareForNetwork(); yield s2.prepareForNetwork(); diff --git a/test/integration/identity-same-pubkey.js b/test/integration/identity-same-pubkey.js index 65480a3d..d42dc006 100644 --- a/test/integration/identity-same-pubkey.js +++ b/test/integration/identity-same-pubkey.js @@ -3,7 +3,7 @@ const co = require('co'); const should = require('should'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); @@ -20,9 +20,9 @@ describe("Identities with shared pubkey", function() { } }); - cat1 = user('cat1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - cat2 = user('cat2', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - catb = user('cat1', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + cat1 = new TestUser('cat1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + cat2 = new TestUser('cat2', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + catb = new TestUser('cat1', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); yield s1.initDalBmaConnections(); diff --git a/test/integration/identity-test.js b/test/integration/identity-test.js index 59612a36..de996d07 100644 --- a/test/integration/identity-test.js +++ b/test/integration/identity-test.js @@ -5,7 +5,7 @@ const co = require('co'); const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const constants = require('../../app/lib/constants'); const rp = require('request-promise'); const httpTest = require('./tools/http'); @@ -44,14 +44,14 @@ describe("Identities collision", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - tic2 = user('tic', { pub: '4KEA63RCFF7AXUePPg5Q7JX9RtzXjywai1iKmE7LcoEC', sec: '48vHGE2xkhnC81ChSu7dHaNv8JqnYubyyHRbkmkeAPKNg8Tv2BE7kVi3voh2ZhfVpQhEJLzceufzqpJ2dqnyXNSp'}, { server: s1 }); - man1 = user('man1', { pub: '12AbjvYY5hxV4v2KrN9pnGzgFxogwrzgYyncYHHsyFDK', sec: '2h8UNKE4YRnjmTGQTrgf4DZp2h3F5LqjnecxP8AgU6aH1x4dvbNVirsNeBiSR2UQfExuLAbdXiyM465hb5qUxYC1'}, { server: s1 }); - man2 = user('man2', { pub: 'E44RxG9jKZQsaPLFSw2ZTJgW7AVRqo1NGy6KGLbKgtNm', sec: 'pJRwpaCWshKZNWsbDxAHFQbVjk6X8gz9eBy9jaLnVY9gUZRqotrZLZPZe68ag4vEX1Y8mX77NhPXV2hj9F1UkX3'}, { server: s1 }); - man3 = user('man3', { pub: '5bfpAfZJ4xYspUBYseASJrofhRm6e6JMombt43HBaRzW', sec: '2VFQtEcYZRwjoc8Lxwfzcejtw9VP8VAi47WjwDDjCJCXu7g1tXUAbVZN3QmvG6NJqaSuLCuYP7WDHWkFmTrUEMaE'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + tic2 = new TestUser('tic', { pub: '4KEA63RCFF7AXUePPg5Q7JX9RtzXjywai1iKmE7LcoEC', sec: '48vHGE2xkhnC81ChSu7dHaNv8JqnYubyyHRbkmkeAPKNg8Tv2BE7kVi3voh2ZhfVpQhEJLzceufzqpJ2dqnyXNSp'}, { server: s1 }); + man1 = new TestUser('man1', { pub: '12AbjvYY5hxV4v2KrN9pnGzgFxogwrzgYyncYHHsyFDK', sec: '2h8UNKE4YRnjmTGQTrgf4DZp2h3F5LqjnecxP8AgU6aH1x4dvbNVirsNeBiSR2UQfExuLAbdXiyM465hb5qUxYC1'}, { server: s1 }); + man2 = new TestUser('man2', { pub: 'E44RxG9jKZQsaPLFSw2ZTJgW7AVRqo1NGy6KGLbKgtNm', sec: 'pJRwpaCWshKZNWsbDxAHFQbVjk6X8gz9eBy9jaLnVY9gUZRqotrZLZPZe68ag4vEX1Y8mX77NhPXV2hj9F1UkX3'}, { server: s1 }); + man3 = new TestUser('man3', { pub: '5bfpAfZJ4xYspUBYseASJrofhRm6e6JMombt43HBaRzW', sec: '2VFQtEcYZRwjoc8Lxwfzcejtw9VP8VAi47WjwDDjCJCXu7g1tXUAbVZN3QmvG6NJqaSuLCuYP7WDHWkFmTrUEMaE'}, { server: s1 }); const commitS1 = commit(s1); diff --git a/test/integration/lookup.js b/test/integration/lookup.js index 44de12ff..381ebf67 100644 --- a/test/integration/lookup.js +++ b/test/integration/lookup.js @@ -4,7 +4,7 @@ const _ = require('underscore'); const co = require('co'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const shutDownEngine = require('./tools/shutDownEngine'); @@ -32,9 +32,9 @@ describe("Lookup identity grouping", () => { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tic1 = user('tic1', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - tic2 = user('tic2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tic1 = new TestUser('tic1', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + tic2 = new TestUser('tic2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); // Server initialization yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); diff --git a/test/integration/network-update.js b/test/integration/network-update.js index 7d533a09..44c7ce92 100644 --- a/test/integration/network-update.js +++ b/test/integration/network-update.js @@ -5,7 +5,7 @@ const _ = require('underscore'); const rp = require('request-promise'); const httpTest = require('./tools/http'); const node = require('./tools/node'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const sync = require('./tools/sync'); const until = require('./tools/until'); @@ -51,8 +51,8 @@ describe("Network updating", function() { s1 = toolbox.server(_.clone(catKeyPair)); s2 = toolbox.server(_.clone(tocKeyPair)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); const commitS1 = commit(s1); const commitS2 = commit(s2); diff --git a/test/integration/newcomers-shuffling.js b/test/integration/newcomers-shuffling.js index 6d9e0ffd..0de6bdc1 100644 --- a/test/integration/newcomers-shuffling.js +++ b/test/integration/newcomers-shuffling.js @@ -3,7 +3,7 @@ const _ = require('underscore'); const co = require('co'); const assert = require('assert'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); @@ -20,10 +20,10 @@ describe("Newcomers shuffling", function() { } }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); yield s1.prepareForNetwork(); diff --git a/test/integration/peer-outdated.js b/test/integration/peer-outdated.js index 31af4bc7..3f2cb0e1 100644 --- a/test/integration/peer-outdated.js +++ b/test/integration/peer-outdated.js @@ -5,7 +5,7 @@ const should = require('should'); const es = require('event-stream'); const _ = require('underscore'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const until = require('./tools/until'); const toolbox = require('./tools/toolbox'); @@ -34,8 +34,8 @@ describe("Peer document expiry", function() { } }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); const commitS1 = commit(s1); diff --git a/test/integration/peerings.js b/test/integration/peerings.js index da7f16c6..4b227f63 100644 --- a/test/integration/peerings.js +++ b/test/integration/peerings.js @@ -5,7 +5,7 @@ const _ = require('underscore'); const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const constants = require('../../app/lib/constants'); const rp = require('request-promise'); const httpTest = require('./tools/http'); @@ -74,9 +74,9 @@ describe("Network", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); const commitS1 = commit(s1); const commitS2 = commit(s2); diff --git a/test/integration/peers-same-pubkey.js b/test/integration/peers-same-pubkey.js index 6afed89f..41c4b9c1 100644 --- a/test/integration/peers-same-pubkey.js +++ b/test/integration/peers-same-pubkey.js @@ -3,7 +3,7 @@ const co = require('co'); const _ = require('underscore'); const should = require('should'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const sync = require('./tools/sync'); const until = require('./tools/until'); @@ -27,8 +27,8 @@ describe("Peer document", function() { s2 = toolbox.server(_.clone(catKeyPair)); s3 = toolbox.server(_.clone(catKeyPair)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); const commitS1 = commit(s1); const commitS2 = commit(s2); diff --git a/test/integration/register-fork-blocks.js b/test/integration/register-fork-blocks.js index cf1faf59..a19df022 100644 --- a/test/integration/register-fork-blocks.js +++ b/test/integration/register-fork-blocks.js @@ -3,7 +3,7 @@ const _ = require('underscore'); const co = require('co'); const assert = require('assert'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); const CommonConstants = require('../../app/lib/common-libs/constants').CommonConstants @@ -56,9 +56,9 @@ describe("Fork blocks", function() { } }); - cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - toc1 = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + cat1 = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac1 = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + toc1 = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); yield s1.prepareForNetwork(); yield s2.prepareForNetwork(); diff --git a/test/integration/revocation-test.js b/test/integration/revocation-test.js index 63300af0..a49dce45 100644 --- a/test/integration/revocation-test.js +++ b/test/integration/revocation-test.js @@ -5,7 +5,7 @@ const co = require('co'); const should = require('should'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -59,11 +59,11 @@ describe("Revocation", function() { } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tacOnS1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - tacOnS2 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s2 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tacOnS1 = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + tacOnS2 = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s2 }); const now = 1400000000 yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); diff --git a/test/integration/revoked_pubkey_replay.ts b/test/integration/revoked_pubkey_replay.ts index dbaddc9a..03f4bab6 100644 --- a/test/integration/revoked_pubkey_replay.ts +++ b/test/integration/revoked_pubkey_replay.ts @@ -1,7 +1,7 @@ import {simpleNodeWith2Users, TestingServer} from "./tools/toolbox" const _ = require('underscore') -const user = require('./tools/user') +const TestUser = require('./tools/TestUser').TestUser describe("Revoked pubkey replay", function() { @@ -15,7 +15,7 @@ describe("Revoked pubkey replay", function() { const res1 = await simpleNodeWith2Users(conf) s1 = res1.s1 cat = res1.cat - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }) + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }) await s1.commit({ time: now }) await s1.commit({ time: now }) // Create the tested identity « tic » diff --git a/test/integration/server-import-export.js b/test/integration/server-import-export.js index b4ab2c49..4c568540 100644 --- a/test/integration/server-import-export.js +++ b/test/integration/server-import-export.js @@ -5,7 +5,7 @@ const fs = require('fs'); const co = require('co'); const unzip = require('unzip'); const toolbox = require('../integration/tools/toolbox'); -const user = require('../integration/tools/user'); +const TestUser = require('../integration/tools/TestUser').TestUser const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; const serverConfig = { @@ -26,8 +26,8 @@ describe('Import/Export', () => { s1 = toolbox.server(_.extend({ homename: 'dev_unit_tests1' }, serverConfig)); - const cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - const tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + const cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + const tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); yield s1.initDalBmaConnections(); yield cat.createIdentity(); diff --git a/test/integration/server-sandbox.js b/test/integration/server-sandbox.js index b5052551..e3d438be 100644 --- a/test/integration/server-sandbox.js +++ b/test/integration/server-sandbox.js @@ -3,7 +3,7 @@ const co = require('co'); const should = require('should'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); const constants = require('../../app/lib/constants'); @@ -43,23 +43,23 @@ describe("Sandboxes", function() { } }); - i1 = user('i1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - i2 = user('i2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - i3 = user('i3', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - i4 = user('i4', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - i5 = user('i5', { pub: '91dWdiyf7KaC4GAiKrwU7nGuue1vvmHqjCXbPziJFYtE', sec: '4Zno2b8ZULwBLY3RU5JcZhUf2a5FfXLVUMaYwPEzzN6i4ow9vXPsiCq7u2pEhkgJywqWdj97Hje1fdqnnzHeFgQe'}, { server: s1 }); - i6 = user('i6', { pub: '3C95HniUZsUN55AJy7z4wkz1UwtebbNd63dVAZ6EaUNm', sec: '3iJMz8JKNeU692L7jvug8xVnKvzN9RDee2m6QkMKbWKrvoHhv6apS4LR9hP786PUyFYJWz8bReMrFK8PY3aGxB8m'}, { server: s1 }); - i7 = user('i7', { pub: '4e9QJhJqHfMzEHgt3GtbfCXjqHVaQuJZKrKt8CNKR3AF', sec: 'TqdT99RpPEUjiz8su5QY7AQwharxPeo4ELCmeaFcvBEd3fW7wY7s9i531LMnTrCYBsgkrES494V6KjkhGppyEcF' }, { server: s1 }); - i7onS2 = user('i7', { pub: '4e9QJhJqHfMzEHgt3GtbfCXjqHVaQuJZKrKt8CNKR3AF', sec: 'TqdT99RpPEUjiz8su5QY7AQwharxPeo4ELCmeaFcvBEd3fW7wY7s9i531LMnTrCYBsgkrES494V6KjkhGppyEcF' }, { server: s2 }); - i8 = user('i8', { pub: '6GiiWjJxr29Stc4Ph4J4EipZJCzaQW1j6QXKANTNzRV3', sec: 'Yju625FGz6FHErshRc7jZyJUJ83MG4Zh9TXUNML62rKLXz7VJmwofnhJzeRRensranFJGQMYBLNSAeycAAsp62m' }, { server: s1 }); - i9 = user('i9', { pub: '6v4HnmiGxNzKwEjnBqxicWAmdKo6Bk51GvfQByS5YmiB', sec: '2wXPPDYfM3a8jmpYiFihS9qzdqFZrLWryu4uwpNPRuw5TRW3JCdJPsMa64eAcpshLTnMXkrKL94argk3FGxzzBKh' }, { server: s1 }); - i10 = user('i10', { pub: '6kr9Xr86qmrrwGq3XEjUXRVpHqS63FL52tcutcYGcRiv', sec: '2jCzQx7XUWoxboH67mMMv2z8VcrQabtYWpxS39iF6hNQnSBwN1d9RVauVC52PTRz6mgMzTjrSMETPrrB5N3oC7qQ' }, { server: s1 }); - i11 = user('i11', { pub: '5VLVTp96iX3YAq7NXwZeM2N6RjCkmxaU4G6bwMg1ZNwf', sec: '3BJtyeH1Q8jPcKuzL35m4eVPGuFXpcfRiGSseVawToCWykz1qAic9V2wk31wzEqXjqCq7ZKW4MjtZrzKCGN5K7sT' }, { server: s1 }); - i12 = user('i12', { pub: 'D6zJSPxZqs1bpgGpzJu9MgkCH7UxkG7D5u4xnnSH62wz', sec: '375vhCZdmVx7MaYD4bMZCevRLtebSuNPucfGevyPiPtdqpRzYLLNfd1h25Q59h4bm54dakpZ1RJ45ZofAyBmX4Et' }, { server: s1 }); - i13 = user('i13', { pub: 'BQ1fhCsJGohYKKfCbt58zQ8RpiSy5M8vwzdXzm4rH7mZ', sec: '4bTX2rMeAv8x79xQdFWPgY8zQLbPZ4HE7MWKXoXHyCoYgeCFpiWLdfvXwTbt31UMGrkNp2CViEt68WkjAZAQkjjm' }, { server: s1 }); - i14 = user('i14', { pub: 'H9dtBFmJohAwMNXSbfoL6xfRtmrqMw8WZnjXMHr4vEHX', sec: '2ANWb1qjjYRtT2TPFv1rBWA4EVfY7pqE4WqFUuzEgWG4vzcuvyUxMtyeBSf93M4V3g4MeEkELaj6NjA72jxnb4yF' }, { server: s1 }); -// i15 = user('i15', { pub: '8cHWEmVrdT249w8vJdiBms9mbu6CguQgXx2gRVE8gfnT', sec: '5Fy9GXiLMyhvRLCpoFf35XXNj24WXX29wM6xeCQiy5Uk7ggNhRcZjjp8GcpjRyE94oNR2jRNK4eAGiYUFnvbEnGB' }, { server: s1 }); -// i16 = user('i16', { pub: 'vi8hUTxss825cFCQE4SzmqBaAwLS236NmtrTQZBAAhG', sec: '5dVvAdWKcndQSaR9pzjEriRhGkCjef74HzecqKnydBVHdxXDewpAu3mcSU72PRKcCkTYTJPpgWmwuCyZubDKmoy4' }, { server: s1 }); + i1 = new TestUser('i1', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + i2 = new TestUser('i2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + i3 = new TestUser('i3', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + i4 = new TestUser('i4', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + i5 = new TestUser('i5', { pub: '91dWdiyf7KaC4GAiKrwU7nGuue1vvmHqjCXbPziJFYtE', sec: '4Zno2b8ZULwBLY3RU5JcZhUf2a5FfXLVUMaYwPEzzN6i4ow9vXPsiCq7u2pEhkgJywqWdj97Hje1fdqnnzHeFgQe'}, { server: s1 }); + i6 = new TestUser('i6', { pub: '3C95HniUZsUN55AJy7z4wkz1UwtebbNd63dVAZ6EaUNm', sec: '3iJMz8JKNeU692L7jvug8xVnKvzN9RDee2m6QkMKbWKrvoHhv6apS4LR9hP786PUyFYJWz8bReMrFK8PY3aGxB8m'}, { server: s1 }); + i7 = new TestUser('i7', { pub: '4e9QJhJqHfMzEHgt3GtbfCXjqHVaQuJZKrKt8CNKR3AF', sec: 'TqdT99RpPEUjiz8su5QY7AQwharxPeo4ELCmeaFcvBEd3fW7wY7s9i531LMnTrCYBsgkrES494V6KjkhGppyEcF' }, { server: s1 }); + i7onS2 = new TestUser('i7', { pub: '4e9QJhJqHfMzEHgt3GtbfCXjqHVaQuJZKrKt8CNKR3AF', sec: 'TqdT99RpPEUjiz8su5QY7AQwharxPeo4ELCmeaFcvBEd3fW7wY7s9i531LMnTrCYBsgkrES494V6KjkhGppyEcF' }, { server: s2 }); + i8 = new TestUser('i8', { pub: '6GiiWjJxr29Stc4Ph4J4EipZJCzaQW1j6QXKANTNzRV3', sec: 'Yju625FGz6FHErshRc7jZyJUJ83MG4Zh9TXUNML62rKLXz7VJmwofnhJzeRRensranFJGQMYBLNSAeycAAsp62m' }, { server: s1 }); + i9 = new TestUser('i9', { pub: '6v4HnmiGxNzKwEjnBqxicWAmdKo6Bk51GvfQByS5YmiB', sec: '2wXPPDYfM3a8jmpYiFihS9qzdqFZrLWryu4uwpNPRuw5TRW3JCdJPsMa64eAcpshLTnMXkrKL94argk3FGxzzBKh' }, { server: s1 }); + i10 = new TestUser('i10', { pub: '6kr9Xr86qmrrwGq3XEjUXRVpHqS63FL52tcutcYGcRiv', sec: '2jCzQx7XUWoxboH67mMMv2z8VcrQabtYWpxS39iF6hNQnSBwN1d9RVauVC52PTRz6mgMzTjrSMETPrrB5N3oC7qQ' }, { server: s1 }); + i11 = new TestUser('i11', { pub: '5VLVTp96iX3YAq7NXwZeM2N6RjCkmxaU4G6bwMg1ZNwf', sec: '3BJtyeH1Q8jPcKuzL35m4eVPGuFXpcfRiGSseVawToCWykz1qAic9V2wk31wzEqXjqCq7ZKW4MjtZrzKCGN5K7sT' }, { server: s1 }); + i12 = new TestUser('i12', { pub: 'D6zJSPxZqs1bpgGpzJu9MgkCH7UxkG7D5u4xnnSH62wz', sec: '375vhCZdmVx7MaYD4bMZCevRLtebSuNPucfGevyPiPtdqpRzYLLNfd1h25Q59h4bm54dakpZ1RJ45ZofAyBmX4Et' }, { server: s1 }); + i13 = new TestUser('i13', { pub: 'BQ1fhCsJGohYKKfCbt58zQ8RpiSy5M8vwzdXzm4rH7mZ', sec: '4bTX2rMeAv8x79xQdFWPgY8zQLbPZ4HE7MWKXoXHyCoYgeCFpiWLdfvXwTbt31UMGrkNp2CViEt68WkjAZAQkjjm' }, { server: s1 }); + i14 = new TestUser('i14', { pub: 'H9dtBFmJohAwMNXSbfoL6xfRtmrqMw8WZnjXMHr4vEHX', sec: '2ANWb1qjjYRtT2TPFv1rBWA4EVfY7pqE4WqFUuzEgWG4vzcuvyUxMtyeBSf93M4V3g4MeEkELaj6NjA72jxnb4yF' }, { server: s1 }); +// i15 = new TestUser('i15', { pub: '8cHWEmVrdT249w8vJdiBms9mbu6CguQgXx2gRVE8gfnT', sec: '5Fy9GXiLMyhvRLCpoFf35XXNj24WXX29wM6xeCQiy5Uk7ggNhRcZjjp8GcpjRyE94oNR2jRNK4eAGiYUFnvbEnGB' }, { server: s1 }); +// i16 = new TestUser('i16', { pub: 'vi8hUTxss825cFCQE4SzmqBaAwLS236NmtrTQZBAAhG', sec: '5dVvAdWKcndQSaR9pzjEriRhGkCjef74HzecqKnydBVHdxXDewpAu3mcSU72PRKcCkTYTJPpgWmwuCyZubDKmoy4' }, { server: s1 }); yield s1.initDalBmaConnections(); yield s2.initDalBmaConnections(); diff --git a/test/integration/single-document-treatment.js b/test/integration/single-document-treatment.js index a525dd8b..9661f462 100644 --- a/test/integration/single-document-treatment.js +++ b/test/integration/single-document-treatment.js @@ -3,7 +3,7 @@ const _ = require('underscore'); const co = require('co'); const assert = require('assert'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); const CommonConstants = require('../../app/lib/common-libs/constants').CommonConstants @@ -35,8 +35,8 @@ describe("Single document treatment", function() { } }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); yield s1.prepareForNetwork(); yield s2.prepareForNetwork(); diff --git a/test/integration/start_generate_blocks.js b/test/integration/start_generate_blocks.js index c71bd8c8..3c79c483 100644 --- a/test/integration/start_generate_blocks.js +++ b/test/integration/start_generate_blocks.js @@ -4,7 +4,7 @@ const co = require('co'); const _ = require('underscore'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -65,10 +65,10 @@ describe("Generation", function() { const commitS1 = commit(s1); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - tuc = user('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + tuc = new TestUser('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', sec: '5ks7qQ8Fpkin7ycXpxQSxxjVhs8VTzpM3vEBMqM7NfC1ZiFJ93uQryDcoM93Mj77T6hDAABdeHZJDFnkDb35bgiU'}, { server: s1 }); let servers = [s1, s2]; for (const server of servers) { diff --git a/test/integration/tests.js b/test/integration/tests.js index 3848b6b9..8f910656 100644 --- a/test/integration/tests.js +++ b/test/integration/tests.js @@ -8,7 +8,7 @@ const bma = require('../../app/modules/bma').BmaDependency.duniter.methods const constants = require('../../app/lib/constants'); const node = require('./tools/node'); const duniter = require('../../index'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const jspckg = require('../../package'); const commit = require('./tools/commit'); const httpTest = require('./tools/http'); @@ -33,10 +33,10 @@ describe("Integration", function() { } }); - const cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, node1); - const tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, node1); - const tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, node1); - const toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, node1); + const cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, node1); + const tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, node1); + const tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, node1); + const toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, node1); before(function(done) { node1.startTesting() @@ -187,10 +187,10 @@ describe("Integration", function() { } }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: node3 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: node3 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: node3 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: node3 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: node3 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: node3 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: node3 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: node3 }); yield node3.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); const now = 1482220000; diff --git a/test/integration/tools/TestUser.ts b/test/integration/tools/TestUser.ts new file mode 100644 index 00000000..f58fd8d5 --- /dev/null +++ b/test/integration/tools/TestUser.ts @@ -0,0 +1,403 @@ +import {KeyGen} from "../../../app/lib/common-libs/crypto/keyring" +import {IdentityDTO} from "../../../app/lib/dto/IdentityDTO"; +import {TestingServer} from "./toolbox" +import {CommonConstants} from "../../../app/lib/common-libs/constants" +import {CertificationDTO} from "../../../app/lib/dto/CertificationDTO" +import {MembershipDTO} from "../../../app/lib/dto/MembershipDTO" +import {RevocationDTO} from "../../../app/lib/dto/RevocationDTO" +import {CrawlerDependency} from "../../../app/modules/crawler/index" +import {Buid} from "../../../app/lib/common-libs/buid" +import {parsers} from "../../../app/lib/common-libs/parsers/index" +import {TransactionDTO} from "../../../app/lib/dto/TransactionDTO" +import {PeerDTO} from "../../../app/lib/dto/PeerDTO" +import {Contacter} from "../../../app/modules/crawler/lib/contacter" + +const request = require('request') +const _ = require('underscore') + +export interface TestInput { + src:string + unlock:string +} + +export interface TestOutput { + qty:number + base:number + lock:string +} + +export class TestUser { + + public pub = "" + public sec = "" + private createdIdentity = "" + + constructor(public uid:string, private options:any, public node:any) { + // For sync code + if (this.options.pub && this.options.sec) { + this.pub = this.options.pub + this.sec = this.options.sec + } + } + + private init(done:()=>void) { + if (this.options.pub && this.options.sec) { + this.pub = this.options.pub + this.sec = this.options.sec + done() + } else { + throw 'Not keypair information given for testing user ' + this.uid + } + } + + public async createIdentity(useRoot?:boolean, fromServer?:any) { + if (!this.pub) { + this.init(() => {}) + } + const current = await this.node.server.BlockchainService.current(); + let buid = !useRoot && current ? Buid.format.buid(current.number, current.hash) : CommonConstants.SPECIAL_BLOCK + this.createdIdentity = IdentityDTO.fromJSONObject({ + buid: buid, + uid: this.uid, + issuer: this.pub, + currency: this.node.server.conf.currency + }).getRawUnSigned() + this.createdIdentity += KeyGen(this.pub, this.sec).signSync(this.createdIdentity) + '\n' + await this.submitIdentity(this.createdIdentity, fromServer); + } + + public submitIdentity(raw:string, fromServer:any) { + return this.doPost('/wot/add', { + "identity": raw + }, fromServer) + } + + public getIdentityRaw() { + return this.createdIdentity + } + + public async makeCert(user:TestUser, fromServer?:TestingServer, overrideProps?:any) { + const lookup = await this.lookup(user.pub, fromServer) + const current = await this.node.server.BlockchainService.current() + const idty = _.filter(lookup.results[0].uids, (uidEntry:{ uid: string }) => uidEntry.uid === user.uid)[0] + let buid = current ? Buid.format.buid(current.number, current.hash) : CommonConstants.SPECIAL_BLOCK + const cert = { + "version": CommonConstants.DOCUMENTS_VERSION, + "currency": this.node.server.conf.currency, + "issuer": this.pub, + "idty_issuer": user.pub, + "idty_uid": idty.uid, + "idty_buid": idty.meta.timestamp, + "idty_sig": idty.self, + "buid": buid, + "sig": "" + } + _.extend(cert, overrideProps || {}); + const rawCert = CertificationDTO.fromJSONObject(cert).getRawUnSigned() + cert.sig = KeyGen(this.pub, this.sec).signSync(rawCert) + return CertificationDTO.fromJSONObject(cert) + } + + public async cert(user:TestUser, fromServer?:TestingServer, toServer?:TestingServer) { + const cert = await this.makeCert(user, fromServer) + await this.doPost('/wot/certify', { + "cert": cert.getRawSigned() + }, toServer); + } + + public async join() { + return await this.sendMembership("IN") + } + + public async leave() { + return await this.sendMembership("OUT") + } + + public async makeRevocation(givenLookupIdty?:any, overrideProps?:any) { + const res = givenLookupIdty || (await this.lookup(this.pub)); + const matchingResult = _.filter(res.results[0].uids, (uidEntry: { uid:string }) => uidEntry.uid === this.uid)[0] + const idty = { + uid: matchingResult.uid, + buid: matchingResult.meta.timestamp, + sig: matchingResult.self + } + const revocation = { + "currency": this.node.server.conf.currency, + "issuer": this.pub, + "uid": idty.uid, + "sig": idty.sig, + "buid": idty.buid, + "revocation": '' + }; + _.extend(revocation, overrideProps || {}); + const rawRevocation = RevocationDTO.fromJSONObject(revocation).getRawUnsigned() + revocation.revocation = KeyGen(this.pub, this.sec).signSync(rawRevocation); + return RevocationDTO.fromJSONObject(revocation) + } + + public async revoke(givenLookupIdty?:any) { + const revocation = await this.makeRevocation(givenLookupIdty) + return this.post('/wot/revoke', { + "revocation": revocation.getRaw() + }) + } + + public async makeMembership(type:string, fromServer?:TestingServer, overrideProps?:any) { + const lookup = await this.lookup(this.pub, fromServer) + const current = await this.node.server.BlockchainService.current(); + const idty = lookup.results[0].uids[0]; + const block = Buid.format.buid(current); + const join = { + "version": CommonConstants.DOCUMENTS_VERSION, + "currency": this.node.server.conf.currency, + "issuer": this.pub, + "block": block, + "membership": type, + "userid": this.uid, + "certts": idty.meta.timestamp, + "signature": "" + }; + _.extend(join, overrideProps || {}); + const rawJoin = MembershipDTO.fromJSONObject(join).getRaw() + join.signature = KeyGen(this.pub, this.sec).signSync(rawJoin) + return MembershipDTO.fromJSONObject(join) + } + + public async sendMembership(type:string) { + const ms = await this.makeMembership(type); + await this.post('/blockchain/membership', { + "membership": ms.getRawSigned() + }) + } + + public send(amount:number, recipient:string, comment?:string) { + const that = this + return async function(done:(e?:any)=>void) { + try { + let raw = await that.prepareITX(amount, recipient, comment) + await that.sendTX(raw) + done() + } catch (e) { + done(e) + } + }; + }; + + public async sendMoney(amount:number, recipient:string, comment?:string) { + const raw = await this.prepareITX(amount, recipient, comment) + await this.sendTX(raw) + } + + public async sendTX(rawTX:string) { + let http = await this.getContacter() + return http.processTransaction(rawTX) + } + + public async prepareUTX(previousTX:string, unlocks:string[], outputs:TestOutput[], opts:any) { + let obj = parsers.parseTransaction.syncWrite(previousTX); + // Unlocks inputs with given "unlocks" strings + let outputsToConsume = obj.outputs; + if (opts.theseOutputsStart !== undefined) { + outputsToConsume = outputsToConsume.slice(opts.theseOutputsStart); + } + let inputs = outputsToConsume.map((out:string, index:number) => { + const output = TransactionDTO.outputStr2Obj(out); + return { + src: [output.amount, output.base, 'T', obj.hash, (opts.theseOutputsStart || 0) + index].join(':'), + unlock: unlocks[index] + } + }) + return this.signed(this.prepareTX(inputs, outputs, opts)) + } + + public async prepareMTX(previousTX:string, user2:TestUser, unlocks:string[], outputs:TestOutput[], opts:any) { + let obj = parsers.parseTransaction.syncWrite(previousTX); + // Unlocks inputs with given "unlocks" strings + let inputs = obj.outputs.map((out:string, index:number) => { + const output = TransactionDTO.outputStr2Obj(out); + return { + src: [output.amount, output.base, 'T', obj.hash, index].join(':'), + unlock: unlocks[index] + } + }) + opts = opts || {} + opts.issuers = [this.pub, user2.pub] + return this.signed(this.prepareTX(inputs, outputs, opts), user2) + } + + public async prepareITX(amount:number, recipient:TestUser|string, comment?:string) { + let sources = [] + if (!amount || !recipient) { + throw 'Amount and recipient are required' + } + let http = await this.getContacter() + let current = await http.getCurrent() + let version = current && Math.min(CommonConstants.LAST_VERSION_FOR_TX, current.version) + let json = await http.getSources(this.pub) + let i = 0 + let cumulated = 0 + let commonbase = 99999999 + while (i < json.sources.length) { + let src = json.sources[i]; + sources.push({ + 'type': src.type, + 'amount': src.amount, + 'base': src.base, + 'noffset': src.noffset, + 'identifier': src.identifier + }) + commonbase = Math.min(commonbase, src.base); + cumulated += src.amount * Math.pow(10, src.base); + i++; + } + if (cumulated < amount) { + throw 'You do not have enough coins! (' + cumulated + ' ' + this.node.server.conf.currency + ' left)'; + } + let sources2 = []; + let total = 0; + for (let j = 0; j < sources.length && total < amount; j++) { + let src = sources[j]; + total += src.amount * Math.pow(10, src.base); + sources2.push(src); + } + let inputSum = 0; + sources2.forEach((src) => inputSum += src.amount * Math.pow(10, src.base)); + let inputs = sources2.map((src) => { + return { + src: [src.amount, src.base].concat([src.type, src.identifier, src.noffset]).join(':'), + unlock: 'SIG(0)' + }; + }); + let outputs = [{ + qty: amount, + base: commonbase, + lock: 'SIG(' + (typeof recipient === 'string' ? recipient : recipient.pub) + ')' + }]; + if (inputSum - amount > 0) { + // Rest back to issuer + outputs.push({ + qty: inputSum - amount, + base: commonbase, + lock: "SIG(" + this.pub + ")" + }); + } + let raw = this.prepareTX(inputs, outputs, { + version: version, + blockstamp: current && [current.number, current.hash].join('-'), + comment: comment + }); + return this.signed(raw) + } + + private signed(raw:string, user2?:TestUser) { + let signatures = [KeyGen(this.pub, this.sec).signSync(raw)]; + if (user2) { + signatures.push(KeyGen(user2.pub, user2.sec).signSync(raw)); + } + return raw + signatures.join('\n') + '\n'; + } + + public makeTX(inputs:TestInput[], outputs:TestOutput[], theOptions:any) { + const raw = this.prepareTX(inputs, outputs, theOptions) + return this.signed(raw) + } + + public prepareTX(inputs:TestInput[], outputs:TestOutput[], theOptions:any) { + let opts = theOptions || {}; + let issuers = opts.issuers || [this.pub]; + let raw = ''; + raw += "Version: " + (opts.version || CommonConstants.TRANSACTION_VERSION) + '\n'; + raw += "Type: Transaction\n"; + raw += "Currency: " + (opts.currency || this.node.server.conf.currency) + '\n'; + raw += "Blockstamp: " + opts.blockstamp + '\n'; + raw += "Locktime: " + (opts.locktime || 0) + '\n'; + raw += "Issuers:\n"; + issuers.forEach((issuer:string) => raw += issuer + '\n'); + raw += "Inputs:\n"; + inputs.forEach(function (input) { + raw += input.src + '\n'; + }); + raw += "Unlocks:\n"; + inputs.forEach(function (input, index) { + if (input.unlock) { + raw += index + ":" + input.unlock + '\n'; + } + }); + raw += "Outputs:\n"; + outputs.forEach(function (output) { + raw += [output.qty, output.base, output.lock].join(':') + '\n'; + }); + raw += "Comment: " + (opts.comment || "") + "\n"; + return raw; + } + + public async makePeer(endpoints:string[], overrideProps:any) { + const peer = PeerDTO.fromJSONObject({ + currency: this.node.server.conf.currency, + pubkey: this.pub, + block: '2-00008DF633FC158F9DB4864ABED696C1AA0FE5D617A7B5F7AB8DE7CA2EFCD4CB', + endpoints: endpoints + }); + _.extend(peer, overrideProps || {}); + const rawPeer = PeerDTO.fromJSONObject(peer).getRawUnsigned() + peer.signature = KeyGen(this.pub, this.sec).signSync(rawPeer) + return PeerDTO.fromJSONObject(peer) + } + + private async post(uri:string, data:any, done?:(e?:any, res?:any, body?:string)=>void) { + return new Promise((resolve, reject) => { + var postReq = request.post({ + "uri": 'http://' + [this.node.server.conf.remoteipv4, this.node.server.conf.remoteport].join(':') + uri, + "timeout": 1000 * 100000 + }, function (err:any, res:any, body:string) { + err = err || (res.statusCode != 200 && body != 'Already up-to-date' && body) || null; + if (err) { + reject(err) + } else { + resolve(res) + } + done && done(err, res, body) + }); + postReq.form(data); + }) + } + + private async doPost(uri:string, data:any, toServer?:TestingServer) { + const ip = toServer ? toServer.conf.ipv4 : this.node.server.conf.remoteipv4; + const port = toServer ? toServer.conf.port : this.node.server.conf.remoteport; + return new Promise((resolve, reject) => { + var postReq = request.post({ + "uri": 'http://' + [ip, port].join(':') + uri, + "timeout": 1000 * 100000 + }, function (err:any, res:any, body:string) { + err = err || (res.statusCode != 200 && body != 'Already up-to-date' && body) || null; + err ? reject(err) : resolve(res); + }); + postReq.form(data); + }); + } + + private async getContacter(fromServer?:TestingServer) { + const that = this + return new Promise(function(resolve){ + let theNode = (fromServer && { server: fromServer }) || that.node + resolve(CrawlerDependency.duniter.methods.contacter(theNode.server.conf.ipv4, theNode.server.conf.port, { + timeout: 1000 * 100000 + })); + }); + } + + public async lookup(pubkey:string, fromServer?:TestingServer) { + const node2 = await this.getContacter(fromServer) + return node2.getLookup(pubkey); + } + + public async sendP(amount:number, userid:string, comment?:string) { + return new Promise((res, rej) => { + this.send(amount, userid, comment)((err) => { + if (err) return rej(err) + res() + }) + }) + } +} diff --git a/test/integration/tools/node.js b/test/integration/tools/node.js index cb65f6ff..2748b3da 100644 --- a/test/integration/tools/node.js +++ b/test/integration/tools/node.js @@ -8,7 +8,6 @@ var duniter = require('../../../index'); var multicaster = require('../../../app/lib/streams/multicaster'); var ConfDTO = require('../../../app/lib/dto/ConfDTO').ConfDTO var PeerDTO = require('../../../app/lib/dto/PeerDTO').PeerDTO -var user = require('./user'); var http = require('./http'); const bma = require('../../../app/modules/bma').BmaDependency.duniter.methods.bma; diff --git a/test/integration/tools/toolbox.ts b/test/integration/tools/toolbox.ts index 0bb986b7..45a7ceb7 100644 --- a/test/integration/tools/toolbox.ts +++ b/test/integration/tools/toolbox.ts @@ -22,6 +22,7 @@ import {WS2PMessageHandler} from "../../../app/modules/ws2p/lib/impl/WS2PMessage import {WS2PCluster} from "../../../app/modules/ws2p/lib/WS2PCluster" import {WS2PServer} from "../../../app/modules/ws2p/lib/WS2PServer" import {WS2PServerMessageHandler} from "../../../app/modules/ws2p/lib/interface/WS2PServerMessageHandler" +import {TestUser} from "./TestUser" const assert = require('assert'); const _ = require('underscore'); @@ -31,7 +32,6 @@ const WebSocketServer = require('ws').Server const httpTest = require('../tools/http'); const sync = require('../tools/sync'); const commit = require('../tools/commit'); -const user = require('../tools/user'); const until = require('../tools/until'); const bma = require('../../../app/modules/bma').BmaDependency.duniter.methods.bma; const logger = require('../../../app/lib/logger').NewLogger('toolbox'); @@ -72,7 +72,7 @@ export const assertThrows = async (promise:Promise, message:string|null = n } export const simpleUser = (uid:string, keyring:{ pub:string, sec:string }, server:TestingServer) => { - return user(uid, keyring, { server }); + return new TestUser(uid, keyring, { server }); } export const simpleNetworkOf2NodesAnd2Users = async (options:any) => { @@ -82,8 +82,8 @@ export const simpleNetworkOf2NodesAnd2Users = async (options:any) => { const s1 = NewTestingServer(_.extend({ pair: catKeyring }, options || {})); const s2 = NewTestingServer(_.extend({ pair: tacKeyring }, options || {})); - const cat = user('cat', catKeyring, { server: s1 }); - const tac = user('tac', tacKeyring, { server: s1 }); + const cat = new TestUser('cat', catKeyring, { server: s1 }); + const tac = new TestUser('tac', tacKeyring, { server: s1 }); await s1.initDalBmaConnections() await s2.initDalBmaConnections() @@ -113,8 +113,8 @@ export const simpleNodeWith2Users = async (options:any) => { const s1 = NewTestingServer(_.extend({ pair: catKeyring }, options || {})); - const cat = user('cat', catKeyring, { server: s1 }); - const tac = user('tac', tacKeyring, { server: s1 }); + const cat = new TestUser('cat', catKeyring, { server: s1 }); + const tac = new TestUser('tac', tacKeyring, { server: s1 }); await s1.initDalBmaConnections() @@ -135,8 +135,8 @@ export const simpleNodeWith2otherUsers = async (options:any) => { const s1 = NewTestingServer(_.extend({ pair: ticKeyring }, options || {})); - const tic = user('cat', ticKeyring, { server: s1 }); - const toc = user('tac', tocKeyring, { server: s1 }); + const tic = new TestUser('cat', ticKeyring, { server: s1 }); + const toc = new TestUser('tac', tocKeyring, { server: s1 }); await s1.initDalBmaConnections() @@ -152,7 +152,7 @@ export const simpleNodeWith2otherUsers = async (options:any) => { export const createUser = async (uid:string, pub:string, sec:string, defaultServer:Server) => { const keyring = { pub: pub, sec: sec }; - return user(uid, keyring, { server: defaultServer }); + return new TestUser(uid, keyring, { server: defaultServer }); } export const fakeSyncServer = async (readBlocksMethod:any, readParticularBlockMethod:any, onPeersRequested:any) => { diff --git a/test/integration/tools/user.js b/test/integration/tools/user.js deleted file mode 100644 index 1f910f88..00000000 --- a/test/integration/tools/user.js +++ /dev/null @@ -1,394 +0,0 @@ -"use strict"; -const co = require('co'); -const _ = require('underscore'); -const async = require('async'); -const request = require('request'); -const contacter = require('../../../app/modules/crawler').CrawlerDependency.duniter.methods.contacter; -const CommonConstants = require('../../../app/lib/common-libs/constants').CommonConstants -const ucp = require('../../../app/lib/common-libs/buid').Buid -const parsers = require('../../../app/lib/common-libs/parsers').parsers -const rawer = require('../../../app/lib/common-libs').rawer -const keyring = require('../../../app/lib/common-libs/crypto/keyring') -const constants = require('../../../app/lib/constants'); -const CertificationDTO = require('../../../app/lib/dto/CertificationDTO').CertificationDTO -const MembershipDTO = require('../../../app/lib/dto/MembershipDTO').MembershipDTO -const RevocationDTO = require('../../../app/lib/dto/RevocationDTO').RevocationDTO -const PeerDTO = require('../../../app/lib/dto/PeerDTO').PeerDTO -const TransactionDTO = require('../../../app/lib/dto/TransactionDTO').TransactionDTO - -module.exports = function (uid, url, node) { - return new User(uid, url, node); -}; - -function User (uid, options, node) { - - var that = this; - var pub, sec; - var createdIdentity = ""; - that.node = node; - that.uid = uid - - // For sync code - if (options.pub && options.sec) { - pub = that.pub = options.pub; - sec = that.sec = options.sec; - } - - function init(done) { - if (options.pub && options.sec) { - pub = that.pub = options.pub; - sec = that.sec = options.sec; - done(); - } else { - throw 'Not keypair information given for testing user ' + uid; - } - } - - this.createIdentity = (useRoot, fromServer) => co(function*() { - if (!pub) { - init(() => {}) - } - const current = yield node.server.BlockchainService.current(); - let buid = !useRoot && current ? ucp.format.buid(current.number, current.hash) : '0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855'; - createdIdentity = rawer.getOfficialIdentity({ - buid: buid, - uid: uid, - issuer: pub, - currency: node.server.conf.currency - }, false); - createdIdentity += keyring.KeyGen(pub, sec).signSync(createdIdentity) + '\n'; - yield that.submitIdentity(createdIdentity, fromServer); - }); - - this.submitIdentity = (raw, fromServer) => doPost('/wot/add', { - "identity": raw - }, fromServer); - - this.getIdentityRaw = () => createdIdentity; - - this.makeCert = (user, fromServer, overrideProps) => co(function*() { - const lookup = yield that.lookup(user.pub, fromServer); - const current = yield node.server.BlockchainService.current(); - const idty = _.filter(lookup.results[0].uids, (uidEntry) => uidEntry.uid === user.uid)[0] - let buid = current ? ucp.format.buid(current.number, current.hash) : ucp.format.buid(); - const cert = { - "version": constants.DOCUMENTS_VERSION, - "currency": node.server.conf.currency, - "issuer": pub, - "idty_issuer": user.pub, - "idty_uid": idty.uid, - "idty_buid": idty.meta.timestamp, - "idty_sig": idty.self, - "buid": buid - }; - _.extend(cert, overrideProps || {}); - const rawCert = rawer.getOfficialCertification(cert); - cert.sig = keyring.KeyGen(pub, sec).signSync(rawCert, sec); - return CertificationDTO.fromJSONObject(cert); - }); - - this.cert = (user, fromServer, toServer) => co(function*() { - const cert = yield that.makeCert(user, fromServer); - yield doPost('/wot/certify', { - "cert": cert.getRawSigned() - }, toServer); - }); - - this.join = () => co(function*() { - return yield that.sendMembership("IN"); - }); - - this.leave = () => co(function*() { - return yield that.sendMembership("OUT"); - }); - - this.makeRevocation = (givenLookupIdty, overrideProps) => co(function*() { - const res = givenLookupIdty || (yield that.lookup(pub)); - const matchingResult = _.filter(res.results[0].uids, (uidEntry) => uidEntry.uid === uid)[0] - const idty = { - uid: matchingResult.uid, - buid: matchingResult.meta.timestamp, - sig: matchingResult.self - } - const revocation = { - "currency": node.server.conf.currency, - "issuer": pub, - "uid": idty.uid, - "sig": idty.sig, - "buid": idty.buid, - "revocation": '' - }; - _.extend(revocation, overrideProps || {}); - const rawRevocation = rawer.getOfficialRevocation(revocation); - revocation.revocation = keyring.KeyGen(pub, sec).signSync(rawRevocation); - return RevocationDTO.fromJSONObject(revocation); - }); - - this.revoke = (givenLookupIdty) => co(function *() { - const revocation = yield that.makeRevocation(givenLookupIdty); - return post('/wot/revoke', { - "revocation": revocation.getRaw() - }) - }); - - this.makeMembership = (type, fromServer, overrideProps) => co(function*() { - const lookup = yield that.lookup(pub, fromServer); - const current = yield node.server.BlockchainService.current(); - const idty = lookup.results[0].uids[0]; - const block = ucp.format.buid(current); - const join = { - "version": constants.DOCUMENTS_VERSION, - "currency": node.server.conf.currency, - "issuer": pub, - "block": block, - "membership": type, - "userid": uid, - "certts": idty.meta.timestamp - }; - _.extend(join, overrideProps || {}); - const rawJoin = rawer.getMembershipWithoutSignature(join); - join.signature = keyring.KeyGen(pub, sec).signSync(rawJoin); - return MembershipDTO.fromJSONObject(join) - }); - - this.sendMembership = (type) => co(function*() { - const ms = yield that.makeMembership(type); - yield post('/blockchain/membership', { - "membership": ms.getRawSigned() - }); - }); - - this.send = function (amount, recipient, comment) { - return function(done) { - return co(function *() { - try { - let raw = yield that.prepareITX(amount, recipient, comment); - yield that.sendTX(raw); - done(); - } catch (e) { - done(e); - } - }); - }; - }; - - this.sendMoney = function (amount, recipient, comment) { - return co(function *() { - let raw = yield that.prepareITX(amount, recipient, comment); - yield that.sendTX(raw); - }) - }; - - this.sendTX = (rawTX) => co(function *() { - let http = yield getContacter(); - return http.processTransaction(rawTX); - }); - - this.prepareUTX = (previousTX, unlocks, outputs, opts) => co(function *() { - let obj = parsers.parseTransaction.syncWrite(previousTX); - // Unlocks inputs with given "unlocks" strings - let outputsToConsume = obj.outputs; - if (opts.theseOutputsStart !== undefined) { - outputsToConsume = outputsToConsume.slice(opts.theseOutputsStart); - } - let inputs = outputsToConsume.map((out, index) => { - const output = TransactionDTO.outputStr2Obj(out); - return { - src: [output.amount, output.base, 'T', obj.hash, (opts.theseOutputsStart || 0) + index].join(':'), - unlock: unlocks[index] - }; - }); - return signed(that.prepareTX(inputs, outputs, opts)); - }); - - this.prepareMTX = (previousTX, user2, unlocks, outputs, opts) => co(function *() { - let obj = parsers.parseTransaction.syncWrite(previousTX); - // Unlocks inputs with given "unlocks" strings - let inputs = obj.outputs.map((out, index) => { - const output = TransactionDTO.outputStr2Obj(out); - return { - src: [output.amount, output.base, 'T', obj.hash, index].join(':'), - unlock: unlocks[index] - }; - }); - opts = opts || {}; - opts.issuers = [pub, user2.pub]; - return signed(that.prepareTX(inputs, outputs, opts), user2); - }); - - this.prepareITX = (amount, recipient, comment) => co(function *() { - let sources = []; - if (!amount || !recipient) { - throw 'Amount and recipient are required'; - } - let http = yield getContacter(); - let current = yield http.getCurrent(); - let version = current && Math.min(CommonConstants.LAST_VERSION_FOR_TX, current.version); - let json = yield http.getSources(pub); - let i = 0; - let cumulated = 0; - let commonbase = null; - while (i < json.sources.length) { - let src = json.sources[i]; - sources.push({ - 'type': src.type, - 'amount': src.amount, - 'base': src.base, - 'noffset': src.noffset, - 'identifier': src.identifier - }); - if (commonbase == null) { - commonbase = src.base; - } - commonbase = Math.min(commonbase, src.base); - cumulated += src.amount * Math.pow(10, src.base); - i++; - } - if (cumulated < amount) { - throw 'You do not have enough coins! (' + cumulated + ' ' + node.server.conf.currency + ' left)'; - } - let sources2 = []; - let total = 0; - for (let j = 0; j < sources.length && total < amount; j++) { - let src = sources[j]; - total += src.amount * Math.pow(10, src.base); - sources2.push(src); - } - let inputSum = 0; - sources2.forEach((src) => inputSum += src.amount * Math.pow(10, src.base)); - let inputs = sources2.map((src) => { - return { - src: [src.amount, src.base].concat([src.type, src.identifier, src.noffset]).join(':'), - unlock: 'SIG(0)' - }; - }); - let outputs = [{ - qty: amount, - base: commonbase, - lock: 'SIG(' + (recipient.pub || recipient) + ')' - }]; - if (inputSum - amount > 0) { - // Rest back to issuer - outputs.push({ - qty: inputSum - amount, - base: commonbase, - lock: "SIG(" + pub + ")" - }); - } - let raw = that.prepareTX(inputs, outputs, { - version: version, - blockstamp: current && [current.number, current.hash].join('-'), - comment: comment - }); - return signed(raw); - }); - - function signed(raw, user2) { - let signatures = [keyring.KeyGen(pub, sec).signSync(raw)]; - if (user2) { - signatures.push(keyring.KeyGen(user2.pub, user2.sec).signSync(raw)); - } - return raw + signatures.join('\n') + '\n'; - } - - this.makeTX = (inputs, outputs, theOptions) => { - const raw = that.prepareTX(inputs, outputs, theOptions); - return signed(raw); - }; - - this.prepareTX = (inputs, outputs, theOptions) => { - let opts = theOptions || {}; - let issuers = opts.issuers || [pub]; - let raw = ''; - raw += "Version: " + (opts.version || constants.TRANSACTION_VERSION) + '\n'; - raw += "Type: Transaction\n"; - raw += "Currency: " + (opts.currency || node.server.conf.currency) + '\n'; - raw += "Blockstamp: " + opts.blockstamp + '\n'; - raw += "Locktime: " + (opts.locktime || 0) + '\n'; - raw += "Issuers:\n"; - issuers.forEach((issuer) => raw += issuer + '\n'); - raw += "Inputs:\n"; - inputs.forEach(function (input) { - raw += input.src + '\n'; - }); - raw += "Unlocks:\n"; - inputs.forEach(function (input, index) { - if (input.unlock) { - raw += index + ":" + input.unlock + '\n'; - } - }); - raw += "Outputs:\n"; - outputs.forEach(function (output) { - raw += [output.qty, output.base, output.lock].join(':') + '\n'; - }); - raw += "Comment: " + (opts.comment || "") + "\n"; - return raw; - }; - - this.makePeer = (endpoints, overrideProps) => co(function*() { - const peer = PeerDTO.fromJSONObject({ - currency: node.server.conf.currency, - pubkey: pub, - block: '2-00008DF633FC158F9DB4864ABED696C1AA0FE5D617A7B5F7AB8DE7CA2EFCD4CB', - endpoints: endpoints - }); - _.extend(peer, overrideProps || {}); - const rawPeer = rawer.getPeerWithoutSignature(peer); - peer.signature = keyring.KeyGen(pub, sec).signSync(rawPeer); - return PeerDTO.fromJSONObject(peer) - }); - - function post(uri, data, done) { - return new Promise((resolve, reject) => { - var postReq = request.post({ - "uri": 'http://' + [node.server.conf.remoteipv4, node.server.conf.remoteport].join(':') + uri, - "timeout": 1000 * 100000 - }, function (err, res, body) { - err = err || (res.statusCode != 200 && body != 'Already up-to-date' && body) || null; - if (err) { - reject(err) - } else { - resolve(res, body) - } - done && done(err, res, body); - }); - postReq.form(data); - }) - } - - function doPost(uri, data, fromServer) { - const ip = fromServer ? fromServer.conf.ipv4 : node.server.conf.remoteipv4; - const port = fromServer ? fromServer.conf.port : node.server.conf.remoteport; - return new Promise((resolve, reject) => { - var postReq = request.post({ - "uri": 'http://' + [ip, port].join(':') + uri, - "timeout": 1000 * 100000 - }, function (err, res, body) { - err = err || (res.statusCode != 200 && body != 'Already up-to-date' && body) || null; - err ? reject(err) : resolve(res); - }); - postReq.form(data); - }); - } - - function getContacter(fromServer) { - return new Promise(function(resolve){ - let theNode = (fromServer && { server: fromServer }) || node; - resolve(contacter(theNode.server.conf.ipv4, theNode.server.conf.port, { - timeout: 1000 * 100000 - })); - }); - } - - this.lookup = (pubkey, fromServer) => co(function*() { - const node2 = yield getContacter(fromServer); - return node2.getLookup(pubkey); - }); - - this.sendP = (amount, userid, comment) => new Promise((res, rej) => { - that.send(amount, userid, comment)((err, data) => { - if (err) return rej(err) - res(data) - }) - }) -} diff --git a/test/integration/transactions-chaining.js b/test/integration/transactions-chaining.js index 600641b7..66a02c1c 100644 --- a/test/integration/transactions-chaining.js +++ b/test/integration/transactions-chaining.js @@ -9,7 +9,7 @@ const bma = require('../../app/modules/bma').BmaDependency.duniter.methods const CommonConstants = require('../../app/lib/common-libs/constants').CommonConstants const toolbox = require('./tools/toolbox'); const node = require('./tools/node'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const unit = require('./tools/unit'); const http = require('./tools/http'); @@ -32,8 +32,8 @@ describe("Transaction chaining", function() { c: 0.1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); yield s1.initDalBmaConnections(); yield tic.createIdentity(); diff --git a/test/integration/transactions-pruning.js b/test/integration/transactions-pruning.js index 13d8c9b1..d5a6f5c3 100644 --- a/test/integration/transactions-pruning.js +++ b/test/integration/transactions-pruning.js @@ -2,7 +2,7 @@ const co = require('co'); const should = require('should'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); const constants = require('../../app/lib/constants'); @@ -23,8 +23,8 @@ describe("Transactions pruning", function() { } }); - cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + cat1 = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac1 = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); yield s1.prepareForNetwork(); diff --git a/test/integration/transactions-test.js b/test/integration/transactions-test.js index ee5cfa15..6b659eb9 100644 --- a/test/integration/transactions-test.js +++ b/test/integration/transactions-test.js @@ -8,7 +8,7 @@ const constants = require('../../app/lib/constants'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; const toolbox = require('./tools/toolbox'); const node = require('./tools/node'); -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const unit = require('./tools/unit'); const http = require('./tools/http'); @@ -35,8 +35,8 @@ describe("Testing transactions", function() { medianTimeBlocks: 1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); yield s1.initDalBmaConnections(); // Self certifications @@ -193,8 +193,8 @@ describe("Testing transactions", function() { (yield s1.get('/tx/sources/DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV')).should.have.property('sources').length(4); // As well as tic let tx3 = yield tic.prepareUTX(tx2, ['XHX(1872767826647264) SIG(0)'], [{ qty: 1200, base: 0, lock: 'SIG(' + toc.pub + ')' }], { comment: 'wrong', blockstamp: [current.number, current.hash].join('-') }); let tx4 = yield toc.prepareUTX(tx2, ['XHX(1872767826647264) SIG(0)'], [{ qty: 1200, base: 0, lock: 'SIG(' + toc.pub + ')' }], { comment: 'ok', blockstamp: [current.number, current.hash].join('-') }); - let tx5 = yield tic.prepareMTX(tx2, toc, ['XHX(1872767826647264) SIG(1) SIG(0) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789) XHX(123456789)'], [{ qty: 1200, base: 0, lock: 'SIG(' + toc.pub + ')' }], { comment: 'multi OK', blockstamp: [current.number, current.hash].join('-') }); - let tx6 = yield toc.prepareMTX(tx2, tic, ['XHX(1872767826647264) SIG(1) SIG(0)'], [{ qty: 1200, base: 0, lock: 'SIG(' + toc.pub + ')' }], { comment: 'multi WRONG', blockstamp: [current.number, current.hash].join('-') }); + let tx5 = yield tic.prepareMTX(tx2, toc, ['XHX(1872767826647264) SIG(1) SIG(0)'], [{ qty: 1200, base: 0, lock: 'SIG(' + toc.pub + ')' }], { comment: 'multi OK', blockstamp: [current.number, current.hash].join('-') }); + let tx6 = yield toc.prepareMTX(tx2, tic, ['XHX(1872767826647264) SIG(1) SIG(0) SIG(0) SIG(0)'], [{ qty: 1200, base: 0, lock: 'SIG(' + toc.pub + ')' }], { comment: 'multi WRONG', blockstamp: [current.number, current.hash].join('-') }); // nLocktime let tx7 = yield tic.prepareMTX(tx2, toc, ['XHX(1872767826647264) SIG(1) SIG(0)'], [{ qty: 1200, base: 0, lock: 'SIG(' + toc.pub + ')' }], { comment: 'wrong locktime', locktime: 100, blockstamp: [current.number, current.hash].join('-') }); yield unit.shouldFail(toc.sendTX(tx3), 'Wrong unlocker in transaction'); diff --git a/test/integration/v1.1-dividend.js b/test/integration/v1.1-dividend.js index cc8698c2..2ba9e404 100644 --- a/test/integration/v1.1-dividend.js +++ b/test/integration/v1.1-dividend.js @@ -3,7 +3,7 @@ const co = require('co'); const should = require('should'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const toolbox = require('./tools/toolbox'); @@ -30,9 +30,9 @@ describe("Protocol 1.1 Dividend", function() { medianTimeBlocks: 1 }); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + tac = new TestUser('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); yield s1.initDalBmaConnections(); diff --git a/test/integration/wotb.js b/test/integration/wotb.js index a9b82f44..d9a7db18 100644 --- a/test/integration/wotb.js +++ b/test/integration/wotb.js @@ -5,7 +5,7 @@ const should = require('should'); const _ = require('underscore'); const duniter = require('../../index'); const bma = require('../../app/modules/bma').BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); +const TestUser = require('./tools/TestUser').TestUser const commit = require('./tools/commit'); const shutDownEngine = require('./tools/shutDownEngine'); @@ -79,17 +79,17 @@ describe("WOTB module", function() { sigValidity: 1400, sigPeriod: 0 }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); - tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); + cat = new TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); + toc = new TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 }); + tic = new TestUser('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 }); - cat2 = user('cat2', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s2 }); - toc2 = user('toc2', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s2 }); - tic2 = user('tic2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); + cat2 = new TestUser('cat2', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s2 }); + toc2 = new TestUser('toc2', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s2 }); + tic2 = new TestUser('tic2', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); - cat3 = user('cat3', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s3 }); - toc3 = user('toc3', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s3 }); - tic3 = user('tic3', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s3 }); + cat3 = new TestUser('cat3', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s3 }); + toc3 = new TestUser('toc3', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s3 }); + tic3 = new TestUser('tic3', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s3 }); /** * cat <==> toc -- GitLab From 9eff3603a06f507e8fad241f21aecd26c2a2a269 Mon Sep 17 00:00:00 2001 From: librelois Date: Sun, 12 Nov 2017 20:19:02 +0100 Subject: [PATCH 29/72] ws2p server : add more log details --- app/modules/ws2p/lib/WS2PServer.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/app/modules/ws2p/lib/WS2PServer.ts b/app/modules/ws2p/lib/WS2PServer.ts index f104f972..7b08e983 100644 --- a/app/modules/ws2p/lib/WS2PServer.ts +++ b/app/modules/ws2p/lib/WS2PServer.ts @@ -121,6 +121,7 @@ export class WS2PServer extends events.EventEmitter { ws.on('close', () => { this.server.unpipe(singleWriteProtection) singleWriteProtection.unpipe(ws2pStreamer) + this.server.logger.info('WS2P: close incoming connection from %s %s:%s', c.pubkey.slice(0, 8), host, port) this.removeConnection(c) this.server.push({ ws2p: 'disconnected', -- GitLab From 3e2012829f099bb3f34879f3cbcd58102f3ee973 Mon Sep 17 00:00:00 2001 From: librelois Date: Sun, 12 Nov 2017 20:21:01 +0100 Subject: [PATCH 30/72] acceptKey : rm server dependence & forbidden oneself connection --- app/modules/ws2p/lib/WS2PCluster.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index e1c48c43..2dc22671 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -392,7 +392,7 @@ export class WS2PCluster { for (const api of apis) { try { // We do not connect to local host - if (api.uuid !== myUUID || api.uuid === '11111111') { + if (api.uuid !== myUUID) { await this.connectToRemoteWS(api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) } } catch (e) { @@ -404,9 +404,7 @@ export class WS2PCluster { if (api) { try { // We do not connect to local host - if (api.uuid !== myUUID || api.uuid === '11111111') { - await this.connectToRemoteWS(api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) - } + await this.connectToRemoteWS(api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) } catch (e) { this.server.logger.debug('WS2P: init: failed connection') } @@ -435,7 +433,7 @@ export class WS2PCluster { const connectedWS2PUID = this.getConnectedWS2PUID() const preferedKeys = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[] const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, connectedWS2PUID, () => this.clientsCount(), this.maxLevel1Size, preferedKeys, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEnpoint.uuid) - if (shouldAccept && (!this.server.conf.ws2p || ws2pEnpoint.uuid !== this.server.conf.ws2p.uuid || peer.pubkey !== this.server.conf.pair.pub || ws2pEnpoint.uuid === '11111111')) { + if (shouldAccept && (!this.server.conf.ws2p || ws2pEnpoint.uuid !== this.server.conf.ws2p.uuid || peer.pubkey !== this.server.conf.pair.pub)) { await this.connectToRemoteWS(ws2pEnpoint.host, ws2pEnpoint.port, ws2pEnpoint.path, this.messageHandler, peer.pubkey, ws2pEnpoint.uuid) await this.trimClientConnections(preferedKeys) } @@ -663,11 +661,6 @@ export class WS2PCluster { priorityKeysOnly:boolean, targetWS2PUID = "" ) { - // We need ws2pServer instance - if (!this.ws2pServer) { - return false - } - if (this.server.conf.pair.pub === pub) { // We do not accept oneself connetion if (this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID) { @@ -709,12 +702,12 @@ export class WS2PCluster { { let minPriorityLevel = WS2PConstants.CONNECTIONS_PRIORITY.MAX_PRIORITY_LEVEL for (const connectedPubkey of connectedPubkeys) { - let connectedPubkeyPriorityLevel = this.ws2pServer.keyPriorityLevel(connectedPubkey, priorityKeys) + let connectedPubkeyPriorityLevel = this.keyPriorityLevel(connectedPubkey, priorityKeys) if (connectedPubkeyPriorityLevel < minPriorityLevel) { minPriorityLevel = connectedPubkeyPriorityLevel } } - if (this.ws2pServer.keyPriorityLevel(pub, priorityKeys) > minPriorityLevel) { + if (this.keyPriorityLevel(pub, priorityKeys) > minPriorityLevel) { return true } } -- GitLab From d7fd4bd61d1406eca27fa8e0af4c0cc4fb7076e4 Mon Sep 17 00:00:00 2001 From: librelois Date: Sun, 12 Nov 2017 20:24:39 +0100 Subject: [PATCH 31/72] expend TestUser typage --- test/integration/tools/TestUser.ts | 2 +- test/integration/ws2p_cluster.ts | 3 ++- test/integration/ws2p_doc_sharing.ts | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/integration/tools/TestUser.ts b/test/integration/tools/TestUser.ts index f58fd8d5..8c6cf130 100644 --- a/test/integration/tools/TestUser.ts +++ b/test/integration/tools/TestUser.ts @@ -183,7 +183,7 @@ export class TestUser { }; }; - public async sendMoney(amount:number, recipient:string, comment?:string) { + public async sendMoney(amount:number, recipient:TestUser, comment?:string) { const raw = await this.prepareITX(amount, recipient, comment) await this.sendTX(raw) } diff --git a/test/integration/ws2p_cluster.ts b/test/integration/ws2p_cluster.ts index 08c976f7..29b65119 100644 --- a/test/integration/ws2p_cluster.ts +++ b/test/integration/ws2p_cluster.ts @@ -8,6 +8,7 @@ import { } from "./tools/toolbox" import {WS2PCluster} from "../../app/modules/ws2p/lib/WS2PCluster" import {WS2PConstants} from "../../app/modules/ws2p/lib/constants" +import { TestUser } from './tools/TestUser'; const assert = require('assert') @@ -18,7 +19,7 @@ describe("WS2P cluster", function() { const now = 1500000000 let s1:TestingServer, s2:TestingServer, s3:TestingServer - let cat:any, tac:any, toc:any + let cat:TestUser, tac:TestUser, toc:TestUser const catKeyring = { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'} const tacKeyring = { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'} const tocKeyring = { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'} diff --git a/test/integration/ws2p_doc_sharing.ts b/test/integration/ws2p_doc_sharing.ts index 9bf60433..be10fa17 100644 --- a/test/integration/ws2p_doc_sharing.ts +++ b/test/integration/ws2p_doc_sharing.ts @@ -1,3 +1,4 @@ +import { TestUser } from './tools/TestUser'; import {simpleTestingConf, simpleTestingServer, simpleUser, simpleWS2PNetwork, TestingServer} from "./tools/toolbox" import {WS2PConstants} from "../../app/modules/ws2p/lib/constants" @@ -10,7 +11,7 @@ describe("WS2P doc sharing", function() { const now = 1500000000 let s1:TestingServer, s2:TestingServer, wss:any - let cat:any, tac:any, toc:any + let cat:TestUser, tac:TestUser, toc:TestUser const catKeyring = { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'} const tacKeyring = { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'} const tocKeyring = { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'} -- GitLab From 92b2ec9435c66688c632ca477b88fe9e6a186665 Mon Sep 17 00:00:00 2001 From: librelois Date: Mon, 13 Nov 2017 00:43:31 +0100 Subject: [PATCH 32/72] [enh] add versioning in ws2p messages --- app/lib/dto/PeerDTO.ts | 2 +- app/modules/ws2p/lib/WS2PClient.ts | 6 ++- app/modules/ws2p/lib/WS2PCluster.ts | 10 ++-- app/modules/ws2p/lib/WS2PConnection.ts | 69 ++++++++++++++++++-------- app/modules/ws2p/lib/WS2PServer.ts | 4 +- app/modules/ws2p/lib/constants.ts | 1 + test/integration/branches2.js | 6 +-- test/integration/tools/toolbox.ts | 8 +-- test/integration/ws2p_connection.ts | 42 ++++++++-------- 9 files changed, 90 insertions(+), 58 deletions(-) diff --git a/app/lib/dto/PeerDTO.ts b/app/lib/dto/PeerDTO.ts index 0704fe14..3b9ca529 100644 --- a/app/lib/dto/PeerDTO.ts +++ b/app/lib/dto/PeerDTO.ts @@ -156,7 +156,7 @@ export class PeerDTO implements Cloneable { } getAllWS2PEndpoints(canReachTorEp:boolean, canReachClearEp:boolean, myUUID:string) { - let apis:{ uuid:string, host:string, port:number, path:string }[] = [] + let apis:{ version:number, uuid:string, host:string, port:number, path:string }[] = [] let uuidExcluded:string[] = [myUUID] let api = this.getOnceWS2PEndpoint(canReachTorEp, canReachClearEp, uuidExcluded) while (api !== null) { diff --git a/app/modules/ws2p/lib/WS2PClient.ts b/app/modules/ws2p/lib/WS2PClient.ts index 0bc7bc11..422b9af1 100644 --- a/app/modules/ws2p/lib/WS2PClient.ts +++ b/app/modules/ws2p/lib/WS2PClient.ts @@ -13,12 +13,14 @@ export class WS2PClient { private constructor(public connection:WS2PConnection) {} - static async connectTo(server:Server, fullEndpointAddress:string, expectedWS2PUID:string, messageHandler:WS2PMessageHandler, expectedPub:string, allowKey:(pub:string)=>Promise ) { + static async connectTo(server:Server, fullEndpointAddress:string, endpointVersion:number, expectedWS2PUID:string, messageHandler:WS2PMessageHandler, expectedPub:string, allowKey:(pub:string)=>Promise ) { const k2 = new Key(server.conf.pair.pub, server.conf.pair.sec) + const myWs2pId = (server.conf.ws2p && server.conf.ws2p.uuid) ? server.conf.ws2p.uuid:"" const c = WS2PConnection.newConnectionToAddress( + endpointVersion, fullEndpointAddress, messageHandler, - new WS2PPubkeyLocalAuth(server.conf.currency , k2, allowKey), + new WS2PPubkeyLocalAuth(server.conf.currency , k2, myWs2pId, allowKey), new WS2PPubkeyRemoteAuth(server.conf.currency, k2, allowKey), ProxiesConf.wsProxy(fullEndpointAddress, server.conf.proxiesConf), { diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 2dc22671..ddd1493a 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -297,13 +297,13 @@ export class WS2PCluster { return (this.ws2pServer) ? this.ws2pServer.countConnexions():0 } - async connectToRemoteWS(host: string, port: number, path:string, messageHandler:WS2PMessageHandler, expectedPub:string, ws2pEndpointUUID:string = ""): Promise { + async connectToRemoteWS(endpointVersion:number, host: string, port: number, path:string, messageHandler:WS2PMessageHandler, expectedPub:string, ws2pEndpointUUID:string = ""): Promise { const uuid = nuuid.v4() let pub = expectedPub.slice(0, 8) const api:string = (host.match(WS2PConstants.HOST_ONION_REGEX) !== null) ? 'WS2PTOR':'WS2P' try { const fullEndpointAddress = WS2PCluster.getFullAddress(host, port, path) - const ws2pc = await WS2PClient.connectTo(this.server, fullEndpointAddress, ws2pEndpointUUID, messageHandler, expectedPub, (pub:string) => { + const ws2pc = await WS2PClient.connectTo(this.server, fullEndpointAddress, endpointVersion, ws2pEndpointUUID, messageHandler, expectedPub, (pub:string) => { const connectedPubkeys = this.getConnectedPubkeys() const connectedWS2PUID = this.getConnectedWS2PUID() const preferedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[] @@ -393,7 +393,7 @@ export class WS2PCluster { try { // We do not connect to local host if (api.uuid !== myUUID) { - await this.connectToRemoteWS(api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) + await this.connectToRemoteWS(api.version, api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) } } catch (e) { this.server.logger.debug('WS2P: init: failed connection') @@ -404,7 +404,7 @@ export class WS2PCluster { if (api) { try { // We do not connect to local host - await this.connectToRemoteWS(api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) + await this.connectToRemoteWS(api.version, api.host, api.port, api.path, this.messageHandler, p.pubkey, api.uuid) } catch (e) { this.server.logger.debug('WS2P: init: failed connection') } @@ -434,7 +434,7 @@ export class WS2PCluster { const preferedKeys = (this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) ? this.server.conf.ws2p.preferedNodes:[] const shouldAccept = await this.acceptPubkey(peer.pubkey, connectedPubkeys, connectedWS2PUID, () => this.clientsCount(), this.maxLevel1Size, preferedKeys, (this.server.conf.ws2p && this.server.conf.ws2p.preferedOnly) || false, ws2pEnpoint.uuid) if (shouldAccept && (!this.server.conf.ws2p || ws2pEnpoint.uuid !== this.server.conf.ws2p.uuid || peer.pubkey !== this.server.conf.pair.pub)) { - await this.connectToRemoteWS(ws2pEnpoint.host, ws2pEnpoint.port, ws2pEnpoint.path, this.messageHandler, peer.pubkey, ws2pEnpoint.uuid) + await this.connectToRemoteWS(ws2pEnpoint.version, ws2pEnpoint.host, ws2pEnpoint.port, ws2pEnpoint.path, this.messageHandler, peer.pubkey, ws2pEnpoint.uuid) await this.trimClientConnections(preferedKeys) } } diff --git a/app/modules/ws2p/lib/WS2PConnection.ts b/app/modules/ws2p/lib/WS2PConnection.ts index eed3dfff..f9687734 100644 --- a/app/modules/ws2p/lib/WS2PConnection.ts +++ b/app/modules/ws2p/lib/WS2PConnection.ts @@ -49,7 +49,7 @@ export interface WS2PAuth { } export interface WS2PRemoteAuth extends WS2PAuth { - registerCONNECT(challenge:string, sig: string, pub: string): Promise + registerCONNECT(ws2pVersion:number, challenge:string, sig: string, pub: string, ws2pId:string): Promise sendACK(ws:any): Promise registerOK(sig: string): Promise isAuthenticatedByRemote(): boolean @@ -57,7 +57,7 @@ export interface WS2PRemoteAuth extends WS2PAuth { } export interface WS2PLocalAuth extends WS2PAuth { - sendCONNECT(ws:any): Promise + sendCONNECT(ws:any, ws2pVersion:number): Promise registerACK(sig: string, pub: string): Promise sendOK(ws:any): Promise isRemoteAuthenticated(): boolean @@ -71,6 +71,8 @@ export class WS2PPubkeyRemoteAuth implements WS2PRemoteAuth { protected challenge:string protected authenticatedByRemote = false protected remotePub = "" + protected remoteWs2pId = "" + protected remoteVersion = 1 protected serverAuth:Promise protected serverAuthResolve:()=>void protected serverAuthReject:(err:any)=>void @@ -102,17 +104,19 @@ export class WS2PPubkeyRemoteAuth implements WS2PRemoteAuth { })) } - async registerCONNECT(challenge:string, sig: string, pub: string): Promise { + async registerCONNECT(ws2pVersion:number, challenge:string, sig: string, pub: string, ws2pId:string = ""): Promise { const allow = await this.tellIsAuthorizedPubkey(pub) if (!allow) { return false } - const challengeMessage = `WS2P:CONNECT:${this.currency}:${pub}:${challenge}` + const challengeMessage = (ws2pVersion > 1) ? `WS2P:CONNECT:${this.currency}:${pub}:${ws2pId}:${challenge}`:`WS2P:CONNECT:${this.currency}:${pub}:${challenge}` Logger.log('registerCONNECT >>> ' + challengeMessage) const verified = verify(challengeMessage, sig, pub) if (verified) { + this.remoteVersion = ws2pVersion this.challenge = challenge this.remotePub = pub + this.remoteWs2pId = ws2pId } return verified } @@ -152,6 +156,7 @@ export class WS2PPubkeyLocalAuth implements WS2PLocalAuth { constructor( protected currency:string, protected pair:Key, + protected ws2pId:string, protected tellIsAuthorizedPubkey:(pub: string) => Promise = () => Promise.resolve(true) ) { this.challenge = nuuid.v4() + nuuid.v4() @@ -161,17 +166,32 @@ export class WS2PPubkeyLocalAuth implements WS2PLocalAuth { }) } - async sendCONNECT(ws:any): Promise { - const challengeMessage = `WS2P:CONNECT:${this.currency}:${this.pair.pub}:${this.challenge}` - Logger.log('sendCONNECT >>> ' + challengeMessage) - const sig = this.pair.signSync(challengeMessage) - await ws.send(JSON.stringify({ - auth: 'CONNECT', - pub: this.pair.pub, - challenge: this.challenge, - sig - })) - return this.serverAuth + async sendCONNECT(ws:any, ws2pVersion:number): Promise { + if (ws2pVersion > 1) { + const challengeMessage = `WS2P:${ws2pVersion}:CONNECT:${this.currency}:${this.pair.pub}:${this.ws2pId}:${this.challenge}` + Logger.log('sendCONNECT >>> ' + challengeMessage) + const sig = this.pair.signSync(challengeMessage) + await ws.send(JSON.stringify({ + auth: 'CONNECT', + version: ws2pVersion, + pub: this.pair.pub, + ws2pid: this.ws2pId, + challenge: this.challenge, + sig + })) + return this.serverAuth + } else if (ws2pVersion == 1) { + const challengeMessage = `WS2P:CONNECT:${this.currency}:${this.pair.pub}:${this.challenge}` + Logger.log('sendCONNECT >>> ' + challengeMessage) + const sig = this.pair.signSync(challengeMessage) + await ws.send(JSON.stringify({ + auth: 'CONNECT', + pub: this.pair.pub, + challenge: this.challenge, + sig + })) + return this.serverAuth + } } async registerACK(sig: string, pub: string): Promise { @@ -243,6 +263,7 @@ export class WS2PConnection { } = {} constructor( + private ws2pVersion:number, private ws:any, private onWsOpened:Promise, private onWsClosed:Promise, @@ -266,6 +287,7 @@ export class WS2PConnection { } static newConnectionToAddress( + ws2pVersion:number, address:string, messageHandler:WS2PMessageHandler, localAuth:WS2PLocalAuth, @@ -294,7 +316,7 @@ export class WS2PConnection { websocket.on('close', () => res()) }) websocket.on('error', () => websocket.close()) - return new WS2PConnection(websocket, onWsOpened, onWsClosed, messageHandler, localAuth, remoteAuth, options, expectedPub, expectedWS2PUID) + return new WS2PConnection(ws2pVersion, websocket, onWsOpened, onWsClosed, messageHandler, localAuth, remoteAuth, options, expectedPub, expectedWS2PUID) } static newConnectionFromWebSocketServer( @@ -314,7 +336,7 @@ export class WS2PConnection { const onWsClosed:Promise = new Promise(res => { websocket.on('close', () => res()) }) - return new WS2PConnection(websocket, onWsOpened, onWsClosed, messageHandler, localAuth, remoteAuth, options, expectedPub) + return new WS2PConnection(WS2PConstants.WS2P_DEFAULT_VERSION, websocket, onWsOpened, onWsClosed, messageHandler, localAuth, remoteAuth, options, expectedPub) } get pubkey() { @@ -367,7 +389,7 @@ export class WS2PConnection { (async () => { await this.onWsOpened try { - await this.localAuth.sendCONNECT(this.ws) + await this.localAuth.sendCONNECT(this.ws, this.ws2pVersion) await Promise.all([ this.localAuth.authenticationIsDone(), this.remoteAuth.authenticationIsDone() @@ -397,17 +419,24 @@ export class WS2PConnection { if (data.auth && typeof data.auth === "string") { if (data.auth === "CONNECT") { + if (data.version) { + if (typeof data.version !== "number") { + await this.errorDetected(WS2P_ERR.AUTH_INVALID_ASK_FIELDS) + } else { + this.ws2pVersion = data.version + } + } if (this.remoteAuth.isAuthenticatedByRemote()) { return this.errorDetected(WS2P_ERR.ALREADY_AUTHENTICATED_BY_REMOTE) } else if ( - typeof data.pub !== "string" || typeof data.sig !== "string" || typeof data.challenge !== "string") { + typeof data.pub !== "string" || typeof data.sig !== "string" || typeof data.challenge !== "string" || (this.ws2pVersion > 1 && data.ws2pId !== "string") ) { await this.errorDetected(WS2P_ERR.AUTH_INVALID_ASK_FIELDS) } else { if (this.expectedPub && data.pub !== this.expectedPub) { await this.errorDetected(WS2P_ERR.INCORRECT_PUBKEY_FOR_REMOTE) } else { - const valid = await this.remoteAuth.registerCONNECT(data.challenge, data.sig, data.pub) + const valid = await this.remoteAuth.registerCONNECT(this.ws2pVersion, data.challenge, data.sig, data.pub, (this.ws2pVersion > 1) ? data.ws2pID:"") if (valid) { await this.remoteAuth.sendACK(this.ws) } else { diff --git a/app/modules/ws2p/lib/WS2PServer.ts b/app/modules/ws2p/lib/WS2PServer.ts index 7b08e983..51ea0e31 100644 --- a/app/modules/ws2p/lib/WS2PServer.ts +++ b/app/modules/ws2p/lib/WS2PServer.ts @@ -86,11 +86,11 @@ export class WS2PServer extends events.EventEmitter { requestTimeout: WS2PConstants.REQUEST_TOR_TIMEOUT } } - + const myWs2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) ? this.server.conf.ws2p.uuid:"" const c = WS2PConnection.newConnectionFromWebSocketServer( ws, messageHandler, - new WS2PPubkeyLocalAuth(this.server.conf.currency, key, acceptPubkey), + new WS2PPubkeyLocalAuth(this.server.conf.currency, key, myWs2pId, acceptPubkey), new WS2PPubkeyRemoteAuth(this.server.conf.currency, key, acceptPubkey), timeout ) diff --git a/app/modules/ws2p/lib/constants.ts b/app/modules/ws2p/lib/constants.ts index 080db10c..553cb979 100644 --- a/app/modules/ws2p/lib/constants.ts +++ b/app/modules/ws2p/lib/constants.ts @@ -1,6 +1,7 @@ import {CommonConstants} from "../../../lib/common-libs/constants" export const WS2PConstants = { + WS2P_DEFAULT_VERSION:1, WS2P_VERSION: 2, WS2P_UPNP_TTL: 600, diff --git a/test/integration/branches2.js b/test/integration/branches2.js index 0970f973..18d05557 100644 --- a/test/integration/branches2.js +++ b/test/integration/branches2.js @@ -13,11 +13,11 @@ const logger_1 = require("../../app/lib/logger"); const index_1 = require("../../app/modules/bma/index"); const index_2 = require("../../app/modules/crawler/index"); const toolbox_1 = require("./tools/toolbox"); +const TestUser_1 = require("./tools/TestUser"); const co = require('co'); const _ = require('underscore'); const duniter = require('../../index'); const bma = index_1.BmaDependency.duniter.methods.bma; -const user = require('./tools/user'); const rp = require('request-promise'); const httpTest = require('./tools/http'); const commit = require('./tools/commit'); @@ -61,8 +61,8 @@ describe("SelfFork", function () { sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' } }, commonConf)); - cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' }, { server: s1 }); - toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' }, { server: s1 }); + cat = new TestUser_1.TestUser('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' }, { server: s1 }); + toc = new TestUser_1.TestUser('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' }, { server: s1 }); const commitS1 = commit(s1); const commitS2 = commit(s2, { time: now + 37180 diff --git a/test/integration/tools/toolbox.ts b/test/integration/tools/toolbox.ts index 45a7ceb7..ea81eb79 100644 --- a/test/integration/tools/toolbox.ts +++ b/test/integration/tools/toolbox.ts @@ -643,7 +643,7 @@ export async function newWS2PBidirectionnalConnection(currency:string, k1:Key, k wss.on('connection', async (ws:any) => { switch (i) { case 1: - s1 = WS2PConnection.newConnectionFromWebSocketServer(ws, serverHandler, new WS2PPubkeyLocalAuth(currency, k1), new WS2PPubkeyRemoteAuth(currency, k1), { + s1 = WS2PConnection.newConnectionFromWebSocketServer(ws, serverHandler, new WS2PPubkeyLocalAuth(currency, k1, ""), new WS2PPubkeyRemoteAuth(currency, k1), { connectionTimeout: 100, requestTimeout: 100 }); @@ -657,13 +657,13 @@ export async function newWS2PBidirectionnalConnection(currency:string, k1:Key, k }) i++ }) - c1 = WS2PConnection.newConnectionToAddress('ws://localhost:' + port, new (class EmptyHandler implements WS2PMessageHandler { + c1 = WS2PConnection.newConnectionToAddress(1, 'ws://localhost:' + port, new (class EmptyHandler implements WS2PMessageHandler { async handlePushMessage(json: any): Promise { } async answerToRequest(json: any): Promise { return {} } - }), new WS2PPubkeyLocalAuth(currency, k2), new WS2PPubkeyRemoteAuth(currency, k2)) + }), new WS2PPubkeyLocalAuth(currency, k2, ""), new WS2PPubkeyRemoteAuth(currency, k2)) }) } @@ -678,7 +678,7 @@ export const simpleWS2PNetwork: (s1: TestingServer, s2: TestingServer) => Promis const connexionPromise = new Promise(res => { ws2ps.on('newConnection', res) }) - const ws2pc = await cluster2.connectToRemoteWS('localhost', port, '', new WS2PServerMessageHandler(s2._server, cluster2), s1._server.conf.pair.pub) + const ws2pc = await cluster2.connectToRemoteWS(1, 'localhost', port, '', new WS2PServerMessageHandler(s2._server, cluster2), s1._server.conf.pair.pub) await connexionPromise w1 = await ws2ps.getConnection(clientPub) diff --git a/test/integration/ws2p_connection.ts b/test/integration/ws2p_connection.ts index c84d9a42..73826eb0 100644 --- a/test/integration/ws2p_connection.ts +++ b/test/integration/ws2p_connection.ts @@ -44,7 +44,7 @@ describe('WS2P', () => { }) it('should be able to create a connection', async () => { - const ws2p = WS2PConnection.newConnectionToAddress('ws://localhost:' + portA, new WS2PMutedHandler(), new WS2PNoLocalAuth(), new WS2PNoRemoteAuth()) + const ws2p = WS2PConnection.newConnectionToAddress(1, 'ws://localhost:' + portA, new WS2PMutedHandler(), new WS2PNoLocalAuth(), new WS2PNoRemoteAuth()) const res = await ws2p.request({ name: 'head' }) assert.deepEqual({ bla: 'aa' }, res) }) @@ -95,7 +95,7 @@ describe('WS2P', () => { it('should refuse the connection if the server does not answer', async () => { const keypair = new Key('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP') - const ws2p = WS2PConnection.newConnectionToAddress('ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, keypair), new WS2PPubkeyRemoteAuth(gtest, keypair), undefined, { + const ws2p = WS2PConnection.newConnectionToAddress(1, 'ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, keypair, ""), new WS2PPubkeyRemoteAuth(gtest, keypair), undefined, { connectionTimeout: 100, requestTimeout: 100 }) @@ -104,7 +104,7 @@ describe('WS2P', () => { it('should refuse the connection if the server answers with a wrong signature', async () => { const keypair = new Key('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP') - const ws2p = WS2PConnection.newConnectionToAddress('ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, keypair), new WS2PPubkeyRemoteAuth(gtest, keypair), undefined, { + const ws2p = WS2PConnection.newConnectionToAddress(1, 'ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, keypair, ""), new WS2PPubkeyRemoteAuth(gtest, keypair), undefined, { connectionTimeout: 100, requestTimeout: 100 }) @@ -113,7 +113,7 @@ describe('WS2P', () => { it('should refuse the connection if the server refuses our signature', async () => { const keypair = new Key('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP') - const ws2p = WS2PConnection.newConnectionToAddress('ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, keypair), new WS2PPubkeyRemoteAuth(gtest, keypair), undefined, { + const ws2p = WS2PConnection.newConnectionToAddress(1, 'ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, keypair, ""), new WS2PPubkeyRemoteAuth(gtest, keypair), undefined, { connectionTimeout: 100, requestTimeout: 100 }) @@ -123,7 +123,7 @@ describe('WS2P', () => { it('should accept the connection if the server answers with a good signature', async () => { const keypair = new Key('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP') - const ws2p = WS2PConnection.newConnectionToAddress('ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, keypair), new WS2PNoRemoteAuth(), undefined, { + const ws2p = WS2PConnection.newConnectionToAddress(1, 'ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, keypair, ""), new WS2PNoRemoteAuth(), undefined, { connectionTimeout: 1000, requestTimeout: 1000 }) @@ -180,7 +180,7 @@ describe('WS2P', () => { it('should be able to create connections and make several requests', async () => { // connection 1 - const c1 = WS2PConnection.newConnectionToAddress('ws://localhost:' + portB, new WS2PMutedHandler(), new WS2PNoLocalAuth(), new WS2PNoRemoteAuth()) + const c1 = WS2PConnection.newConnectionToAddress(1, 'ws://localhost:' + portB, new WS2PMutedHandler(), new WS2PNoLocalAuth(), new WS2PNoRemoteAuth()) assert.deepEqual({ answer: 'world' }, await c1.request({ name: 'hello!' })) assert.deepEqual({ answer: 'world' }, await c1.request({ name: 'hello2!' })) assert.equal(s1.nbRequests, 0) @@ -192,7 +192,7 @@ describe('WS2P', () => { assert.equal(s1.nbPushsByRemote, 0) assert.equal(c1.nbPushsByRemote, 0) // connection 2 - const c2 = WS2PConnection.newConnectionToAddress('ws://localhost:' + portB, new WS2PMutedHandler(), new WS2PNoLocalAuth(), new WS2PNoRemoteAuth()) + const c2 = WS2PConnection.newConnectionToAddress(1 ,'ws://localhost:' + portB, new WS2PMutedHandler(), new WS2PNoLocalAuth(), new WS2PNoRemoteAuth()) assert.deepEqual({ answer: 'this is s2![j = 0]' }, await c2.request({ name: 'test?' })) assert.deepEqual({ answer: 'this is s2![j = 1]' }, await c2.request({ name: 'test!' })) assert.deepEqual({ answer: 'this is s2![j = 2]' }, await c2.request({ name: 'test!!!' })) @@ -230,7 +230,7 @@ describe('WS2P', () => { wss.on('connection', async (ws:any) => { switch (i) { case 1: - resolveS1(WS2PConnection.newConnectionFromWebSocketServer(ws, new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, serverKeypair), new WS2PPubkeyRemoteAuth(gtest, serverKeypair), { + resolveS1(WS2PConnection.newConnectionFromWebSocketServer(ws, new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, serverKeypair, ""), new WS2PPubkeyRemoteAuth(gtest, serverKeypair), { connectionTimeout: 100, requestTimeout: 100 })); @@ -244,7 +244,7 @@ describe('WS2P', () => { } } - resolveS2(WS2PConnection.newConnectionFromWebSocketServer(ws, new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, serverKeypair), new WS2PPubkeyNotAnsweringWithOKAuth(gtest, serverKeypair), { + resolveS2(WS2PConnection.newConnectionFromWebSocketServer(ws, new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, serverKeypair, ""), new WS2PPubkeyNotAnsweringWithOKAuth(gtest, serverKeypair), { connectionTimeout: 100, requestTimeout: 100 })); @@ -252,7 +252,7 @@ describe('WS2P', () => { break case 3: - resolveS3(WS2PConnection.newConnectionFromWebSocketServer(ws, new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, serverKeypair), new WS2PPubkeyRemoteAuth(gtest, serverKeypair), { + resolveS3(WS2PConnection.newConnectionFromWebSocketServer(ws, new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, serverKeypair, ""), new WS2PPubkeyRemoteAuth(gtest, serverKeypair), { connectionTimeout: 100, requestTimeout: 100 })); @@ -260,7 +260,7 @@ describe('WS2P', () => { break case 4: - resolveS4(WS2PConnection.newConnectionFromWebSocketServer(ws, new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, serverKeypair), new WS2PPubkeyRemoteAuth(gtest, serverKeypair), { + resolveS4(WS2PConnection.newConnectionFromWebSocketServer(ws, new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, serverKeypair, ""), new WS2PPubkeyRemoteAuth(gtest, serverKeypair), { connectionTimeout: 100, requestTimeout: 100 })); @@ -268,13 +268,13 @@ describe('WS2P', () => { break case 5: - resolveS5(WS2PConnection.newConnectionFromWebSocketServer(ws, new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, serverKeypair), new WS2PPubkeyRemoteAuth(gtest, serverKeypair))); + resolveS5(WS2PConnection.newConnectionFromWebSocketServer(ws, new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, serverKeypair, ""), new WS2PPubkeyRemoteAuth(gtest, serverKeypair))); (await s5p).connect().catch((e:any) => logger.error('WS2P: newConnectionFromWebSocketServer connection error')) break case 6: - resolveS6(WS2PConnection.newConnectionFromWebSocketServer(ws, new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, serverKeypair), new WS2PPubkeyRemoteAuth(gtest, serverKeypair), { + resolveS6(WS2PConnection.newConnectionFromWebSocketServer(ws, new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, serverKeypair, ""), new WS2PPubkeyRemoteAuth(gtest, serverKeypair), { connectionTimeout: 100, requestTimeout: 100 })); @@ -298,7 +298,7 @@ describe('WS2P', () => { } const keypair = new Key('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP') - const c1 = WS2PConnection.newConnectionToAddress('ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, keypair), new WS2PPubkeyNotAnsweringWithACKAuth(gtest, keypair)) + const c1 = WS2PConnection.newConnectionToAddress(1, 'ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, keypair, ""), new WS2PPubkeyNotAnsweringWithACKAuth(gtest, keypair)) c1.connect().catch((e:any) => logger.error('WS2P: connection error')) const s1 = await s1p await assertThrows(s1.request({ name: 'something' }), "WS2P connection timeout") @@ -306,7 +306,7 @@ describe('WS2P', () => { it('should refuse the connection if the client not confirm with OK', async () => { const keypair = new Key('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP') - WS2PConnection.newConnectionToAddress('ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, keypair), new WS2PPubkeyRemoteAuth(gtest, keypair)) + WS2PConnection.newConnectionToAddress(1, 'ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, keypair, ""), new WS2PPubkeyRemoteAuth(gtest, keypair)) const s2 = await s2p await assertThrows(s2.request({ name: 'something' }), "WS2P connection timeout") }) @@ -326,7 +326,7 @@ describe('WS2P', () => { } const keypair = new Key('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP') - const c3 = WS2PConnection.newConnectionToAddress('ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, keypair), new WS2PPubkeyAnsweringWithWrongSigForACK(gtest, keypair)) + const c3 = WS2PConnection.newConnectionToAddress(1, 'ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyLocalAuth(gtest, keypair, ""), new WS2PPubkeyAnsweringWithWrongSigForACK(gtest, keypair)) c3.connect().catch((e:any) => logger.error('WS2P: connection error')) const s3 = await s3p await assertThrows(s3.request({ name: 'something' }), "Wrong signature from server ACK") @@ -349,20 +349,20 @@ describe('WS2P', () => { } const keypair = new Key('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP') - const c4 = WS2PConnection.newConnectionToAddress('ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyRefusingACKSignature(gtest, keypair), new WS2PPubkeyRemoteAuth(gtest, keypair)) + const c4 = WS2PConnection.newConnectionToAddress(1, 'ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyRefusingACKSignature(gtest, keypair, ""), new WS2PPubkeyRemoteAuth(gtest, keypair)) const s4 = await s4p await assertThrows(c4.connect(), "Wrong signature from server ACK") }) it('should accept the connection if everything is OK on both side', async () => { const keypair = new Key('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP') - const c5 = WS2PConnection.newConnectionToAddress('ws://localhost:20903', new (class TmpHandler implements WS2PMessageHandler { + const c5 = WS2PConnection.newConnectionToAddress(1, 'ws://localhost:20903', new (class TmpHandler implements WS2PMessageHandler { async handlePushMessage(json: any): Promise { } async answerToRequest(json: any): Promise { return { answer: 'success!' } } - }), new WS2PPubkeyLocalAuth(gtest, keypair), new WS2PPubkeyRemoteAuth(gtest, keypair)) + }), new WS2PPubkeyLocalAuth(gtest, keypair, ""), new WS2PPubkeyRemoteAuth(gtest, keypair)) await c5.connect().catch((e:any) => logger.error('WS2P: connection error')) const s5 = await s5p assert.deepEqual({ answer: 'success!' }, await s5.request({ name: 'connection?'} )) @@ -376,7 +376,7 @@ describe('WS2P', () => { } const keypair = new Key('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP') - const c6 = WS2PConnection.newConnectionToAddress('ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyNotAnsweringWithOKAuth(gtest, keypair), new WS2PPubkeyRemoteAuth(gtest, keypair)) + const c6 = WS2PConnection.newConnectionToAddress(1, 'ws://localhost:20903', new WS2PMutedHandler(), new WS2PPubkeyNotAnsweringWithOKAuth(gtest, keypair, ""), new WS2PPubkeyRemoteAuth(gtest, keypair)) c6.connect().catch((e:any) => logger.error('WS2P: connection error')) const s6 = await s6p await assertThrows(s6.request({ name: 'something' }), "WS2P connection timeout") @@ -422,7 +422,7 @@ class WS2PNoRemoteAuth implements WS2PRemoteAuth { async sendACK(ws: any): Promise { } - async registerCONNECT(challenge:string, sig: string, pub: string): Promise { + async registerCONNECT(version:number, challenge:string, sig: string, pub: string, ws2pId:string): Promise { return true } -- GitLab From f58c7c7568aad3fec027b38cccc5c5c0d42f81fa Mon Sep 17 00:00:00 2001 From: librelois Date: Mon, 13 Nov 2017 14:03:01 +0100 Subject: [PATCH 33/72] [fix] #1198 --- app/cli.ts | 1 + app/modules/prover/index.ts | 3 +++ app/modules/prover/lib/engine.ts | 2 +- index.ts | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/cli.ts b/app/cli.ts index 26accf24..3c2e4951 100644 --- a/app/cli.ts +++ b/app/cli.ts @@ -42,6 +42,7 @@ export const ExecuteCommand = () => { .option('--remep ', 'With `config` command, remove given endpoint to the list of endpoints of this node') .option('--cpu ', 'Percent of CPU usage for proof-of-work computation', parsePercent) + .option('--nb-cores ', 'Number of cores uses for proof-of-work computation', parseInt) .option('--prefix ', 'Prefix node id for the first character of nonce', parseInt) .option('-c, --currency ', 'Name of the currency managed by this node.') diff --git a/app/modules/prover/index.ts b/app/modules/prover/index.ts index 7bdd8346..01b4bc71 100644 --- a/app/modules/prover/index.ts +++ b/app/modules/prover/index.ts @@ -21,6 +21,9 @@ export const ProverDependency = { if (conf.cpu === null || conf.cpu === undefined) { conf.cpu = Constants.DEFAULT_CPU; } + if (conf.nbCores === null || conf.nbCores === undefined) { + conf.nbCores = Math.min(Constants.CORES_MAXIMUM_USE_IN_PARALLEL, require('os').cpus().length) + } if (conf.prefix === null || conf.prefix === undefined) { conf.prefix = Constants.DEFAULT_PEER_ID; } diff --git a/app/modules/prover/lib/engine.ts b/app/modules/prover/lib/engine.ts index 12d2751d..116963e4 100644 --- a/app/modules/prover/lib/engine.ts +++ b/app/modules/prover/lib/engine.ts @@ -20,7 +20,7 @@ export class PowEngine { constructor(private conf:ConfDTO, logger:any) { // We use as much cores as available, but not more than CORES_MAXIMUM_USE_IN_PARALLEL - this.nbWorkers = (conf && conf.nbCores) || Math.min(Constants.CORES_MAXIMUM_USE_IN_PARALLEL, require('os').cpus().length) + this.nbWorkers = conf.nbCores this.cluster = new PowCluster(this.nbWorkers, logger) this.id = this.cluster.clusterId } diff --git a/index.ts b/index.ts index f9e3cf44..1086b3aa 100644 --- a/index.ts +++ b/index.ts @@ -444,6 +444,7 @@ function commandLineConf(program:any, conf:any = {}) { const cli = { currency: program.currency, cpu: program.cpu, + nbCores: program.nbCores, prefix: program.prefix, server: { port: program.port, -- GitLab From 0ac6978e719e40d371b8e5e4c16ecf98e2af56b0 Mon Sep 17 00:00:00 2001 From: librelois Date: Mon, 13 Nov 2017 14:27:01 +0100 Subject: [PATCH 34/72] [fix] #1197 --- app/modules/prover/lib/engine.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/modules/prover/lib/engine.ts b/app/modules/prover/lib/engine.ts index 116963e4..efbf0f47 100644 --- a/app/modules/prover/lib/engine.ts +++ b/app/modules/prover/lib/engine.ts @@ -35,8 +35,10 @@ export class PowEngine { await this.cluster.cancelWork() } - if (os.arch().match(/arm/)) { - stuff.newPoW.conf.cpu /= 2; // Don't know exactly why is ARM so much saturated by PoW, so let's divide by 2 + const cpus = os.cpus() + + if (os.arch().match(/arm/) || cpus[0].model.match(/Atom/)) { + stuff.newPoW.conf.cpu /= 2; // Don't know exactly why is ARM and Atom so much saturated by PoW, so let's divide by 2 } return await this.cluster.proveByWorkers(stuff) } -- GitLab From 481898276b1c3d52729ef635d9c7618a39f298f2 Mon Sep 17 00:00:00 2001 From: librelois Date: Mon, 13 Nov 2017 15:00:38 +0100 Subject: [PATCH 35/72] [test] always define nbCores in pow integration tests --- test/integration/branches_revert2.js | 1 + test/integration/register-fork-blocks.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/test/integration/branches_revert2.js b/test/integration/branches_revert2.js index 9800c3ad..511b55c4 100644 --- a/test/integration/branches_revert2.js +++ b/test/integration/branches_revert2.js @@ -23,6 +23,7 @@ const MEMORY_MODE = true; const commonConf = { ipv4: '127.0.0.1', currency: 'bb', + nbCores:1, httpLogs: true, forksize: 3, sigQty: 1 diff --git a/test/integration/register-fork-blocks.js b/test/integration/register-fork-blocks.js index cf1faf59..09c02dff 100644 --- a/test/integration/register-fork-blocks.js +++ b/test/integration/register-fork-blocks.js @@ -20,6 +20,7 @@ describe("Fork blocks", function() { s1 = toolbox.server({ // The common conf + nbCores:1, medianTimeBlocks: 1, avgGenTime: 11, udTime0: now, @@ -35,6 +36,7 @@ describe("Fork blocks", function() { s2 = toolbox.server({ // Particular conf + nbCores:1, switchOnHeadAdvance: 5, forksize, @@ -47,6 +49,7 @@ describe("Fork blocks", function() { s3 = toolbox.server({ // Particular conf + nbCores:1, switchOnHeadAdvance: 5, forksize, -- GitLab From 8812f311626b92422d3149bf99732092486c5b8c Mon Sep 17 00:00:00 2001 From: librelois Date: Mon, 13 Nov 2017 15:30:23 +0100 Subject: [PATCH 36/72] #1197 Make sure that only once each physical core is used (for Hyperthreading) --- app/modules/prover/lib/engine.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/modules/prover/lib/engine.ts b/app/modules/prover/lib/engine.ts index efbf0f47..352de59c 100644 --- a/app/modules/prover/lib/engine.ts +++ b/app/modules/prover/lib/engine.ts @@ -38,7 +38,7 @@ export class PowEngine { const cpus = os.cpus() if (os.arch().match(/arm/) || cpus[0].model.match(/Atom/)) { - stuff.newPoW.conf.cpu /= 2; // Don't know exactly why is ARM and Atom so much saturated by PoW, so let's divide by 2 + stuff.newPoW.conf.nbCores /= 2; // Make sure that only once each physical core is used (for Hyperthreading). } return await this.cluster.proveByWorkers(stuff) } -- GitLab From 3ac9d67176bc083053764fc80197e640d404ffbf Mon Sep 17 00:00:00 2001 From: librelois Date: Mon, 13 Nov 2017 16:47:22 +0100 Subject: [PATCH 37/72] test ws2p server limitations --- app/modules/ws2p/lib/WS2PCluster.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index ddd1493a..4a31062f 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -663,7 +663,7 @@ export class WS2PCluster { ) { if (this.server.conf.pair.pub === pub) { // We do not accept oneself connetion - if (this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID) { + if (this.server.conf.ws2p && this.server.conf.ws2p.uuid === targetWS2PUID || targetWS2PUID === '11111111') { return false } else { // We always accept self nodes, and they have a supreme priority (these are siblings) -- GitLab From 762ce29d227aae370777d89d1765393049b2e38b Mon Sep 17 00:00:00 2001 From: librelois Date: Mon, 13 Nov 2017 18:13:37 +0100 Subject: [PATCH 38/72] [fix] completely close a removed connection --- app/modules/ws2p/lib/WS2PServer.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/app/modules/ws2p/lib/WS2PServer.ts b/app/modules/ws2p/lib/WS2PServer.ts index 51ea0e31..de94ba4e 100644 --- a/app/modules/ws2p/lib/WS2PServer.ts +++ b/app/modules/ws2p/lib/WS2PServer.ts @@ -171,6 +171,7 @@ export class WS2PServer extends events.EventEmitter { if (index !== -1) { // Remove the connection this.connections.splice(index, 1) + c.close() } } -- GitLab From 5b1df4c10a545dde40ba45f35c8c19bb5abd3d80 Mon Sep 17 00:00:00 2001 From: librelois Date: Mon, 13 Nov 2017 18:38:50 +0100 Subject: [PATCH 39/72] repair test ws2p server limitations --- test/integration/ws2p_server_limitations.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/integration/ws2p_server_limitations.ts b/test/integration/ws2p_server_limitations.ts index 8130d186..4acf4d9f 100644 --- a/test/integration/ws2p_server_limitations.ts +++ b/test/integration/ws2p_server_limitations.ts @@ -167,7 +167,10 @@ describe("WS2P server limitations", function() { it('should connect to s3 because of configuration favorism', async () => { cluster3.maxLevel2Peers = 1 if (s1._server.conf.ws2p) s1._server.conf.ws2p.privateAccess = true - if (s3._server.conf.ws2p) s3._server.conf.ws2p.publicAccess = true + if (s3._server.conf.ws2p) { + s3._server.conf.ws2p.publicAccess = true + s3._server.conf.ws2p.maxPublic = 1 + } await s3.writeBlock(b3) await s3._server.PeeringService.generateSelfPeer(s3._server.conf) await s3._server.PeeringService.generateSelfPeer(s3._server.conf) -- GitLab From 7cb81e2bed5fa609c4d253bbc6039bd6952639fe Mon Sep 17 00:00:00 2001 From: librelois Date: Mon, 13 Nov 2017 19:50:10 +0100 Subject: [PATCH 40/72] test ws2p server limitations : rm waitDisconnection --- test/integration/ws2p_server_limitations.ts | 34 ++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/test/integration/ws2p_server_limitations.ts b/test/integration/ws2p_server_limitations.ts index 4acf4d9f..4b82509c 100644 --- a/test/integration/ws2p_server_limitations.ts +++ b/test/integration/ws2p_server_limitations.ts @@ -183,23 +183,23 @@ describe("WS2P server limitations", function() { const p3 = await s3.getPeer() await s2.writePeer(p3) await waitForkWS2PConnection(s3._server, 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd') - await waitForkWS2PDisconnection(s3._server, '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc') - await s1.expect('/network/ws2p/info', (res:any) => { - assert.equal(res.peers.level1, 1) // <- New connection to s3 - assert.equal(res.peers.level2, 1) - }) - await s2.expect('/network/ws2p/info', (res:any) => { - assert.equal(res.peers.level1, 1) - assert.equal(res.peers.level2, 0) - }) - await s3.expect('/network/ws2p/info', (res:any) => { - assert.equal(res.peers.level1, 0) - assert.equal(res.peers.level2, 1) // <- New connection from s1 - }) - await s4.expect('/network/ws2p/info', (res:any) => { - assert.equal(res.peers.level1, 0) - assert.equal(res.peers.level2, 0) - }) + //await waitForkWS2PDisconnection(s3._server, '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc') + await s1.expect('/network/ws2p/info', (res:any) => { + assert.equal(res.peers.level1, 1) // <- New connection to s3 + assert.equal(res.peers.level2, 1) + }) + await s2.expect('/network/ws2p/info', (res:any) => { + assert.equal(res.peers.level1, 1) + assert.equal(res.peers.level2, 0) + }) + await s3.expect('/network/ws2p/info', (res:any) => { + assert.equal(res.peers.level1, 0) + assert.equal(res.peers.level2, 1) // <- New connection from s1 + }) + await s4.expect('/network/ws2p/info', (res:any) => { + assert.equal(res.peers.level1, 0) + assert.equal(res.peers.level2, 0) + }) }) function getTestingServer(keyring:{ pub:string, sec:string }) { -- GitLab From 06909cc43fe7c1fec5115c70df30dad3e33a9021 Mon Sep 17 00:00:00 2001 From: librelois Date: Mon, 13 Nov 2017 20:07:12 +0100 Subject: [PATCH 41/72] [fix] We do not accept keys already connected --- app/modules/ws2p/lib/WS2PCluster.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 4a31062f..4eee090c 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -690,6 +690,11 @@ export class WS2PCluster { return false } + // We do not accept keys already connected + if (connectedPubkeys.indexOf(pub) !== -1) { + return false + } + // Is member key ? const isMemberPeer = await this.server.dal.isMember(pub) @@ -698,8 +703,7 @@ export class WS2PCluster { // Yes: just connect to it return true } - else if (connectedPubkeys.indexOf(pub) === -1) - { + else { let minPriorityLevel = WS2PConstants.CONNECTIONS_PRIORITY.MAX_PRIORITY_LEVEL for (const connectedPubkey of connectedPubkeys) { let connectedPubkeyPriorityLevel = this.keyPriorityLevel(connectedPubkey, priorityKeys) @@ -711,6 +715,7 @@ export class WS2PCluster { return true } } + return false } -- GitLab From c65929548b26538d298484b7cf0023327b685732 Mon Sep 17 00:00:00 2001 From: librelois Date: Mon, 13 Nov 2017 21:00:31 +0100 Subject: [PATCH 42/72] [typage] use type WS2PEndpoint --- app/lib/dto/PeerDTO.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/lib/dto/PeerDTO.ts b/app/lib/dto/PeerDTO.ts index 3b9ca529..4d735bd3 100644 --- a/app/lib/dto/PeerDTO.ts +++ b/app/lib/dto/PeerDTO.ts @@ -5,9 +5,11 @@ import {Cloneable} from "./Cloneable" import { WS2PConstants } from '../../modules/ws2p/lib/constants'; export interface WS2PEndpoint { + version:number uuid:string host:string port:number + path:string } export class PeerDTO implements Cloneable { @@ -96,7 +98,7 @@ export class PeerDTO implements Cloneable { } getOnceWS2PEndpoint(canReachTorEp:boolean, canReachClearEp:boolean, uuidExcluded:string[] = []) { - let api:{ version:number, uuid:string, host:string, port:number, path:string }|null = null + let api:WS2PEndpoint|null = null let bestWS2PVersionAvailable:number = 0 let bestWS2PTORVersionAvailable:number = 0 for (const ep of this.endpoints) { @@ -156,7 +158,7 @@ export class PeerDTO implements Cloneable { } getAllWS2PEndpoints(canReachTorEp:boolean, canReachClearEp:boolean, myUUID:string) { - let apis:{ version:number, uuid:string, host:string, port:number, path:string }[] = [] + let apis:WS2PEndpoint[] = [] let uuidExcluded:string[] = [myUUID] let api = this.getOnceWS2PEndpoint(canReachTorEp, canReachClearEp, uuidExcluded) while (api !== null) { -- GitLab From c80f81d4d784025f6e45ac8ea57b5a85682a8ecd Mon Sep 17 00:00:00 2001 From: librelois Date: Mon, 13 Nov 2017 21:03:09 +0100 Subject: [PATCH 43/72] [enh] reconnect all ten minutes and create a clique between own peers --- app/modules/ws2p/lib/WS2PCluster.ts | 36 +++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 4eee090c..27e3ce21 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -7,7 +7,7 @@ import {CrawlerConstants} from "../../crawler/lib/constants" import {WS2PBlockPuller} from "./WS2PBlockPuller" import {WS2PDocpoolPuller} from "./WS2PDocpoolPuller" import {WS2PConstants} from "./constants" -import {PeerDTO} from "../../../lib/dto/PeerDTO" +import { PeerDTO, WS2PEndpoint } from '../../../lib/dto/PeerDTO'; import {GlobalFifoPromise} from "../../../service/GlobalFifoPromise" import {OtherConstants} from "../../../lib/other_constants" import {Key, verify} from "../../../lib/common-libs/crypto/keyring" @@ -293,6 +293,16 @@ export class WS2PCluster { return count } + numberOfConnectedPublicNodesWithSameKey() { + let count = 0 + for (const ws2pid of Object.keys(this.ws2pClients)) { + if (this.ws2pClients[ws2pid].connection.pubkey === this.server.conf.pair.pub) { + count++ + } + } + return count + } + servedCount() { return (this.ws2pServer) ? this.ws2pServer.countConnexions():0 } @@ -383,13 +393,16 @@ export class WS2PCluster { } } }) - let i = 0 const canReachClearEndpoint = ProxiesConf.canReachClearEndpoint(this.server.conf.proxiesConf) - while (i < peers.length && this.clientsCount() < this.maxLevel1Size) { + let i = 0 + let countPublicNodesWithSameKey:number = 1 // Necessary if maxPrivate = 0 + let endpointsNodesWithSameKey:WS2PEndpoint[] = [] + while (i < peers.length && (this.clientsCount() < this.maxLevel1Size || this.numberOfConnectedPublicNodesWithSameKey() < countPublicNodesWithSameKey) ) { const p = peers[i] if (p.pubkey === this.server.conf.pair.pub) { - const apis = p.getAllWS2PEndpoints(canReachTorEndpoint, canReachClearEndpoint, myUUID) - for (const api of apis) { + endpointsNodesWithSameKey = p.getAllWS2PEndpoints(canReachTorEndpoint, canReachClearEndpoint, myUUID) + countPublicNodesWithSameKey = endpointsNodesWithSameKey.length + for (const api of endpointsNodesWithSameKey) { try { // We do not connect to local host if (api.uuid !== myUUID) { @@ -414,6 +427,8 @@ export class WS2PCluster { // Trim the eventual extra connections setTimeout(() => this.trimClientConnections(prefered), WS2PConstants.CONNEXION_TIMEOUT) } + // Retry to connect to ws2p peers every WS2PConstants.RECONNEXION_INTERVAL_IN_SEC + setTimeout(() => this.connectToWS2Peers(), WS2PConstants.RECONNEXION_INTERVAL_IN_SEC) } listenServerFlow() { @@ -565,7 +580,7 @@ export class WS2PCluster { serverPubkeys = this.ws2pServer.getConnexions().map(c => c.pubkey) } let disconnectedOne = true - // Disconnect Private connexions already present under Public + // Disconnect Private connexions already present (under Public or under Private) while (disconnectedOne) { disconnectedOne = false let uuids = Object.keys(this.ws2pClients) @@ -575,7 +590,14 @@ export class WS2PCluster { const pub = client.connection.pubkey const isNotOurself = pub !== this.server.conf.pair.pub const isAlreadyInPublic = serverPubkeys.indexOf(pub) !== -1 - if (isNotOurself && isAlreadyInPublic) { + // Check if isAlreadyInPrivate + let isAlreadyInPrivate = 0 + for (const ws2pid of Object.keys(this.ws2pClients)) { + if (this.ws2pClients[ws2pid].connection.pubkey === pub) { + isAlreadyInPrivate++ + } + } + if (isNotOurself && (isAlreadyInPublic || isAlreadyInPrivate > 1)) { client.connection.close() await client.connection.closed disconnectedOne = true -- GitLab From 6e07c0ccd40deb83c8375f5eee6f62d62b57fdac Mon Sep 17 00:00:00 2001 From: librelois Date: Mon, 13 Nov 2017 21:47:30 +0100 Subject: [PATCH 44/72] [mod] rm CONNECTIONS_LOW_LEVEL --- app/modules/ws2p/lib/WS2PCluster.ts | 19 +------------------ app/modules/ws2p/lib/constants.ts | 1 - 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 27e3ce21..3d874f37 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -427,8 +427,6 @@ export class WS2PCluster { // Trim the eventual extra connections setTimeout(() => this.trimClientConnections(prefered), WS2PConstants.CONNEXION_TIMEOUT) } - // Retry to connect to ws2p peers every WS2PConstants.RECONNEXION_INTERVAL_IN_SEC - setTimeout(() => this.connectToWS2Peers(), WS2PConstants.RECONNEXION_INTERVAL_IN_SEC) } listenServerFlow() { @@ -471,21 +469,6 @@ export class WS2PCluster { this.server.logger.warn(e) } } - - // WS2P disconnection - else if (data.ws2p === 'disconnected') { - const nbConnections = this.getAllConnections().length - if (nbConnections < WS2PConstants.CONNECTIONS_LOW_LEVEL && !connectingToNodesByFlow) { - try { - connectingToNodesByFlow = true - await this.connectToWS2Peers() - } catch (e) { - throw e - } finally { - connectingToNodesByFlow = false - } - } - } })() return data @@ -772,7 +755,7 @@ export class WS2PCluster { async startCrawling(waitConnection = false) { // For connectivity - this.reconnectionInteval = setInterval(() => this.server.push({ ws2p: 'disconnected' }), 1000 * WS2PConstants.RECONNEXION_INTERVAL_IN_SEC) + this.reconnectionInteval = setInterval(() => this.connectToWS2Peers(), 1000 * WS2PConstants.RECONNEXION_INTERVAL_IN_SEC) // For blocks if (this.syncBlockInterval) clearInterval(this.syncBlockInterval); diff --git a/app/modules/ws2p/lib/constants.ts b/app/modules/ws2p/lib/constants.ts index 553cb979..b13299f4 100644 --- a/app/modules/ws2p/lib/constants.ts +++ b/app/modules/ws2p/lib/constants.ts @@ -21,7 +21,6 @@ export const WS2PConstants = { MAX_LEVEL_1_PEERS: 10, MAX_LEVEL_2_PEERS: 10, - CONNECTIONS_LOW_LEVEL: 3, CONNECTIONS_PRIORITY: { MEMBER_KEY_LEVEL: 1, -- GitLab From 0b29109c8c49715328c21b1dd81fcf0c625e3abf Mon Sep 17 00:00:00 2001 From: librelois Date: Mon, 13 Nov 2017 22:39:35 +0100 Subject: [PATCH 45/72] communicate only in ws2p V1 for the moment --- app/modules/ws2p/lib/WS2PClient.ts | 2 +- app/modules/ws2p/lib/constants.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PClient.ts b/app/modules/ws2p/lib/WS2PClient.ts index 422b9af1..830b3572 100644 --- a/app/modules/ws2p/lib/WS2PClient.ts +++ b/app/modules/ws2p/lib/WS2PClient.ts @@ -17,7 +17,7 @@ export class WS2PClient { const k2 = new Key(server.conf.pair.pub, server.conf.pair.sec) const myWs2pId = (server.conf.ws2p && server.conf.ws2p.uuid) ? server.conf.ws2p.uuid:"" const c = WS2PConnection.newConnectionToAddress( - endpointVersion, + Math.min(endpointVersion, WS2PConstants.WS2P_VERSION), fullEndpointAddress, messageHandler, new WS2PPubkeyLocalAuth(server.conf.currency , k2, myWs2pId, allowKey), diff --git a/app/modules/ws2p/lib/constants.ts b/app/modules/ws2p/lib/constants.ts index b13299f4..0c9836fb 100644 --- a/app/modules/ws2p/lib/constants.ts +++ b/app/modules/ws2p/lib/constants.ts @@ -2,7 +2,7 @@ import {CommonConstants} from "../../../lib/common-libs/constants" export const WS2PConstants = { WS2P_DEFAULT_VERSION:1, - WS2P_VERSION: 2, + WS2P_VERSION: 1, WS2P_UPNP_TTL: 600, WS2P_PORTS_START: 20900, -- GitLab From a7a7e5fa3734d7eccf9f47de954dbb19b81fa48d Mon Sep 17 00:00:00 2001 From: librelois Date: Tue, 14 Nov 2017 17:03:04 +0100 Subject: [PATCH 46/72] [fix) treat the case nbCores <= 0 --- app/modules/prover/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/modules/prover/index.ts b/app/modules/prover/index.ts index 01b4bc71..d4b13826 100644 --- a/app/modules/prover/index.ts +++ b/app/modules/prover/index.ts @@ -23,6 +23,8 @@ export const ProverDependency = { } if (conf.nbCores === null || conf.nbCores === undefined) { conf.nbCores = Math.min(Constants.CORES_MAXIMUM_USE_IN_PARALLEL, require('os').cpus().length) + } else if (conf.nbCores <= 0) { + conf.nbCores = 1 } if (conf.prefix === null || conf.prefix === undefined) { conf.prefix = Constants.DEFAULT_PEER_ID; -- GitLab From 5a190a7aae9766bf0d393406d8c49b85d7f4e049 Mon Sep 17 00:00:00 2001 From: cgeek Date: Tue, 14 Nov 2017 18:38:05 +0100 Subject: [PATCH 47/72] [enh] Remove unecessary comment, hash is well filled in --- app/lib/dal/sqliteDAL/TxsDAL.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/app/lib/dal/sqliteDAL/TxsDAL.ts b/app/lib/dal/sqliteDAL/TxsDAL.ts index 204ae827..dbc82ca9 100644 --- a/app/lib/dal/sqliteDAL/TxsDAL.ts +++ b/app/lib/dal/sqliteDAL/TxsDAL.ts @@ -173,7 +173,6 @@ export class TxsDAL extends AbstractSQLite { dbTx.received = moment().unix() dbTx.written = false dbTx.removed = false - //dbTx.hash = tx.getHash() return this.saveEntity(dbTx) } -- GitLab From 04d22756e4f15e27e8027faae4ccbfc0714c67ae Mon Sep 17 00:00:00 2001 From: cgeek Date: Tue, 14 Nov 2017 18:38:31 +0100 Subject: [PATCH 48/72] [enh] Sandbox: keep `pubkey` + add `issuer` control --- app/lib/dal/sqliteDAL/DocumentDAL.ts | 4 +++- app/lib/dal/sqliteDAL/SandBox.ts | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/lib/dal/sqliteDAL/DocumentDAL.ts b/app/lib/dal/sqliteDAL/DocumentDAL.ts index d427e3e5..a60aa335 100644 --- a/app/lib/dal/sqliteDAL/DocumentDAL.ts +++ b/app/lib/dal/sqliteDAL/DocumentDAL.ts @@ -1,3 +1,5 @@ export interface DBDocument { - issuers: string[]; + pubkey?: string + issuer?: string + issuers?: string[] } \ No newline at end of file diff --git a/app/lib/dal/sqliteDAL/SandBox.ts b/app/lib/dal/sqliteDAL/SandBox.ts index 8a0d3077..85ae101c 100644 --- a/app/lib/dal/sqliteDAL/SandBox.ts +++ b/app/lib/dal/sqliteDAL/SandBox.ts @@ -1,4 +1,4 @@ -import { DBDocument } from './DocumentDAL'; +import {DBDocument} from './DocumentDAL'; export class SandBox { @@ -13,7 +13,9 @@ export class SandBox { } async acceptNewSandBoxEntry(element:T, pubkey:string) { - if (element.issuers !== undefined && element.issuers.indexOf(pubkey) !== -1) { + if (element.pubkey === pubkey + || element.issuer === pubkey + || (element.issuers !== undefined && element.issuers.indexOf(pubkey) !== -1)) { return true; } const elements = await this.findElements() -- GitLab From 1408b5d05e6ae4258754b219188d69bf670923a6 Mon Sep 17 00:00:00 2001 From: cgeek Date: Tue, 14 Nov 2017 18:44:58 +0100 Subject: [PATCH 49/72] [enh] Sandbox: also missing the `from` case --- app/lib/dal/sqliteDAL/DocumentDAL.ts | 7 ++++--- app/lib/dal/sqliteDAL/SandBox.ts | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/lib/dal/sqliteDAL/DocumentDAL.ts b/app/lib/dal/sqliteDAL/DocumentDAL.ts index a60aa335..fe8fc2e0 100644 --- a/app/lib/dal/sqliteDAL/DocumentDAL.ts +++ b/app/lib/dal/sqliteDAL/DocumentDAL.ts @@ -1,5 +1,6 @@ export interface DBDocument { - pubkey?: string - issuer?: string - issuers?: string[] + pubkey?: string // idty table + from?: string // cert table + issuer?: string // membership table + issuers?: string[] // txs table } \ No newline at end of file diff --git a/app/lib/dal/sqliteDAL/SandBox.ts b/app/lib/dal/sqliteDAL/SandBox.ts index 85ae101c..fe96af44 100644 --- a/app/lib/dal/sqliteDAL/SandBox.ts +++ b/app/lib/dal/sqliteDAL/SandBox.ts @@ -13,7 +13,9 @@ export class SandBox { } async acceptNewSandBoxEntry(element:T, pubkey:string) { + // Accept any document which has the exception pubkey (= the node pubkey) if (element.pubkey === pubkey + || element.from === pubkey || element.issuer === pubkey || (element.issuers !== undefined && element.issuers.indexOf(pubkey) !== -1)) { return true; -- GitLab From f253bb6b9a5595062f0282b9c1b221aa7bd277fa Mon Sep 17 00:00:00 2001 From: cgeek Date: Tue, 14 Nov 2017 18:54:26 +0100 Subject: [PATCH 50/72] [fix] Revert my 2 lasts commits: original sandbox case was good --- app/lib/dal/sqliteDAL/DocumentDAL.ts | 5 +---- app/lib/dal/sqliteDAL/SandBox.ts | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/app/lib/dal/sqliteDAL/DocumentDAL.ts b/app/lib/dal/sqliteDAL/DocumentDAL.ts index fe8fc2e0..d2097d7f 100644 --- a/app/lib/dal/sqliteDAL/DocumentDAL.ts +++ b/app/lib/dal/sqliteDAL/DocumentDAL.ts @@ -1,6 +1,3 @@ export interface DBDocument { - pubkey?: string // idty table - from?: string // cert table - issuer?: string // membership table - issuers?: string[] // txs table + issuers?: string[] } \ No newline at end of file diff --git a/app/lib/dal/sqliteDAL/SandBox.ts b/app/lib/dal/sqliteDAL/SandBox.ts index fe96af44..09431c3a 100644 --- a/app/lib/dal/sqliteDAL/SandBox.ts +++ b/app/lib/dal/sqliteDAL/SandBox.ts @@ -14,10 +14,7 @@ export class SandBox { async acceptNewSandBoxEntry(element:T, pubkey:string) { // Accept any document which has the exception pubkey (= the node pubkey) - if (element.pubkey === pubkey - || element.from === pubkey - || element.issuer === pubkey - || (element.issuers !== undefined && element.issuers.indexOf(pubkey) !== -1)) { + if (element.issuers !== undefined && element.issuers.indexOf(pubkey) !== -1) { return true; } const elements = await this.findElements() -- GitLab From 89fa0a52c56dfc8968890b0b05f0374d31510afb Mon Sep 17 00:00:00 2001 From: cgeek Date: Tue, 14 Nov 2017 19:04:44 +0100 Subject: [PATCH 51/72] [fix] Wrong import --- app/modules/prover/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/modules/prover/index.ts b/app/modules/prover/index.ts index 624f456d..856e1423 100644 --- a/app/modules/prover/index.ts +++ b/app/modules/prover/index.ts @@ -22,7 +22,7 @@ export const ProverDependency = { conf.cpu = ProverConstants.DEFAULT_CPU; } if (conf.nbCores === null || conf.nbCores === undefined) { - conf.nbCores = Math.min(Constants.CORES_MAXIMUM_USE_IN_PARALLEL, require('os').cpus().length) + conf.nbCores = Math.min(ProverConstants.CORES_MAXIMUM_USE_IN_PARALLEL, require('os').cpus().length) } else if (conf.nbCores <= 0) { conf.nbCores = 1 } -- GitLab From 9e4ddd51fb2a21d7942830fca713ce186a19c453 Mon Sep 17 00:00:00 2001 From: librelois Date: Tue, 14 Nov 2017 22:19:05 +0100 Subject: [PATCH 52/72] remove Duplicate incoming Connections --- app/modules/ws2p/lib/WS2PServer.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/modules/ws2p/lib/WS2PServer.ts b/app/modules/ws2p/lib/WS2PServer.ts index de94ba4e..428b9f3c 100644 --- a/app/modules/ws2p/lib/WS2PServer.ts +++ b/app/modules/ws2p/lib/WS2PServer.ts @@ -144,6 +144,7 @@ export class WS2PServer extends events.EventEmitter { } async removeExcessIncomingConnections() { + await this.removeDuplicateConnections() const ws2pPublicMax = (this.server.conf.ws2p && this.server.conf.ws2p.maxPublic) ? this.server.conf.ws2p.maxPublic:10 let privilegedKeys = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[] while (this.countConnexions() > ws2pPublicMax) { @@ -151,6 +152,17 @@ export class WS2PServer extends events.EventEmitter { } } + async removeDuplicateConnections() { + let connectedPubkeys:string[] = [] + for (const c of this.connections) { + if (connectedPubkeys.indexOf(c.pubkey) !== -1) { + this.removeConnection(c) + } else if (c.pubkey !== this.server.conf.pair.pub) { + connectedPubkeys.push(c.pubkey) + } + } + } + async removeLowPriorityConnection(privilegedKeys:string[]) { let lowPriorityConnection:WS2PConnection = this.connections[0] let minPriorityLevel = this.keyPriorityLevel(lowPriorityConnection.pubkey, privilegedKeys) -- GitLab From 3c90b511992dacb7ee9ef9e00e96e7fc0857f705 Mon Sep 17 00:00:00 2001 From: librelois Date: Wed, 15 Nov 2017 03:43:09 +0100 Subject: [PATCH 53/72] retry travis test --- app/cli.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/cli.ts b/app/cli.ts index 3c2e4951..887724f4 100644 --- a/app/cli.ts +++ b/app/cli.ts @@ -1,7 +1,7 @@ const Command = require('commander').Command; const pjson = require('../package.json'); const duniter = require('../index'); - + export const ExecuteCommand = () => { const options:any = []; -- GitLab From fe063ef0584fcf3cee3eb449a29190817f7a0565 Mon Sep 17 00:00:00 2001 From: librelois Date: Wed, 15 Nov 2017 17:15:24 +0100 Subject: [PATCH 54/72] [fix] insoleet feedbacks --- app/lib/dto/PeerDTO.ts | 4 ++-- app/modules/ws2p/lib/WS2PCluster.ts | 15 +++++++++++---- app/modules/ws2p/lib/WS2PConnection.ts | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/lib/dto/PeerDTO.ts b/app/lib/dto/PeerDTO.ts index 4d735bd3..4b9555bf 100644 --- a/app/lib/dto/PeerDTO.ts +++ b/app/lib/dto/PeerDTO.ts @@ -103,9 +103,9 @@ export class PeerDTO implements Cloneable { let bestWS2PTORVersionAvailable:number = 0 for (const ep of this.endpoints) { if (canReachTorEp) { - let matches:any = ep.match(CommonConstants.WS2PTOR_V2_REGEXP) + let matches:RegExpMatchArray | null = ep.match(CommonConstants.WS2PTOR_V2_REGEXP) if (matches && parseInt(matches[1]) > bestWS2PTORVersionAvailable && (uuidExcluded.indexOf(matches[2]) === -1)) { - bestWS2PTORVersionAvailable = matches[1] + bestWS2PTORVersionAvailable = parseInt(matches[1]) api = { version: parseInt(matches[1]), uuid: matches[2], diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 8bcfd4fb..77719628 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -267,8 +267,7 @@ export class WS2PCluster { await this.ws2pServer.close() } this.ws2pServer = await WS2PServer.bindOn(this.server, host, port, this.fifo, (pubkey:string, connectedPubkeys:string[]) => { - const privilegedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[] - return this.acceptPubkey(pubkey, connectedPubkeys, [], () => this.servedCount(), this.maxLevel2Peers, privilegedNodes, (this.server.conf.ws2p !== undefined && this.server.conf.ws2p.privilegedOnly)) + return this.acceptPubkey(pubkey, connectedPubkeys, [], () => this.servedCount(), this.maxLevel2Peers, this.privilegedNodes(), (this.server.conf.ws2p !== undefined && this.server.conf.ws2p.privilegedOnly)) }, this.keyPriorityLevel, this.messageHandler) this.host = host this.port = port @@ -285,7 +284,7 @@ export class WS2PCluster { clientsCount() { let count = 0 - for (const ws2pid of Object.keys(this.ws2pClients)) { + for (const ws2pid in this.ws2pClients) { if (this.ws2pClients[ws2pid].connection.pubkey != this.server.conf.pair.pub) { count++ } @@ -295,7 +294,7 @@ export class WS2PCluster { numberOfConnectedPublicNodesWithSameKey() { let count = 0 - for (const ws2pid of Object.keys(this.ws2pClients)) { + for (const ws2pid in this.ws2pClients) { if (this.ws2pClients[ws2pid].connection.pubkey === this.server.conf.pair.pub) { count++ } @@ -307,6 +306,14 @@ export class WS2PCluster { return (this.ws2pServer) ? this.ws2pServer.countConnexions():0 } + privilegedNodes() { + if (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) { + return this.server.conf.ws2p.privilegedNodes + } else { + return  [] + } + } + async connectToRemoteWS(endpointVersion:number, host: string, port: number, path:string, messageHandler:WS2PMessageHandler, expectedPub:string, ws2pEndpointUUID:string = ""): Promise { const uuid = nuuid.v4() let pub = expectedPub.slice(0, 8) diff --git a/app/modules/ws2p/lib/WS2PConnection.ts b/app/modules/ws2p/lib/WS2PConnection.ts index f9687734..2d57a2ab 100644 --- a/app/modules/ws2p/lib/WS2PConnection.ts +++ b/app/modules/ws2p/lib/WS2PConnection.ts @@ -430,7 +430,7 @@ export class WS2PConnection { return this.errorDetected(WS2P_ERR.ALREADY_AUTHENTICATED_BY_REMOTE) } else if ( - typeof data.pub !== "string" || typeof data.sig !== "string" || typeof data.challenge !== "string" || (this.ws2pVersion > 1 && data.ws2pId !== "string") ) { + typeof data.pub !== "string" || typeof data.sig !== "string" || typeof data.challenge !== "string" || (this.ws2pVersion > 1 && typeof data.ws2pId !== "string") ) { await this.errorDetected(WS2P_ERR.AUTH_INVALID_ASK_FIELDS) } else { if (this.expectedPub && data.pub !== this.expectedPub) { -- GitLab From 7dda307f909b645ec19a32cf2fb8f8e09ab4ce2d Mon Sep 17 00:00:00 2001 From: librelois Date: Tue, 28 Nov 2017 01:31:32 +0100 Subject: [PATCH 55/72] [enh] #1205 #1214 --- app/modules/ws2p/lib/WS2PClient.ts | 2 +- app/modules/ws2p/lib/WS2PCluster.ts | 309 +++++++++++++++++-------- app/modules/ws2p/lib/WS2PConnection.ts | 15 +- app/modules/ws2p/lib/constants.ts | 3 +- test/integration/ws2p_connection.ts | 4 + 5 files changed, 230 insertions(+), 103 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PClient.ts b/app/modules/ws2p/lib/WS2PClient.ts index 830b3572..af885353 100644 --- a/app/modules/ws2p/lib/WS2PClient.ts +++ b/app/modules/ws2p/lib/WS2PClient.ts @@ -17,7 +17,7 @@ export class WS2PClient { const k2 = new Key(server.conf.pair.pub, server.conf.pair.sec) const myWs2pId = (server.conf.ws2p && server.conf.ws2p.uuid) ? server.conf.ws2p.uuid:"" const c = WS2PConnection.newConnectionToAddress( - Math.min(endpointVersion, WS2PConstants.WS2P_VERSION), + Math.min(endpointVersion, WS2PConstants.WS2P_API_VERSION), fullEndpointAddress, messageHandler, new WS2PPubkeyLocalAuth(server.conf.currency , k2, myWs2pId, allowKey), diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 2498faff..ff238cbf 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -26,6 +26,8 @@ const _ = require('underscore') export interface WS2PHead { message:string sig:string + messageV2?:string + sigV2?:string step?:number } @@ -99,13 +101,14 @@ export class WS2PCluster { const heads:WS2PHead[] = [] const ws2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) || '000000' const localPub = this.server.conf.pair.pub - const fullId = [localPub, ws2pId].join('-') - if (!this.headsCache[fullId]) { + const myFullId = [localPub, ws2pId].join('-') + if (!this.headsCache[myFullId]) { const current = await this.server.dal.getCurrentBlockOrNull() if (current) { - const { sig, message } = this.sayHeadChangedTo(current.number, current.hash) + const myHead = this.sayHeadChangedTo(current.number, current.hash) const blockstamp = [current.number, current.hash].join('-') - this.headsCache[fullId] = { blockstamp, message, sig } + this.headsCache[myFullId] = { blockstamp, message: myHead.message,sig: myHead.sig, messageV2: myHead.message, sigV2: myHead.sig } + } } for (const ws2pFullId of Object.keys(this.headsCache)) { @@ -121,94 +124,85 @@ export class WS2PCluster { const added:WS2PHead[] = [] await Promise.all(heads.map(async (h:WS2PHead) => { try { - const step = (h.step !== undefined) ? h.step:undefined + const step = h.step const message = h.message const sig = h.sig - if (!message) { - throw "EMPTY_MESSAGE_FOR_HEAD" - } - if (message.match(WS2PConstants.HEAD_V0_REGEXP)) { - const [,, pub, blockstamp]:string[] = message.split(':') - const ws2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) || '000000' - const fullId = [pub, ws2pId].join('-') - const sigOK = verify(message, sig, pub) - if (sigOK) { - // Already known? - if (!this.headsCache[fullId] || this.headsCache[fullId].blockstamp !== blockstamp) { - // More recent? - if (!this.headsCache[fullId] || parseInt(this.headsCache[fullId].blockstamp) < parseInt(blockstamp)) { - // Check that issuer is a member and that the block exists - const isAllowed = pub === this.server.conf.pair.pub || this.isConnectedKey(pub) || (await this.isMemberKey(pub)) - if (isAllowed) { - const exists = await this.existsBlock(blockstamp) - if (exists) { - this.headsCache[fullId] = { blockstamp, message, sig } - this.newHeads.push({message, sig}) - added.push({message, sig}) - // Cancel a pending "heads" to be spread - if (this.headsTimeout) { - clearTimeout(this.headsTimeout) - } - // Reprogram it a few moments later - this.headsTimeout = setTimeout(async () => { - const heads = this.newHeads.splice(0, this.newHeads.length) - if (heads.length) { - await this.spreadNewHeads(heads) - } - }, WS2PConstants.HEADS_SPREAD_TIMEOUT) - } - } - } - } - } else { + const messageV2 = h.messageV2 + const sigV2 = h.sigV2 + let sigOK = false + let fullId = '' + let pubkey = '' + let blockstamp = '' + if (messageV2) { + if (!sigV2) { throw "HEAD_MESSAGE_WRONGLY_SIGNED" } - } - else if (message.match(WS2PConstants.HEAD_V1_REGEXP)) { - const [,,, pub, blockstamp, ws2pId, software, softVersion, prefix]:string[] = message.split(':') - const sigOK = verify(message, sig, pub) + const [,,, pub, blockstamp, ws2pId,,,,,]:string[] = messageV2.split(':') const fullId = [pub, ws2pId].join('-') - if (sigOK) { - // Already known? - if (!this.headsCache[fullId] || this.headsCache[fullId].blockstamp !== blockstamp) { - // More recent? - if (!this.headsCache[fullId] || parseInt(this.headsCache[fullId].blockstamp) < parseInt(blockstamp)) { - // Check that issuer is a member and that the block exists - const isAllowed = pub === this.server.conf.pair.pub || this.isConnectedKey(pub) || (await this.isMemberKey(pub)) - if (isAllowed) { - const exists = await this.existsBlock(blockstamp) - if (exists) { - this.headsCache[fullId] = { blockstamp, message, sig } - this.newHeads.push({message, sig}) - added.push({message, sig}) - // Cancel a pending "heads" to be spread - if (this.headsTimeout) { - clearTimeout(this.headsTimeout) - } - // Reprogram it a few moments later - this.headsTimeout = setTimeout(async () => { - const heads = this.newHeads.splice(0, this.newHeads.length) - if (heads.length) { - await this.spreadNewHeads(heads) - } - }, WS2PConstants.HEADS_SPREAD_TIMEOUT) - } - } - } - } - } else { - throw "HEAD_MESSAGE_WRONGLY_SIGNED" + this.headReceived(messageV2, sigV2, pub, fullId, blockstamp) + } + if (!message) { + throw "EMPTY_MESSAGE_FOR_HEAD" + } + if (message.match(WS2PConstants.HEAD_V0_REGEXP)) { + const [,, pub, blockstamp]:string[] = message.split(':') + const ws2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) || '000000' + const fullId = [pub, ws2pId].join('-') + this.headReceived(message, sig, pub, fullId, blockstamp) } + else if (message.match(WS2PConstants.HEAD_V1_REGEXP)) { + const [,,, pub, blockstamp, ws2pId, software, softVersion, prefix]:string[] = message.split(':') + const sigOK = verify(message, sig, pub) + const fullId = [pub, ws2pId].join('-') + await this.headReceived(message, sig, pub, fullId, blockstamp) + } + } catch (e) { + this.server.logger.trace(e) } - } catch (e) { - this.server.logger.trace(e) - } })) this.server.push({ ws2p: 'heads', - added + added: this.newHeads }) - return added + this.newHeads = [] + } + + private async headReceived(message:string, sig:string, pub:string, fullId:string, blockstamp:string) { + try { + const sigOK = verify(message, sig, pub) + if (sigOK) { + // Already known? + if (!this.headsCache[fullId] || this.headsCache[fullId].blockstamp !== blockstamp) { + // More recent? + if (!this.headsCache[fullId] || parseInt(this.headsCache[fullId].blockstamp) < parseInt(blockstamp)) { + // Check that issuer is a member and that the block exists + const isAllowed = pub === this.server.conf.pair.pub || this.isConnectedKey(pub) || (await this.isMemberKey(pub)) + if (isAllowed) { + const exists = await this.existsBlock(blockstamp) + if (exists) { + this.headsCache[fullId] = { blockstamp, message, sig } + this.newHeads.push({message, sig}) + // Cancel a pending "heads" to be spread + if (this.headsTimeout) { + clearTimeout(this.headsTimeout) + } + // Reprogram it a few moments later + this.headsTimeout = setTimeout(async () => { + const heads = this.newHeads.splice(0, this.newHeads.length) + if (heads.length) { + await this.spreadNewHeads(heads) + } + }, WS2PConstants.HEADS_SPREAD_TIMEOUT) + } + } + } + } + } else { + throw "HEAD_MESSAGE_WRONGLY_SIGNED" + } + } catch (e) { + this.server.logger.trace(e) + } } private async isMemberKey(pub:string) { @@ -366,6 +360,7 @@ export class WS2PCluster { const prefered = ((this.server.conf.ws2p && this.server.conf.ws2p.preferedNodes) || []).slice() // Copy // Our key is also a prefered one, so we connect to our siblings const canReachTorEndpoint = ProxiesConf.canReachTorEndpoint(this.server.conf.proxiesConf) + const canReachClearEndpoint = ProxiesConf.canReachClearEndpoint(this.server.conf.proxiesConf) peers.sort((a, b) => { // Top priority at our own nodes if (a.pubkey === this.server.conf.pair.pub && b.pubkey !== this.server.conf.pair.pub) { @@ -376,6 +371,8 @@ export class WS2PCluster { const aIsPrefered = prefered.indexOf(a.pubkey) !== -1 const bIsPrefered = prefered.indexOf(b.pubkey) !== -1 + const aNumberOfFreeRooms = this.numberOfFreeRooms(a, canReachTorEndpoint, canReachClearEndpoint) + const bNumberOfFreeRooms = this.numberOfFreeRooms(b, canReachTorEndpoint, canReachClearEndpoint) if (canReachTorEndpoint) { const aAtWs2pTorEnpoint = a.endpoints.filter(function (element) { return element.match(CommonConstants.WS2PTOR_REGEXP); }).length > 0 @@ -383,30 +380,36 @@ export class WS2PCluster { if ( (aAtWs2pTorEnpoint && bAtWs2pTorEnpoint) || (!aAtWs2pTorEnpoint && !bAtWs2pTorEnpoint) ) { if ((aIsPrefered && bIsPrefered) || (!aIsPrefered && !bIsPrefered)) { + if (aNumberOfFreeRooms > bNumberOfFreeRooms) { + return -1 + } else if (aNumberOfFreeRooms < bNumberOfFreeRooms) { + return 1 + } return 0 } else if (aIsPrefered) { return -1 - } else { - return 1 } + return 1 } else { if (aAtWs2pTorEnpoint) { return -1 - } else { - return 1 } + return 1 } } else { if ((aIsPrefered && bIsPrefered) || (!aIsPrefered && !bIsPrefered)) { + if (aNumberOfFreeRooms > bNumberOfFreeRooms) { + return -1 + } else if (aNumberOfFreeRooms < bNumberOfFreeRooms) { + return 1 + } return 0 } else if (aIsPrefered) { return -1 - } else { - return 1 } + return 1 } }) - const canReachClearEndpoint = ProxiesConf.canReachClearEndpoint(this.server.conf.proxiesConf) let i = 0 let countPublicNodesWithSameKey:number = 1 // Necessary if maxPrivate = 0 let endpointsNodesWithSameKey:WS2PEndpoint[] = [] @@ -426,7 +429,7 @@ export class WS2PCluster { } } } else { - const api = p.getOnceWS2PEndpoint(canReachTorEndpoint, canReachClearEndpoint) + const api = p.getOnceWS2PEndpoint(canReachTorEndpoint, canReachClearEndpoint) if (api) { try { // We do not connect to local host @@ -442,6 +445,22 @@ export class WS2PCluster { } } + private numberOfFreeRooms(p:PeerDTO, canReachTorEndpoint:boolean, canReachClearEndpoint:boolean) { + const api = p.getOnceWS2PEndpoint(canReachTorEndpoint, canReachClearEndpoint) + if (api) { + for (const ws2pFullId in this.headsCache) { + if (ws2pFullId.slice(0, 8) == api.uuid) { + const messageV2 = this.headsCache[ws2pFullId].messageV2 + if (messageV2 !== undefined) { + const [,,, pub, blockstamp, ws2pId,,,,freeMemberRoom,freeMirorRoom]:string[] = messageV2.split(':') + return (this.server.dal.isMember(this.server.conf.pair.pub)) ? freeMemberRoom:freeMirorRoom + } + } + } + } + return 0 + } + listenServerFlow() { let connectingToNodesByFlow = false @@ -475,9 +494,9 @@ export class WS2PCluster { // HEAD changed else if (data.bcEvent === OtherConstants.BC_EVENT.HEAD_CHANGED || data.bcEvent === OtherConstants.BC_EVENT.SWITCHED) { // Propagate this change to the network - const { sig, message } = this.sayHeadChangedTo(data.block.number, data.block.hash) + const myHead = this.sayHeadChangedTo(data.block.number, data.block.hash) try { - await this.broadcastHead(message, sig) + await this.broadcastHead(myHead) } catch (e) { this.server.logger.warn(e) } @@ -488,33 +507,123 @@ export class WS2PCluster { })) } - private async broadcastHead(message:string, sig:string) { - await this.headsReceived([{ message, sig }]) - return this.spreadNewHeads([{ message, sig }]) + private async broadcastHead(head:WS2PHead) { + await this.headsReceived([head]) + return this.spreadNewHeads([head]) } - private async spreadNewHeads(heads:{ message:string, sig:string }[]) { + private async spreadNewHeads(heads:WS2PHead[]) { + heads = this.incrementHeadsStep(heads) const connexions = this.getAllConnections() return Promise.all(connexions.map(async (c) => { try { - await c.pushHeads(heads) + if (c.version >= 2) { + await c.pushHeadsV2(heads) + } else { + await c.pushHeads(heads) + } } catch (e) { this.server.logger.warn('Could not spread new HEAD info to %s WS2PID %s', c.pubkey, c.uuid) } })) } + private incrementHeadsStep(heads:WS2PHead[]) { + for (let head of heads) { + if (head.step) { + head.step++ + } + } + return heads + } + private sayHeadChangedTo(number:number, hash:string) { - const api = (this.server.conf.ws2p && this.server.conf.ws2p.remotehost && this.server.conf.ws2p.remotehost.match(WS2PConstants.HOST_ONION_REGEX)) ? 'WS2P':'WS2P' + const api = this.getApi() const key = new Key(this.server.conf.pair.pub, this.server.conf.pair.sec) - const pub = key.publicKey const software = 'duniter' const softVersion = Package.getInstance().version const ws2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) || '00000000' const prefix = this.server.conf.prefix || ProverConstants.DEFAULT_PEER_ID - const message = `${api}:HEAD:1:${pub}:${number}-${hash}:${ws2pId}:${software}:${softVersion}:${prefix}` + const { freeMemberRoom , freeMirorRoom } = this.countFreeRooms() + const message = `${api}:HEAD:1:${key.publicKey}:${number}-${hash}:${ws2pId}:${software}:${softVersion}:${prefix}` const sig = key.signSync(message) - return { sig, message, pub } + const messageV2 = `${api}:HEAD:2:${key.publicKey}:${number}-${hash}:${ws2pId}:${software}:${softVersion}:${prefix}:${freeMemberRoom}:${freeMirorRoom}` + const sigV2 = key.signSync(messageV2) + + const myHead:WS2PHead = { + message, + sig, + messageV2, + sigV2, + step: 0 } + + return myHead + } + + private getApi() { + let api = 'WS2P' + let network = '' + let ws2pPrivate = '' + let ws2pPublic = '' + if (this.server.conf.proxiesConf && (this.server.conf.proxiesConf.proxyTorAddress || this.server.conf.proxiesConf.forceTor)) { + network = 'TOR' + } + if (this.server.conf.ws2p) { + if (this.server.conf.ws2p.remotehost) { + if (this.server.conf.ws2p.remotehost.match(WS2PConstants.HOST_ONION_REGEX)) { + network = 'TOR' + } + if (this.server.conf.ws2p.publicAccess) { + ws2pPublic = 'I' + switch (network) { + case 'TOR': ws2pPublic += 'T'; break; + default: ws2pPublic += 'C'; break; + } + } + } + if (this.server.conf.ws2p.privateAccess) { + ws2pPrivate = 'O' + switch (network) { + case 'TOR': ws2pPrivate += 'T'; + if (this.server.conf.proxiesConf && this.server.conf.proxiesConf.reachingClearEp) { + switch (this.server.conf.proxiesConf.reachingClearEp) { + case 'none': ws2pPrivate += 'S'; break; + case 'tor': ws2pPrivate += 'A'; break; + default: ws2pPrivate += 'M'; break; + } + } + break; + default: ws2pPrivate += 'C'; break; + } + } + } + + + api += network + ws2pPrivate + ws2pPublic + return api + } + + private countFreeRooms() { + if (!this.ws2pServer) { + return { + freeMemberRoom: 0, + freeMirorRoom: 0 + } + } + + let freeMirorRoom = this.maxLevel2Peers - this.ws2pServer.countConnexions() + let freeMemberRoom = freeMirorRoom + const privilegedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[] + for (const c of this.ws2pServer.getConnexions()) { + if (this.keyPriorityLevel(c.pubkey, privilegedNodes) < WS2PConstants.CONNECTIONS_PRIORITY.MEMBER_KEY_LEVEL) { + freeMemberRoom++ + } + } + + return { + freeMemberRoom, + freeMirorRoom + } } async removeLowPriorityConnections(privilegedKeys:string[]) { diff --git a/app/modules/ws2p/lib/WS2PConnection.ts b/app/modules/ws2p/lib/WS2PConnection.ts index 2d57a2ab..72d30ace 100644 --- a/app/modules/ws2p/lib/WS2PConnection.ts +++ b/app/modules/ws2p/lib/WS2PConnection.ts @@ -6,7 +6,7 @@ import {CertificationDTO} from "../../../lib/dto/CertificationDTO" import {MembershipDTO} from "../../../lib/dto/MembershipDTO" import {TransactionDTO} from "../../../lib/dto/TransactionDTO" import {PeerDTO} from "../../../lib/dto/PeerDTO" -import {WS2PConstants} from "./constants" +import { WS2PConstants } from './constants'; import { ProxiesConf } from '../../../lib/proxy'; const ws = require('ws') const SocksProxyAgent = require('socks-proxy-agent'); @@ -54,6 +54,7 @@ export interface WS2PRemoteAuth extends WS2PAuth { registerOK(sig: string): Promise isAuthenticatedByRemote(): boolean getPubkey(): string + getVersion(): number } export interface WS2PLocalAuth extends WS2PAuth { @@ -89,6 +90,10 @@ export class WS2PPubkeyRemoteAuth implements WS2PRemoteAuth { }) } + getVersion() { + return this.remoteVersion + } + getPubkey() { return this.remotePub } @@ -339,6 +344,10 @@ export class WS2PConnection { return new WS2PConnection(WS2PConstants.WS2P_DEFAULT_VERSION, websocket, onWsOpened, onWsClosed, messageHandler, localAuth, remoteAuth, options, expectedPub) } + get version() { + return Math.min(WS2PConstants.WS2P_HEAD_VERSION, this.remoteAuth.getVersion()) + } + get pubkey() { return this.remoteAuth.getPubkey() } @@ -610,6 +619,10 @@ export class WS2PConnection { return this.pushData(WS2P_PUSH.HEAD, 'heads', heads) } + async pushHeadsV2(heads:{ message:string, sig:string, messageV2?:string, sigV2?:string, step?:number }[]) { + return this.pushData(WS2P_PUSH.HEAD, 'heads', heads) + } + async pushData(type:WS2P_PUSH, key:string, data:any) { await this.connect() return new Promise((resolve, reject) => { diff --git a/app/modules/ws2p/lib/constants.ts b/app/modules/ws2p/lib/constants.ts index 25e37e2c..74d5c586 100644 --- a/app/modules/ws2p/lib/constants.ts +++ b/app/modules/ws2p/lib/constants.ts @@ -2,7 +2,8 @@ import {CommonConstants} from "../../../lib/common-libs/constants" export const WS2PConstants = { WS2P_DEFAULT_VERSION:1, - WS2P_VERSION: 1, + WS2P_API_VERSION: 1, + WS2P_HEAD_VERSION: 2, WS2P_UPNP_TTL: 600, WS2P_PORTS_START: 20900, diff --git a/test/integration/ws2p_connection.ts b/test/integration/ws2p_connection.ts index 73826eb0..e444726b 100644 --- a/test/integration/ws2p_connection.ts +++ b/test/integration/ws2p_connection.ts @@ -415,6 +415,10 @@ class WS2PNoLocalAuth implements WS2PLocalAuth { class WS2PNoRemoteAuth implements WS2PRemoteAuth { + getVersion(): number { + return 1 + } + getPubkey(): string { return "" } -- GitLab From 5230520f384326046c9e772e895b3cb2615c6939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Tue, 28 Nov 2017 00:41:50 +0000 Subject: [PATCH 56/72] Add new file --- .gitlab-ci.yml | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..1e70f0a8 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,55 @@ +stages: + - github-sync + - test + + +push_to_github: + stage: github-sync + variables: + GIT_STRATEGY: none + tags: + - github + script: + - rm -rf ./* + - rm -rf .git + - git clone --mirror $CI_REPOSITORY_URL . + - git remote add github $GITHUB_URL_AND_KEY + - git config --global user.email "contact@duniter.org" + - git config --global user.name "Duniter" + # Job would fail if we don't remove refs about pull requests + - bash -c "cat packed-refs | grep -v 'refs/pull' > packed-refs-new; echo 'Removed pull refs.'" + - mv packed-refs-new packed-refs + - bash -c "git push --force --mirror github 2>&1 | grep -v duniter-gitlab; echo $?" + +enforce_readme: + stage: github-sync + variables: + GIT_STRATEGY: none + tags: + - github + script: + - rm -rf ./* + - rm -rf .git + - git clone $GITHUB_URL_AND_KEY . + - git config --global user.email "contact@duniter.org" + - git config --global user.name "Duniter" + - git checkout master + - cat .github/github_disclaimer.md > README.md.new + - cat README.md >> README.md.new + - mv README.md.new README.md + - git commit -am "Enforce github readme" + - git push origin master + +test: + stage: test + tags: + - nodejs + image: registry.duniter.org/docker/ubuntu-node:17.10-DUNITER-2 + script: + - bash -c ". ~/.nvm/nvm.sh && npm install -g yarn" + - bash -c ". ~/.nvm/nvm.sh && yarn install" + - bash -c ". ~/.nvm/nvm.sh && yarn run test-travis" + cache: + paths: + - node_modules/ + -- GitLab From 1237abbcf1137adf2bfaa78af18d37cc37ae7203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Tue, 28 Nov 2017 01:15:12 +0000 Subject: [PATCH 57/72] Update .gitlab-ci.yml --- .gitlab-ci.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1e70f0a8..b0dbca2b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,5 @@ stages: - github-sync - - test push_to_github: @@ -39,17 +38,4 @@ enforce_readme: - mv README.md.new README.md - git commit -am "Enforce github readme" - git push origin master - -test: - stage: test - tags: - - nodejs - image: registry.duniter.org/docker/ubuntu-node:17.10-DUNITER-2 - script: - - bash -c ". ~/.nvm/nvm.sh && npm install -g yarn" - - bash -c ". ~/.nvm/nvm.sh && yarn install" - - bash -c ". ~/.nvm/nvm.sh && yarn run test-travis" - cache: - paths: - - node_modules/ -- GitLab From 3a604a7638218a8bd9a55dfd8c8752a971a7e255 Mon Sep 17 00:00:00 2001 From: librelois Date: Tue, 28 Nov 2017 17:45:19 +0100 Subject: [PATCH 58/72] [fix] integration test ws2p_heads --- test/integration/ws2p_heads.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/ws2p_heads.ts b/test/integration/ws2p_heads.ts index 7f0e78e5..7d20af4b 100644 --- a/test/integration/ws2p_heads.ts +++ b/test/integration/ws2p_heads.ts @@ -86,7 +86,7 @@ describe("WS2P heads propagation", function() { b3 = s1.commit({ time: now }) await Promise.all([ s2.waitToHaveBlock(3), - s2.waitForHeads(1) + s2.waitForHeads(2) // head v2 + head v1 ]) await s1.expect('/network/ws2p/info', (res:any) => { assert.equal(res.peers.level1, 0) -- GitLab From 294b85b8db097ab4f17fa9b284859e207b28ef74 Mon Sep 17 00:00:00 2001 From: librelois Date: Tue, 28 Nov 2017 21:07:07 +0100 Subject: [PATCH 59/72] [fix] ws2pHead V2 --- app/modules/ws2p/lib/WS2PCluster.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index ff238cbf..6467efd6 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -107,14 +107,17 @@ export class WS2PCluster { if (current) { const myHead = this.sayHeadChangedTo(current.number, current.hash) const blockstamp = [current.number, current.hash].join('-') - this.headsCache[myFullId] = { blockstamp, message: myHead.message,sig: myHead.sig, messageV2: myHead.message, sigV2: myHead.sig } + this.headsCache[myFullId] = { blockstamp, message: myHead.message, sig: myHead.sig, messageV2: myHead.messageV2, sigV2: myHead.sigV2, step:myHead.step } } } for (const ws2pFullId of Object.keys(this.headsCache)) { heads.push({ message: this.headsCache[ws2pFullId].message, - sig: this.headsCache[ws2pFullId].sig + sig: this.headsCache[ws2pFullId].sig, + messageV2: this.headsCache[ws2pFullId].messageV2, + sigV2: this.headsCache[ws2pFullId].sigV2, + step: this.headsCache[ws2pFullId].step }) } return heads -- GitLab From 3be08088f2e01a457734c4cdc383c43fa4a974c4 Mon Sep 17 00:00:00 2001 From: librelois Date: Tue, 28 Nov 2017 21:44:45 +0100 Subject: [PATCH 60/72] [fix] step reception --- app/modules/ws2p/lib/WS2PCluster.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 6467efd6..8c4bc952 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -142,7 +142,7 @@ export class WS2PCluster { } const [,,, pub, blockstamp, ws2pId,,,,,]:string[] = messageV2.split(':') const fullId = [pub, ws2pId].join('-') - this.headReceived(messageV2, sigV2, pub, fullId, blockstamp) + this.headReceived(messageV2, sigV2, pub, fullId, blockstamp, step) } if (!message) { throw "EMPTY_MESSAGE_FOR_HEAD" @@ -170,7 +170,7 @@ export class WS2PCluster { this.newHeads = [] } - private async headReceived(message:string, sig:string, pub:string, fullId:string, blockstamp:string) { + private async headReceived(message:string, sig:string, pub:string, fullId:string, blockstamp:string, step?:number) { try { const sigOK = verify(message, sig, pub) if (sigOK) { @@ -183,8 +183,8 @@ export class WS2PCluster { if (isAllowed) { const exists = await this.existsBlock(blockstamp) if (exists) { - this.headsCache[fullId] = { blockstamp, message, sig } - this.newHeads.push({message, sig}) + this.headsCache[fullId] = { blockstamp, message, sig, step } + this.newHeads.push({message, sig, step}) // Cancel a pending "heads" to be spread if (this.headsTimeout) { clearTimeout(this.headsTimeout) -- GitLab From 032d928dba7d9ea721a97e889913a04040fe31ca Mon Sep 17 00:00:00 2001 From: librelois Date: Wed, 29 Nov 2017 15:45:03 +0100 Subject: [PATCH 61/72] [fix] ws2p step incrementation --- app/modules/ws2p/lib/WS2PCluster.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 8c4bc952..decebbf7 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -533,7 +533,7 @@ export class WS2PCluster { private incrementHeadsStep(heads:WS2PHead[]) { for (let head of heads) { - if (head.step) { + if (head.step !== undefined) { head.step++ } } -- GitLab From 813e3352db13d57d7bf824aa3ebc77db49ffea6b Mon Sep 17 00:00:00 2001 From: librelois Date: Wed, 29 Nov 2017 16:13:57 +0100 Subject: [PATCH 62/72] [fix] head network stats --- app/modules/ws2p/lib/WS2PCluster.ts | 18 +++++++++++------- app/modules/ws2p/lib/WS2PConnection.ts | 2 +- app/modules/ws2p/lib/constants.ts | 14 +++++++++++++- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index decebbf7..e60bad06 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -1,3 +1,4 @@ +import { DEFAULT_ENCODING } from 'crypto'; import {WS2PServer} from "./WS2PServer" import {Server} from "../../../../server" import {WS2PClient} from "./WS2PClient" @@ -565,29 +566,32 @@ export class WS2PCluster { private getApi() { let api = 'WS2P' - let network = '' + let network = { + in: WS2PConstants.NETWORK.INCOMING.DEFAULT, + out: WS2PConstants.NETWORK.OUTCOMING.DEFAULT, + } let ws2pPrivate = '' let ws2pPublic = '' if (this.server.conf.proxiesConf && (this.server.conf.proxiesConf.proxyTorAddress || this.server.conf.proxiesConf.forceTor)) { - network = 'TOR' + network.out = WS2PConstants.NETWORK.OUTCOMING.TOR } if (this.server.conf.ws2p) { if (this.server.conf.ws2p.remotehost) { if (this.server.conf.ws2p.remotehost.match(WS2PConstants.HOST_ONION_REGEX)) { - network = 'TOR' + network.in = WS2PConstants.NETWORK.INCOMING.TOR } if (this.server.conf.ws2p.publicAccess) { ws2pPublic = 'I' - switch (network) { - case 'TOR': ws2pPublic += 'T'; break; + switch (network.in) { + case WS2PConstants.NETWORK.INCOMING.TOR: ws2pPublic += 'T'; break; default: ws2pPublic += 'C'; break; } } } if (this.server.conf.ws2p.privateAccess) { ws2pPrivate = 'O' - switch (network) { - case 'TOR': ws2pPrivate += 'T'; + switch (network.out) { + case WS2PConstants.NETWORK.OUTCOMING.TOR: ws2pPrivate += 'T'; if (this.server.conf.proxiesConf && this.server.conf.proxiesConf.reachingClearEp) { switch (this.server.conf.proxiesConf.reachingClearEp) { case 'none': ws2pPrivate += 'S'; break; diff --git a/app/modules/ws2p/lib/WS2PConnection.ts b/app/modules/ws2p/lib/WS2PConnection.ts index 72d30ace..64e85414 100644 --- a/app/modules/ws2p/lib/WS2PConnection.ts +++ b/app/modules/ws2p/lib/WS2PConnection.ts @@ -341,7 +341,7 @@ export class WS2PConnection { const onWsClosed:Promise = new Promise(res => { websocket.on('close', () => res()) }) - return new WS2PConnection(WS2PConstants.WS2P_DEFAULT_VERSION, websocket, onWsOpened, onWsClosed, messageHandler, localAuth, remoteAuth, options, expectedPub) + return new WS2PConnection(WS2PConstants.WS2P_DEFAULT_API_VERSION, websocket, onWsOpened, onWsClosed, messageHandler, localAuth, remoteAuth, options, expectedPub) } get version() { diff --git a/app/modules/ws2p/lib/constants.ts b/app/modules/ws2p/lib/constants.ts index 74d5c586..0a281b56 100644 --- a/app/modules/ws2p/lib/constants.ts +++ b/app/modules/ws2p/lib/constants.ts @@ -1,7 +1,19 @@ import {CommonConstants} from "../../../lib/common-libs/constants" export const WS2PConstants = { - WS2P_DEFAULT_VERSION:1, + NETWORK: { + INCOMING: { + DEFAULT: 0, + TOR: 1 + }, + OUTCOMING: { + DEFAULT: 0, + TOR: 1 + }, + }, + + WS2P_DEFAULT_API_VERSION:1, + WS2P_DEFAULT_HEAD_VERSION:1, WS2P_API_VERSION: 1, WS2P_HEAD_VERSION: 2, -- GitLab From eb3532eab572f4a9196f1797ed6644042a87ef4e Mon Sep 17 00:00:00 2001 From: librelois Date: Wed, 29 Nov 2017 16:18:38 +0100 Subject: [PATCH 63/72] [fix] error in head api --- app/modules/ws2p/lib/WS2PCluster.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index e60bad06..8faf0aed 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -606,7 +606,7 @@ export class WS2PCluster { } - api += network + ws2pPrivate + ws2pPublic + api += ws2pPrivate + ws2pPublic return api } -- GitLab From 9b84d20d53187e9229c041e0e8f3911c14290099 Mon Sep 17 00:00:00 2001 From: librelois Date: Wed, 29 Nov 2017 17:03:24 +0100 Subject: [PATCH 64/72] [fix] ws2p : broadcast headv2 + head v1 --- app/modules/ws2p/lib/WS2PCluster.ts | 51 +++++++++----------------- app/modules/ws2p/lib/WS2PConnection.ts | 6 +-- 2 files changed, 19 insertions(+), 38 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 8faf0aed..b25aaec9 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -128,37 +128,25 @@ export class WS2PCluster { const added:WS2PHead[] = [] await Promise.all(heads.map(async (h:WS2PHead) => { try { - const step = h.step - const message = h.message - const sig = h.sig - const messageV2 = h.messageV2 - const sigV2 = h.sigV2 - let sigOK = false - let fullId = '' - let pubkey = '' - let blockstamp = '' - if (messageV2) { - if (!sigV2) { + if (h.messageV2) { + if (!h.sigV2) { throw "HEAD_MESSAGE_WRONGLY_SIGNED" } - const [,,, pub, blockstamp, ws2pId,,,,,]:string[] = messageV2.split(':') - const fullId = [pub, ws2pId].join('-') - this.headReceived(messageV2, sigV2, pub, fullId, blockstamp, step) + const [,,, pub, blockstamp, ws2pId,,,,,]:string[] = h.messageV2.split(':') + this.headReceived(h, pub, [pub, ws2pId].join('-'), blockstamp) } - if (!message) { + if (!h.message) { throw "EMPTY_MESSAGE_FOR_HEAD" } - if (message.match(WS2PConstants.HEAD_V0_REGEXP)) { - const [,, pub, blockstamp]:string[] = message.split(':') + if (h.message.match(WS2PConstants.HEAD_V0_REGEXP)) { + const [,, pub, blockstamp]:string[] = h.message.split(':') const ws2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) || '000000' - const fullId = [pub, ws2pId].join('-') - this.headReceived(message, sig, pub, fullId, blockstamp) + this.headReceived(h, pub, [pub, ws2pId].join('-'), blockstamp) } - else if (message.match(WS2PConstants.HEAD_V1_REGEXP)) { - const [,,, pub, blockstamp, ws2pId, software, softVersion, prefix]:string[] = message.split(':') - const sigOK = verify(message, sig, pub) - const fullId = [pub, ws2pId].join('-') - await this.headReceived(message, sig, pub, fullId, blockstamp) + else if (h.message.match(WS2PConstants.HEAD_V1_REGEXP)) { + const [,,, pub, blockstamp, ws2pId, software, softVersion, prefix]:string[] = h.message.split(':') + const fullId = + await this.headReceived(h, pub, [pub, ws2pId].join('-'), blockstamp) } } catch (e) { this.server.logger.trace(e) @@ -171,10 +159,11 @@ export class WS2PCluster { this.newHeads = [] } - private async headReceived(message:string, sig:string, pub:string, fullId:string, blockstamp:string, step?:number) { + private async headReceived(head:WS2PHead, pub:string, fullId:string, blockstamp:string) { try { - const sigOK = verify(message, sig, pub) - if (sigOK) { + const sigOK = verify(head.message, head.sig, pub) + const sigV2OK = (head.messageV2 !== undefined && head.sigV2 !== undefined) ? verify(head.messageV2, head.sigV2, pub):false + if ((sigV2OK && sigOK) || sigOK) { // Already known? if (!this.headsCache[fullId] || this.headsCache[fullId].blockstamp !== blockstamp) { // More recent? @@ -184,8 +173,8 @@ export class WS2PCluster { if (isAllowed) { const exists = await this.existsBlock(blockstamp) if (exists) { - this.headsCache[fullId] = { blockstamp, message, sig, step } - this.newHeads.push({message, sig, step}) + this.headsCache[fullId] = { blockstamp, message: head.message, sig: head.sig, messageV2: head.messageV2, sigV2: head.sigV2, step: head.step } + this.newHeads.push(head) // Cancel a pending "heads" to be spread if (this.headsTimeout) { clearTimeout(this.headsTimeout) @@ -521,11 +510,7 @@ export class WS2PCluster { const connexions = this.getAllConnections() return Promise.all(connexions.map(async (c) => { try { - if (c.version >= 2) { - await c.pushHeadsV2(heads) - } else { await c.pushHeads(heads) - } } catch (e) { this.server.logger.warn('Could not spread new HEAD info to %s WS2PID %s', c.pubkey, c.uuid) } diff --git a/app/modules/ws2p/lib/WS2PConnection.ts b/app/modules/ws2p/lib/WS2PConnection.ts index 64e85414..752a3cf4 100644 --- a/app/modules/ws2p/lib/WS2PConnection.ts +++ b/app/modules/ws2p/lib/WS2PConnection.ts @@ -615,11 +615,7 @@ export class WS2PConnection { return this.pushData(WS2P_PUSH.PEER, 'peer', peer) } - async pushHeads(heads:{ message:string, sig:string }[]) { - return this.pushData(WS2P_PUSH.HEAD, 'heads', heads) - } - - async pushHeadsV2(heads:{ message:string, sig:string, messageV2?:string, sigV2?:string, step?:number }[]) { + async pushHeads(heads:{ message:string, sig:string, messageV2?:string, sigV2?:string, step?:number }[]) { return this.pushData(WS2P_PUSH.HEAD, 'heads', heads) } -- GitLab From cb1ae9b79185ef83a35a8f359e7f131d6f9a5b92 Mon Sep 17 00:00:00 2001 From: librelois Date: Wed, 29 Nov 2017 21:43:44 +0100 Subject: [PATCH 65/72] [fix] #1214 accept closer heads --- app/modules/ws2p/lib/WS2PCluster.ts | 45 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index b25aaec9..28726455 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -164,29 +164,30 @@ export class WS2PCluster { const sigOK = verify(head.message, head.sig, pub) const sigV2OK = (head.messageV2 !== undefined && head.sigV2 !== undefined) ? verify(head.messageV2, head.sigV2, pub):false if ((sigV2OK && sigOK) || sigOK) { - // Already known? - if (!this.headsCache[fullId] || this.headsCache[fullId].blockstamp !== blockstamp) { - // More recent? - if (!this.headsCache[fullId] || parseInt(this.headsCache[fullId].blockstamp) < parseInt(blockstamp)) { - // Check that issuer is a member and that the block exists - const isAllowed = pub === this.server.conf.pair.pub || this.isConnectedKey(pub) || (await this.isMemberKey(pub)) - if (isAllowed) { - const exists = await this.existsBlock(blockstamp) - if (exists) { - this.headsCache[fullId] = { blockstamp, message: head.message, sig: head.sig, messageV2: head.messageV2, sigV2: head.sigV2, step: head.step } - this.newHeads.push(head) - // Cancel a pending "heads" to be spread - if (this.headsTimeout) { - clearTimeout(this.headsTimeout) - } - // Reprogram it a few moments later - this.headsTimeout = setTimeout(async () => { - const heads = this.newHeads.splice(0, this.newHeads.length) - if (heads.length) { - await this.spreadNewHeads(heads) - } - }, WS2PConstants.HEADS_SPREAD_TIMEOUT) + // Already known or more recent or closer ? + const step = this.headsCache[fullId].step || 0 + if (!this.headsCache[fullId] // unknow head + || parseInt(this.headsCache[fullId].blockstamp) < parseInt(blockstamp) // more recent head + || (head.step !== undefined && head.step < step && this.headsCache[fullId].blockstamp === blockstamp) // closer head + ) { + // Check that issuer is a member and that the block exists + const isAllowed = pub === this.server.conf.pair.pub || this.isConnectedKey(pub) || (await this.isMemberKey(pub)) + if (isAllowed) { + const exists = await this.existsBlock(blockstamp) + if (exists) { + this.headsCache[fullId] = { blockstamp, message: head.message, sig: head.sig, messageV2: head.messageV2, sigV2: head.sigV2, step: head.step } + this.newHeads.push(head) + // Cancel a pending "heads" to be spread + if (this.headsTimeout) { + clearTimeout(this.headsTimeout) } + // Reprogram it a few moments later + this.headsTimeout = setTimeout(async () => { + const heads = this.newHeads.splice(0, this.newHeads.length) + if (heads.length) { + await this.spreadNewHeads(heads) + } + }, WS2PConstants.HEADS_SPREAD_TIMEOUT) } } } -- GitLab From f417c09f10850a20536c45b3d70a9e60b629efec Mon Sep 17 00:00:00 2001 From: librelois Date: Wed, 29 Nov 2017 22:28:26 +0100 Subject: [PATCH 66/72] [fix] head reception : undefined error --- app/modules/ws2p/lib/WS2PCluster.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 28726455..e00e4173 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -140,7 +140,7 @@ export class WS2PCluster { } if (h.message.match(WS2PConstants.HEAD_V0_REGEXP)) { const [,, pub, blockstamp]:string[] = h.message.split(':') - const ws2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) || '000000' + const ws2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) || '00000000' this.headReceived(h, pub, [pub, ws2pId].join('-'), blockstamp) } else if (h.message.match(WS2PConstants.HEAD_V1_REGEXP)) { @@ -165,7 +165,7 @@ export class WS2PCluster { const sigV2OK = (head.messageV2 !== undefined && head.sigV2 !== undefined) ? verify(head.messageV2, head.sigV2, pub):false if ((sigV2OK && sigOK) || sigOK) { // Already known or more recent or closer ? - const step = this.headsCache[fullId].step || 0 + const step = (this.headsCache[fullId]) ? this.headsCache[fullId].step || 0:0 if (!this.headsCache[fullId] // unknow head || parseInt(this.headsCache[fullId].blockstamp) < parseInt(blockstamp) // more recent head || (head.step !== undefined && head.step < step && this.headsCache[fullId].blockstamp === blockstamp) // closer head -- GitLab From 5eb2f7d422d06a7f5c2ca9d17f0ace9ab4390948 Mon Sep 17 00:00:00 2001 From: librelois Date: Wed, 29 Nov 2017 22:48:06 +0100 Subject: [PATCH 67/72] [enh] #1219 --- app/modules/ws2p/lib/WS2PCluster.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index e00e4173..6588f032 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -348,6 +348,11 @@ export class WS2PCluster { } async connectToWS2Peers() { + // If incoming connections quota is full, delete one low-priority connection + if (this.ws2pServer !== null && this.ws2pServer.countConnexions() === this.ws2pServer.maxLevel2Peers) { + const privilegedKeys = ((this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) || []).slice() // Copy + this.ws2pServer.removeLowPriorityConnection(privilegedKeys) + } const myUUID = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) ? this.server.conf.ws2p.uuid:"" const potentials = await this.server.dal.getWS2Peers() const peers:PeerDTO[] = potentials.map((p:any) => PeerDTO.fromJSONObject(p)) -- GitLab From 7e836f3fdecd531b1572608be05647bbb1e235a6 Mon Sep 17 00:00:00 2001 From: librelois Date: Thu, 30 Nov 2017 00:38:44 +0100 Subject: [PATCH 68/72] [fix] #1220 --- app/modules/ws2p/lib/WS2PCluster.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 6588f032..8c36f0cd 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -278,9 +278,12 @@ export class WS2PCluster { clientsCount() { let count = 0 + let connectedKeys:string[] = [] for (const ws2pid in this.ws2pClients) { - if (this.ws2pClients[ws2pid].connection.pubkey != this.server.conf.pair.pub) { + if (this.ws2pClients[ws2pid].connection.pubkey != this.server.conf.pair.pub + && connectedKeys.indexOf(this.ws2pClients[ws2pid].connection.pubkey) == -1) { count++ + connectedKeys.push(this.ws2pClients[ws2pid].connection.pubkey) } } return count -- GitLab From cf7d20689cee49d98105cc079ccb715e7ea9fad5 Mon Sep 17 00:00:00 2001 From: librelois Date: Thu, 30 Nov 2017 16:33:23 +0100 Subject: [PATCH 69/72] [fix] async isMember --- app/lib/dal/fileDAL.ts | 6 +++--- app/modules/ws2p/lib/WS2PCluster.ts | 23 +++++++++++++---------- app/modules/ws2p/lib/WS2PServer.ts | 4 ++-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/lib/dal/fileDAL.ts b/app/lib/dal/fileDAL.ts index a79dc8d8..e7f5794e 100644 --- a/app/lib/dal/fileDAL.ts +++ b/app/lib/dal/fileDAL.ts @@ -503,13 +503,13 @@ export class FileDAL { return this.sindexDAL.getSource(identifier, pos) } - async isMember(pubkey:string) { + async isMember(pubkey:string):Promise { try { const idty = await this.iindexDAL.getFromPubkey(pubkey); - if (!idty) { + if (idty === null) { return false } - return idty.member; + return true; } catch (err) { return false; } diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 8c36f0cd..7d19f953 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -106,7 +106,7 @@ export class WS2PCluster { if (!this.headsCache[myFullId]) { const current = await this.server.dal.getCurrentBlockOrNull() if (current) { - const myHead = this.sayHeadChangedTo(current.number, current.hash) + const myHead = await this.sayHeadChangedTo(current.number, current.hash) const blockstamp = [current.number, current.hash].join('-') this.headsCache[myFullId] = { blockstamp, message: myHead.message, sig: myHead.sig, messageV2: myHead.messageV2, sigV2: myHead.sigV2, step:myHead.step } @@ -496,7 +496,7 @@ export class WS2PCluster { // HEAD changed else if (data.bcEvent === OtherConstants.BC_EVENT.HEAD_CHANGED || data.bcEvent === OtherConstants.BC_EVENT.SWITCHED) { // Propagate this change to the network - const myHead = this.sayHeadChangedTo(data.block.number, data.block.hash) + const myHead = await this.sayHeadChangedTo(data.block.number, data.block.hash) try { await this.broadcastHead(myHead) } catch (e) { @@ -535,14 +535,14 @@ export class WS2PCluster { return heads } - private sayHeadChangedTo(number:number, hash:string) { + private async sayHeadChangedTo(number:number, hash:string) { const api = this.getApi() const key = new Key(this.server.conf.pair.pub, this.server.conf.pair.sec) const software = 'duniter' const softVersion = Package.getInstance().version const ws2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) || '00000000' const prefix = this.server.conf.prefix || ProverConstants.DEFAULT_PEER_ID - const { freeMemberRoom , freeMirorRoom } = this.countFreeRooms() + const { freeMemberRoom , freeMirorRoom } = await this.countFreeRooms() const message = `${api}:HEAD:1:${key.publicKey}:${number}-${hash}:${ws2pId}:${software}:${softVersion}:${prefix}` const sig = key.signSync(message) const messageV2 = `${api}:HEAD:2:${key.publicKey}:${number}-${hash}:${ws2pId}:${software}:${softVersion}:${prefix}:${freeMemberRoom}:${freeMirorRoom}` @@ -604,7 +604,7 @@ export class WS2PCluster { return api } - private countFreeRooms() { + private async countFreeRooms() { if (!this.ws2pServer) { return { freeMemberRoom: 0, @@ -616,7 +616,8 @@ export class WS2PCluster { let freeMemberRoom = freeMirorRoom const privilegedNodes = (this.server.conf.ws2p && this.server.conf.ws2p.privilegedNodes) ? this.server.conf.ws2p.privilegedNodes:[] for (const c of this.ws2pServer.getConnexions()) { - if (this.keyPriorityLevel(c.pubkey, privilegedNodes) < WS2PConstants.CONNECTIONS_PRIORITY.MEMBER_KEY_LEVEL) { + const connexionPriority = await this.keyPriorityLevel(c.pubkey, privilegedNodes) + if (connexionPriority < WS2PConstants.CONNECTIONS_PRIORITY.MEMBER_KEY_LEVEL) { freeMemberRoom++ } } @@ -673,8 +674,9 @@ export class WS2PCluster { } } - keyPriorityLevel(pubkey:string, preferedOrPrivilegedKeys:string[]) { - let priorityLevel = (this.server.dal.isMember(pubkey)) ? WS2PConstants.CONNECTIONS_PRIORITY.MEMBER_KEY_LEVEL:0 + async keyPriorityLevel(pubkey:string, preferedOrPrivilegedKeys:string[]) { + const isMember = await this.server.dal.isMember(pubkey) + let priorityLevel = (isMember) ? WS2PConstants.CONNECTIONS_PRIORITY.MEMBER_KEY_LEVEL:0 priorityLevel += (preferedOrPrivilegedKeys.indexOf(pubkey) !== -1) ? WS2PConstants.CONNECTIONS_PRIORITY.PREFERED_PRIVILEGED_KEY_LEVEL:0 priorityLevel += (this.server.conf.pair.pub === pubkey) ? WS2PConstants.CONNECTIONS_PRIORITY.SELF_KEY_LEVEL:0 return priorityLevel @@ -834,12 +836,13 @@ export class WS2PCluster { else { let minPriorityLevel = WS2PConstants.CONNECTIONS_PRIORITY.MAX_PRIORITY_LEVEL for (const connectedPubkey of connectedPubkeys) { - let connectedPubkeyPriorityLevel = this.keyPriorityLevel(connectedPubkey, priorityKeys) + const connectedPubkeyPriorityLevel = await this.keyPriorityLevel(connectedPubkey, priorityKeys) if (connectedPubkeyPriorityLevel < minPriorityLevel) { minPriorityLevel = connectedPubkeyPriorityLevel } } - if (this.keyPriorityLevel(pub, priorityKeys) > minPriorityLevel) { + const pubkeyPriorityLevel = await this.keyPriorityLevel(pub, priorityKeys) + if (pubkeyPriorityLevel > minPriorityLevel) { return true } } diff --git a/app/modules/ws2p/lib/WS2PServer.ts b/app/modules/ws2p/lib/WS2PServer.ts index 428b9f3c..566d5f4a 100644 --- a/app/modules/ws2p/lib/WS2PServer.ts +++ b/app/modules/ws2p/lib/WS2PServer.ts @@ -23,7 +23,7 @@ export class WS2PServer extends events.EventEmitter { private port:number, private fifo:GlobalFifoPromise, private shouldAcceptConnection:(pubkey:string, connectedPubkeys:string[])=>Promise, - public keyPriorityLevel:(pubkey:string, privilegedKeys:string[])=>number) { + public keyPriorityLevel:(pubkey:string, privilegedKeys:string[])=>Promise) { super() // Conf: max public connections if (this.server.conf.ws2p && this.server.conf.ws2p.maxPublic !== undefined) { @@ -212,7 +212,7 @@ export class WS2PServer extends events.EventEmitter { })) } - static async bindOn(server:Server, host:string, port:number, fifo:GlobalFifoPromise, shouldAcceptConnection:(pubkey:string, connectedPubkeys:string[])=>Promise, keyPriorityLevel:(pubkey:string, privilegedKeys:string[])=>number, messageHandler:WS2PMessageHandler) { + static async bindOn(server:Server, host:string, port:number, fifo:GlobalFifoPromise, shouldAcceptConnection:(pubkey:string, connectedPubkeys:string[])=>Promise, keyPriorityLevel:(pubkey:string, privilegedKeys:string[])=>Promise, messageHandler:WS2PMessageHandler) { const ws2ps = new WS2PServer(server, host, port, fifo, shouldAcceptConnection, keyPriorityLevel) await ws2ps.listenToWebSocketConnections(messageHandler) server.logger.info('WS2P server %s listening on %s:%s', server.conf.pair.pub, host, port) -- GitLab From db4f5b18d0acefb64e9fe13a9d1537a16cd4cb07 Mon Sep 17 00:00:00 2001 From: librelois Date: Thu, 30 Nov 2017 21:30:16 +0100 Subject: [PATCH 70/72] all DBDocuments are issuers --- app/lib/dal/sqliteDAL/DocumentDAL.ts | 2 +- app/lib/dal/sqliteDAL/SandBox.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/lib/dal/sqliteDAL/DocumentDAL.ts b/app/lib/dal/sqliteDAL/DocumentDAL.ts index d2097d7f..e5ce3c56 100644 --- a/app/lib/dal/sqliteDAL/DocumentDAL.ts +++ b/app/lib/dal/sqliteDAL/DocumentDAL.ts @@ -1,3 +1,3 @@ export interface DBDocument { - issuers?: string[] + issuers: string[] } \ No newline at end of file diff --git a/app/lib/dal/sqliteDAL/SandBox.ts b/app/lib/dal/sqliteDAL/SandBox.ts index 09431c3a..d8e9f3d9 100644 --- a/app/lib/dal/sqliteDAL/SandBox.ts +++ b/app/lib/dal/sqliteDAL/SandBox.ts @@ -14,7 +14,7 @@ export class SandBox { async acceptNewSandBoxEntry(element:T, pubkey:string) { // Accept any document which has the exception pubkey (= the node pubkey) - if (element.issuers !== undefined && element.issuers.indexOf(pubkey) !== -1) { + if (element.issuers.indexOf(pubkey) !== -1) { return true; } const elements = await this.findElements() -- GitLab From 121cebe44627b9cb09feffc6ac6e1a6b589f6a03 Mon Sep 17 00:00:00 2001 From: librelois Date: Fri, 1 Dec 2017 00:54:44 +0100 Subject: [PATCH 71/72] [fix] wrong head v2 broadcasting & prevent fileds injection --- app/modules/ws2p/lib/WS2PCluster.ts | 52 +++++++++++++++++------------ 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 7d19f953..36f64467 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -125,7 +125,6 @@ export class WS2PCluster { } async headsReceived(heads:WS2PHead[]) { - const added:WS2PHead[] = [] await Promise.all(heads.map(async (h:WS2PHead) => { try { if (h.messageV2) { @@ -134,29 +133,42 @@ export class WS2PCluster { } const [,,, pub, blockstamp, ws2pId,,,,,]:string[] = h.messageV2.split(':') this.headReceived(h, pub, [pub, ws2pId].join('-'), blockstamp) - } - if (!h.message) { + } else if (!h.message) { throw "EMPTY_MESSAGE_FOR_HEAD" - } + } else if (!h.sig) { + throw "HEAD_MESSAGE_WRONGLY_SIGNED" + } else { if (h.message.match(WS2PConstants.HEAD_V0_REGEXP)) { const [,, pub, blockstamp]:string[] = h.message.split(':') const ws2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) || '00000000' this.headReceived(h, pub, [pub, ws2pId].join('-'), blockstamp) } else if (h.message.match(WS2PConstants.HEAD_V1_REGEXP)) { - const [,,, pub, blockstamp, ws2pId, software, softVersion, prefix]:string[] = h.message.split(':') + const [,,, pub, blockstamp, ws2pId,,,]:string[] = h.message.split(':') const fullId = await this.headReceived(h, pub, [pub, ws2pId].join('-'), blockstamp) } - } catch (e) { - this.server.logger.trace(e) } + } catch (e) { + this.server.logger.trace(e) + } })) + // Cancel a pending "heads" to be spread + if (this.headsTimeout) { + clearTimeout(this.headsTimeout) + } + // Reprogram it a few moments later + this.headsTimeout = setTimeout(async () => { + const heads = this.newHeads.splice(0, this.newHeads.length) + if (heads.length) { + await this.spreadNewHeads(heads) + } + }, WS2PConstants.HEADS_SPREAD_TIMEOUT) + this.server.push({ ws2p: 'heads', added: this.newHeads }) - this.newHeads = [] } private async headReceived(head:WS2PHead, pub:string, fullId:string, blockstamp:string) { @@ -177,17 +189,6 @@ export class WS2PCluster { if (exists) { this.headsCache[fullId] = { blockstamp, message: head.message, sig: head.sig, messageV2: head.messageV2, sigV2: head.sigV2, step: head.step } this.newHeads.push(head) - // Cancel a pending "heads" to be spread - if (this.headsTimeout) { - clearTimeout(this.headsTimeout) - } - // Reprogram it a few moments later - this.headsTimeout = setTimeout(async () => { - const heads = this.newHeads.splice(0, this.newHeads.length) - if (heads.length) { - await this.spreadNewHeads(heads) - } - }, WS2PConstants.HEADS_SPREAD_TIMEOUT) } } } @@ -526,11 +527,20 @@ export class WS2PCluster { })) } - private incrementHeadsStep(heads:WS2PHead[]) { - for (let head of heads) { + private incrementHeadsStep(heads_:WS2PHead[]) { + let heads:WS2PHead[] = [] + for (let head of heads_) { if (head.step !== undefined) { head.step++ } + // Prevent injections + heads.push({ + message: head.message, + sig: head.sig, + messageV2: head.messageV2, + sigV2: head.sigV2, + step: head.step + }) } return heads } -- GitLab From febdf7f7b612e177a88234e798ff69376db46a25 Mon Sep 17 00:00:00 2001 From: librelois Date: Thu, 7 Dec 2017 18:24:32 +0100 Subject: [PATCH 72/72] [fix] ws2p heads : prevent fields injection & refactoring headsReceived --- app/lib/common-libs/constants.ts | 3 +- app/modules/ws2p/lib/WS2PCluster.ts | 82 ++++++++++++++++++----------- app/modules/ws2p/lib/constants.ts | 13 +++++ 3 files changed, 65 insertions(+), 33 deletions(-) diff --git a/app/lib/common-libs/constants.ts b/app/lib/common-libs/constants.ts index 907e5256..b34cb627 100644 --- a/app/lib/common-libs/constants.ts +++ b/app/lib/common-libs/constants.ts @@ -83,7 +83,8 @@ export const CommonConstants = { SOFTWARE, SOFT_VERSION, POW_PREFIX, - ZERO_OR_POSITIVE_INT + ZERO_OR_POSITIVE_INT, + SIGNATURE }, BLOCK_GENERATED_VERSION: 10, diff --git a/app/modules/ws2p/lib/WS2PCluster.ts b/app/modules/ws2p/lib/WS2PCluster.ts index 36f64467..e486d3a3 100644 --- a/app/modules/ws2p/lib/WS2PCluster.ts +++ b/app/modules/ws2p/lib/WS2PCluster.ts @@ -127,28 +127,34 @@ export class WS2PCluster { async headsReceived(heads:WS2PHead[]) { await Promise.all(heads.map(async (h:WS2PHead) => { try { - if (h.messageV2) { + // HEAD v2 + if (h.messageV2 && h.messageV2.match(WS2PConstants.HEAD_V2_REGEXP)) { if (!h.sigV2) { throw "HEAD_MESSAGE_WRONGLY_SIGNED" - } - const [,,, pub, blockstamp, ws2pId,,,,,]:string[] = h.messageV2.split(':') - this.headReceived(h, pub, [pub, ws2pId].join('-'), blockstamp) - } else if (!h.message) { - throw "EMPTY_MESSAGE_FOR_HEAD" - } else if (!h.sig) { - throw "HEAD_MESSAGE_WRONGLY_SIGNED" - } else { - if (h.message.match(WS2PConstants.HEAD_V0_REGEXP)) { - const [,, pub, blockstamp]:string[] = h.message.split(':') - const ws2pId = (this.server.conf.ws2p && this.server.conf.ws2p.uuid) || '00000000' + } else { + const [,,, pub, blockstamp, ws2pId,,,,,]:string[] = h.messageV2.split(':') this.headReceived(h, pub, [pub, ws2pId].join('-'), blockstamp) } - else if (h.message.match(WS2PConstants.HEAD_V1_REGEXP)) { + } + // HEAD v1 and HEAD v0 + else if (h.message && h.sig) { + if (h.message.match(WS2PConstants.HEAD_V1_REGEXP)) { const [,,, pub, blockstamp, ws2pId,,,]:string[] = h.message.split(':') - const fullId = await this.headReceived(h, pub, [pub, ws2pId].join('-'), blockstamp) + } else if (h.message.match(WS2PConstants.HEAD_V0_REGEXP)) { + const [,,pub, blockstamp]:string[] = h.message.split(':') + await this.headReceived(h, pub, [pub, "00000000"].join('-'), blockstamp) + } else { + throw "HEAD_WRONG_FORMAT" } } + else if (!h.message) { + throw "EMPTY_MESSAGE_FOR_HEAD" + } else if (!h.sig) { + throw "HEAD_MESSAGE_WRONGLY_SIGNED" + } else { + throw "HEAD_WRONG_FORMAT" + } } catch (e) { this.server.logger.trace(e) } @@ -171,29 +177,41 @@ export class WS2PCluster { }) } - private async headReceived(head:WS2PHead, pub:string, fullId:string, blockstamp:string) { + private async headReceived(h:WS2PHead, pub:string, fullId:string, blockstamp:string) { try { - const sigOK = verify(head.message, head.sig, pub) - const sigV2OK = (head.messageV2 !== undefined && head.sigV2 !== undefined) ? verify(head.messageV2, head.sigV2, pub):false - if ((sigV2OK && sigOK) || sigOK) { - // Already known or more recent or closer ? - const step = (this.headsCache[fullId]) ? this.headsCache[fullId].step || 0:0 - if (!this.headsCache[fullId] // unknow head - || parseInt(this.headsCache[fullId].blockstamp) < parseInt(blockstamp) // more recent head - || (head.step !== undefined && head.step < step && this.headsCache[fullId].blockstamp === blockstamp) // closer head - ) { - // Check that issuer is a member and that the block exists - const isAllowed = pub === this.server.conf.pair.pub || this.isConnectedKey(pub) || (await this.isMemberKey(pub)) - if (isAllowed) { - const exists = await this.existsBlock(blockstamp) - if (exists) { - this.headsCache[fullId] = { blockstamp, message: head.message, sig: head.sig, messageV2: head.messageV2, sigV2: head.sigV2, step: head.step } - this.newHeads.push(head) + // Prevent fields injection + if ( (h.message.match(WS2PConstants.HEAD_V1_REGEXP) || h.message.match(WS2PConstants.HEAD_V0_REGEXP)) + && h.sig.match(WS2PConstants.HEAD_SIG_REGEXP) + && (!h.messageV2 || h.messageV2.match(WS2PConstants.HEAD_V2_REGEXP)) + && (!h.sigV2 || h.sigV2.match(WS2PConstants.HEAD_SIG_REGEXP)) + && (!h.step || h.step.toFixed(0).match(/^[0-9]*$/)) + ) { + const head:WS2PHead = { message: h.message, sig: h.sig, messageV2: h.messageV2, sigV2: h.sigV2, step: h.step } + + const sigOK = verify(head.message, head.sig, pub) + const sigV2OK = (head.messageV2 !== undefined && head.sigV2 !== undefined) ? verify(head.messageV2, head.sigV2, pub):false + if ((sigV2OK && sigOK) || sigOK) { + // Already known or more recent or closer ? + const step = (this.headsCache[fullId]) ? this.headsCache[fullId].step || 0:0 + if (!this.headsCache[fullId] // unknow head + || parseInt(this.headsCache[fullId].blockstamp) < parseInt(blockstamp) // more recent head + || (head.step !== undefined && head.step < step && this.headsCache[fullId].blockstamp === blockstamp) // closer head + ) { + // Check that issuer is a member and that the block exists + const isAllowed = pub === this.server.conf.pair.pub || this.isConnectedKey(pub) || (await this.isMemberKey(pub)) + if (isAllowed) { + const exists = await this.existsBlock(blockstamp) + if (exists) { + this.headsCache[fullId] = { blockstamp, message: head.message, sig: head.sig, messageV2: head.messageV2, sigV2: head.sigV2, step: head.step } + this.newHeads.push(head) + } } } + } else { + throw "HEAD_MESSAGE_WRONGLY_SIGNED" } } else { - throw "HEAD_MESSAGE_WRONGLY_SIGNED" + throw "HEAD_WRONG_FORMAT" } } catch (e) { this.server.logger.trace(e) diff --git a/app/modules/ws2p/lib/constants.ts b/app/modules/ws2p/lib/constants.ts index a48d3464..b57598b7 100644 --- a/app/modules/ws2p/lib/constants.ts +++ b/app/modules/ws2p/lib/constants.ts @@ -59,8 +59,21 @@ export const WS2PConstants = { + '(' + CommonConstants.FORMATS.SOFTWARE + '):' + '(' + CommonConstants.FORMATS.SOFT_VERSION + '):' + '(' + CommonConstants.FORMATS.POW_PREFIX + ')' + + '$'), + + HEAD_V2_REGEXP: new RegExp('^WS2P(?:O[CT][SAM])?(?:I[CT])?:HEAD:2:' + + '(' + CommonConstants.FORMATS.PUBKEY + '):' + + '(' + CommonConstants.FORMATS.BLOCKSTAMP + '):' + + '(' + CommonConstants.FORMATS.WS2PID + '):' + + '(' + CommonConstants.FORMATS.SOFTWARE + '):' + + '(' + CommonConstants.FORMATS.SOFT_VERSION + '):' + + '(' + CommonConstants.FORMATS.POW_PREFIX + '):' + + '(' + CommonConstants.FORMATS.ZERO_OR_POSITIVE_INT + '):' + + '(' + CommonConstants.FORMATS.ZERO_OR_POSITIVE_INT + ')' + '(?::' + CommonConstants.FORMATS.TIMESTAMP + ')?' + '$'), + + HEAD_SIG_REGEXP: new RegExp(CommonConstants.FORMATS.SIGNATURE), HOST_ONION_REGEX: CommonConstants.HOST_ONION_REGEX, FULL_ADDRESS_ONION_REGEX: CommonConstants.WS_FULL_ADDRESS_ONION_REGEX, -- GitLab