diff --git a/core/src/main/java/org/bitcoinj/core/VersionMessage.java b/core/src/main/java/org/bitcoinj/core/VersionMessage.java index cdd4d5f6..e0264563 100644 --- a/core/src/main/java/org/bitcoinj/core/VersionMessage.java +++ b/core/src/main/java/org/bitcoinj/core/VersionMessage.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.io.OutputStream; import java.math.BigInteger; import java.net.InetAddress; -import java.net.UnknownHostException; import java.nio.charset.StandardCharsets; import java.util.Locale; @@ -68,13 +67,13 @@ public class VersionMessage extends Message { */ public long time; /** - * What the other side believes the address of this program is. Not used. + * The network address of the node receiving this message. Not used. */ - public PeerAddress myAddr; + public PeerAddress receivingAddr; /** - * What the other side believes their own address is. Not used. + * The network address of the node emitting this message. Not used. */ - public PeerAddress theirAddr; + public PeerAddress fromAddr; /** * User-Agent as defined in BIP 14. * Bitcoin Core sets it to something like "/Satoshi:0.9.1/". @@ -106,8 +105,8 @@ public class VersionMessage extends Message { // 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. InetAddress localhost = InetAddresses.forString("127.0.0.1"); - myAddr = new PeerAddress(params, localhost, params.getPort(), 0, BigInteger.ZERO); - theirAddr = new PeerAddress(params, localhost, params.getPort(), 0, BigInteger.ZERO); + receivingAddr = new PeerAddress(params, localhost, params.getPort(), 0, BigInteger.ZERO); + fromAddr = new PeerAddress(params, localhost, params.getPort(), 0, BigInteger.ZERO); subVer = LIBRARY_SUBVER; bestHeight = newBestHeight; relayTxesBeforeFilter = true; @@ -123,10 +122,10 @@ public class VersionMessage extends Message { clientVersion = (int) readUint32(); localServices = readUint64().longValue(); time = readUint64().longValue(); - myAddr = new PeerAddress(params, payload, cursor, 0); - cursor += myAddr.getMessageSize(); - theirAddr = new PeerAddress(params, payload, cursor, 0); - cursor += theirAddr.getMessageSize(); + receivingAddr = new PeerAddress(params, payload, cursor, 0); + cursor += receivingAddr.getMessageSize(); + fromAddr = new PeerAddress(params, payload, cursor, 0); + cursor += fromAddr.getMessageSize(); // uint64 localHostNonce (random data) // We don't care about the localhost nonce. It's used to detect connecting back to yourself in cases where // there are NATs and proxies in the way. However we don't listen for inbound connections so it's irrelevant. @@ -160,12 +159,8 @@ public class VersionMessage extends Message { Utils.uint32ToByteStreamLE(time, buf); Utils.uint32ToByteStreamLE(time >> 32, buf); try { - // My address. - myAddr.bitcoinSerialize(buf); - // Their address. - theirAddr.bitcoinSerialize(buf); - } catch (UnknownHostException e) { - throw new RuntimeException(e); // Can't happen. + receivingAddr.bitcoinSerialize(buf); + fromAddr.bitcoinSerialize(buf); } catch (IOException e) { throw new RuntimeException(e); // Can't happen. } @@ -201,15 +196,15 @@ public class VersionMessage extends Message { other.localServices == localServices && other.time == time && other.subVer.equals(subVer) && - other.myAddr.equals(myAddr) && - other.theirAddr.equals(theirAddr) && + other.receivingAddr.equals(receivingAddr) && + other.fromAddr.equals(fromAddr) && other.relayTxesBeforeFilter == relayTxesBeforeFilter; } @Override public int hashCode() { return Objects.hashCode(bestHeight, clientVersion, localServices, - time, subVer, myAddr, theirAddr, relayTxesBeforeFilter); + time, subVer, receivingAddr, fromAddr, relayTxesBeforeFilter); } @Override @@ -219,8 +214,8 @@ public class VersionMessage extends Message { stringBuilder.append("client version: ").append(clientVersion).append("\n"); stringBuilder.append("local services: ").append(localServices).append("\n"); stringBuilder.append("time: ").append(time).append("\n"); - stringBuilder.append("my addr: ").append(myAddr).append("\n"); - stringBuilder.append("their addr: ").append(theirAddr).append("\n"); + stringBuilder.append("receiving addr: ").append(receivingAddr).append("\n"); + stringBuilder.append("from addr: ").append(fromAddr).append("\n"); stringBuilder.append("sub version: ").append(subVer).append("\n"); stringBuilder.append("best height: ").append(bestHeight).append("\n"); stringBuilder.append("delay tx relay: ").append(!relayTxesBeforeFilter).append("\n"); @@ -232,8 +227,8 @@ public class VersionMessage extends Message { v.clientVersion = clientVersion; v.localServices = localServices; v.time = time; - v.myAddr = myAddr; - v.theirAddr = theirAddr; + v.receivingAddr = receivingAddr; + v.fromAddr = fromAddr; v.subVer = subVer; v.relayTxesBeforeFilter = relayTxesBeforeFilter; return v;