mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 13:16:44 +00:00
upgrade tern to 1.0.6
This commit is contained in:
parent
6927423d68
commit
4f00fabd23
4 changed files with 67 additions and 21 deletions
|
@ -1,7 +1,7 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'application'
|
id 'application'
|
||||||
id 'org-openjfx-javafxplugin'
|
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'
|
id 'org.gradlex.extra-java-module-info' version '1.9'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ dependencies {
|
||||||
exclude group: 'org.slf4j'
|
exclude group: 'org.slf4j'
|
||||||
}
|
}
|
||||||
implementation('com.sparrowwallet.bokmakierie:bokmakierie:1.0')
|
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:rxjava:2.2.15')
|
||||||
implementation('io.reactivex.rxjava2:rxjavafx:2.2.2')
|
implementation('io.reactivex.rxjava2:rxjavafx:2.2.2')
|
||||||
implementation('org.apache.commons:commons-lang3:3.7')
|
implementation('org.apache.commons:commons-lang3:3.7')
|
||||||
|
|
|
@ -6,7 +6,23 @@ import javafx.concurrent.Task;
|
||||||
|
|
||||||
public class HttpClientService extends com.sparrowwallet.tern.http.client.HttpClientService {
|
public class HttpClientService extends com.sparrowwallet.tern.http.client.HttpClientService {
|
||||||
public HttpClientService(HostAndPort torProxy) {
|
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> {
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue