com.google.bitcoin.core
Class PeerAddress

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

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.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.bitcoin.core.Message
Message.LazyParseException
 
Field Summary
 
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
PeerAddress(InetAddress addr)
          Constructs a peer address from the given IP address.
PeerAddress(InetAddress addr, int port)
          Constructs a peer address from the given IP address and port.
PeerAddress(InetAddress addr, int port, int protocolVersion)
          Construct a peer address from a memorized or hardcoded address.
PeerAddress(InetSocketAddress addr)
           
PeerAddress(NetworkParameters params, byte[] payload, int offset, int protocolVersion)
          Construct a peer address from a serialized payload.
PeerAddress(NetworkParameters params, byte[] msg, int offset, int protocolVersion, Message parent, boolean parseLazy, boolean parseRetain)
          Construct a peer address from a serialized payload.
 
Method Summary
protected  void bitcoinSerializeToStream(OutputStream stream)
          Serializes this message to the provided stream.
 boolean equals(Object o)
           
 InetAddress getAddr()
           
 int getMessageSize()
          This should be overridden to extract correct message size in the case of lazy parsing.
 int getPort()
           
 BigInteger getServices()
           
 long getTime()
           
 int hashCode()
           
static PeerAddress localhost(NetworkParameters params)
           
protected  void parse()
           
protected  void parseLite()
          Perform the most minimal parse possible to calculate the length of the message.
 void setAddr(InetAddress addr)
           
 void setPort(int port)
           
 void setServices(BigInteger services)
           
 void setTime(long time)
           
 InetSocketAddress toSocketAddress()
           
 String toString()
           
 
Methods inherited from class com.google.bitcoin.core.ChildMessage
adjustLength, adjustLength, setParent, unCache
 
Methods inherited from class com.google.bitcoin.core.Message
bitcoinSerialize, bitcoinSerialize, ensureParsed, getHash, getParams, isCached, isParsed, isRecached, maybeParse, unsafeBitcoinSerialize
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PeerAddress

public PeerAddress(NetworkParameters params,
                   byte[] payload,
                   int offset,
                   int protocolVersion)
            throws ProtocolException
Construct a peer address from a serialized payload.

Throws:
ProtocolException

PeerAddress

public PeerAddress(NetworkParameters params,
                   byte[] msg,
                   int offset,
                   int protocolVersion,
                   Message parent,
                   boolean parseLazy,
                   boolean parseRetain)
            throws ProtocolException
Construct a peer address from a serialized payload.

Parameters:
params - NetworkParameters object.
msg - Bitcoin protocol formatted byte array containing message content.
offset - The location of the first msg byte within the array.
protocolVersion - Bitcoin protocol version.
parseLazy - Whether to perform a full parse immediately or delay until a read is requested.
parseRetain - Whether to retain the backing byte array for quick reserialization. If true and the backing byte array is invalidated due to modification of a field then the cached bytes may be repopulated and retained if the message is serialized again in the future.
Throws:
ProtocolException

PeerAddress

public PeerAddress(InetAddress addr,
                   int port,
                   int protocolVersion)
Construct a peer address from a memorized or hardcoded address.


PeerAddress

public PeerAddress(InetAddress addr,
                   int port)
Constructs a peer address from the given IP address and port. Protocol version is the default.


PeerAddress

public PeerAddress(InetAddress addr)
Constructs a peer address from the given IP address. Port and protocol version are default for the prodnet.


PeerAddress

public PeerAddress(InetSocketAddress addr)
Method Detail

localhost

public static PeerAddress localhost(NetworkParameters params)

bitcoinSerializeToStream

protected void bitcoinSerializeToStream(OutputStream stream)
                                 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

parseLite

protected void parseLite()
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

parse

protected void parse()
              throws ProtocolException
Throws:
ProtocolException

getMessageSize

public int getMessageSize()
Description copied from class: Message
This should be overridden to extract correct message size in the case of lazy parsing. Until this method is implemented in a subclass of ChildMessage lazy parsing may have no effect. This default implementation is a safe fall back that will ensure it returns a correct value by parsing the message.

Overrides:
getMessageSize in class Message

getAddr

public InetAddress getAddr()
Returns:
the addr

setAddr

public void setAddr(InetAddress addr)
Parameters:
addr - the addr to set

getPort

public int getPort()
Returns:
the port

setPort

public void setPort(int port)
Parameters:
port - the port to set

getServices

public BigInteger getServices()
Returns:
the services

setServices

public void setServices(BigInteger services)
Parameters:
services - the services to set

getTime

public long getTime()
Returns:
the time

setTime

public void setTime(long time)
Parameters:
time - the time to set

toString

public String toString()
Overrides:
toString in class Object

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toSocketAddress

public InetSocketAddress toSocketAddress()


Copyright © 2014. All rights reserved.