Package org.bitcoinj.core
Class InventoryMessage
- java.lang.Object
-
- org.bitcoinj.core.BaseMessage
-
- org.bitcoinj.core.ListMessage
-
- org.bitcoinj.core.InventoryMessage
-
- All Implemented Interfaces:
Message
- Direct Known Subclasses:
NotFoundMessage
public class InventoryMessage extends ListMessage
Represents the "inv" P2P network message. An inv contains a list of hashes of either blocks or transactions. It's a bandwidth optimization - on receiving some data, a (fully validating) peer sends every connected peer an inv containing the hash of what it saw. It'll only transmit the full thing if a peer asks for it with a
GetDataMessage
.Instances of this class are not safe for use by multiple threads.
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_INV_SIZE
A hard coded constant in the protocol.-
Fields inherited from class org.bitcoinj.core.ListMessage
items, MAX_INVENTORY_ITEMS
-
-
Constructor Summary
Constructors Modifier Constructor Description InventoryMessage()
protected
InventoryMessage(java.util.List<InventoryItem> items)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBlock(Block block)
void
addTransaction(Transaction tx)
static InventoryMessage
read(java.nio.ByteBuffer payload)
Deserialize this message from a given payload.static InventoryMessage
with(Transaction... txns)
Creates a new inv message for the given transactions.-
Methods inherited from class org.bitcoinj.core.ListMessage
addItem, bitcoinSerializeToStream, equals, getItems, hashCode, readItems, removeItem, toString
-
Methods inherited from class org.bitcoinj.core.BaseMessage
messageSize, serialize
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.bitcoinj.core.Message
bitcoinSerialize, getMessageSize, unsafeBitcoinSerialize
-
-
-
-
Field Detail
-
MAX_INV_SIZE
public static final int MAX_INV_SIZE
A hard coded constant in the protocol.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
InventoryMessage
public InventoryMessage()
-
InventoryMessage
protected InventoryMessage(java.util.List<InventoryItem> items)
-
-
Method Detail
-
read
public static InventoryMessage read(java.nio.ByteBuffer payload) throws java.nio.BufferUnderflowException, ProtocolException
Deserialize this message from a given payload.- Parameters:
payload
- payload to deserialize from- Returns:
- read message
- Throws:
java.nio.BufferUnderflowException
- if the read message extends beyond the remaining bytes of the payloadProtocolException
-
addBlock
public void addBlock(Block block)
-
addTransaction
public void addTransaction(Transaction tx)
-
with
public static InventoryMessage with(Transaction... txns)
Creates a new inv message for the given transactions.
-
-