3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-13 10:45:51 +00:00

Add thread safety warning to JavaDocs of entire Message class hierarchy.

This commit is contained in:
Andreas Schildbach 2016-02-03 17:19:18 +01:00
parent 5f3ca35b89
commit becd8641c9
31 changed files with 103 additions and 38 deletions

View File

@ -24,9 +24,11 @@ import java.util.Collections;
import java.util.List;
/**
* Represents an "addr" message on the P2P network, which contains broadcast IP addresses of other peers. This is
* <p>Represents an "addr" message on the P2P network, which contains broadcast IP addresses of other peers. This is
* one of the ways peers can find each other without using the DNS or IRC discovery mechanisms. However storing and
* using addr messages is not presently implemented.
* using addr messages is not presently implemented.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class AddressMessage extends Message {

View File

@ -33,7 +33,9 @@ import java.util.Set;
* that software upgrades could be distributed independently of a hard-coded website, in order to allow everything to
* be purely peer-to-peer. You don't have to use this of course, and indeed it often makes more sense not to.<p>
*
* Before doing anything with an alert, you should check {@link AlertMessage#isSignatureValid()}.
* <p>Before doing anything with an alert, you should check {@link AlertMessage#isSignatureValid()}.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class AlertMessage extends Message {
private byte[] content;

View File

@ -38,8 +38,10 @@ import static org.bitcoinj.core.Sha256Hash.*;
* <a href="http://www.bitcoin.org/bitcoin.pdf">the Bitcoin technical paper</a> for
* more detail on blocks. <p/>
*
* To get a block, you can either build one from the raw bytes you can get from another implementation, or request one
* specifically using {@link Peer#getBlock(Sha256Hash)}, or grab one from a downloaded {@link BlockChain}.
* <p>To get a block, you can either build one from the raw bytes you can get from another implementation, or request one
* specifically using {@link Peer#getBlock(Sha256Hash)}, or grab one from a downloaded {@link BlockChain}.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class Block extends Message {
/**

View File

@ -40,6 +40,8 @@ import static java.lang.Math.*;
* match transactions that weren't inserted into it, but it will never fail to match transactions that were. This is
* a useful privacy feature - if you have spare bandwidth the false positive rate can be increased so the remote peer
* gets a noisy picture of what transactions are relevant to your wallet.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class BloomFilter extends Message {
/** The BLOOM_UPDATE_* constants control when the bloom filter is auto-updated by the peer using

View File

@ -18,8 +18,10 @@ package org.bitcoinj.core;
import javax.annotation.Nullable;
/**
* Represents a Message type that can be contained within another Message. ChildMessages that have a cached
* backing byte array need to invalidate their parent's caches as well as their own if they are modified.
* <p>Represents a Message type that can be contained within another Message. ChildMessages that have a cached
* backing byte array need to invalidate their parent's caches as well as their own if they are modified.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public abstract class ChildMessage extends Message {

View File

@ -21,8 +21,10 @@ import java.io.IOException;
import java.io.OutputStream;
/**
* Parent class for header only messages that don't have a payload.
* Currently this includes getaddr, verack and special bitcoinj class UnknownMessage.
* <p>Parent class for header only messages that don't have a payload.
* Currently this includes getaddr, verack and special bitcoinj class UnknownMessage.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public abstract class EmptyMessage extends Message {

View File

@ -25,6 +25,8 @@ import java.util.*;
/**
* <p>A FilteredBlock is used to relay a block with its transactions filtered using a {@link BloomFilter}. It consists
* of the block header and a {@link PartialMerkleTree} which contains the transactions which matched the filter.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class FilteredBlock extends Message {
private Block header;

View File

@ -17,8 +17,10 @@
package org.bitcoinj.core;
/**
* Represents the "getaddr" P2P protocol message, which requests network {@link AddressMessage}s from a peer. Not to
* be confused with {@link Address} which is sort of like an account number.
* <p>Represents the "getaddr" P2P protocol message, which requests network {@link AddressMessage}s from a peer. Not to
* be confused with {@link Address} which is sort of like an account number.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class GetAddrMessage extends EmptyMessage {

View File

@ -23,8 +23,10 @@ import java.util.ArrayList;
import java.util.List;
/**
* Represents the "getblocks" P2P network message, which requests the hashes of the parts of the block chain we're
* missing. Those blocks can then be downloaded with a {@link GetDataMessage}.
* <p>Represents the "getblocks" P2P network message, which requests the hashes of the parts of the block chain we're
* missing. Those blocks can then be downloaded with a {@link GetDataMessage}.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class GetBlocksMessage extends Message {

View File

@ -17,8 +17,10 @@
package org.bitcoinj.core;
/**
* Represents the "getdata" P2P network message, which requests the contents of blocks or transactions given their
* hashes.
* <p>Represents the "getdata" P2P network message, which requests the contents of blocks or transactions given their
* hashes.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class GetDataMessage extends ListMessage {

View File

@ -19,10 +19,12 @@ package org.bitcoinj.core;
import java.util.List;
/**
* The "getheaders" command is structurally identical to "getblocks", but has different meaning. On receiving this
* <p>The "getheaders" command is structurally identical to "getblocks", but has different meaning. On receiving this
* message a Bitcoin node returns matching blocks up to the limit, but without the bodies. It is useful as an
* optimization: when your wallet does not contain any keys created before a particular time, you don't have to download
* the bodies for those blocks because you know there are no relevant transactions.
* the bodies for those blocks because you know there are no relevant transactions.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class GetHeadersMessage extends GetBlocksMessage {
public GetHeadersMessage(NetworkParameters params, List<Sha256Hash> locator, Sha256Hash stopHash) {

View File

@ -37,6 +37,8 @@ import java.util.List;
* space and time. If you want to look up unspent outputs by address, you can either query a block explorer site,
* or you can use the {@link FullPrunedBlockChain} class to build the required indexes yourself. Bear in that it will
* be quite slow and disk intensive to do that!</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class GetUTXOsMessage extends Message {
public static final int MIN_PROTOCOL_VERSION = 70002;

View File

@ -27,9 +27,11 @@ import java.util.Arrays;
import java.util.List;
/**
* A protocol message that contains a repeated series of block headers, sent in response to the "getheaders" command.
* <p>A protocol message that contains a repeated series of block headers, sent in response to the "getheaders" command.
* This is useful when you want to traverse the chain but know you don't care about the block contents, for example,
* because you have a freshly created wallet with no keys.
* because you have a freshly created wallet with no keys.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class HeadersMessage extends Message {
private static final Logger log = LoggerFactory.getLogger(HeadersMessage.class);

View File

@ -23,6 +23,8 @@ import static com.google.common.base.Preconditions.checkArgument;
* 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
* {@link GetDataMessage}.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class InventoryMessage extends ListMessage {

View File

@ -24,7 +24,9 @@ import java.util.Collections;
import java.util.List;
/**
* Abstract superclass of classes with list based payload, ie InventoryMessage and GetDataMessage.
* <p>Abstract superclass of classes with list based payload, ie InventoryMessage and GetDataMessage.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public abstract class ListMessage extends Message {

View File

@ -21,11 +21,13 @@ import java.io.IOException;
import java.io.OutputStream;
/**
* The "mempool" message asks a remote peer to announce all transactions in its memory pool, possibly restricted by
* <p>The "mempool" message asks a remote peer to announce all transactions in its memory pool, possibly restricted by
* any Bloom filter set on the connection. The list of transaction hashes comes back in an inv message. Note that
* this is different to the {@link TxConfidenceTable} object which doesn't try to keep track of all pending transactions,
* it's just a holding area for transactions that a part of the app may find interesting. The mempool message has
* no fields.
* no fields.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class MemoryPoolMessage extends Message {
@Override

View File

@ -30,6 +30,8 @@ import static com.google.common.base.Preconditions.checkState;
* <p>A Message is a data structure that can be serialized/deserialized using the Bitcoin serialization format.
* Specific types of messages that are used both in the block chain, and on the wire, are derived from this
* class.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public abstract class Message {
private static final Logger log = LoggerFactory.getLogger(Message.class);

View File

@ -20,8 +20,10 @@ import java.util.ArrayList;
import java.util.List;
/**
* Sent by a peer when a getdata request doesn't find the requested data in the mempool. It has the same format
* as an inventory message and lists the hashes of the missing items.
* <p>Sent by a peer when a getdata request doesn't find the requested data in the mempool. It has the same format
* as an inventory message and lists the hashes of the missing items.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class NotFoundMessage extends InventoryMessage {
public static int MIN_PROTOCOL_VERSION = 70001;

View File

@ -52,6 +52,8 @@ import com.google.common.base.Objects;
* - varint number of bytes of flag bits (1-3 bytes)
* - byte[] flag bits, packed per 8 in a byte, least significant bit first (&lt;= 2*N-1 bits)
* The size constraints follow from this.</pre></p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class PartialMerkleTree extends Message {
// the total number of transactions in the block

View File

@ -33,8 +33,10 @@ import static org.bitcoinj.core.Utils.uint64ToByteStreamLE;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* 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.
* <p>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.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class PeerAddress extends ChildMessage {

View File

@ -20,6 +20,9 @@ package org.bitcoinj.core;
import java.io.IOException;
import java.io.OutputStream;
/**
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class Ping extends Message {
private long nonce;
private boolean hasNonce;

View File

@ -20,6 +20,9 @@ package org.bitcoinj.core;
import java.io.IOException;
import java.io.OutputStream;
/**
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class Pong extends Message {
private long nonce;

View File

@ -23,7 +23,9 @@ import java.io.OutputStream;
import java.util.Locale;
/**
* A message sent by nodes when a message we sent was rejected (ie a transaction had too little fee/was invalid/etc)
* <p>A message sent by nodes when a message we sent was rejected (ie a transaction had too little fee/was invalid/etc).</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class RejectMessage extends Message {

View File

@ -54,6 +54,8 @@ import java.math.BigInteger;
* Whether to trust a transaction is something that needs to be decided on a case by case basis - a rule that makes
* sense for selling MP3s might not make sense for selling cars, or accepting payments from a family member. If you
* are building a wallet, how to present confidence to your users is something to consider carefully.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class Transaction extends ChildMessage {
/**

View File

@ -36,10 +36,12 @@ import static com.google.common.base.Preconditions.checkElementIndex;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* A transfer of coins from one address to another creates a transaction in which the outputs
* <p>A transfer of coins from one address to another creates a transaction in which the outputs
* can be claimed by the recipient in the input of another transaction. You can imagine a
* transaction as being a module which is wired up to others, the inputs of one have to be wired
* to the outputs of another. The exceptions are coinbase transactions, which create new coins.
* to the outputs of another. The exceptions are coinbase transactions, which create new coins.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class TransactionInput extends ChildMessage {
/** Magic sequence number that indicates there is no sequence number. */

