mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-13 02:35:52 +00:00
PeerGroup: make use of peer discovery optional with Tor
This commit is contained in:
parent
469a589951
commit
db42dc4630
@ -295,9 +295,27 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||||||
* <p>The user does not need any additional software for this: it's all pure Java. As of April 2014 <b>this mode
|
* <p>The user does not need any additional software for this: it's all pure Java. As of April 2014 <b>this mode
|
||||||
* is experimental</b>.</p>
|
* is experimental</b>.</p>
|
||||||
*
|
*
|
||||||
* @throws java.util.concurrent.TimeoutException if Tor fails to start within 20 seconds.
|
* @throws TimeoutException if Tor fails to start within 20 seconds.
|
||||||
*/
|
*/
|
||||||
public static PeerGroup newWithTor(Context context, @Nullable AbstractBlockChain chain, TorClient torClient) throws TimeoutException {
|
public static PeerGroup newWithTor(Context context, @Nullable AbstractBlockChain chain, TorClient torClient) throws TimeoutException {
|
||||||
|
return newWithTor(context, chain, torClient, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Creates a PeerGroup that accesses the network via the Tor network. The provided TorClient is used so you can
|
||||||
|
* preconfigure it beforehand. It should not have been already started. You can just use "new TorClient()" if
|
||||||
|
* you don't have any particular configuration requirements.</p>
|
||||||
|
*
|
||||||
|
* <p>If running on the Oracle JDK the unlimited strength jurisdiction checks will also be overridden,
|
||||||
|
* as they no longer apply anyway and can cause startup failures due to the requirement for AES-256.</p>
|
||||||
|
*
|
||||||
|
* <p>The user does not need any additional software for this: it's all pure Java. As of April 2014 <b>this mode
|
||||||
|
* is experimental</b>.</p>
|
||||||
|
*
|
||||||
|
* @params doDiscovery if true, DNS or HTTP peer discovery will be performed via Tor: this is almost always what you want.
|
||||||
|
* @throws java.util.concurrent.TimeoutException if Tor fails to start within 20 seconds.
|
||||||
|
*/
|
||||||
|
public static PeerGroup newWithTor(Context context, @Nullable AbstractBlockChain chain, TorClient torClient, boolean doDiscovery) throws TimeoutException {
|
||||||
checkNotNull(torClient);
|
checkNotNull(torClient);
|
||||||
DRMWorkaround.maybeDisableExportControls();
|
DRMWorkaround.maybeDisableExportControls();
|
||||||
BlockingClientManager manager = new BlockingClientManager(torClient.getSocketFactory());
|
BlockingClientManager manager = new BlockingClientManager(torClient.getSocketFactory());
|
||||||
@ -306,15 +324,17 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||||||
PeerGroup result = new PeerGroup(context, chain, manager, torClient);
|
PeerGroup result = new PeerGroup(context, chain, manager, torClient);
|
||||||
result.setConnectTimeoutMillis(CONNECT_TIMEOUT_MSEC);
|
result.setConnectTimeoutMillis(CONNECT_TIMEOUT_MSEC);
|
||||||
|
|
||||||
NetworkParameters params = context.getParams();
|
if (doDiscovery) {
|
||||||
HttpDiscovery.Details[] httpSeeds = params.getHttpSeeds();
|
NetworkParameters params = context.getParams();
|
||||||
if (httpSeeds.length > 0) {
|
HttpDiscovery.Details[] httpSeeds = params.getHttpSeeds();
|
||||||
// Use HTTP discovery when Tor is active and there is a Cartographer seed, for a much needed speed boost.
|
if (httpSeeds.length > 0) {
|
||||||
OkHttpClient client = new OkHttpClient();
|
// Use HTTP discovery when Tor is active and there is a Cartographer seed, for a much needed speed boost.
|
||||||
client.setSocketFactory(torClient.getSocketFactory());
|
OkHttpClient client = new OkHttpClient();
|
||||||
result.addPeerDiscovery(new HttpDiscovery(params, httpSeeds[0], client));
|
client.setSocketFactory(torClient.getSocketFactory());
|
||||||
} else {
|
result.addPeerDiscovery(new HttpDiscovery(params, httpSeeds[0], client));
|
||||||
result.addPeerDiscovery(new TorDiscovery(params, torClient));
|
} else {
|
||||||
|
result.addPeerDiscovery(new TorDiscovery(params, torClient));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user