Commit 2257e5c4 authored by zeroleak's avatar zeroleak
Browse files

improve CLI connectivity after long downtimes

parent 8b38a9ef
......@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.samourai.code.whirlpool</groupId>
<artifactId>whirlpool-client-cli</artifactId>
<version>0.10.10</version>
<version>develop-SNAPSHOT</version>
<name>whirlpool-client-cli</name>
<properties>
<spring-boot.version>2.1.6.RELEASE</spring-boot.version>
......@@ -17,7 +17,7 @@
<dependency>
<groupId>io.samourai.code.whirlpool</groupId>
<artifactId>whirlpool-client</artifactId>
<version>0.23.26</version>
<version>0.23.28-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
......
......@@ -24,16 +24,13 @@ public class JavaTorClient {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private CliConfig cliConfig;
private Collection<HttpUsage> torHttpUsages;
private TorOnionProxyInstance torInstance;
private boolean started = false;
public JavaTorClient(CliConfig cliConfig, Collection<HttpUsage> torHttpUsages) {
public JavaTorClient(CliConfig cliConfig, Collection<HttpUsage> torHttpUsages) throws Exception {
this.cliConfig = cliConfig;
this.torHttpUsages = torHttpUsages;
}
public void setup() throws Exception {
// setup
TorSettings torSettings = computeTorSettings();
WhirlpoolTorInstaller torInstaller = computeTorInstaller();
this.torInstance = new TorOnionProxyInstance(torInstaller, torSettings, torHttpUsages);
......
......@@ -3,6 +3,7 @@ package com.samourai.whirlpool.cli.config;
import com.samourai.http.client.HttpUsage;
import com.samourai.http.client.IHttpClientService;
import com.samourai.stomp.client.IStompClientService;
import com.samourai.tor.client.TorClientService;
import com.samourai.wallet.api.backend.BackendApi;
import com.samourai.wallet.api.backend.BackendServer;
import com.samourai.wallet.util.FormatsUtilGeneric;
......@@ -30,6 +31,7 @@ public class CliConfig extends CliConfigFile {
public WhirlpoolWalletConfig computeWhirlpoolWalletConfig(
IHttpClientService httpClientService,
IStompClientService stompClientService,
TorClientService torClientService,
BackendApi backendApi,
String passphrase)
throws NotifiableException {
......@@ -41,7 +43,7 @@ public class CliConfig extends CliConfigFile {
WhirlpoolWalletConfig config =
super.computeWhirlpoolWalletConfig(
httpClientService, stompClientService, backendApi, passphrase);
httpClientService, stompClientService, torClientService, backendApi, passphrase);
config.setAutoTx0PoolId(autoTx0PoolId);
return config;
}
......
......@@ -2,6 +2,7 @@ package com.samourai.whirlpool.cli.config;
import com.samourai.http.client.IHttpClientService;
import com.samourai.stomp.client.IStompClientService;
import com.samourai.tor.client.TorClientService;
import com.samourai.wallet.api.backend.BackendApi;
import com.samourai.wallet.crypto.AESUtil;
import com.samourai.wallet.util.CharSequenceX;
......@@ -620,6 +621,7 @@ public abstract class CliConfigFile {
protected WhirlpoolWalletConfig computeWhirlpoolWalletConfig(
IHttpClientService httpClientService,
IStompClientService stompClientService,
TorClientService torClientService,
BackendApi backendApi,
String passphrase)
throws NotifiableException {
......@@ -628,7 +630,13 @@ public abstract class CliConfigFile {
ServerApi serverApi = new ServerApi(serverUrl, httpClientService);
WhirlpoolWalletConfig config =
new WhirlpoolWalletConfig(
httpClientService, stompClientService, serverApi, params, false, backendApi);
httpClientService,
stompClientService,
torClientService,
serverApi,
params,
false,
backendApi);
if (!Strings.isEmpty(scode)) {
config.setScode(scode);
}
......
......@@ -2,6 +2,7 @@ package com.samourai.whirlpool.cli.services;
import com.samourai.http.client.HttpUsage;
import com.samourai.tor.client.JavaTorClient;
import com.samourai.tor.client.TorClientService;
import com.samourai.whirlpool.cli.beans.CliProxy;
import com.samourai.whirlpool.cli.config.CliConfig;
import com.samourai.whirlpool.client.exception.NotifiableException;
......@@ -12,9 +13,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
// JavaTorClient wrapper for watching for cliConfig changes
@Service
public class CliTorClientService {
public class CliTorClientService extends TorClientService {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private Optional<JavaTorClient> torClient;
......@@ -22,6 +22,7 @@ public class CliTorClientService {
private Collection<HttpUsage> torHttpUsages;
public CliTorClientService(CliConfig cliConfig) {
super();
this.torClient = Optional.empty();
this.cliConfig = cliConfig;
this.torHttpUsages = cliConfig.computeTorHttpUsages();
......@@ -34,8 +35,7 @@ public class CliTorClientService {
log.debug("Enabling Tor for: " + torHttpUsages);
}
// instanciate & initialize
JavaTorClient tc = new JavaTorClient(cliConfig, torHttpUsages);
tc.setup(); // throws
JavaTorClient tc = new JavaTorClient(cliConfig, torHttpUsages); // throws
torClient = Optional.of(tc);
if (log.isDebugEnabled()) {
log.debug("Tor is enabled.");
......@@ -66,6 +66,7 @@ public class CliTorClientService {
}
}
@Override
public void changeIdentity() {
if (torClient.isPresent()) {
torClient.get().changeIdentity();
......
......@@ -130,7 +130,11 @@ public class CliWalletService extends WhirlpoolWalletService {
// open wallet
WhirlpoolWalletConfig config =
cliConfig.computeWhirlpoolWalletConfig(
httpClientService, stompClientService, backendApiService, passphrase);
httpClientService,
stompClientService,
cliTorClientService,
backendApiService,
passphrase);
String walletStateFileName = computeIndexFile(walletIdentifier).getAbsolutePath();
String utxoConfigFileName = computeUtxosFile(walletIdentifier).getAbsolutePath();
......
......@@ -67,9 +67,8 @@ public class CliWallet extends WhirlpoolWallet {
public void onMixSuccess(WhirlpoolUtxo whirlpoolUtxo, MixSuccess mixSuccess) {
super.onMixSuccess(whirlpoolUtxo, mixSuccess);
// change Tor identity
// change http Tor identity
if (cliConfig.getTor()) {
cliTorClientService.changeIdentity();
httpClientService.changeIdentityRest();
}
}
......
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