DnsLookupTor: Close socket after usage

This commit is contained in:
Alva Swanson 2024-11-05 01:02:25 +00:00
parent e1c7a0dc30
commit f92f4e8da0
No known key found for this signature in database
GPG Key ID: 004760E77F753090

View File

@ -60,16 +60,14 @@ public class DnsLookupTor {
* Performs DNS lookup and returns a single InetAddress * Performs DNS lookup and returns a single InetAddress
*/ */
public static InetAddress lookup(Socks5Proxy proxy, String host) throws DnsLookupException { public static InetAddress lookup(Socks5Proxy proxy, String host) throws DnsLookupException {
try { // note: This is creating a new connection to our proxy, without any authentication.
// note: This is creating a new connection to our proxy, without any authentication. // This works fine when connecting to bisq's internal Tor proxy, but
// This works fine when connecting to bisq's internal Tor proxy, but // would fail if user has configured an external proxy that requires auth.
// would fail if user has configured an external proxy that requires auth. // It would be much better to use the already connected proxy socket, but when I
// It would be much better to use the already connected proxy socket, but when I // tried that I get weird errors and the lookup fails.
// tried that I get weird errors and the lookup fails. //
// // So this is an area for future improvement.
// So this is an area for future improvement. try (Socket proxySocket = new Socket(proxy.getInetAddress(), proxy.getPort())) {
Socket proxySocket = new Socket(proxy.getInetAddress(), proxy.getPort());
proxySocket.getOutputStream().write(new byte[]{b('\u0005'), b('\u0001'), b('\u0000')}); proxySocket.getOutputStream().write(new byte[]{b('\u0005'), b('\u0001'), b('\u0000')});
byte[] buf = new byte[2]; byte[] buf = new byte[2];
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored