com.google.bitcoin.core
Class VersionMessage

java.lang.Object
  extended by com.google.bitcoin.core.Message
      extended by com.google.bitcoin.core.VersionMessage
All Implemented Interfaces:
Serializable

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. If blank, it means the Satoshi client.

After creating yourself a VersionMessage, you can pass it to PeerGroup.setVersionMessage(VersionMessage) to ensure it will be used for each new connection.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.bitcoin.core.Message
Message.LazyParseException
 
Field Summary
 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 is supported.
 PeerAddress myAddr
          What the other side believes the address of this program is.
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
          An additional string that today the official client sets to the empty string.
 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.
 
Fields inherited from class com.google.bitcoin.core.Message
bytes, checksum, cursor, length, MAX_SIZE, offset, params, parsed, parseLazy, parseRetain, protocolVersion, recached, UNKNOWN_LENGTH
 
Constructor Summary
VersionMessage(NetworkParameters params, byte[] msg)
           
VersionMessage(NetworkParameters params, int newBestHeight)
          Equivalent to VersionMessage(params, newBestHeight, true)
VersionMessage(NetworkParameters params, int newBestHeight, boolean relayTxesBeforeFilter)
           
 
Method Summary
 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 isPingPongSupported()
          Returns true if the clientVersion field is >= Pong.MIN_PROTOCOL_VERSION.
 void parse()
           
protected  void parseLite()
          Perform the most minimal parse possible to calculate the length of the message.
 String toString()
           
 
Methods inherited from class com.google.bitcoin.core.Message
adjustLength, bitcoinSerialize, bitcoinSerialize, ensureParsed, getHash, getMessageSize, getParams, isCached, isParsed, isRecached, maybeParse, unCache, unsafeBitcoinSerialize
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NODE_NETWORK

public static final int NODE_NETWORK
A services flag that denotes whether the peer has a copy of the block chain or not.

See Also:
Constant Field Values

clientVersion

public int clientVersion
The version number of the protocol spoken.


localServices

public long localServices
Flags defining what is supported. Right now NODE_NETWORK is the only flag defined.


time

public long time
What the other side believes the current time to be, in seconds.


myAddr

public PeerAddress myAddr
What the other side believes the address of this program is. Not used.


theirAddr

public PeerAddress theirAddr
What the other side believes their own address is. Not used.


subVer

public String subVer
An additional string that today the official client sets to the empty string. We treat it as something like an HTTP User-Agent header.


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


BITCOINJ_VERSION

public static final String BITCOINJ_VERSION
The version of this library release, as a string.

See Also:
Constant Field Values

LIBRARY_SUBVER

public static final String LIBRARY_SUBVER
The value that is prepended to the subVer field of this application.

See Also:
Constant Field Values
Constructor Detail

VersionMessage

public VersionMessage(NetworkParameters params,
                      byte[] msg)
               throws ProtocolException
Throws:
ProtocolException

VersionMessage

public VersionMessage(NetworkParameters params,
                      int newBestHeight)
Equivalent to VersionMessage(params, newBestHeight, true)


VersionMessage

public VersionMessage(NetworkParameters params,
                      int newBestHeight,
                      boolean relayTxesBeforeFilter)
Method Detail

parseLite

protected void parseLite()
                  throws ProtocolException
Description copied from class: Message
Perform the most minimal parse possible to calculate the length of the message. This is only required for subclasses of ChildClass as root level messages will have their length passed into the constructor.

Implementations should adhere to the following contract: If parseLazy = true the 'length' field must be set before returning. If parseLazy = false the length field must be set either within the parseLite() method OR the parse() method. The overriding requirement is that length must be set to non UNKNOWN_MESSAGE value by the time the constructor exits.

Specified by:
parseLite in class Message
Throws:
ProtocolException

parse

public void parse()
           throws ProtocolException
Throws:
ProtocolException

bitcoinSerializeToStream

public void bitcoinSerializeToStream(OutputStream buf)
                              throws IOException
Description copied from class: Message
Serializes this message to the provided stream. If you just want the raw bytes use bitcoinSerialize().

Throws:
IOException

hasBlockChain

public 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).


equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

duplicate

public VersionMessage duplicate()

appendToSubVer

public void appendToSubVer(String name,
                           String version,
                           @Nullable
                           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.4-SNAPSHOT/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:
IllegalArgumentException - if name, version or comments contains invalid characters.

isPingPongSupported

public boolean isPingPongSupported()
Returns true if the clientVersion field is >= Pong.MIN_PROTOCOL_VERSION. If it is then ping() is usable.


isBloomFilteringSupported

public boolean isBloomFilteringSupported()
Returns true if the clientVersion field is >= FilteredBlock.MIN_PROTOCOL_VERSION. If it is then Bloom filtering is available and the memory pool of the remote peer will be queried when the downloadData property is true.



Copyright © 2014. All rights reserved.