Commit 8136c8e2 authored by zeroleak's avatar zeroleak
Browse files

add cli.mix.clientsPerPool = 1

set cli.mix.clients = 3
parent 8cc43509
......@@ -26,7 +26,8 @@ public class ApiCliConfig {
private static final String KEY_SCODE = "cli.scode";
public static final String KEY_TOR = "cli.tor";
private static final String KEY_PROXY = "cli.proxy";
private static final String KEY_MIX_CLIENTS = "cli.mix.clients";
public static final String KEY_MIX_CLIENTS = "cli.mix.clients";
private static final String KEY_MIX_CLIENTS_PER_POOL = "cli.mix.clientsPerPool";
private static final String KEY_MIX_CLIENT_DELAY = "cli.mix.clientDelay";
private static final String KEY_MIX_TX0_MAX_OUTPUTS = "cli.mix.tx0MaxOutputs";
private static final String KEY_MIX_AUTO_MIX = "cli.mix.autoMix";
......@@ -124,6 +125,7 @@ public class ApiCliConfig {
public static class ApiMixConfig {
private Integer clients;
private Integer clientsPerPool;
private Integer clientDelay;
private Integer tx0MaxOutputs;
private Boolean autoMix;
......@@ -133,6 +135,7 @@ public class ApiCliConfig {
public ApiMixConfig(CliConfigFile.MixConfig mixConfig) {
this.clients = mixConfig.getClients();
this.clientsPerPool = mixConfig.getClientsPerPool();
this.clientDelay = mixConfig.getClientDelay();
this.tx0MaxOutputs = mixConfig.getTx0MaxOutputs();
this.autoMix = mixConfig.isAutoMix();
......@@ -146,6 +149,12 @@ public class ApiCliConfig {
}
props.put(KEY_MIX_CLIENTS, Integer.toString(clients));
}
if (clientsPerPool != null) {
if (clientsPerPool < 1) {
throw new NotifiableException("mix.clientsPerPool should be > 0");
}
props.put(KEY_MIX_CLIENTS_PER_POOL, Integer.toString(clientsPerPool));
}
if (clientDelay != null) {
if (clientDelay < 1) {
throw new NotifiableException("mix.clientDelay should be > 1");
......@@ -177,6 +186,14 @@ public class ApiCliConfig {
this.clients = clients;
}
public Integer getClientsPerPool() {
return clientsPerPool;
}
public void setClientsPerPool(Integer clientsPerPool) {
this.clientsPerPool = clientsPerPool;
}
public Integer getClientDelay() {
return clientDelay;
}
......
......@@ -174,6 +174,7 @@ public abstract class CliConfigFile {
public static class MixConfig {
@NotEmpty private int clients;
@NotEmpty private int clientsPerPool;
@NotEmpty private int clientDelay;
@NotEmpty private int tx0Delay;
@NotEmpty private int tx0MaxOutputs;
......@@ -184,6 +185,7 @@ public abstract class CliConfigFile {
public MixConfig(MixConfig copy) {
this.clients = copy.clients;
this.clientsPerPool = copy.clientsPerPool;
this.clientDelay = copy.clientDelay;
this.tx0Delay = copy.tx0Delay;
this.tx0MaxOutputs = copy.tx0MaxOutputs;
......@@ -199,6 +201,14 @@ public abstract class CliConfigFile {
this.clients = clients;
}
public int getClientsPerPool() {
return clientsPerPool;
}
public void setClientsPerPool(int clientsPerPool) {
this.clientsPerPool = clientsPerPool;
}
public int getClientDelay() {
return clientDelay;
}
......@@ -242,6 +252,7 @@ public abstract class CliConfigFile {
public Map<String, String> getConfigInfo() {
Map<String, String> configInfo = new HashMap<>();
configInfo.put("cli/mix/clients", Integer.toString(clients));
configInfo.put("cli/mix/clientsPerPool", Integer.toString(clientsPerPool));
configInfo.put("cli/mix/clientDelay", Integer.toString(clientDelay));
configInfo.put("cli/mix/tx0Delay", Integer.toString(tx0Delay));
configInfo.put("cli/mix/tx0MaxOutputs", Integer.toString(tx0MaxOutputs));
......@@ -376,6 +387,7 @@ public abstract class CliConfigFile {
config.setRefreshPoolsDelay(refreshPoolsDelay);
config.setMaxClients(mix.getClients());
config.setMaxClientsPerPool(mix.getClientsPerPool());
config.setClientDelay(mix.getClientDelay());
config.setTx0Delay(mix.getTx0Delay());
config.setTx0MaxOutputs(mix.getTx0MaxOutputs() > 0 ? mix.getTx0MaxOutputs() : null);
......
package com.samourai.whirlpool.cli.run;
import com.samourai.whirlpool.cli.api.protocol.beans.ApiCliConfig;
import com.samourai.whirlpool.cli.config.CliConfig;
import com.samourai.whirlpool.cli.services.CliConfigService;
import java.lang.invoke.MethodHandles;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -10,6 +12,7 @@ public class RunUpgradeCli {
private Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final int CLI_V1 = 1;
private static final int CLI_V2 = 2;
private CliConfig cliConfig;
private CliConfigService cliConfigService;
......@@ -24,11 +27,22 @@ public class RunUpgradeCli {
if (lastVersion < CLI_V1) {
upgradeV1();
}
if (lastVersion < CLI_V2) {
upgradeV2();
}
}
public void upgradeV1() throws Exception {
log.info(" - Upgrading to: V1");
// set cli.seedAppendPassphrase=true
cliConfigService.setVersionCurrent();
}
public void upgradeV2() throws Exception {
log.info(" - Upgrading to: V2");
// set mix.clients=3
Properties props = cliConfigService.loadProperties();
props.put(ApiCliConfig.KEY_MIX_CLIENTS, Integer.toString(3));
cliConfigService.saveProperties(props);
}
}
......@@ -31,7 +31,7 @@ import org.springframework.util.DefaultPropertiesPersister;
public class CliConfigService {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final int CLI_VERSION = 1;
public static final int CLI_VERSION = 2;
public static final String CLI_CONFIG_FILENAME = "whirlpool-cli-config.properties";
private static final String KEY_APIKEY = "cli.apiKey";
private static final String KEY_SEED = "cli.seed";
......@@ -174,30 +174,35 @@ public class CliConfigService {
return apiKey;
}
private Properties loadEntries() throws Exception {
public Properties loadProperties() throws Exception {
Resource resource = new FileSystemResource(getConfigurationFile());
Properties props = PropertiesLoaderUtils.loadProperties(resource);
return props;
}
public synchronized void saveProperties(Properties props) throws Exception {
// save
save(props);
// restart needed
this.setCliStatusNotReady("CLI restart required. Configuration updated.");
}
public synchronized void setApiConfig(ApiCliConfig apiCliConfig) throws Exception {
if (apiCliConfig.getDojo() && !apiCliConfig.getTor()) {
throw new NotifiableException("Tor is required for DOJO");
}
Properties props = loadEntries();
Properties props = loadProperties();
apiCliConfig.toProperties(props);
// save
save(props);
// restart needed
this.setCliStatusNotReady("CLI restart required. Configuration updated.");
saveProperties(props);
}
public synchronized void setVersionCurrent() throws Exception {
Properties props = loadEntries();
Properties props = loadProperties();
props.put(KEY_VERSION, Integer.toString(CLI_VERSION));
// save
......@@ -256,7 +261,7 @@ public class CliConfigService {
boolean shouldRestart = false;
int lastVersion = cliConfig.getVersion();
if (lastVersion < CliConfigService.CLI_VERSION) {
if (lastVersion < CLI_VERSION) {
// older version => run upgrade
if (log.isDebugEnabled()) {
log.debug(" • Upgrading cli wallet: " + lastVersion + " -> " + CLI_VERSION);
......
......@@ -20,7 +20,8 @@ cli.persistDelay = 2
cli.refreshPoolsDelay = 30
cli.proxy =
cli.mix.clients = 1
cli.mix.clients = 3
cli.mix.clientsPerPool = 1
cli.mix.tx0MaxOutputs = 0
cli.mix.clientDelay = 15
cli.mix.tx0Delay = 30
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment