From 88fec4e937fc7e3f1cb487ac5a1f251732e1ad1d Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Tue, 10 Jan 2017 10:59:56 +0100 Subject: [PATCH] VersionMessage: Use Guava InetAddresses for localhost address. --- .../java/org/bitcoinj/core/VersionMessage.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/VersionMessage.java b/core/src/main/java/org/bitcoinj/core/VersionMessage.java index 86aa5e26..4a2bc575 100644 --- a/core/src/main/java/org/bitcoinj/core/VersionMessage.java +++ b/core/src/main/java/org/bitcoinj/core/VersionMessage.java @@ -17,6 +17,8 @@ package org.bitcoinj.core; import com.google.common.base.Objects; +import com.google.common.net.InetAddresses; + import javax.annotation.Nullable; import java.io.IOException; import java.io.OutputStream; @@ -97,15 +99,9 @@ public class VersionMessage extends Message { time = System.currentTimeMillis() / 1000; // Note that the Bitcoin Core doesn't do anything with these, and finding out your own external IP address // is kind of tricky anyway, so we just put nonsense here for now. - try { - // We hard-code the IPv4 localhost address here rather than use InetAddress.getLocalHost() because some - // mobile phones have broken localhost DNS entries, also, this is faster. - final byte[] localhost = { 127, 0, 0, 1 }; - myAddr = new PeerAddress(params, InetAddress.getByAddress(localhost), params.getPort(), 0); - theirAddr = new PeerAddress(params, InetAddress.getByAddress(localhost), params.getPort(), 0); - } catch (UnknownHostException e) { - throw new RuntimeException(e); // Cannot happen (illegal IP length). - } + InetAddress localhost = InetAddresses.forString("127.0.0.1"); + myAddr = new PeerAddress(params, localhost, params.getPort(), 0); + theirAddr = new PeerAddress(params, localhost, params.getPort(), 0); subVer = LIBRARY_SUBVER; bestHeight = newBestHeight; relayTxesBeforeFilter = true;