From 15d534149e5c5089addcd27576b1e82575d8445b Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Fri, 3 Nov 2017 16:20:57 +0100 Subject: [PATCH] [enh] add option to use bma without crawler #1174 --- app/lib/dto/ConfDTO.ts | 4 +++- app/modules/bma/index.ts | 7 +++++++ app/modules/bma/lib/network.ts | 1 + app/modules/crawler/lib/crawler.ts | 4 ++-- app/modules/router.ts | 4 ++-- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/lib/dto/ConfDTO.ts b/app/lib/dto/ConfDTO.ts index 1227913e3..f6c57cc5e 100644 --- a/app/lib/dto/ConfDTO.ts +++ b/app/lib/dto/ConfDTO.ts @@ -49,6 +49,7 @@ export interface KeypairConfDTO { export interface NetworkConfDTO { proxiesConf: ProxiesConf|undefined nobma: boolean + bmaWithCrawler: boolean remoteport: number remotehost: string|null remoteipv4: string|null @@ -136,6 +137,7 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO, public homename: string, public memory: boolean, public nobma: boolean, + public bmaWithCrawler: boolean, public proxiesConf: ProxiesConf|undefined, public ws2p?: { privateAccess: boolean @@ -155,7 +157,7 @@ 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, undefined) + 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, false, true, undefined) } static defaultConf() { diff --git a/app/modules/bma/index.ts b/app/modules/bma/index.ts index 914a6ecf4..2abe0ba7a 100644 --- a/app/modules/bma/index.ts +++ b/app/modules/bma/index.ts @@ -29,6 +29,8 @@ export const BmaDependency = { { value: '--noupnp', desc: 'Do not use UPnP to open remote port.' }, { value: '--bma', desc: 'Enables BMA API and its crawlers.' }, { value: '--nobma', desc: 'Disables BMA API and its crawlers.' }, + { value: '--bma-with-crawler', desc: 'Enables BMA Crawler.' }, + { value: '--bma-without-crawler', desc: 'Disable BMA Crawler.' }, { value: '-p, --port <port>', desc: 'Port to listen for requests', parser: (val:string) => parseInt(val) }, { value: '--ipv4 <address>', desc: 'IPv4 interface to listen for requests' }, { value: '--ipv6 <address>', desc: 'IPv6 interface to listen for requests' }, @@ -73,6 +75,9 @@ export const BmaDependency = { } } + // If bmaWithCrawler hasn't been defined yet + if (conf.bmaWithCrawler === undefined) { conf.bmaWithCrawler = false } + if (program.port !== undefined) conf.port = parseInt(program.port) if (program.ipv4 !== undefined) conf.ipv4 = program.ipv4; if (program.ipv6 !== undefined) conf.ipv6 = program.ipv6; @@ -82,6 +87,8 @@ export const BmaDependency = { if (program.remotep !== undefined) conf.remoteport = parseInt(program.remotep) if (program.bma !== undefined) conf.nobma = false if (program.nobma !== undefined) conf.nobma = true + if (program.bmaWithCrawler !== undefined) conf.bmaWithCrawler = true + if (program.bmaWithoutCrawler !== undefined) conf.bmaWithCrawler = false if (!conf.ipv4) delete conf.ipv4; if (!conf.ipv6) delete conf.ipv6; diff --git a/app/modules/bma/lib/network.ts b/app/modules/bma/lib/network.ts index 250a622bf..3e9e026f9 100644 --- a/app/modules/bma/lib/network.ts +++ b/app/modules/bma/lib/network.ts @@ -339,6 +339,7 @@ async function upnpConf (noupnp:boolean, logger:any) { const conf:NetworkConfDTO = { proxiesConf: undefined, nobma: true, + bmaWithCrawler: false, port: privatePort, ipv4: '127.0.0.1', ipv6: '::1', diff --git a/app/modules/crawler/lib/crawler.ts b/app/modules/crawler/lib/crawler.ts index 44bf5a217..9520c5e3a 100644 --- a/app/modules/crawler/lib/crawler.ts +++ b/app/modules/crawler/lib/crawler.ts @@ -48,7 +48,7 @@ export class Crawler extends stream.Transform implements DuniterService { } startService() { - if (this.conf.nobma) { + if (this.conf.nobma || !this.conf.bmaWithCrawler) { return Promise.resolve() } return Promise.all([ @@ -60,7 +60,7 @@ export class Crawler extends stream.Transform implements DuniterService { } stopService() { - if (this.conf.nobma) { + if (this.conf.nobma || !this.conf.bmaWithCrawler) { return Promise.resolve() } return Promise.all([ diff --git a/app/modules/router.ts b/app/modules/router.ts index 1530cc43e..d6484f05b 100644 --- a/app/modules/router.ts +++ b/app/modules/router.ts @@ -44,7 +44,7 @@ class Router extends stream.Transform { }; async startService() { - if (this.server.conf.nobma) { + if (this.server.conf.nobma || !this.server.conf.bmaWithCrawler) { // Disable BMA return Promise.resolve() } @@ -69,7 +69,7 @@ class Router extends stream.Transform { } async stopService() { - if (this.server.conf.nobma) { + if (this.server.conf.nobma || !this.server.conf.bmaWithCrawler) { // Disable BMA return Promise.resolve() } -- GitLab