com.google.bitcoin.core
Interface PeerEventListener

All Known Implementing Classes:
AbstractPeerEventListener, DownloadListener, NativePeerEventListener

public interface PeerEventListener

Implementors can listen to events like blocks being downloaded/transactions being broadcast/connect/disconnects, they can pre-filter messages before they are procesesed by a Peer or PeerGroup, and they can provide transactions to remote peers when they ask for them.


Method Summary
 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, 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.
 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.
 

Method Detail

onBlocksDownloaded

void onBlocksDownloaded(Peer peer,
                        Block block,
                        int blocksLeft)
Called on a Peer thread when a block is received.

The block may have transactions or may be a header only once getheaders is implemented.

Parameters:
peer - the peer receiving the block
block - the downloaded block
blocksLeft - the number of blocks left to download

onChainDownloadStarted

void onChainDownloadStarted(Peer peer,
                            int blocksLeft)
Called when a download is started with the initial number of blocks to be downloaded.

Parameters:
peer - the peer receiving the block
blocksLeft - the number of blocks left to download

onPeerConnected

void onPeerConnected(Peer peer,
                     int peerCount)
Called when a peer is connected. If this listener is registered to a Peer instead of a PeerGroup, peerCount will always be 1.

Parameters:
peer -
peerCount - the total number of connected peers

onPeerDisconnected

void onPeerDisconnected(Peer peer,
                        int peerCount)
Called when a peer is disconnected. Note that this won't be called if the listener is registered on a 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.

Parameters:
peer -
peerCount - the total number of connected peers

onPreMessageReceived

Message onPreMessageReceived(Peer peer,
                             Message m)

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


onTransaction

void onTransaction(Peer peer,
                   Transaction t)
Called when a new transaction is broadcast over the network.


getData

@Nullable
List<Message> getData(Peer peer,
                               GetDataMessage m)

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



Copyright © 2014. All rights reserved.