View File

@ -27,7 +27,9 @@ import java.io.*;
import static com.google.common.base.Preconditions.*;
/**
* This message is a reference or pointer to an output of a different transaction.
* <p>This message is a reference or pointer to an output of a different transaction.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class TransactionOutPoint extends ChildMessage {

View File

@ -28,8 +28,10 @@ import java.util.*;
import static com.google.common.base.Preconditions.*;
/**
* A TransactionOutput message contains a scriptPubKey that controls who is able to spend its value. It is a sub-part
* of the Transaction message.
* <p>A TransactionOutput message contains a scriptPubKey that controls who is able to spend its value. It is a sub-part
* of the Transaction message.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class TransactionOutput extends ChildMessage {
private static final Logger log = LoggerFactory.getLogger(TransactionOutput.class);

View File

@ -38,6 +38,8 @@ import java.util.List;
* if the data is occasionally wrong. Bear in mind that the answer can be wrong even in the absence of malicious intent
* just through the nature of querying an ever changing data source: the UTXO set may be updated by a new transaction
* immediately after this message is returned.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class UTXOsMessage extends Message {
private long height;

View File

@ -17,6 +17,9 @@
package org.bitcoinj.core;
/**
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class UnknownMessage extends EmptyMessage {
private String name;

View File

@ -17,8 +17,10 @@
package org.bitcoinj.core;
/**
* The verack message, sent by a client accepting the version message they
* received from their peer.
* <p>The verack message, sent by a client accepting the version message they
* received from their peer.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class VersionAck extends EmptyMessage {
public VersionAck() {

View File

@ -25,13 +25,15 @@ import java.net.UnknownHostException;
import java.util.Locale;
/**
* A VersionMessage holds information exchanged during connection setup with another peer. Most of the fields are not
* <p>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. <p>
* the subVer field received from other nodes to see what they are running.</p>
*
* After creating yourself a VersionMessage, you can pass it to {@link PeerGroup#setVersionMessage(VersionMessage)}
* to ensure it will be used for each new connection.
* <p>After creating yourself a VersionMessage, you can pass it to {@link PeerGroup#setVersionMessage(VersionMessage)}
* to ensure it will be used for each new connection.</p>
*
* <p>Instances of this class are not safe for use by multiple threads.</p>
*/
public class VersionMessage extends Message {