public class NativePeerEventListener extends Object implements PeerConnectionEventListener, PeerDataEventListener, OnTransactionBroadcastListener
Modifier and Type | Field and Description |
---|---|
long |
ptr |
Constructor and Description |
---|
NativePeerEventListener() |
Modifier and Type | Method and Description |
---|---|
List<Message> |
getData(Peer peer,
GetDataMessage m)
Called when a peer receives a getdata message, usually in response to an "inv" being broadcast.
|
void |
onBlocksDownloaded(Peer peer,
Block block,
FilteredBlock filteredBlock,
int blocksLeft)
Called on a Peer thread when a block is received.
|
void |
onChainDownloadStarted(Peer peer,
int blocksLeft)
Called when a download is started with the initial number of blocks to be downloaded.
|
void |
onPeerConnected(Peer peer,
int peerCount)
Called when a peer is connected.
|
void |
onPeerDisconnected(Peer peer,
int peerCount)
Called when a peer is disconnected.
|
void |
onPeersDiscovered(Set<PeerAddress> peerAddresses)
Called when peers are discovered, this happens at startup of
PeerGroup or if we run out of
suitable Peer s to connect to. |
Message |
onPreMessageReceived(Peer peer,
Message m)
Called when a message is received by a peer, before the message is processed.
|
void |
onTransaction(Peer peer,
Transaction t)
Called when a new transaction is broadcast over the network.
|
public void onPeersDiscovered(Set<PeerAddress> peerAddresses)
PeerDiscoveredEventListener
Called when peers are discovered, this happens at startup of PeerGroup
or if we run out of
suitable Peer
s to connect to.
onPeersDiscovered
in interface PeerDiscoveredEventListener
peerAddresses
- the set of discovered PeerAddress
espublic void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft)
BlocksDownloadedEventListener
Called on a Peer thread when a block is received.
The block may be a Block object that contains transactions, a Block object that is only a header when fast catchup is being used. If set, filteredBlock can be used to retrieve the list of associated transactions.
onBlocksDownloaded
in interface BlocksDownloadedEventListener
peer
- the peer receiving the blockblock
- the downloaded blockfilteredBlock
- if non-null, the object that wraps the block header passed as the block param.blocksLeft
- the number of blocks left to downloadpublic void onChainDownloadStarted(Peer peer, int blocksLeft)
ChainDownloadStartedEventListener
onChainDownloadStarted
in interface ChainDownloadStartedEventListener
peer
- the peer receiving the blockblocksLeft
- the number of blocks left to downloadpublic void onPeerConnected(Peer peer, int peerCount)
PeerConnectedEventListener
Peer
instead of a PeerGroup
,
peerCount will always be 1.onPeerConnected
in interface PeerConnectedEventListener
peerCount
- the total number of connected peerspublic void onPeerDisconnected(Peer peer, int peerCount)
PeerConnectionEventListener
PeerGroup
and the group is in the process of shutting down. If this listener is registered to a
Peer
instead of a PeerGroup
, peerCount will always be 0. This handler can be called without
a corresponding invocation of onPeerConnected if the initial connection is never successful.onPeerDisconnected
in interface PeerConnectionEventListener
onPeerDisconnected
in interface PeerDisconnectedEventListener
peerCount
- the total number of connected peerspublic Message onPreMessageReceived(Peer peer, Message m)
PreMessageReceivedEventListener
Called when a message is received by a peer, before the message is processed. The returned message is processed instead. Returning null will cause the message to be ignored by the Peer returning the same message object allows you to see the messages received but not change them. The result from one event listeners callback is passed as "m" to the next, forming a chain.
Note that this will never be called if registered with any executor other than
Threading.SAME_THREAD
onPreMessageReceived
in interface PreMessageReceivedEventListener
public void onTransaction(Peer peer, Transaction t)
OnTransactionBroadcastListener
onTransaction
in interface OnTransactionBroadcastListener
public List<Message> getData(Peer peer, GetDataMessage m)
GetDataEventListener
Called when a peer receives a getdata message, usually in response to an "inv" being broadcast. Return as many
items as possible which appear in the GetDataMessage
, or null if you're not interested in responding.
Note that this will never be called if registered with any executor other than
Threading.SAME_THREAD
getData
in interface GetDataEventListener
Copyright © 2016. All rights reserved.