mirror of
https://github.com/boldsuck/haveno.git
synced 2024-12-23 04:29:22 +00:00
disable tor for private ip addresses to fix #1026
This commit is contained in:
parent
4819e5ebfa
commit
4494af8bc0
6 changed files with 41 additions and 20 deletions
|
@ -253,12 +253,12 @@ public final class XmrConnectionService {
|
|||
connectionList.setAutoSwitch(autoSwitch);
|
||||
}
|
||||
|
||||
public boolean isConnectionLocal() {
|
||||
return isConnectionLocal(getConnection());
|
||||
public boolean isConnectionLocalHost() {
|
||||
return isConnectionLocalHost(getConnection());
|
||||
}
|
||||
|
||||
public boolean isConnectionTor() {
|
||||
return useTorProxy(getConnection());
|
||||
public boolean isProxyApplied() {
|
||||
return isProxyApplied(getConnection());
|
||||
}
|
||||
|
||||
public long getRefreshPeriodMs() {
|
||||
|
@ -328,26 +328,26 @@ public final class XmrConnectionService {
|
|||
downloadListener.doneDownload();
|
||||
}
|
||||
|
||||
private boolean isConnectionLocal(MoneroRpcConnection connection) {
|
||||
private boolean isConnectionLocalHost(MoneroRpcConnection connection) {
|
||||
return connection != null && HavenoUtils.isLocalHost(connection.getUri());
|
||||
}
|
||||
|
||||
private long getDefaultRefreshPeriodMs() {
|
||||
MoneroRpcConnection connection = getConnection();
|
||||
if (connection == null) return XmrLocalNode.REFRESH_PERIOD_LOCAL_MS;
|
||||
if (isConnectionLocal(connection)) {
|
||||
if (isConnectionLocalHost(connection)) {
|
||||
if (lastInfo != null && (lastInfo.isBusySyncing() || (lastInfo.getHeightWithoutBootstrap() != null && lastInfo.getHeightWithoutBootstrap() > 0 && lastInfo.getHeightWithoutBootstrap() < lastInfo.getHeight()))) return REFRESH_PERIOD_HTTP_MS; // refresh slower if syncing or bootstrapped
|
||||
else return XmrLocalNode.REFRESH_PERIOD_LOCAL_MS; // TODO: announce faster refresh after done syncing
|
||||
} else if (useTorProxy(connection)) {
|
||||
} else if (isProxyApplied(connection)) {
|
||||
return REFRESH_PERIOD_ONION_MS;
|
||||
} else {
|
||||
return REFRESH_PERIOD_HTTP_MS;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean useTorProxy(MoneroRpcConnection connection) {
|
||||
private boolean isProxyApplied(MoneroRpcConnection connection) {
|
||||
if (connection == null) return false;
|
||||
return connection.isOnion() || (preferences.getUseTorForXmr().isUseTorForXmr() && !HavenoUtils.isLocalHost(connection.getUri()));
|
||||
return connection.isOnion() || (preferences.getUseTorForXmr().isUseTorForXmr() && !HavenoUtils.isPrivateIp(connection.getUri()));
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
|
@ -475,7 +475,7 @@ public final class XmrConnectionService {
|
|||
// set connection proxies
|
||||
log.info("TOR proxy URI: " + getProxyUri());
|
||||
for (MoneroRpcConnection connection : connectionManager.getConnections()) {
|
||||
if (useTorProxy(connection)) connection.setProxyUri(getProxyUri());
|
||||
if (isProxyApplied(connection)) connection.setProxyUri(getProxyUri());
|
||||
}
|
||||
|
||||
// restore auto switch
|
||||
|
@ -495,7 +495,7 @@ public final class XmrConnectionService {
|
|||
// set connection from startup argument if given
|
||||
connectionManager.setAutoSwitch(false);
|
||||
MoneroRpcConnection connection = new MoneroRpcConnection(config.xmrNode, config.xmrNodeUsername, config.xmrNodePassword).setPriority(1);
|
||||
if (useTorProxy(connection)) connection.setProxyUri(getProxyUri());
|
||||
if (isProxyApplied(connection)) connection.setProxyUri(getProxyUri());
|
||||
connectionManager.setConnection(connection);
|
||||
|
||||
// start local node if applicable
|
||||
|
|
|
@ -268,9 +268,9 @@ public class WalletAppSetup {
|
|||
|
||||
private String getXmrDaemonNetworkAsString() {
|
||||
String postFix;
|
||||
if (xmrConnectionService.isConnectionLocal())
|
||||
if (xmrConnectionService.isConnectionLocalHost())
|
||||
postFix = " " + Res.get("mainView.footer.localhostMoneroNode");
|
||||
else if (xmrConnectionService.isConnectionTor())
|
||||
else if (xmrConnectionService.isProxyApplied())
|
||||
postFix = " " + Res.get("mainView.footer.usingTor");
|
||||
else
|
||||
postFix = "";
|
||||
|
@ -279,7 +279,7 @@ public class WalletAppSetup {
|
|||
|
||||
private String getXmrWalletNetworkAsString() {
|
||||
String postFix;
|
||||
if (xmrConnectionService.isConnectionLocal())
|
||||
if (xmrConnectionService.isConnectionLocalHost())
|
||||
postFix = " " + Res.get("mainView.footer.localhostMoneroNode");
|
||||
else if (xmrWalletService.isProxyApplied())
|
||||
postFix = " " + Res.get("mainView.footer.usingTor");
|
||||
|
|
|
@ -293,7 +293,7 @@ public class OfferBookService {
|
|||
}
|
||||
|
||||
private long getKeyImageRefreshPeriodMs() {
|
||||
return xmrConnectionService.isConnectionLocal() ? KEY_IMAGE_REFRESH_PERIOD_MS_LOCAL : KEY_IMAGE_REFRESH_PERIOD_MS_REMOTE;
|
||||
return xmrConnectionService.isConnectionLocalHost() ? KEY_IMAGE_REFRESH_PERIOD_MS_LOCAL : KEY_IMAGE_REFRESH_PERIOD_MS_REMOTE;
|
||||
}
|
||||
|
||||
private void updateAffectedOffers(String keyImage) {
|
||||
|
|
|
@ -288,7 +288,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
|||
}
|
||||
|
||||
private long getKeyImageRefreshPeriodMs() {
|
||||
return xmrConnectionService.isConnectionLocal() ? KEY_IMAGE_REFRESH_PERIOD_MS_LOCAL : KEY_IMAGE_REFRESH_PERIOD_MS_REMOTE;
|
||||
return xmrConnectionService.isConnectionLocalHost() ? KEY_IMAGE_REFRESH_PERIOD_MS_LOCAL : KEY_IMAGE_REFRESH_PERIOD_MS_REMOTE;
|
||||
}
|
||||
|
||||
public void onAllServicesInitialized() {
|
||||
|
|
|
@ -40,6 +40,7 @@ import haveno.core.xmr.wallet.XmrWalletService;
|
|||
import haveno.network.p2p.NodeAddress;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.security.PrivateKey;
|
||||
import java.text.DecimalFormat;
|
||||
|
@ -418,12 +419,32 @@ public class HavenoUtils {
|
|||
/**
|
||||
* Check if the given URI is on local host.
|
||||
*/
|
||||
public static boolean isLocalHost(String uri) {
|
||||
public static boolean isLocalHost(String uriString) {
|
||||
try {
|
||||
String host = new URI(uri).getHost();
|
||||
String host = new URI(uriString).getHost();
|
||||
return LOOPBACK_HOST.equals(host) || LOCALHOST.equals(host);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given URI is local or a private IP address.
|
||||
*/
|
||||
public static boolean isPrivateIp(String uriString) {
|
||||
if (isLocalHost(uriString)) return true;
|
||||
try {
|
||||
|
||||
// get the host
|
||||
URI uri = new URI(uriString);
|
||||
String host = uri.getHost();
|
||||
|
||||
// check if private IP address
|
||||
if (host == null) return false;
|
||||
InetAddress inetAddress = InetAddress.getByName(host);
|
||||
return inetAddress.isAnyLocalAddress() || inetAddress.isLoopbackAddress() || inetAddress.isSiteLocalAddress();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -322,7 +322,7 @@ public class XmrWalletService {
|
|||
}
|
||||
|
||||
public boolean isProxyApplied(boolean wasWalletSynced) {
|
||||
return preferences.isProxyApplied(wasWalletSynced);
|
||||
return preferences.isProxyApplied(wasWalletSynced) && xmrConnectionService.isProxyApplied();
|
||||
}
|
||||
|
||||
public String getWalletPassword() {
|
||||
|
|
Loading…
Reference in a new issue