Class VersionMessage
- java.lang.Object
-
- org.bitcoinj.core.Message
-
- org.bitcoinj.core.VersionMessage
-
public class VersionMessage extends Message
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 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.
After creating yourself a VersionMessage, you can pass it to
PeerGroup.setVersionMessage(VersionMessage)
to ensure it will be used for each new connection.Instances of this class are not safe for use by multiple threads.
-
-
Field Summary
Fields Modifier and Type Field Description long
bestHeight
How many blocks are in the chain, according to the other side.static java.lang.String
BITCOINJ_VERSION
The version of this library release, as a string.int
clientVersion
The version number of the protocol spoken.PeerAddress
fromAddr
The network address of the node emitting this message.static java.lang.String
LIBRARY_SUBVER
The value that is prepended to the subVer field of this application.long
localServices
Flags defining what optional services are supported.static int
NODE_BITCOIN_CASH
A service bit used by Bitcoin-ABC to announce Bitcoin Cash nodes.static int
NODE_BLOOM
A service bit that denotes whether the peer supports BIP37 bloom filters or not.static int
NODE_NETWORK
A service bit that denotes whether the peer has a full copy of the block chain or not.static int
NODE_NETWORK_LIMITED
A service bit that denotes whether the peer has at least the last two days worth of blockchain (BIP159).static int
NODE_WITNESS
Indicates that a node can be asked for blocks and transactions including witness data.PeerAddress
receivingAddr
The network address of the node receiving this message.boolean
relayTxesBeforeFilter
Whether or not to relay tx invs before a filter is received.java.lang.String
subVer
User-Agent as defined in BIP 14.java.time.Instant
time
What the other side believes the current time to be.-
Fields inherited from class org.bitcoinj.core.Message
MAX_SIZE, params, payload, serializer
-
-
Constructor Summary
Constructors Constructor Description VersionMessage(NetworkParameters params, int newBestHeight)
VersionMessage(NetworkParameters params, java.nio.ByteBuffer payload)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendToSubVer(java.lang.String name, java.lang.String version, java.lang.String comments)
Appends the given user-agent information to the subVer field.void
bitcoinSerializeToStream(java.io.OutputStream buf)
Serializes this message to the provided stream.VersionMessage
duplicate()
boolean
equals(java.lang.Object o)
boolean
hasBlockChain()
Returns true if the version message indicates the sender has a full copy of the block chain, or false if it's running in client mode (only has the headers).int
hashCode()
boolean
hasLimitedBlockChain()
Returns true if the peer has at least the last two days worth of blockchain (BIP159).boolean
isBloomFilteringSupported()
Returns true if the peer supports bloom filtering according to BIP37 and BIP111.boolean
isPingPongSupported()
Returns true if the clientVersion field isNetworkParameters.ProtocolVersion.PONG
or higher.boolean
isWitnessSupported()
Returns true if a peer can be asked for blocks and transactions including witness data.protected void
parse()
java.lang.String
toString()
static java.lang.String
toStringServices(long services)
-
Methods inherited from class org.bitcoinj.core.Message
bitcoinSerialize, getHash, getMessageSize, getParams, readByte, readByteArray, readBytes, readHash, readInt32, readInt64, readStr, readUint32, readUint64, readVarInt, skipBytes, unCache, unsafeBitcoinSerialize
-
-
-
-
Field Detail
-
BITCOINJ_VERSION
public static final java.lang.String BITCOINJ_VERSION
The version of this library release, as a string.- See Also:
- Constant Field Values
-
LIBRARY_SUBVER
public static final java.lang.String LIBRARY_SUBVER
The value that is prepended to the subVer field of this application.- See Also:
- Constant Field Values
-
NODE_NETWORK
public static final int NODE_NETWORK
A service bit that denotes whether the peer has a full copy of the block chain or not.- See Also:
- Constant Field Values
-
NODE_BLOOM
public static final int NODE_BLOOM
A service bit that denotes whether the peer supports BIP37 bloom filters or not. The service bit is defined in BIP111.- See Also:
- Constant Field Values
-
NODE_WITNESS
public static final int NODE_WITNESS
Indicates that a node can be asked for blocks and transactions including witness data.- See Also:
- Constant Field Values
-
NODE_NETWORK_LIMITED
public static final int NODE_NETWORK_LIMITED
A service bit that denotes whether the peer has at least the last two days worth of blockchain (BIP159).- See Also:
- Constant Field Values
-
NODE_BITCOIN_CASH
public static final int NODE_BITCOIN_CASH
A service bit used by Bitcoin-ABC to announce Bitcoin Cash nodes.- See Also:
- Constant Field Values
-
clientVersion
public int clientVersion
The version number of the protocol spoken.
-
localServices
public long localServices
Flags defining what optional services are supported.
-
time
public java.time.Instant time
What the other side believes the current time to be.
-
receivingAddr
public PeerAddress receivingAddr
The network address of the node receiving this message.
-
fromAddr
public PeerAddress fromAddr
The network address of the node emitting this message. Not used.
-
subVer
public java.lang.String subVer
User-Agent as defined in BIP 14. Bitcoin Core sets it to something like "/Satoshi:0.9.1/".
-
bestHeight
public long bestHeight
How many blocks are in the chain, according to the other side.
-
relayTxesBeforeFilter
public boolean relayTxesBeforeFilter
Whether or not to relay tx invs before a filter is received. See BIP 37.
-
-
Constructor Detail
-
VersionMessage
public VersionMessage(NetworkParameters params, java.nio.ByteBuffer payload) throws ProtocolException
- Throws:
ProtocolException
-
VersionMessage
public VersionMessage(NetworkParameters params, int newBestHeight)
-
-
Method Detail
-
parse
protected void parse() throws java.nio.BufferUnderflowException, ProtocolException
- Specified by:
parse
in classMessage
- Throws:
java.nio.BufferUnderflowException
ProtocolException
-
bitcoinSerializeToStream
public void bitcoinSerializeToStream(java.io.OutputStream buf) throws java.io.IOException
Description copied from class:Message
Serializes this message to the provided stream. If you just want the raw bytes use bitcoinSerialize().- Overrides:
bitcoinSerializeToStream
in classMessage
- Throws:
java.io.IOException
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
duplicate
public VersionMessage duplicate()
-
appendToSubVer
public void appendToSubVer(java.lang.String name, java.lang.String version, @Nullable java.lang.String comments)
Appends the given user-agent information to the subVer field. The subVer is composed of a series of name:version pairs separated by slashes in the form of a path. For example a typical subVer field for bitcoinj users might look like "/bitcoinj:0.13/MultiBit:1.2/" where libraries come further to the left.
There can be as many components as you feel a need for, and the version string can be anything, but it is recommended to use A.B.C where A = major, B = minor and C = revision for software releases, and dates for auto-generated source repository snapshots. A valid subVer begins and ends with a slash, therefore name and version are not allowed to contain such characters.
Anything put in the "comments" field will appear in brackets and may be used for platform info, or anything else. For example, calling
appendToSubVer("MultiBit", "1.0", "Windows")
will result in a subVer being set of "/bitcoinj:1.0/MultiBit:1.0(Windows)/". Therefore the / ( and ) characters are reserved in all these components. If you don't want to add a comment (recommended), pass null.See BIP 14 for more information.
- Parameters:
comments
- Optional (can be null) platform or other node specific information.- Throws:
java.lang.IllegalArgumentException
- if name, version or comments contains invalid characters.
-
isPingPongSupported
public boolean isPingPongSupported()
Returns true if the clientVersion field isNetworkParameters.ProtocolVersion.PONG
or higher. If it is thenPeer.sendPing()
is usable.
-
isBloomFilteringSupported
public boolean isBloomFilteringSupported()
Returns true if the peer supports bloom filtering according to BIP37 and BIP111.
-
isWitnessSupported
public boolean isWitnessSupported()
Returns true if a peer can be asked for blocks and transactions including witness data.
-
hasBlockChain
public boolean hasBlockChain()
Returns true if the version message indicates the sender has a full copy of the block chain, or false if it's running in client mode (only has the headers).
-
hasLimitedBlockChain
public boolean hasLimitedBlockChain()
Returns true if the peer has at least the last two days worth of blockchain (BIP159).
-
toStringServices
public static java.lang.String toStringServices(long services)
-
-