Commit 2ac47850 authored by T Dev. D's avatar T Dev. D 😎
Browse files

don't follow incompatible chain

parent 13a2c80f
...@@ -564,6 +564,15 @@ public class Peer extends PeerSocketHandler { ...@@ -564,6 +564,15 @@ public class Peer extends PeerSocketHandler {
close(); close();
return; return;
} }
if (((vPeerVersionMessage.localServices
& VersionMessage.NODE_BITCOIN_CASH) == VersionMessage.NODE_BITCOIN_CASH) ||
((vPeerVersionMessage.localServices
& VersionMessage.NODE_SEGWIT2X) == VersionMessage.NODE_SEGWIT2X)) {
log.info("{}: Peer follows an incompatible block chain.", this);
// Shut down the channel gracefully.
close();
return;
}
if (vPeerVersionMessage.bestHeight < 0) if (vPeerVersionMessage.bestHeight < 0)
// In this case, it's a protocol violation. // In this case, it's a protocol violation.
throw new ProtocolException("Peer reports invalid best height: " + vPeerVersionMessage.bestHeight); throw new ProtocolException("Peer reports invalid best height: " + vPeerVersionMessage.bestHeight);
......
...@@ -29,13 +29,13 @@ import java.util.Locale; ...@@ -29,13 +29,13 @@ import java.util.Locale;
/** /**
* <p>A VersionMessage holds information exchanged during connection setup with another peer. Most of the fields are not * <p>A VersionMessage holds information exchanged during connection setup with another peer. Most of the fields are not
* particularly interesting. The subVer field, since BIP 14, acts as a User-Agent string would. You can and should * particularly interesting. The subVer field, since BIP 14, acts as a User-Agent string would. You can and should
* append to or change the subVer for your own software so other implementations can identify it, and you can look at * append to or change the subVer for your own software so other implementations can identify it, and you can look at
* the subVer field received from other nodes to see what they are running.</p> * the subVer field received from other nodes to see what they are running.</p>
* *
* <p>After creating yourself a VersionMessage, you can pass it to {@link PeerGroup#setVersionMessage(VersionMessage)} * <p>After creating yourself a VersionMessage, you can pass it to {@link PeerGroup#setVersionMessage(VersionMessage)}
* to ensure it will be used for each new connection.</p> * to ensure it will be used for each new connection.</p>
* *
* <p>Instances of this class are not safe for use by multiple threads.</p> * <p>Instances of this class are not safe for use by multiple threads.</p>
*/ */
public class VersionMessage extends Message { public class VersionMessage extends Message {
...@@ -49,6 +49,10 @@ public class VersionMessage extends Message { ...@@ -49,6 +49,10 @@ public class VersionMessage extends Message {
public static final int NODE_NETWORK = 1 << 0; public static final int NODE_NETWORK = 1 << 0;
/** A flag that denotes whether the peer supports the getutxos message or not. */ /** A flag that denotes whether the peer supports the getutxos message or not. */
public static final int NODE_GETUTXOS = 1 << 1; public static final int NODE_GETUTXOS = 1 << 1;
/** A service bit used by Bitcoin-ABC to announce Bitcoin Cash nodes. */
public static final int NODE_BITCOIN_CASH = 1 << 5;
/** A service bit used by BTC1 to announce Segwit2x nodes. */
public static final int NODE_SEGWIT2X = 1 << 7;
/** Indicates that a node can be asked for blocks and transactions including witness data. */ /** Indicates that a node can be asked for blocks and transactions including witness data. */
public static final int NODE_WITNESS = 1 << 3; public static final int NODE_WITNESS = 1 << 3;
...@@ -94,7 +98,7 @@ public class VersionMessage extends Message { ...@@ -94,7 +98,7 @@ public class VersionMessage extends Message {
// It doesn't really make sense to ever lazily parse a version message or to retain the backing bytes. // It doesn't really make sense to ever lazily parse a version message or to retain the backing bytes.
// If you're receiving this on the wire you need to check the protocol version and it will never need to be sent // If you're receiving this on the wire you need to check the protocol version and it will never need to be sent
// back down the wire. // back down the wire.
public VersionMessage(NetworkParameters params, int newBestHeight) { public VersionMessage(NetworkParameters params, int newBestHeight) {
super(params); super(params);
clientVersion = params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.CURRENT); clientVersion = params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.CURRENT);
...@@ -167,7 +171,7 @@ public class VersionMessage extends Message { ...@@ -167,7 +171,7 @@ public class VersionMessage extends Message {
throw new RuntimeException(e); // Can't happen. throw new RuntimeException(e); // Can't happen.
} }
// Next up is the "local host nonce", this is to detect the case of connecting // 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 // back to yourself. We don't care about this as we won't be accepting inbound
// connections. // connections.
Utils.uint32ToByteStreamLE(0, buf); Utils.uint32ToByteStreamLE(0, buf);
Utils.uint32ToByteStreamLE(0, buf); Utils.uint32ToByteStreamLE(0, buf);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment