Skip to content
Snippets Groups Projects
Commit cbcfd1b6 authored by Éloïs's avatar Éloïs
Browse files

[enh] add cli options for proxies conf

parent 005a8c2d
No related branches found
No related tags found
1 merge request!1178Add WS2PTOR features
...@@ -49,6 +49,11 @@ export const ExecuteCommand = () => { ...@@ -49,6 +49,11 @@ export const ExecuteCommand = () => {
.option('--nostdout', 'Disable stdout printing for `export-bc` command') .option('--nostdout', 'Disable stdout printing for `export-bc` command')
.option('--noshuffle', 'Disable peers shuffling for `sync` command') .option('--noshuffle', 'Disable peers shuffling for `sync` command')
.option('--proxy-socks <host:port>', 'Use Socks Proxy')
.option('--proxy-tor <host:port>', 'Use Tor Socks Proxy')
.option('--tor-always', 'Pass all outgoing requests through the tor network')
.option('--tor-mixed', 'Pass only ".onion" outgoing requests through the tor network. It\'s the default behavior')
.option('--timeout <milliseconds>', 'Timeout to use when contacting peers', parseInt) .option('--timeout <milliseconds>', 'Timeout to use when contacting peers', parseInt)
.option('--httplogs', 'Enable HTTP logs') .option('--httplogs', 'Enable HTTP logs')
.option('--nohttplogs', 'Disable HTTP logs') .option('--nohttplogs', 'Disable HTTP logs')
......
...@@ -8,6 +8,7 @@ import {CrawlerDependency} from "./app/modules/crawler/index" ...@@ -8,6 +8,7 @@ import {CrawlerDependency} from "./app/modules/crawler/index"
import {BmaDependency} from "./app/modules/bma/index" import {BmaDependency} from "./app/modules/bma/index"
import {WS2PDependency} from "./app/modules/ws2p/index" import {WS2PDependency} from "./app/modules/ws2p/index"
import {Constants} from "./app/modules/prover/lib/constants" import {Constants} from "./app/modules/prover/lib/constants"
import { Proxy } from './app/lib/proxy';
const path = require('path'); const path = require('path');
const _ = require('underscore'); const _ = require('underscore');
...@@ -437,10 +438,9 @@ class Stack { ...@@ -437,10 +438,9 @@ class Stack {
} }
} }
function commandLineConf(program:any, conf:any = {}) { function commandLineConf(program:any, conf:ConfDTO = ConfDTO.mock()) {
conf = conf || {}; conf = conf || {};
conf.sync = conf.sync || {};
const cli = { const cli = {
currency: program.currency, currency: program.currency,
cpu: program.cpu, cpu: program.cpu,
...@@ -448,10 +448,11 @@ function commandLineConf(program:any, conf:any = {}) { ...@@ -448,10 +448,11 @@ function commandLineConf(program:any, conf:any = {}) {
server: { server: {
port: program.port, port: program.port,
}, },
db: { proxies: {
mport: program.mport, proxySocks: program.proxySocks,
mdb: program.mdb, proxyTor: program.proxyTor,
home: program.home torAlways: program.torAlways,
torMixed: program.torMixed
}, },
logs: { logs: {
http: program.httplogs, http: program.httplogs,
...@@ -465,16 +466,22 @@ function commandLineConf(program:any, conf:any = {}) { ...@@ -465,16 +466,22 @@ function commandLineConf(program:any, conf:any = {}) {
timeout: program.timeout timeout: program.timeout
}; };
// Declare proxyConf
if (cli.proxies.proxySocks || cli.proxies.proxyTor || cli.proxies.torAlways || cli.proxies.torMixed) {
conf.proxyConf = Proxy.defaultConf()
}
// Update conf // Update conf
if (cli.currency) conf.currency = cli.currency; if (cli.currency) conf.currency = cli.currency;
if (cli.server.port) conf.port = cli.server.port; 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.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(Constants.MIN_PEER_ID, Math.min(Constants.MAX_PEER_ID, cli.prefix));
if (cli.proxies.proxySocks && conf.proxyConf) conf.proxyConf.proxySocksAddress = cli.proxies.proxySocks;
if (cli.proxies.proxyTor && conf.proxyConf) conf.proxyConf.proxyTorAddress = cli.proxies.proxyTor;
if (cli.proxies.torAlways && conf.proxyConf) conf.proxyConf.alwaysUseTor = true;
if (cli.proxies.torMixed && conf.proxyConf) conf.proxyConf.alwaysUseTor = false;
if (cli.logs.http) conf.httplogs = true; if (cli.logs.http) conf.httplogs = true;
if (cli.logs.nohttp) conf.httplogs = false; if (cli.logs.nohttp) conf.httplogs = false;
if (cli.db.mport) conf.mport = cli.db.mport;
if (cli.db.home) conf.home = cli.db.home;
if (cli.db.mdb) conf.mdb = cli.db.mdb;
if (cli.isolate) conf.isolate = cli.isolate; if (cli.isolate) conf.isolate = cli.isolate;
if (cli.timeout) conf.timeout = cli.timeout; if (cli.timeout) conf.timeout = cli.timeout;
if (cli.forksize != null) conf.forksize = cli.forksize; if (cli.forksize != null) conf.forksize = cli.forksize;
......
...@@ -24,6 +24,7 @@ import {PeerDTO} from "./app/lib/dto/PeerDTO" ...@@ -24,6 +24,7 @@ import {PeerDTO} from "./app/lib/dto/PeerDTO"
import {OtherConstants} from "./app/lib/other_constants" import {OtherConstants} from "./app/lib/other_constants"
import {WS2PCluster} from "./app/modules/ws2p/lib/WS2PCluster" import {WS2PCluster} from "./app/modules/ws2p/lib/WS2PCluster"
import {DBBlock} from "./app/lib/db/DBBlock" import {DBBlock} from "./app/lib/db/DBBlock"
import { Proxy } from './app/lib/proxy';
export interface HookableServer { export interface HookableServer {
generatorGetJoinData: (...args:any[]) => Promise<any> generatorGetJoinData: (...args:any[]) => Promise<any>
...@@ -72,7 +73,7 @@ export class Server extends stream.Duplex implements HookableServer { ...@@ -72,7 +73,7 @@ export class Server extends stream.Duplex implements HookableServer {
TransactionsService:TransactionService TransactionsService:TransactionService
private documentFIFO:GlobalFifoPromise private documentFIFO:GlobalFifoPromise
constructor(home:string, memoryOnly:boolean, private overrideConf:any) { constructor(home:string, memoryOnly:boolean, private overrideConf:ConfDTO) {
super({ objectMode: true }) super({ objectMode: true })
this.home = home; this.home = home;
...@@ -148,6 +149,8 @@ export class Server extends stream.Duplex implements HookableServer { ...@@ -148,6 +149,8 @@ export class Server extends stream.Duplex implements HookableServer {
logger.debug('Loading conf...'); logger.debug('Loading conf...');
this.conf = await this.dal.loadConf(this.overrideConf, useDefaultConf) this.conf = await this.dal.loadConf(this.overrideConf, useDefaultConf)
// Default values // Default values
this.conf.proxyConf = this.conf.proxyConf === undefined ? Proxy.defaultConf() : this.conf.proxyConf
this.conf.proxyConf.alwaysUseTor = this.conf.proxyConf.alwaysUseTor === undefined ? false : this.conf.proxyConf.alwaysUseTor
this.conf.remoteipv6 = this.conf.remoteipv6 === undefined ? this.conf.ipv6 : this.conf.remoteipv6 this.conf.remoteipv6 = this.conf.remoteipv6 === undefined ? this.conf.ipv6 : this.conf.remoteipv6
this.conf.remoteport = this.conf.remoteport === undefined ? this.conf.port : this.conf.remoteport this.conf.remoteport = this.conf.remoteport === undefined ? this.conf.port : this.conf.remoteport
this.conf.c = this.conf.c === undefined ? constants.CONTRACT.DEFAULT.C : this.conf.c this.conf.c = this.conf.c === undefined ? constants.CONTRACT.DEFAULT.C : this.conf.c
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment