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.
Modifier and Type | Field and Description |
---|---|
long |
bestHeight
How many blocks are in the chain, according to the other side.
|
static String |
BITCOINJ_VERSION
The version of this library release, as a string.
|
int |
clientVersion
The version number of the protocol spoken.
|
static String |
LIBRARY_SUBVER
The value that is prepended to the subVer field of this application.
|
long |
localServices
Flags defining what optional services are supported.
|
PeerAddress |
myAddr
What the other side believes the address of this program is.
|
static int |
NODE_GETUTXOS
A flag that denotes whether the peer supports the getutxos message or not.
|
static int |
NODE_NETWORK
A services flag that denotes whether the peer has a copy of the block chain or not.
|
boolean |
relayTxesBeforeFilter
Whether or not to relay tx invs before a filter is received.
|
String |
subVer
User-Agent as defined in BIP 14.
|
PeerAddress |
theirAddr
What the other side believes their own address is.
|
long |
time
What the other side believes the current time to be, in seconds.
|
cursor, length, MAX_SIZE, offset, params, payload, protocolVersion, recached, serializer, UNKNOWN_LENGTH
Constructor and Description |
---|
VersionMessage(NetworkParameters params,
byte[] payload) |
VersionMessage(NetworkParameters params,
int newBestHeight) |
Modifier and Type | Method and Description |
---|---|
void |
appendToSubVer(String name,
String version,
String comments)
Appends the given user-agent information to the subVer field.
|
void |
bitcoinSerializeToStream(OutputStream buf)
Serializes this message to the provided stream.
|
VersionMessage |
duplicate() |
boolean |
equals(Object o) |
boolean |
hasBlockChain()
Returns true if the version message indicates the sender has a full copy of the block chain,
or if it's running in client mode (only has the headers).
|
int |
hashCode() |
boolean |
isBloomFilteringSupported()
Returns true if the clientVersion field is >= FilteredBlock.MIN_PROTOCOL_VERSION.
|
boolean |
isGetUTXOsSupported()
Returns true if the protocol version and service bits both indicate support for the getutxos message.
|
boolean |
isPingPongSupported()
Returns true if the clientVersion field is >= Pong.MIN_PROTOCOL_VERSION.
|
protected void |
parse() |
String |
toString() |
adjustLength, bitcoinSerialize, bitcoinSerialize, getHash, getMessageSize, getParams, hasMoreBytes, isCached, isRecached, readByteArray, readBytes, readHash, readInt64, readStr, readUint32, readUint64, readVarInt, readVarInt, unCache, unsafeBitcoinSerialize
public static final int NODE_NETWORK
public static final int NODE_GETUTXOS
public int clientVersion
public long localServices
public long time
public PeerAddress myAddr
public PeerAddress theirAddr
public String subVer
public long bestHeight
public boolean relayTxesBeforeFilter
public static final String BITCOINJ_VERSION
public static final String LIBRARY_SUBVER
public VersionMessage(NetworkParameters params, byte[] payload) throws ProtocolException
ProtocolException
public VersionMessage(NetworkParameters params, int newBestHeight)
protected void parse() throws ProtocolException
parse
in class Message
ProtocolException
public void bitcoinSerializeToStream(OutputStream buf) throws IOException
Message
bitcoinSerializeToStream
in class Message
IOException
public boolean hasBlockChain()
public VersionMessage duplicate()
public void appendToSubVer(String name, String version, @Nullable String comments)
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.
comments
- Optional (can be null) platform or other node specific information.IllegalArgumentException
- if name, version or comments contains invalid characters.public boolean isPingPongSupported()
public boolean isBloomFilteringSupported()
public boolean isGetUTXOsSupported()
Copyright © 2016. All rights reserved.