mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-19 09:50:32 +01:00
VersionMessage: remove field fromAddr
The field is unused by the Bitcoin protocol. Bitcoin Core fills it up with zeros. From now on, we'll do the same.
This commit is contained in:
parent
d4f8058164
commit
7383a32e2a
@ -70,10 +70,6 @@ public class VersionMessage extends Message {
|
||||
* The network address of the node receiving this message.
|
||||
*/
|
||||
public PeerAddress receivingAddr;
|
||||
/**
|
||||
* The network address of the node emitting this message. Not used.
|
||||
*/
|
||||
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/".
|
||||
@ -89,6 +85,8 @@ public class VersionMessage extends Message {
|
||||
*/
|
||||
public boolean relayTxesBeforeFilter;
|
||||
|
||||
private static int NETADDR_BYTES = Services.BYTES + /* IPv6 */ 16 + /* port */ Short.BYTES;
|
||||
|
||||
public VersionMessage(ByteBuffer payload) throws ProtocolException {
|
||||
super(payload);
|
||||
}
|
||||
@ -108,19 +106,17 @@ public class VersionMessage extends Message {
|
||||
InetAddress localhost = InetAddresses.forString("127.0.0.1");
|
||||
MessageSerializer serializer = new DummySerializer(0);
|
||||
this.receivingAddr = new PeerAddress(localhost, params.getPort(), Services.none(), serializer);
|
||||
this.fromAddr = new PeerAddress(localhost, params.getPort(), Services.none(), serializer);
|
||||
this.subVer = LIBRARY_SUBVER;
|
||||
this.bestHeight = bestHeight;
|
||||
this.relayTxesBeforeFilter = true;
|
||||
}
|
||||
|
||||
private VersionMessage(int clientVersion, Services localServices, Instant time, PeerAddress receivingAddr,
|
||||
PeerAddress fromAddr, String subVer, long bestHeight, boolean relayTxesBeforeFilter) {
|
||||
String subVer, long bestHeight, boolean relayTxesBeforeFilter) {
|
||||
this.clientVersion = clientVersion;
|
||||
this.localServices = localServices;
|
||||
this.time = time;
|
||||
this.receivingAddr = receivingAddr;
|
||||
this.fromAddr = fromAddr;
|
||||
this.subVer = subVer;
|
||||
this.bestHeight = bestHeight;
|
||||
this.relayTxesBeforeFilter = relayTxesBeforeFilter;
|
||||
@ -152,7 +148,7 @@ public class VersionMessage extends Message {
|
||||
localServices = Services.read(payload);
|
||||
time = Instant.ofEpochSecond(ByteUtils.readInt64(payload));
|
||||
receivingAddr = new PeerAddress(payload, new DummySerializer(0));
|
||||
fromAddr = new PeerAddress(payload, new DummySerializer(0));
|
||||
Buffers.skipBytes(payload, NETADDR_BYTES); // addr_from
|
||||
// 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
|
||||
@ -174,7 +170,7 @@ public class VersionMessage extends Message {
|
||||
buf.write(localServices.serialize());
|
||||
ByteUtils.writeInt64LE(time.getEpochSecond(), buf);
|
||||
receivingAddr.bitcoinSerializeToStream(buf);
|
||||
fromAddr.bitcoinSerializeToStream(buf);
|
||||
buf.write(new byte[NETADDR_BYTES]); // addr_from
|
||||
// Next up is the "local host nonce", this is to detect the case of connecting
|
||||
// back to yourself. We don't care about this as we won't be accepting inbound
|
||||
// connections.
|
||||
@ -200,14 +196,13 @@ public class VersionMessage extends Message {
|
||||
other.time.equals(time) &&
|
||||
other.subVer.equals(subVer) &&
|
||||
other.receivingAddr.equals(receivingAddr) &&
|
||||
other.fromAddr.equals(fromAddr) &&
|
||||
other.relayTxesBeforeFilter == relayTxesBeforeFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(bestHeight, clientVersion, localServices,
|
||||
time, subVer, receivingAddr, fromAddr, relayTxesBeforeFilter);
|
||||
time, subVer, receivingAddr, relayTxesBeforeFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -219,7 +214,6 @@ public class VersionMessage extends Message {
|
||||
builder.append("\n");
|
||||
builder.append("time: ").append(TimeUtils.dateTimeFormat(time)).append("\n");
|
||||
builder.append("receiving addr: ").append(receivingAddr).append("\n");
|
||||
builder.append("from addr: ").append(fromAddr).append("\n");
|
||||
builder.append("sub version: ").append(subVer).append("\n");
|
||||
builder.append("best height: ").append(bestHeight).append("\n");
|
||||
builder.append("delay tx relay: ").append(!relayTxesBeforeFilter).append("\n");
|
||||
@ -227,7 +221,7 @@ public class VersionMessage extends Message {
|
||||
}
|
||||
|
||||
public VersionMessage duplicate() {
|
||||
return new VersionMessage(clientVersion, localServices, time, receivingAddr, fromAddr, subVer, bestHeight,
|
||||
return new VersionMessage(clientVersion, localServices, time, receivingAddr, subVer, bestHeight,
|
||||
relayTxesBeforeFilter);
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,6 @@ public class VersionMessageTest {
|
||||
ver.time = Instant.ofEpochSecond(23456);
|
||||
ver.subVer = "/bitcoinj/";
|
||||
ver.localServices = Services.of(1);
|
||||
ver.fromAddr = new PeerAddress(InetAddress.getByName("1.2.3.4"), 3888);
|
||||
ver.receivingAddr = new PeerAddress(InetAddress.getByName("4.3.2.1"), 8333);
|
||||
byte[] serialized = ver.bitcoinSerialize();
|
||||
VersionMessage ver2 = new VersionMessage(ByteBuffer.wrap(serialized));
|
||||
@ -81,8 +80,6 @@ public class VersionMessageTest {
|
||||
assertEquals("/bitcoinj/", ver2.subVer);
|
||||
assertEquals(ProtocolVersion.CURRENT.intValue(), ver2.clientVersion);
|
||||
assertEquals(1, ver2.localServices.bits());
|
||||
assertEquals("1.2.3.4", ver2.fromAddr.getAddr().getHostAddress());
|
||||
assertEquals(3888, ver2.fromAddr.getPort());
|
||||
assertEquals("4.3.2.1", ver2.receivingAddr.getAddr().getHostAddress());
|
||||
assertEquals(8333, ver2.receivingAddr.getPort());
|
||||
}
|
||||
@ -93,7 +90,6 @@ public class VersionMessageTest {
|
||||
ver.time = Instant.ofEpochSecond(23456);
|
||||
ver.subVer = "/bitcoinj/";
|
||||
ver.localServices = Services.of(1);
|
||||
ver.fromAddr = new PeerAddress(InetAddress.getByName("2001:db8:85a3:0:0:8a2e:370:7334"), 3888);
|
||||
ver.receivingAddr = new PeerAddress(InetAddress.getByName("2002:db8:85a3:0:0:8a2e:370:7335"), 8333);
|
||||
byte[] serialized = ver.bitcoinSerialize();
|
||||
VersionMessage ver2 = new VersionMessage(ByteBuffer.wrap(serialized));
|
||||
@ -102,8 +98,6 @@ public class VersionMessageTest {
|
||||
assertEquals("/bitcoinj/", ver2.subVer);
|
||||
assertEquals(ProtocolVersion.CURRENT.intValue(), ver2.clientVersion);
|
||||
assertEquals(1, ver2.localServices.bits());
|
||||
assertEquals("2001:db8:85a3:0:0:8a2e:370:7334", ver2.fromAddr.getAddr().getHostAddress());
|
||||
assertEquals(3888, ver2.fromAddr.getPort());
|
||||
assertEquals("2002:db8:85a3:0:0:8a2e:370:7335", ver2.receivingAddr.getAddr().getHostAddress());
|
||||
assertEquals(8333, ver2.receivingAddr.getPort());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user