3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-13 10:45:51 +00:00

PeerGroup: make use of peer discovery optional with Tor

This commit is contained in:
Mike Hearn 2015-06-25 19:02:18 +02:00
parent 469a589951
commit db42dc4630

View File

@ -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,6 +324,7 @@ 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);
if (doDiscovery) {
NetworkParameters params = context.getParams(); NetworkParameters params = context.getParams();
HttpDiscovery.Details[] httpSeeds = params.getHttpSeeds(); HttpDiscovery.Details[] httpSeeds = params.getHttpSeeds();
if (httpSeeds.length > 0) { if (httpSeeds.length > 0) {
@ -316,6 +335,7 @@ public class PeerGroup implements TransactionBroadcaster {
} else { } else {
result.addPeerDiscovery(new TorDiscovery(params, torClient)); result.addPeerDiscovery(new TorDiscovery(params, torClient));
} }
}
return result; return result;
} }