Commit 550c019d authored by zeroleak's avatar zeroleak
Browse files

add cli.torConfig.onionServer + cli.torConfig.onionBackend

parent 41835135
......@@ -110,6 +110,14 @@ cli.torConfig.executable = /path/to/bin/tor
- Use `local` to detect a local tor install.
- Use custom path to `tor` binary to use your own tor build.
```
cli.torConfig.onionServer = true
cli.torConfig.onionBackend = true
```
How to connect to whirlpool server and wallet backend:
- `true`: connect to Tor v3 hidden services
- `false`: connect to clearnet over Tor
### API
whirlpool-client-cli can be managed with a REST API. See [README-API.md](README-API.md)
......
......@@ -32,7 +32,10 @@ public class CliController extends AbstractRestController {
ApiCliStateResponse response =
new ApiCliStateResponse(
cliWalletService.getCliState(), cliConfig.getServer(), cliConfig.getTor());
cliWalletService.getCliState(),
cliConfig.getServer(),
cliConfig.computeServerUrl(),
cliConfig.getTor());
return response;
}
......
......@@ -15,14 +15,15 @@ public class ApiCliStateResponse {
private String serverName;
private boolean tor;
public ApiCliStateResponse(CliState cliState, WhirlpoolServer server, boolean tor) {
public ApiCliStateResponse(
CliState cliState, WhirlpoolServer server, String serverUrl, boolean tor) {
this.cliStatus = cliState.getCliStatus();
this.cliMessage = cliState.getCliMessage();
this.loggedIn = cliState.isLoggedIn();
this.torProgress = cliState.getTorProgress();
this.network = server.getParams().getPaymentProtocolId();
this.serverUrl = server.computeServerUrl(tor);
this.serverUrl = serverUrl;
this.serverName = server.name();
this.tor = tor;
}
......
package com.samourai.whirlpool.cli.config;
import com.samourai.api.client.BackendServer;
import com.samourai.http.client.IHttpClient;
import com.samourai.stomp.client.IStompClientService;
import com.samourai.wallet.util.FormatsUtilGeneric;
import com.samourai.whirlpool.client.utils.ClientUtils;
import com.samourai.whirlpool.client.wallet.WhirlpoolWalletConfig;
import com.samourai.whirlpool.client.wallet.persist.WhirlpoolWalletPersistHandler;
......@@ -35,6 +37,13 @@ public class CliConfig extends CliConfigFile {
return config;
}
public String computeBackendUrl() {
boolean isTestnet = FormatsUtilGeneric.getInstance().isTestNet(getServer().getParams());
BackendServer backendServer = isTestnet ? BackendServer.TESTNET : BackendServer.MAINNET;
boolean useOnion = getTor() && getTorConfig().isOnionBackend();
return backendServer.getBackendUrl(useOnion);
}
public boolean isAutoAggregatePostmix() {
return autoAggregatePostmix;
}
......
......@@ -265,11 +265,15 @@ public abstract class CliConfigFile {
public static final String EXECUTABLE_AUTO = "auto";
public static final String EXECUTABLE_LOCAL = "local";
@NotEmpty private String executable;
@NotEmpty private boolean onionServer;
@NotEmpty private boolean onionBackend;
public TorConfig() {}
public TorConfig(TorConfig copy) {
this.executable = copy.executable;
this.onionServer = copy.onionServer;
this.onionBackend = copy.onionBackend;
}
public String getExecutable() {
......@@ -288,18 +292,42 @@ public abstract class CliConfigFile {
return EXECUTABLE_LOCAL.equals(this.executable);
}
public boolean isOnionServer() {
return onionServer;
}
public void setOnionServer(boolean onionServer) {
this.onionServer = onionServer;
}
public boolean isOnionBackend() {
return onionBackend;
}
public void setOnionBackend(boolean onionBackend) {
this.onionBackend = onionBackend;
}
public Map<String, String> getConfigInfo() {
Map<String, String> configInfo = new HashMap<>();
configInfo.put("cli/tor/executable", executable);
configInfo.put("cli/tor/onionServer", Boolean.toString(onionServer));
configInfo.put("cli/tor/onionBackend", Boolean.toString(onionBackend));
return configInfo;
}
}
public String computeServerUrl() {
boolean useOnion = tor && torConfig.onionServer;
String serverUrl = server.computeServerUrl(useOnion);
return serverUrl;
}
public WhirlpoolWalletConfig computeWhirlpoolWalletConfig(
IHttpClient httpClient,
IStompClientService stompClientService,
WhirlpoolWalletPersistHandler persistHandler) {
String serverUrl = server.computeServerUrl(tor);
String serverUrl = computeServerUrl();
WhirlpoolWalletConfig config =
new WhirlpoolWalletConfig(
httpClient, stompClientService, persistHandler, serverUrl, server);
......
package com.samourai.whirlpool.cli.services;
import com.samourai.api.client.SamouraiApi;
import com.samourai.wallet.api.backend.BackendServer;
import com.samourai.wallet.util.FormatsUtilGeneric;
import com.samourai.whirlpool.cli.config.CliConfig;
import org.springframework.stereotype.Service;
......@@ -10,10 +8,6 @@ import org.springframework.stereotype.Service;
public class SamouraiApiService extends SamouraiApi {
public SamouraiApiService(JavaHttpClientService httpClient, CliConfig cliConfig) {
super(
httpClient,
FormatsUtilGeneric.getInstance().isTestNet(cliConfig.getServer().getParams())
? BackendServer.TESTNET
: BackendServer.MAINNET);
super(httpClient, cliConfig.computeBackendUrl());
}
}
......@@ -9,6 +9,8 @@ cli.scode =
cli.pushtx = auto
cli.tor = false
cli.torConfig.executable = auto
cli.torConfig.onionServer = false
cli.torConfig.onionBackend = false
cli.apiKey =
cli.seed =
cli.seedAppendPassphrase = true
......
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