Class VersionMessage

java.lang.Object
org.bitcoinj.core.BaseMessage
org.bitcoinj.core.VersionMessage
All Implemented Interfaces:
Message

public class VersionMessage extends BaseMessage

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 Details

  • Constructor Details

    • VersionMessage

      public VersionMessage(NetworkParameters params, int bestHeight)
      Construct own version message from given NetworkParameters and our best height of the chain.
      Parameters:
      params - network parameters to construct own version message from
      bestHeight - our best height to announce
  • Method Details

    • read

      Deserialize this message from a given payload.
      Parameters:
      payload - payload to deserialize from
      Returns:
      read message
      Throws:
      BufferUnderflowException - if the read message extends beyond the remaining bytes of the payload
      ProtocolException
    • clientVersion

      public int clientVersion()
      Gets the client version.
      Returns:
      client version
    • services

      public Services services()
      Get the service bitfield that represents the node services being provided.
      Returns:
      service bitfield
    • bitcoinSerializeToStream

      public void bitcoinSerializeToStream(OutputStream buf) throws IOException
      Description copied from class: BaseMessage
      Serializes this message to the provided stream. If you just want the raw bytes use BaseMessage.serialize().
      Specified by:
      bitcoinSerializeToStream in class BaseMessage
      Throws:
      IOException
    • 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.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:
      IllegalArgumentException - if name, version or comments contains invalid characters.
    • isPingPongSupported

      @Deprecated public boolean isPingPongSupported()
      Deprecated.
      just assume Ping and Pong are supported
    • toStringServices

      @Deprecated public static String toStringServices(long services)