mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
allow configuration of a maximum server timeout (maxServerTimeout) in sparrow config
This commit is contained in:
parent
e84f82f47b
commit
8b42399423
2 changed files with 22 additions and 3 deletions
|
@ -1,7 +1,6 @@
|
||||||
package com.sparrowwallet.sparrow.io;
|
package com.sparrowwallet.sparrow.io;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import com.samourai.whirlpool.client.wallet.beans.IndexRange;
|
|
||||||
import com.sparrowwallet.drongo.BitcoinUnit;
|
import com.sparrowwallet.drongo.BitcoinUnit;
|
||||||
import com.sparrowwallet.sparrow.Mode;
|
import com.sparrowwallet.sparrow.Mode;
|
||||||
import com.sparrowwallet.sparrow.Theme;
|
import com.sparrowwallet.sparrow.Theme;
|
||||||
|
@ -16,6 +15,8 @@ import java.lang.reflect.Type;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.sparrowwallet.sparrow.net.TcpTransport.DEFAULT_MAX_TIMEOUT;
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
private static final Logger log = LoggerFactory.getLogger(Config.class);
|
private static final Logger log = LoggerFactory.getLogger(Config.class);
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ public class Config {
|
||||||
private File electrumServerCert;
|
private File electrumServerCert;
|
||||||
private boolean useProxy;
|
private boolean useProxy;
|
||||||
private String proxyServer;
|
private String proxyServer;
|
||||||
|
private int maxServerTimeout = DEFAULT_MAX_TIMEOUT;
|
||||||
private boolean usePayNym;
|
private boolean usePayNym;
|
||||||
private boolean sameAppMixing;
|
private boolean sameAppMixing;
|
||||||
private Double appWidth;
|
private Double appWidth;
|
||||||
|
@ -503,6 +505,15 @@ public class Config {
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxServerTimeout() {
|
||||||
|
return maxServerTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxServerTimeout(int maxServerTimeout) {
|
||||||
|
this.maxServerTimeout = maxServerTimeout;
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isUsePayNym() {
|
public boolean isUsePayNym() {
|
||||||
return usePayNym;
|
return usePayNym;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import java.io.*;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.Condition;
|
import java.util.concurrent.locks.Condition;
|
||||||
|
@ -25,7 +26,8 @@ public class TcpTransport implements Transport, Closeable {
|
||||||
private static final Logger log = LoggerFactory.getLogger(TcpTransport.class);
|
private static final Logger log = LoggerFactory.getLogger(TcpTransport.class);
|
||||||
|
|
||||||
public static final int DEFAULT_PORT = 50001;
|
public static final int DEFAULT_PORT = 50001;
|
||||||
private static final int[] BASE_READ_TIMEOUT_SECS = {3, 8, 16, 34};
|
public static final int DEFAULT_MAX_TIMEOUT = 34;
|
||||||
|
private static final int[] BASE_READ_TIMEOUT_SECS = {3, 8, 16, DEFAULT_MAX_TIMEOUT};
|
||||||
private static final int[] SLOW_READ_TIMEOUT_SECS = {34, 68, 124, 208};
|
private static final int[] SLOW_READ_TIMEOUT_SECS = {34, 68, 124, 208};
|
||||||
public static final long PER_REQUEST_READ_TIMEOUT_MILLIS = 50;
|
public static final long PER_REQUEST_READ_TIMEOUT_MILLIS = 50;
|
||||||
public static final int SOCKET_READ_TIMEOUT_MILLIS = 5000;
|
public static final int SOCKET_READ_TIMEOUT_MILLIS = 5000;
|
||||||
|
@ -61,7 +63,13 @@ public class TcpTransport implements Transport, Closeable {
|
||||||
public TcpTransport(HostAndPort server, HostAndPort proxy) {
|
public TcpTransport(HostAndPort server, HostAndPort proxy) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.socketFactory = (proxy == null ? SocketFactory.getDefault() : new ProxySocketFactory(proxy));
|
this.socketFactory = (proxy == null ? SocketFactory.getDefault() : new ProxySocketFactory(proxy));
|
||||||
this.readTimeouts = (Config.get().getServerType() == ServerType.BITCOIN_CORE && Protocol.isOnionAddress(Config.get().getCoreServer()) ? SLOW_READ_TIMEOUT_SECS : BASE_READ_TIMEOUT_SECS);
|
|
||||||
|
int[] timeouts = (Config.get().getServerType() == ServerType.BITCOIN_CORE && Protocol.isOnionAddress(Config.get().getCoreServer()) ?
|
||||||
|
Arrays.copyOf(SLOW_READ_TIMEOUT_SECS, SLOW_READ_TIMEOUT_SECS.length) : Arrays.copyOf(BASE_READ_TIMEOUT_SECS, BASE_READ_TIMEOUT_SECS.length));
|
||||||
|
if(Config.get().getMaxServerTimeout() > timeouts[timeouts.length - 1]) {
|
||||||
|
timeouts[timeouts.length - 1] = Config.get().getMaxServerTimeout();
|
||||||
|
}
|
||||||
|
this.readTimeouts = timeouts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue