Browse Source

avoid resolution of onion hosts when creating proxied server socket addresses

terminal
Craig Raw 2 years ago
parent
commit
ca782dfc69
  1. 6
      src/main/java/com/sparrowwallet/sparrow/net/Protocol.java
  2. 12
      src/main/java/com/sparrowwallet/sparrow/net/ProxySocketFactory.java

6
src/main/java/com/sparrowwallet/sparrow/net/Protocol.java

@ -117,8 +117,12 @@ public enum Protocol {
return toUrlString() + hostAndPort.toString();
}
public static boolean isOnionHost(String host) {
return host != null && host.toLowerCase(Locale.ROOT).endsWith(TorService.TOR_ADDRESS_SUFFIX);
}
public static boolean isOnionAddress(HostAndPort server) {
return server.getHost().toLowerCase(Locale.ROOT).endsWith(TorService.TOR_ADDRESS_SUFFIX);
return isOnionHost(server.getHost());
}
public static boolean isOnionAddress(String address) {

12
src/main/java/com/sparrowwallet/sparrow/net/ProxySocketFactory.java

@ -33,12 +33,12 @@ public class ProxySocketFactory extends SocketFactory {
@Override
public Socket createSocket(String address, int port) throws IOException {
return createSocket(new InetSocketAddress(address, port), null);
return createSocket(createAddress(address, port), null);
}
@Override
public Socket createSocket(String address, int port, InetAddress localAddress, int localPort) throws IOException {
return createSocket(new InetSocketAddress(address, port), new InetSocketAddress(localAddress, localPort));
return createSocket(createAddress(address, port), new InetSocketAddress(localAddress, localPort));
}
@Override
@ -51,6 +51,14 @@ public class ProxySocketFactory extends SocketFactory {
return createSocket(new InetSocketAddress(address, port), new InetSocketAddress(localAddress, localPort));
}
private InetSocketAddress createAddress(String address, int port) {
if(Protocol.isOnionHost(address)) {
return InetSocketAddress.createUnresolved(address, port);
} else {
return new InetSocketAddress(address, port);
}
}
private Socket createSocket(InetSocketAddress address, InetSocketAddress bindAddress) throws IOException {
Socket socket = new Socket(proxy);
if(bindAddress != null) {

Loading…
Cancel
Save