From bb017a5dab25a699300b9b8e3da8ee6576f46cf8 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Fri, 25 Mar 2011 20:41:26 +0000 Subject: [PATCH] Change the order of the messages in the version handshake. This fixes connections to BitCoin nodes beyond v0.30.20.2 which are "shy", that is, they do not announce their version on accepting a connection. The intent of that change is to make port scanning harder, though it is questionable whether this really is effective. --- src/com/google/bitcoin/core/NetworkConnection.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/com/google/bitcoin/core/NetworkConnection.java b/src/com/google/bitcoin/core/NetworkConnection.java index d2b480fb..eea12c55 100644 --- a/src/com/google/bitcoin/core/NetworkConnection.java +++ b/src/com/google/bitcoin/core/NetworkConnection.java @@ -73,11 +73,13 @@ public class NetworkConnection { out = socket.getOutputStream(); in = socket.getInputStream(); + // Announce ourselves. This has to come first to connect to clients beyond v0.30.20.2 which wait to hear + // from us until they send their version message back. + writeMessage(MSG_VERSION, new VersionMessage(params)); // When connecting, the remote peer sends us a version message with various bits of // useful data in it. We need to know the peer protocol version before we can talk to it. versionMessage = (VersionMessage) readMessage(); // Now it's our turn ... - writeMessage(MSG_VERSION, new VersionMessage(params)); // Send an ACK message stating we accept the peers protocol version. writeMessage(MSG_VERACK, new byte[] {}); // And get one back ...