cormorant: only use proxy when connecting to onion addresses

This commit is contained in:
Craig Raw 2023-02-10 09:12:09 +02:00
parent 58d10cbba4
commit eff0e201f3

View file

@ -4,6 +4,7 @@ import com.github.arteam.simplejsonrpc.client.Transport;
import com.sparrowwallet.drongo.Network; import com.sparrowwallet.drongo.Network;
import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.AppServices;
import com.sparrowwallet.sparrow.io.Server; import com.sparrowwallet.sparrow.io.Server;
import com.sparrowwallet.sparrow.net.Protocol;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -23,6 +24,7 @@ public class BitcoindTransport implements Transport {
private static final Logger log = LoggerFactory.getLogger(BitcoindTransport.class); private static final Logger log = LoggerFactory.getLogger(BitcoindTransport.class);
public static final String COOKIE_FILENAME = ".cookie"; public static final String COOKIE_FILENAME = ".cookie";
private final Server bitcoindServer;
private URL bitcoindUrl; private URL bitcoindUrl;
private File cookieFile; private File cookieFile;
private Long cookieFileTimestamp; private Long cookieFileTimestamp;
@ -39,6 +41,7 @@ public class BitcoindTransport implements Transport {
} }
private BitcoindTransport(Server bitcoindServer, String bitcoindWallet) { private BitcoindTransport(Server bitcoindServer, String bitcoindWallet) {
this.bitcoindServer = bitcoindServer;
try { try {
this.bitcoindUrl = new URL(bitcoindServer.getUrl() + "/wallet/" + bitcoindWallet); this.bitcoindUrl = new URL(bitcoindServer.getUrl() + "/wallet/" + bitcoindWallet);
} catch(MalformedURLException e) { } catch(MalformedURLException e) {
@ -49,7 +52,7 @@ public class BitcoindTransport implements Transport {
@Override @Override
public String pass(String request) throws IOException { public String pass(String request) throws IOException {
Proxy proxy = AppServices.getProxy(); Proxy proxy = AppServices.getProxy();
HttpURLConnection connection = proxy == null ? (HttpURLConnection)bitcoindUrl.openConnection() : (HttpURLConnection)bitcoindUrl.openConnection(proxy); HttpURLConnection connection = proxy != null && Protocol.isOnionAddress(bitcoindServer) ? (HttpURLConnection)bitcoindUrl.openConnection(proxy) : (HttpURLConnection)bitcoindUrl.openConnection();
if(connection instanceof HttpsURLConnection httpsURLConnection) { if(connection instanceof HttpsURLConnection httpsURLConnection) {
SSLSocketFactory sslSocketFactory = getTrustAllSocketFactory(); SSLSocketFactory sslSocketFactory = getTrustAllSocketFactory();