mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
avoid resolution of onion hosts when creating proxied server socket addresses
This commit is contained in:
parent
f1a662ba8a
commit
ca782dfc69
2 changed files with 15 additions and 3 deletions
|
@ -117,8 +117,12 @@ public enum Protocol {
|
||||||
return toUrlString() + hostAndPort.toString();
|
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) {
|
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) {
|
public static boolean isOnionAddress(String address) {
|
||||||
|
|
|
@ -33,12 +33,12 @@ public class ProxySocketFactory extends SocketFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Socket createSocket(String address, int port) throws IOException {
|
public Socket createSocket(String address, int port) throws IOException {
|
||||||
return createSocket(new InetSocketAddress(address, port), null);
|
return createSocket(createAddress(address, port), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Socket createSocket(String address, int port, InetAddress localAddress, int localPort) throws IOException {
|
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
|
@Override
|
||||||
|
@ -51,6 +51,14 @@ public class ProxySocketFactory extends SocketFactory {
|
||||||
return createSocket(new InetSocketAddress(address, port), new InetSocketAddress(localAddress, localPort));
|
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 {
|
private Socket createSocket(InetSocketAddress address, InetSocketAddress bindAddress) throws IOException {
|
||||||
Socket socket = new Socket(proxy);
|
Socket socket = new Socket(proxy);
|
||||||
if(bindAddress != null) {
|
if(bindAddress != null) {
|
||||||
|
|
Loading…
Reference in a new issue