Class PeerAddress


  • public class PeerAddress
    extends ChildMessage

    A PeerAddress holds an IP address and port number representing the network location of a peer in the Bitcoin P2P network. It exists primarily for serialization purposes.

    This class abuses the protocol version contained in its serializer. It can only contain 0 (format within VersionMessage), 1 (AddressV1Message) or 2 (AddressV2Message).

    Instances of this class are not safe for use by multiple threads.

    • Constructor Detail

      • PeerAddress

        public PeerAddress​(NetworkParameters params,
                           java.nio.ByteBuffer payload,
                           Message parent,
                           MessageSerializer serializer)
                    throws ProtocolException
        Construct a peer address from a serialized payload.
        Parameters:
        params - NetworkParameters object.
        payload - Bitcoin protocol formatted byte array containing message content.
        serializer - the serializer to use for this message.
        Throws:
        ProtocolException
      • PeerAddress

        public PeerAddress​(NetworkParameters params,
                           java.net.InetAddress addr,
                           int port,
                           java.math.BigInteger services,
                           MessageSerializer serializer)
        Construct a peer address from a memorized or hardcoded address.
      • PeerAddress

        public PeerAddress​(NetworkParameters params,
                           java.net.InetAddress addr,
                           int port,
                           java.math.BigInteger services)
        Constructs a peer address from the given IP address, port and services. Version number is default for the given parameters.
      • PeerAddress

        public PeerAddress​(NetworkParameters params,
                           java.net.InetAddress addr,
                           int port)
        Constructs a peer address from the given IP address and port. Version number is default for the given parameters.
      • PeerAddress

        public PeerAddress​(NetworkParameters params,
                           java.net.InetAddress addr)
        Constructs a peer address from the given IP address. Port and version number are default for the given parameters.
      • PeerAddress

        public PeerAddress​(NetworkParameters params,
                           java.net.InetSocketAddress addr)
        Constructs a peer address from an InetSocketAddress. An InetSocketAddress can take in as parameters an InetAddress or a String hostname. If you want to connect to a .onion, set the hostname to the .onion address.
      • PeerAddress

        public PeerAddress​(NetworkParameters params,
                           java.lang.String hostname,
                           int port)
        Constructs a peer address from a stringified hostname+port. Use this if you want to connect to a Tor .onion address.
    • Method Detail

      • bitcoinSerializeToStream

        protected void bitcoinSerializeToStream​(java.io.OutputStream stream)
                                         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 class Message
        Throws:
        java.io.IOException
      • getHostname

        public java.lang.String getHostname()
      • getAddr

        public java.net.InetAddress getAddr()
      • getSocketAddress

        public java.net.InetSocketAddress getSocketAddress()
      • getPort

        public int getPort()
      • getServices

        public java.math.BigInteger getServices()
      • time

        public java.util.Optional<java.time.Instant> time()
        Gets the time that the node was last seen as connected to the network, or empty if that time isn't known (for old `addr` messages).
        Returns:
        time that the node was last seen, or empty if unknown
      • getTime

        @Deprecated
        public long getTime()
        Deprecated.
        use time()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toSocketAddress

        public java.net.InetSocketAddress toSocketAddress()