3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-11 17:55:53 +00:00

Add 20 second timeout to HttpDiscovery

This commit is contained in:
Mike Hearn 2015-01-27 21:52:19 +01:00
parent 9b5307ad45
commit f9338519be

View File

@ -38,6 +38,8 @@ import static com.google.common.base.Preconditions.checkArgument;
* This is not currently in use by the Bitcoin community, but rather, is here for experimentation.
*/
public class HttpDiscovery implements PeerDiscovery {
private static final int TIMEOUT_SECS = 20;
private final ECKey pubkey;
private final URI uri;
private final NetworkParameters params;
@ -57,6 +59,8 @@ public class HttpDiscovery implements PeerDiscovery {
public InetSocketAddress[] getPeers(long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
try {
HttpURLConnection conn = (HttpURLConnection) uri.toURL().openConnection();
conn.setReadTimeout(TIMEOUT_SECS * 1000);
conn.setConnectTimeout(TIMEOUT_SECS * 1000);
conn.setRequestProperty("User-Agent", "bitcoinj " + VersionMessage.BITCOINJ_VERSION);
InputStream stream = conn.getInputStream();
GZIPInputStream zip = new GZIPInputStream(stream);