Skip to content

Commit

Permalink
VersionMessage: Fix names of addr fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Schildbach committed Apr 7, 2018
1 parent 3975a89 commit 321ac5d
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions core/src/main/java/org/bitcoinj/core/VersionMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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;

Expand Down Expand Up @@ -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 <a href="https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki">BIP 14</a>.
* Bitcoin Core sets it to something like "/Satoshi:0.9.1/".
Expand Down Expand Up @@ -106,8 +105,8 @@ public VersionMessage(NetworkParameters params, int newBestHeight) {
// 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;
Expand All @@ -123,10 +122,10 @@ protected void parse() throws ProtocolException {
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.
Expand Down Expand Up @@ -160,12 +159,8 @@ public void bitcoinSerializeToStream(OutputStream buf) throws IOException {
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.
}
Expand Down Expand Up @@ -201,15 +196,15 @@ public boolean equals(Object o) {
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
Expand All @@ -219,8 +214,8 @@ public String toString() {
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");
Expand All @@ -232,8 +227,8 @@ public VersionMessage duplicate() {
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;
Expand Down

0 comments on commit 321ac5d

Please sign in to comment.