mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2025-11-05 11:56:37 +00:00
avoid server address resolution for public servers, and assume non local for failures where a proxy is configured
This commit is contained in:
parent
b777c8c64d
commit
e31aa7fc80
3 changed files with 29 additions and 2 deletions
|
|
@ -118,7 +118,8 @@ public class ElectrumServer {
|
|||
previousServer = electrumServer;
|
||||
|
||||
HostAndPort hostAndPort = electrumServer.getHostAndPort();
|
||||
boolean localNetworkAddress = !protocol.isOnionAddress(hostAndPort) && IpAddressMatcher.isLocalNetworkAddress(hostAndPort.getHost());
|
||||
boolean localNetworkAddress = !Protocol.isOnionAddress(hostAndPort) && !PublicElectrumServer.isPublicServer(hostAndPort)
|
||||
&& IpAddressMatcher.isLocalNetworkAddress(hostAndPort.getHost());
|
||||
|
||||
if(!localNetworkAddress && Config.get().isUseProxy() && proxyServer != null && !proxyServer.isBlank()) {
|
||||
HostAndPort proxy = HostAndPort.fromString(proxyServer);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ package com.sparrowwallet.sparrow.net;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
|
|
@ -32,6 +36,8 @@ import java.net.UnknownHostException;
|
|||
* Slightly modified by omidzk to have zero dependency to any frameworks other than the JRE.
|
||||
*/
|
||||
public final class IpAddressMatcher {
|
||||
private static final Logger log = LoggerFactory.getLogger(IpAddressMatcher.class);
|
||||
|
||||
private static final IpAddressMatcher LOCAL_RANGE_1 = new IpAddressMatcher("10.0.0.0/8");
|
||||
private static final IpAddressMatcher LOCAL_RANGE_2 = new IpAddressMatcher("172.16.0.0/12");
|
||||
private static final IpAddressMatcher LOCAL_RANGE_3 = new IpAddressMatcher("192.168.0.0/16");
|
||||
|
|
@ -102,6 +108,15 @@ public final class IpAddressMatcher {
|
|||
}
|
||||
|
||||
public static boolean isLocalNetworkAddress(String address) {
|
||||
return "localhost".equals(address) || "127.0.0.1".equals(address) || LOCAL_RANGE_1.matches(address) || LOCAL_RANGE_2.matches(address) || LOCAL_RANGE_3.matches(address) || LOCAL_RANGE_4.matches(address);
|
||||
try {
|
||||
return "localhost".equals(address) || "127.0.0.1".equals(address) || LOCAL_RANGE_1.matches(address) || LOCAL_RANGE_2.matches(address) || LOCAL_RANGE_3.matches(address) || LOCAL_RANGE_4.matches(address);
|
||||
} catch(IllegalArgumentException e) {
|
||||
if(AppServices.isUsingProxy()) {
|
||||
log.info(e.getMessage() + ", assuming it is a non-local address to be resolved by the configured proxy");
|
||||
return false;
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.sparrowwallet.sparrow.net;
|
||||
|
||||
import com.google.common.net.HostAndPort;
|
||||
import com.sparrowwallet.drongo.Network;
|
||||
import com.sparrowwallet.sparrow.io.Server;
|
||||
|
||||
|
|
@ -61,6 +62,16 @@ public enum PublicElectrumServer {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static boolean isPublicServer(HostAndPort hostAndPort) {
|
||||
for(PublicElectrumServer publicServer : values()) {
|
||||
if(publicServer.getServer().getHostAndPort().equals(hostAndPort)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return server.getAlias();
|
||||
|
|
|
|||
Loading…
Reference in a new issue