mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2026-08-09 08:14:43 +00:00
upgrade tern to 1.0.6
This commit is contained in:
@@ -6,7 +6,23 @@ import javafx.concurrent.Task;
|
||||
|
||||
public class HttpClientService extends com.sparrowwallet.tern.http.client.HttpClientService {
|
||||
public HttpClientService(HostAndPort torProxy) {
|
||||
super(new HttpProxySupplier(torProxy));
|
||||
super(new TorHttpProxySupplier(torProxy));
|
||||
}
|
||||
|
||||
public HostAndPort getTorProxy() {
|
||||
if(getHttpProxySupplier() instanceof TorHttpProxySupplier torHttpProxySupplier) {
|
||||
return torHttpProxySupplier.getTorProxy();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setTorProxy(HostAndPort torProxy) {
|
||||
if(getHttpProxySupplier() instanceof TorHttpProxySupplier torHttpProxySupplier) {
|
||||
//Ensure all http clients are shutdown first
|
||||
stop();
|
||||
torHttpProxySupplier._setTorProxy(torProxy);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ShutdownService extends Service<Boolean> {
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.sparrowwallet.sparrow.net;
|
||||
|
||||
import com.google.common.net.HostAndPort;
|
||||
import com.sparrowwallet.tern.http.client.TorHttpProxySupplier;
|
||||
|
||||
public class HttpProxySupplier extends TorHttpProxySupplier {
|
||||
public HttpProxySupplier(HostAndPort torProxy) {
|
||||
super(torProxy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeIdentity() {
|
||||
HostAndPort torProxy = getTorProxy();
|
||||
if(torProxy != null) {
|
||||
TorUtils.changeIdentity(torProxy);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.sparrowwallet.sparrow.net;
|
||||
|
||||
import com.google.common.net.HostAndPort;
|
||||
import com.sparrowwallet.tern.http.client.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class TorHttpProxySupplier implements IHttpProxySupplier {
|
||||
private HostAndPort torProxy;
|
||||
private HttpProxy httpProxy;
|
||||
|
||||
public TorHttpProxySupplier(HostAndPort torProxy) {
|
||||
this.torProxy = torProxy;
|
||||
this.httpProxy = computeHttpProxy(torProxy);
|
||||
}
|
||||
|
||||
private HttpProxy computeHttpProxy(HostAndPort hostAndPort) {
|
||||
if (hostAndPort == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new HttpProxy(HttpProxyProtocol.SOCKS, hostAndPort.getHost(), hostAndPort.getPort());
|
||||
}
|
||||
|
||||
public HostAndPort getTorProxy() {
|
||||
return torProxy;
|
||||
}
|
||||
|
||||
// shouldn't call directly but use httpClientService.setTorProxy()
|
||||
public void _setTorProxy(HostAndPort hostAndPort) {
|
||||
// set proxy
|
||||
this.torProxy = hostAndPort;
|
||||
this.httpProxy = computeHttpProxy(hostAndPort);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HttpProxy> getHttpProxy(HttpUsage httpUsage) {
|
||||
return Optional.ofNullable(httpProxy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeIdentity() {
|
||||
HostAndPort torProxy = getTorProxy();
|
||||
if(torProxy != null) {
|
||||
TorUtils.changeIdentity(torProxy);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user