3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 14:54:15 +00:00

Fix Java 6 compatibility.

This commit is contained in:
Mike Hearn 2014-07-31 15:53:14 +02:00
parent 0f124b9ef4
commit 4dc3392719
3 changed files with 11 additions and 4 deletions

View File

@ -17,6 +17,7 @@
package com.google.bitcoin.core;
import com.google.bitcoin.params.MainNetParams;
import com.google.common.net.InetAddresses;
import java.io.IOException;
import java.io.OutputStream;
@ -100,7 +101,7 @@ public class PeerAddress extends ChildMessage {
}
public static PeerAddress localhost(NetworkParameters params) {
return new PeerAddress(InetAddress.getLoopbackAddress(), params.getPort());
return new PeerAddress(InetAddresses.forString("127.0.0.1"), params.getPort());
}
@Override

View File

@ -34,6 +34,7 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import com.google.common.io.Closeables;
import com.google.common.net.InetAddresses;
import com.google.common.primitives.Ints;
import com.google.common.primitives.Longs;
import com.google.common.util.concurrent.*;
@ -706,9 +707,13 @@ public class PeerGroup extends AbstractExecutionThreadService implements Transac
// Do a fast blocking connect to see if anything is listening.
try {
Socket socket = new Socket();
socket.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), params.getPort()), vConnectTimeoutMillis);
socket.connect(new InetSocketAddress(InetAddresses.forString("127.0.0.1"), params.getPort()), vConnectTimeoutMillis);
localhostCheckState = LocalhostCheckState.FOUND;
Closeables.close(socket, true);
try {
socket.close();
} catch (IOException e) {
// Ignore.
}
return true;
} catch (IOException e) {
log.info("Localhost peer not detected.");

View File

@ -26,6 +26,7 @@ import com.google.bitcoin.testing.TestWithPeerGroup;
import com.google.bitcoin.utils.Threading;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.net.InetAddresses;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import org.junit.After;
@ -652,7 +653,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
@Test
public void preferLocalPeer() throws IOException {
// Check that if we have a localhost port 8333 then it's used instead of the p2p network.
ServerSocket local = new ServerSocket(params.getPort(), 100, InetAddress.getLoopbackAddress());
ServerSocket local = new ServerSocket(params.getPort(), 100, InetAddresses.forString("127.0.0.1"));
try {
peerGroup.startAsync();
peerGroup.awaitRunning();