Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Wallet
bitcoinj
Commits
2ac47850
Commit
2ac47850
authored
Oct 03, 2017
by
T Dev. D
😎
Browse files
don't follow incompatible chain
parent
13a2c80f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
4 deletions
+17
-4
core/src/main/java/org/bitcoinj/core/Peer.java
core/src/main/java/org/bitcoinj/core/Peer.java
+9
-0
core/src/main/java/org/bitcoinj/core/VersionMessage.java
core/src/main/java/org/bitcoinj/core/VersionMessage.java
+8
-4
No files found.
core/src/main/java/org/bitcoinj/core/Peer.java
View file @
2ac47850
...
...
@@ -564,6 +564,15 @@ public class Peer extends PeerSocketHandler {
close
();
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
)
// In this case, it's a protocol violation.
throw
new
ProtocolException
(
"Peer reports invalid best height: "
+
vPeerVersionMessage
.
bestHeight
);
...
...
core/src/main/java/org/bitcoinj/core/VersionMessage.java
View file @
2ac47850
...
...
@@ -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
* 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
* 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)}
* 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>
*/
public
class
VersionMessage
extends
Message
{
...
...
@@ -49,6 +49,10 @@ public class VersionMessage extends Message {
public
static
final
int
NODE_NETWORK
=
1
<<
0
;
/** A flag that denotes whether the peer supports the getutxos message or not. */
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. */
public
static
final
int
NODE_WITNESS
=
1
<<
3
;
...
...
@@ -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.
// 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.
public
VersionMessage
(
NetworkParameters
params
,
int
newBestHeight
)
{
super
(
params
);
clientVersion
=
params
.
getProtocolVersionNum
(
NetworkParameters
.
ProtocolVersion
.
CURRENT
);
...
...
@@ -167,7 +171,7 @@ public class VersionMessage extends Message {
throw
new
RuntimeException
(
e
);
// Can't happen.
}
// 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.
Utils
.
uint32ToByteStreamLE
(
0
,
buf
);
Utils
.
uint32ToByteStreamLE
(
0
,
buf
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment