upgrade tern to 1.0.6

This commit is contained in:
Craig Raw 2024-11-28 11:03:49 +02:00
parent 6927423d68
commit 4f00fabd23
4 changed files with 67 additions and 21 deletions

View file

@ -1,7 +1,7 @@
plugins {
id 'application'
id 'org-openjfx-javafxplugin'
id 'org.beryx.jlink' version '3.0.1'
id 'org.beryx.jlink' version '3.1.1'
id 'org.gradlex.extra-java-module-info' version '1.9'
}
@ -132,7 +132,7 @@ dependencies {
exclude group: 'org.slf4j'
}
implementation('com.sparrowwallet.bokmakierie:bokmakierie:1.0')
implementation('com.sparrowwallet:tern:1.0.3')
implementation('com.sparrowwallet:tern:1.0.6')
implementation('io.reactivex.rxjava2:rxjava:2.2.15')
implementation('io.reactivex.rxjava2:rxjavafx:2.2.2')
implementation('org.apache.commons:commons-lang3:3.7')

View file

@ -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> {

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}