Class Peer
- java.lang.Object
-
- org.bitcoinj.core.PeerSocketHandler
-
- org.bitcoinj.core.Peer
-
- All Implemented Interfaces:
StreamConnection
,TimeoutHandler
public class Peer extends PeerSocketHandler
A Peer handles the high level communication with a Bitcoin node, extending a
PeerSocketHandler
which handles low-level message (de)serialization.Note that timeouts are handled by the implemented
TimeoutHandler
and timeout is automatically disabled (usingTimeoutHandler.setTimeoutEnabled(boolean)
) once the version handshake completes.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.locks.ReentrantLock
lock
-
Fields inherited from class org.bitcoinj.core.PeerSocketHandler
peerAddress, writeTarget
-
-
Constructor Summary
Constructors Constructor Description Peer(NetworkParameters params, AbstractBlockChain blockChain, PeerAddress peerAddress, java.lang.String thisSoftwareName, java.lang.String thisSoftwareVersion)
Construct a peer that reads/writes from the given chain.Peer(NetworkParameters params, VersionMessage ver, AbstractBlockChain chain, PeerAddress remoteAddress)
Peer(NetworkParameters params, VersionMessage ver, PeerAddress remoteAddress, AbstractBlockChain chain)
Construct a peer that reads/writes from the given block chain.Peer(NetworkParameters params, VersionMessage ver, PeerAddress remoteAddress, AbstractBlockChain chain, long requiredServices, int downloadTxDependencyDepth)
Construct a peer that reads/writes from the given block chain.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addAddressEventListener(java.util.concurrent.Executor executor, AddressEventListener listener)
Registers a listener that is called when addr or addrv2 messages are received.void
addAddressEventListener(AddressEventListener listener)
Registers a listener that is called when addr or addrv2 messages are received.void
addBlocksDownloadedEventListener(java.util.concurrent.Executor executor, BlocksDownloadedEventListener listener)
Registers a listener that is invoked when new blocks are downloaded.void
addBlocksDownloadedEventListener(BlocksDownloadedEventListener listener)
Registers a listener that is invoked when new blocks are downloaded.void
addChainDownloadStartedEventListener(java.util.concurrent.Executor executor, ChainDownloadStartedEventListener listener)
Registers a listener that is invoked when a blockchain downloaded starts.void
addChainDownloadStartedEventListener(ChainDownloadStartedEventListener listener)
Registers a listener that is invoked when a blockchain downloaded starts.void
addConnectedEventListener(java.util.concurrent.Executor executor, PeerConnectedEventListener listener)
Registers a listener that is invoked when a peer is connected.void
addConnectedEventListener(PeerConnectedEventListener listener)
Registers a listener that is invoked when a peer is connected.void
addDisconnectedEventListener(java.util.concurrent.Executor executor, PeerDisconnectedEventListener listener)
Registers a listener that is invoked when a peer is disconnected.void
addDisconnectedEventListener(PeerDisconnectedEventListener listener)
Registers a listener that is invoked when a peer is disconnected.void
addGetDataEventListener(java.util.concurrent.Executor executor, GetDataEventListener listener)
Registers a listener that is called when messages are received.void
addGetDataEventListener(GetDataEventListener listener)
Registers a listener that is called when messages are received.void
addOnTransactionBroadcastListener(java.util.concurrent.Executor executor, OnTransactionBroadcastListener listener)
Registers a listener that is called when a transaction is broadcast across the networkvoid
addOnTransactionBroadcastListener(OnTransactionBroadcastListener listener)
Registers a listener that is called when a transaction is broadcast across the networkvoid
addPreMessageReceivedEventListener(java.util.concurrent.Executor executor, PreMessageReceivedEventListener listener)
Registers a listener that is called immediately before a message is receivedvoid
addPreMessageReceivedEventListener(PreMessageReceivedEventListener listener)
Registers a listener that is called immediately before a message is receivedvoid
addWallet(Wallet wallet)
Links the given wallet to this peer.void
connectionClosed()
Called when the connection socket is closedvoid
connectionOpened()
Called when the connection socket is first openedListenableCompletableFuture<java.util.List<Transaction>>
downloadDependencies(Transaction tx)
Returns a future that wraps a list of all transactions that the given transaction depends on, recursively.protected java.util.concurrent.CompletableFuture<java.util.List<Transaction>>
downloadDependenciesInternal(Transaction rootTx, int maxDepth, int depth)
Internal, recursive dependency downloaderprotected void
endFilteredBlock(FilteredBlock m)
ListenableCompletableFuture<AddressMessage>
getAddr()
Sends a getaddr request to the peer and returns a future that completes with the answer once the peer has replied.long
getBestHeight()
ListenableCompletableFuture<Block>
getBlock(Sha256Hash blockHash)
Asks the connected peer for the block of the given hash, and returns a future representing the answer.BloomFilter
getBloomFilter()
Returns the lastBloomFilter
set bysetBloomFilter(BloomFilter)
.ListenableCompletableFuture<Peer>
getConnectionOpenFuture()
Provides a ListenableCompletableFuture that can be used to wait for the socket to connect.Coin
getFeeFilter()
Returns the fee filter announced by the remote peer, interpreted as satoshis per kB.long
getLastPingTime()
Deprecated.int
getPeerBlockHeightDifference()
Returns the difference between our best chain height and the peers, which can either be positive if we are behind the peer, or negative if the peer is ahead of us.ListenableCompletableFuture<Transaction>
getPeerMempoolTransaction(Sha256Hash hash)
Asks the connected peer for the given transaction from its memory pool.VersionMessage
getPeerVersionMessage()
Returns version data announced by the remote peer.long
getPingTime()
Deprecated.usepingInterval()
ListenableCompletableFuture<Peer>
getVersionHandshakeFuture()
VersionMessage
getVersionMessage()
Returns version data we announce to our remote peers.boolean
isDownloadData()
Returns true if this peer will try and download things it is sent in "inv" messages.boolean
isDownloadTxDependencies()
Returns true if this peer will use getdata/notfound messages to walk backwards through transaction dependencies before handing the transaction off to the wallet.java.util.Optional<java.time.Duration>
lastPingInterval()
Returns the elapsed time of the last ping/pong cycle.ListenableCompletableFuture<java.lang.Long>
ping()
Deprecated.UsesendPing()
java.util.Optional<java.time.Duration>
pingInterval()
Returns a moving average of the last N ping/pong cycles.protected void
processBlock(Block m)
protected void
processGetData(GetDataMessage getdata)
protected void
processHeaders(HeadersMessage m)
protected void
processInv(InventoryMessage inv)
protected void
processMessage(Message m)
Called every time a message is received from the networkprotected void
processNotFoundMessage(NotFoundMessage m)
protected void
processPong(Pong m)
protected void
processTransaction(Transaction tx)
boolean
removeAddressEventListener(AddressEventListener listener)
boolean
removeBlocksDownloadedEventListener(BlocksDownloadedEventListener listener)
boolean
removeChainDownloadStartedEventListener(ChainDownloadStartedEventListener listener)
boolean
removeConnectedEventListener(PeerConnectedEventListener listener)
boolean
removeDisconnectedEventListener(PeerDisconnectedEventListener listener)
boolean
removeGetDataEventListener(GetDataEventListener listener)
boolean
removeOnTransactionBroadcastListener(OnTransactionBroadcastListener listener)
boolean
removePreMessageReceivedEventListener(PreMessageReceivedEventListener listener)
void
removeWallet(Wallet wallet)
Unlinks the given wallet from peer.java.util.concurrent.CompletableFuture<java.time.Duration>
sendPing()
Sends the peer a ping message and returns a future that will be completed when the pong is received back.protected java.util.concurrent.CompletableFuture<java.time.Duration>
sendPing(long nonce)
void
setBloomFilter(BloomFilter filter)
Sets a Bloom filter on this connection.void
setBloomFilter(BloomFilter filter, boolean andQueryMemPool)
Sets a Bloom filter on this connection.void
setDownloadData(boolean downloadData)
If set to false, the peer won't try and fetch blocks and transactions it hears about.void
setDownloadParameters(boolean useFilteredBlocks)
Always download full blocks.void
setDownloadParameters(long fastCatchupTimeSecs, boolean useFilteredBlocks)
Deprecated.void
setDownloadTxDependencies(boolean enable)
Sets if this peer will use getdata/notfound messages to walk backwards through transaction dependencies before handing the transaction off to the wallet.void
setDownloadTxDependencies(int depth)
Sets if this peer will use getdata/notfound messages to walk backwards through transaction dependencies before handing the transaction off to the wallet.void
setFastDownloadParameters(boolean useFilteredBlocks, java.time.Instant fastCatchupTime)
When downloading the block chain, the bodies will be skipped for blocks created before the given date.boolean
setMinProtocolVersion(int minProtocolVersion)
The minimum P2P protocol version that is accepted.void
startBlockChainDownload()
Starts an asynchronous download of the block chain.protected void
startFilteredBlock(FilteredBlock m)
protected void
timeoutOccurred()
java.lang.String
toString()
-
Methods inherited from class org.bitcoinj.core.PeerSocketHandler
close, getAddress, getMaxMessageSize, receiveBytes, sendMessage, setSocketTimeout, setTimeoutEnabled, setWriteTarget
-
-
-
-
Constructor Detail
-
Peer
@Deprecated public Peer(NetworkParameters params, VersionMessage ver, @Nullable AbstractBlockChain chain, PeerAddress remoteAddress)
-
Peer
public Peer(NetworkParameters params, VersionMessage ver, PeerAddress remoteAddress, @Nullable AbstractBlockChain chain)
Construct a peer that reads/writes from the given block chain. Transactions stored in a
TxConfidenceTable
will have their confidence levels updated when a peer announces it, to reflect the greater likelihood that the transaction is valid.Note that this does NOT make a connection to the given remoteAddress, it only creates a handler for a connection. If you want to create a one-off connection, create a Peer and pass it to
NioClientManager.openConnection(SocketAddress, StreamConnection)
orNioClient(SocketAddress, StreamConnection, Duration)
.The remoteAddress provided should match the remote address of the peer which is being connected to, and is used to keep track of which peers relayed transactions and offer more descriptive logging.
-
Peer
public Peer(NetworkParameters params, VersionMessage ver, PeerAddress remoteAddress, @Nullable AbstractBlockChain chain, long requiredServices, int downloadTxDependencyDepth)
Construct a peer that reads/writes from the given block chain. Transactions stored in a
TxConfidenceTable
will have their confidence levels updated when a peer announces it, to reflect the greater likelihood that the transaction is valid.Note that this does NOT make a connection to the given remoteAddress, it only creates a handler for a connection. If you want to create a one-off connection, create a Peer and pass it to
NioClientManager.openConnection(SocketAddress, StreamConnection)
orNioClient(SocketAddress, StreamConnection, Duration)
.The remoteAddress provided should match the remote address of the peer which is being connected to, and is used to keep track of which peers relayed transactions and offer more descriptive logging.
-
Peer
public Peer(NetworkParameters params, AbstractBlockChain blockChain, PeerAddress peerAddress, java.lang.String thisSoftwareName, java.lang.String thisSoftwareVersion)
Construct a peer that reads/writes from the given chain. Automatically creates a VersionMessage for you from the given software name/version strings, which should be something like "MySimpleTool", "1.0" and which will tell the remote node to relay transaction inv messages before it has received a filter.
Note that this does NOT make a connection to the given remoteAddress, it only creates a handler for a connection. If you want to create a one-off connection, create a Peer and pass it to
NioClientManager.openConnection(SocketAddress, StreamConnection)
orNioClient(SocketAddress, StreamConnection, Duration)
.The remoteAddress provided should match the remote address of the peer which is being connected to, and is used to keep track of which peers relayed transactions and offer more descriptive logging.
-
-
Method Detail
-
addBlocksDownloadedEventListener
public void addBlocksDownloadedEventListener(BlocksDownloadedEventListener listener)
Registers a listener that is invoked when new blocks are downloaded.
-
addBlocksDownloadedEventListener
public void addBlocksDownloadedEventListener(java.util.concurrent.Executor executor, BlocksDownloadedEventListener listener)
Registers a listener that is invoked when new blocks are downloaded.
-
addChainDownloadStartedEventListener
public void addChainDownloadStartedEventListener(ChainDownloadStartedEventListener listener)
Registers a listener that is invoked when a blockchain downloaded starts.
-
addChainDownloadStartedEventListener
public void addChainDownloadStartedEventListener(java.util.concurrent.Executor executor, ChainDownloadStartedEventListener listener)
Registers a listener that is invoked when a blockchain downloaded starts.
-
addConnectedEventListener
public void addConnectedEventListener(PeerConnectedEventListener listener)
Registers a listener that is invoked when a peer is connected.
-
addConnectedEventListener
public void addConnectedEventListener(java.util.concurrent.Executor executor, PeerConnectedEventListener listener)
Registers a listener that is invoked when a peer is connected.
-
addDisconnectedEventListener
public void addDisconnectedEventListener(PeerDisconnectedEventListener listener)
Registers a listener that is invoked when a peer is disconnected.
-
addDisconnectedEventListener
public void addDisconnectedEventListener(java.util.concurrent.Executor executor, PeerDisconnectedEventListener listener)
Registers a listener that is invoked when a peer is disconnected.
-
addGetDataEventListener
public void addGetDataEventListener(GetDataEventListener listener)
Registers a listener that is called when messages are received.
-
addGetDataEventListener
public void addGetDataEventListener(java.util.concurrent.Executor executor, GetDataEventListener listener)
Registers a listener that is called when messages are received.
-
addOnTransactionBroadcastListener
public void addOnTransactionBroadcastListener(OnTransactionBroadcastListener listener)
Registers a listener that is called when a transaction is broadcast across the network
-
addOnTransactionBroadcastListener
public void addOnTransactionBroadcastListener(java.util.concurrent.Executor executor, OnTransactionBroadcastListener listener)
Registers a listener that is called when a transaction is broadcast across the network
-
addPreMessageReceivedEventListener
public void addPreMessageReceivedEventListener(PreMessageReceivedEventListener listener)
Registers a listener that is called immediately before a message is received
-
addPreMessageReceivedEventListener
public void addPreMessageReceivedEventListener(java.util.concurrent.Executor executor, PreMessageReceivedEventListener listener)
Registers a listener that is called immediately before a message is received
-
addAddressEventListener
public void addAddressEventListener(AddressEventListener listener)
Registers a listener that is called when addr or addrv2 messages are received.
-
addAddressEventListener
public void addAddressEventListener(java.util.concurrent.Executor executor, AddressEventListener listener)
Registers a listener that is called when addr or addrv2 messages are received.
-
removeBlocksDownloadedEventListener
public boolean removeBlocksDownloadedEventListener(BlocksDownloadedEventListener listener)
-
removeChainDownloadStartedEventListener
public boolean removeChainDownloadStartedEventListener(ChainDownloadStartedEventListener listener)
-
removeConnectedEventListener
public boolean removeConnectedEventListener(PeerConnectedEventListener listener)
-
removeDisconnectedEventListener
public boolean removeDisconnectedEventListener(PeerDisconnectedEventListener listener)
-
removeGetDataEventListener
public boolean removeGetDataEventListener(GetDataEventListener listener)
-
removeOnTransactionBroadcastListener
public boolean removeOnTransactionBroadcastListener(OnTransactionBroadcastListener listener)
-
removePreMessageReceivedEventListener
public boolean removePreMessageReceivedEventListener(PreMessageReceivedEventListener listener)
-
removeAddressEventListener
public boolean removeAddressEventListener(AddressEventListener listener)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
timeoutOccurred
protected void timeoutOccurred()
- Overrides:
timeoutOccurred
in classPeerSocketHandler
-
connectionClosed
public void connectionClosed()
Description copied from interface:StreamConnection
Called when the connection socket is closed
-
connectionOpened
public void connectionOpened()
Description copied from interface:StreamConnection
Called when the connection socket is first opened
-
getConnectionOpenFuture
public ListenableCompletableFuture<Peer> getConnectionOpenFuture()
Provides a ListenableCompletableFuture that can be used to wait for the socket to connect. A socket connection does not mean that protocol handshake has occurred.
-
getVersionHandshakeFuture
public ListenableCompletableFuture<Peer> getVersionHandshakeFuture()
-
processMessage
protected void processMessage(Message m) throws java.lang.Exception
Description copied from class:PeerSocketHandler
Called every time a message is received from the network- Specified by:
processMessage
in classPeerSocketHandler
- Throws:
java.lang.Exception
-
startFilteredBlock
protected void startFilteredBlock(FilteredBlock m)
-
processNotFoundMessage
protected void processNotFoundMessage(NotFoundMessage m)
-
processHeaders
protected void processHeaders(HeadersMessage m) throws ProtocolException
- Throws:
ProtocolException
-
processGetData
protected void processGetData(GetDataMessage getdata)
-
processTransaction
protected void processTransaction(Transaction tx) throws VerificationException
- Throws:
VerificationException
-
downloadDependencies
public ListenableCompletableFuture<java.util.List<Transaction>> downloadDependencies(Transaction tx)
Returns a future that wraps a list of all transactions that the given transaction depends on, recursively. Only transactions in peers memory pools are included; the recursion stops at transactions that are in the current best chain. So it doesn't make much sense to provide a tx that was already in the best chain and a precondition checks this.
For example, if tx has 2 inputs that connect to transactions A and B, and transaction B is unconfirmed and has one input connecting to transaction C that is unconfirmed, and transaction C connects to transaction D that is in the chain, then this method will return either {B, C} or {C, B}. No ordering is guaranteed.
This method is useful for apps that want to learn about how long an unconfirmed transaction might take to confirm, by checking for unexpectedly time locked transactions, unusually deep dependency trees or fee-paying transactions that depend on unconfirmed free transactions.
Note that dependencies downloaded this way will not trigger the onTransaction method of event listeners.
- Parameters:
tx
- The transaction- Returns:
- A Future for a list of dependent transactions
-
downloadDependenciesInternal
protected java.util.concurrent.CompletableFuture<java.util.List<Transaction>> downloadDependenciesInternal(Transaction rootTx, int maxDepth, int depth)
Internal, recursive dependency downloader- Parameters:
rootTx
- The root transactionmaxDepth
- maximum recursion depthdepth
- current recursion depth (starts at 0)- Returns:
- A Future for a list of dependent transactions
-
processBlock
protected void processBlock(Block m)
-
endFilteredBlock
protected void endFilteredBlock(FilteredBlock m)
-
processInv
protected void processInv(InventoryMessage inv)
-
getBlock
public ListenableCompletableFuture<Block> getBlock(Sha256Hash blockHash)
Asks the connected peer for the block of the given hash, and returns a future representing the answer. If you want the block right away and don't mind waiting for it, just call .get() on the result. Your thread will block until the peer answers.
-
getPeerMempoolTransaction
public ListenableCompletableFuture<Transaction> getPeerMempoolTransaction(Sha256Hash hash)
Asks the connected peer for the given transaction from its memory pool. Transactions in the chain cannot be retrieved this way because peers don't have a transaction ID to transaction-pos-on-disk index, and besides, in future many peers will delete old transaction data they don't need.
-
getAddr
public ListenableCompletableFuture<AddressMessage> getAddr()
Sends a getaddr request to the peer and returns a future that completes with the answer once the peer has replied.
-
setFastDownloadParameters
public void setFastDownloadParameters(boolean useFilteredBlocks, java.time.Instant fastCatchupTime)
When downloading the block chain, the bodies will be skipped for blocks created before the given date. Any transactions relevant to the wallet will therefore not be found, but if you know your wallet has no such transactions it doesn't matter and can save a lot of bandwidth and processing time. Note that the times of blocks isn't known until their headers are available and they are requested in chunks, so some headers may be downloaded twice using this scheme, but this optimization can still be a large win for newly created wallets.- Parameters:
useFilteredBlocks
- whether to request filtered blocks if the protocol version allows for themfastCatchupTime
- time before which block bodies are skipped
-
setDownloadParameters
public void setDownloadParameters(boolean useFilteredBlocks)
Always download full blocks.- Parameters:
useFilteredBlocks
- whether to request filtered blocks if the protocol version allows for them
-
setDownloadParameters
@Deprecated public void setDownloadParameters(long fastCatchupTimeSecs, boolean useFilteredBlocks)
Deprecated.
-
addWallet
public void addWallet(Wallet wallet)
Links the given wallet to this peer. If you have multiple peers, you should use aPeerGroup
to manage them and use thePeerGroup.addWallet(Wallet)
method instead of registering the wallet with each peer independently, otherwise the wallet will receive duplicate notifications.
-
removeWallet
public void removeWallet(Wallet wallet)
Unlinks the given wallet from peer. SeeaddWallet(Wallet)
.
-
startBlockChainDownload
public void startBlockChainDownload()
Starts an asynchronous download of the block chain. The chain download is deemed to be complete once we've downloaded the same number of blocks that the peer advertised having in its version handshake message.
-
sendPing
public java.util.concurrent.CompletableFuture<java.time.Duration> sendPing()
Sends the peer a ping message and returns a future that will be completed when the pong is received back. The future provides aDuration
which contains the time elapsed between the ping and the pong. Once the pong is received the value returned bylastPingInterval()
is updated. The future completes exceptionally with aProtocolException
if the peer version is too low to support measurable pings.- Returns:
- A future for the duration representing elapsed time
-
sendPing
protected java.util.concurrent.CompletableFuture<java.time.Duration> sendPing(long nonce)
-
ping
@Deprecated public ListenableCompletableFuture<java.lang.Long> ping()
Deprecated.UsesendPing()
-
lastPingInterval
public java.util.Optional<java.time.Duration> lastPingInterval()
Returns the elapsed time of the last ping/pong cycle. IfsendPing()
has never been called or we did not hear back the "pong" message yet, returns empty.- Returns:
- last ping, or empty
-
getLastPingTime
@Deprecated public long getLastPingTime()
Deprecated.
-
pingInterval
public java.util.Optional<java.time.Duration> pingInterval()
Returns a moving average of the last N ping/pong cycles. IfsendPing()
has never been called or we did not hear back the "pong" message yet, returns empty. The moving average window isPING_MOVING_AVERAGE_WINDOW
buckets.- Returns:
- moving average, or empty
-
getPingTime
@Deprecated public long getPingTime()
Deprecated.usepingInterval()
-
processPong
protected void processPong(Pong m)
-
getPeerBlockHeightDifference
public int getPeerBlockHeightDifference()
Returns the difference between our best chain height and the peers, which can either be positive if we are behind the peer, or negative if the peer is ahead of us.
-
isDownloadData
public boolean isDownloadData()
Returns true if this peer will try and download things it is sent in "inv" messages. Normally you only need one peer to be downloading data. Defaults to true.
-
setDownloadData
public void setDownloadData(boolean downloadData)
If set to false, the peer won't try and fetch blocks and transactions it hears about. Normally, only one peer should download missing blocks. Defaults to true. Changing this value from false to true may trigger a request to the remote peer for the contents of its memory pool, if Bloom filtering is active.
-
getPeerVersionMessage
public VersionMessage getPeerVersionMessage()
Returns version data announced by the remote peer.
-
getFeeFilter
public Coin getFeeFilter()
Returns the fee filter announced by the remote peer, interpreted as satoshis per kB.
-
getVersionMessage
public VersionMessage getVersionMessage()
Returns version data we announce to our remote peers.
-
getBestHeight
public long getBestHeight()
- Returns:
- the height of the best chain as claimed by peer: sum of its ver announcement and blocks announced since.
-
setMinProtocolVersion
public boolean setMinProtocolVersion(int minProtocolVersion)
The minimum P2P protocol version that is accepted. If the peer speaks a protocol version lower than this, it will be disconnected.- Returns:
- true if the peer was disconnected as a result
-
setBloomFilter
public void setBloomFilter(BloomFilter filter)
Sets a Bloom filter on this connection. This will cause the given
BloomFilter
object to be sent to the remote peer and if either a memory pool has been set using the constructor or the vDownloadData property is true, aMemoryPoolMessage
is sent as well to trigger downloading of any pending transactions that may be relevant.The Peer does not automatically request filters from any wallets added using
addWallet(Wallet)
. This is to allow callers to avoid redundantly recalculating the same filter repeatedly when using multiple peers and multiple wallets together.Therefore, you should not use this method if your app uses a
PeerGroup
. It is called for you.If the remote peer doesn't support Bloom filtering, then this call is ignored. Once set you presently cannot unset a filter, though the underlying p2p protocol does support it.
-
setBloomFilter
public void setBloomFilter(BloomFilter filter, boolean andQueryMemPool)
Sets a Bloom filter on this connection. This will cause the given
BloomFilter
object to be sent to the remote peer and if requested, aMemoryPoolMessage
is sent as well to trigger downloading of any pending transactions that may be relevant.The Peer does not automatically request filters from any wallets added using
addWallet(Wallet)
. This is to allow callers to avoid redundantly recalculating the same filter repeatedly when using multiple peers and multiple wallets together.Therefore, you should not use this method if your app uses a
PeerGroup
. It is called for you.If the remote peer doesn't support Bloom filtering, then this call is ignored. Once set you presently cannot unset a filter, though the underlying p2p protocol does support it.
-
getBloomFilter
public BloomFilter getBloomFilter()
Returns the lastBloomFilter
set bysetBloomFilter(BloomFilter)
. Bloom filters tell the remote node what transactions to send us, in a compact manner.
-
isDownloadTxDependencies
public boolean isDownloadTxDependencies()
Returns true if this peer will use getdata/notfound messages to walk backwards through transaction dependencies before handing the transaction off to the wallet. The wallet can do risk analysis on pending/recent transactions to try and discover if a pending tx might be at risk of double spending.
-
setDownloadTxDependencies
public void setDownloadTxDependencies(boolean enable)
Sets if this peer will use getdata/notfound messages to walk backwards through transaction dependencies before handing the transaction off to the wallet. The wallet can do risk analysis on pending/recent transactions to try and discover if a pending tx might be at risk of double spending.
-
setDownloadTxDependencies
public void setDownloadTxDependencies(int depth)
Sets if this peer will use getdata/notfound messages to walk backwards through transaction dependencies before handing the transaction off to the wallet. The wallet can do risk analysis on pending/recent transactions to try and discover if a pending tx might be at risk of double spending.
-
-