Class PeerGroup
- java.lang.Object
- 
- org.bitcoinj.core.PeerGroup
 
- 
- All Implemented Interfaces:
- TransactionBroadcaster
 
 public class PeerGroup extends java.lang.Object implements TransactionBroadcaster Runs a set of connections to the P2P network, brings up connections to replace disconnected nodes and manages the interaction between them all. Most applications will want to use one of these. PeerGroup tries to maintain a constant number of connections to a set of distinct peers. Each peer runs a network listener in its own thread. When a connection is lost, a new peer will be tried after a delay as long as the number of connections less than the maximum. Connections are made to addresses from a provided list. When that list is exhausted, we start again from the head of the list. The PeerGroup can broadcast a transaction to the currently connected set of peers. It can also handle download of the blockchain from peers, restarting the process when peers die. A PeerGroup won't do anything until you call the start()method which will block until peer discovery is completed and some outbound connections have been initiated (it will return before handshaking is done, however). You should callstop()when finished. Note that not all methods of PeerGroup are safe to call from a UI thread as some may do network IO, but starting and stopping the service should be fine.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classPeerGroup.FilterRecalculateMode
 - 
Field SummaryFields Modifier and Type Field Description protected AbstractBlockChainchainstatic doubleDEFAULT_BLOOM_FILTER_FP_RATEThe default Bloom filter false positive rate, which is selected to be extremely low such that you hardly ever download false positives.static java.time.DurationDEFAULT_CONNECT_TIMEOUTThe default timeout between when a connection attempt begins and version message exchange completesstatic intDEFAULT_CONNECTIONSThe default number of connections to the p2p network the library will try to build.static longDEFAULT_PING_INTERVAL_MSECHow many milliseconds to wait after receiving a pong before sending another ping.protected java.util.concurrent.ScheduledExecutorServiceexecutorprotected java.util.concurrent.locks.ReentrantLocklockstatic intMAX_ADDRESSES_PER_ADDR_MESSAGEstatic doubleMAX_FP_RATE_INCREASEMaximum increase in FP rate before forced refresh of the bloom filterprotected NetworkParametersparamsprotected java.util.concurrent.CopyOnWriteArrayList<ListenerRegistration<PeerConnectedEventListener>>peerConnectedEventListenersCallbacks for events related to peers connectingprotected java.util.concurrent.CopyOnWriteArrayList<ListenerRegistration<PeerDisconnectedEventListener>>peerDisconnectedEventListenersCallbacks for events related to peers disconnectingprotected java.util.concurrent.CopyOnWriteArrayList<ListenerRegistration<PeerDiscoveredEventListener>>peerDiscoveredEventListenersCallbacks for events related to peer connection/disconnectionprotected java.util.concurrent.CopyOnWriteArrayList<ListenerRegistration<OnTransactionBroadcastListener>>peersTransactionBroadastEventListeners
 - 
Constructor SummaryConstructors Modifier Constructor Description PeerGroup(Network network)Creates a PeerGroup for the given network.PeerGroup(Network network, AbstractBlockChain chain)Creates a PeerGroup for the given network and chain.protectedPeerGroup(Network network, AbstractBlockChain chain, ClientConnectionManager connectionManager)Create a PeerGroup for the given network, chain and connection manager.PeerGroup(NetworkParameters params)Deprecated.PeerGroup(NetworkParameters params, AbstractBlockChain chain)Deprecated.protectedPeerGroup(NetworkParameters params, AbstractBlockChain chain, ClientConnectionManager connectionManager)Create a PeerGroup for the given network, chain and connection manager.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddAddress(java.net.InetAddress address)Convenience method foraddAddress(PeerAddress).voidaddAddress(java.net.InetAddress address, int priority)Convenience method foraddAddress(PeerAddress, int).voidaddAddress(PeerAddress peerAddress)Add an address to the list of potential peers to connect to.voidaddAddress(PeerAddress peerAddress, int priority)Add an address to the list of potential peers to connect to.voidaddBlocksDownloadedEventListener(java.util.concurrent.Executor executor, BlocksDownloadedEventListener listener)Adds a listener that will be notified on the given executor when blocks are downloaded by the download peer.voidaddBlocksDownloadedEventListener(BlocksDownloadedEventListener listener)voidaddChainDownloadStartedEventListener(java.util.concurrent.Executor executor, ChainDownloadStartedEventListener listener)Adds a listener that will be notified on the given executor when chain download starts.voidaddChainDownloadStartedEventListener(ChainDownloadStartedEventListener listener)voidaddConnectedEventListener(java.util.concurrent.Executor executor, PeerConnectedEventListener listener)Adds a listener that will be notified on the given executor when new peers are connected to.voidaddConnectedEventListener(PeerConnectedEventListener listener)voidaddDisconnectedEventListener(java.util.concurrent.Executor executor, PeerDisconnectedEventListener listener)Adds a listener that will be notified on the given executor when peers are disconnected from.voidaddDisconnectedEventListener(PeerDisconnectedEventListener listener)voidaddDiscoveredEventListener(java.util.concurrent.Executor executor, PeerDiscoveredEventListener listener)Adds a listener that will be notified on the given executor when new peers are discovered.voidaddDiscoveredEventListener(PeerDiscoveredEventListener listener)voidaddGetDataEventListener(java.util.concurrent.Executor executor, GetDataEventListener listener)voidaddGetDataEventListener(GetDataEventListener listener)voidaddOnTransactionBroadcastListener(java.util.concurrent.Executor executor, OnTransactionBroadcastListener listener)voidaddOnTransactionBroadcastListener(OnTransactionBroadcastListener listener)voidaddPeerDiscovery(PeerDiscovery peerDiscovery)Add addresses from a discovery source to the list of potential peers to connect to.ListenableCompletableFuture<BloomFilter>addPeerFilterProvider(PeerFilterProvider provider)Link the given PeerFilterProvider to this PeerGroup.voidaddPreMessageReceivedEventListener(java.util.concurrent.Executor executor, PreMessageReceivedEventListener listener)voidaddPreMessageReceivedEventListener(PreMessageReceivedEventListener listener)voidaddWallet(Wallet wallet)Link the given wallet to this PeerGroup.TransactionBroadcastbroadcastTransaction(Transaction tx)CallsbroadcastTransaction(Transaction, int, boolean)with getMinBroadcastConnections() as the number of connections to wait for before commencing broadcast.TransactionBroadcastbroadcastTransaction(Transaction tx, int minConnections, boolean dropPeersAfterBroadcast)Given a transaction, sends it un-announced to one peer and then waits for it to be received back from other peers.PeerconnectTo(java.net.InetSocketAddress address)Connect to a peer by creating a channel to the destination address.protected PeerconnectTo(PeerAddress address, boolean incrementMaxConnections, java.time.Duration connectTimeout)Creates a version message to send, constructs a Peer object and attempts to connect it.PeerconnectToLocalHost()Helper for forcing a connection to localhost.protected PeercreatePeer(PeerAddress address, VersionMessage ver)You can override this to customise the creation ofPeerobjects.protected java.util.concurrent.ScheduledExecutorServicecreatePrivateExecutor()protected intdiscoverPeers()Returns number of discovered peers.voiddownloadBlockChain()Download the blockchain from peers.voiddropAllPeers()Gracefully drops all connected peers.java.time.InstantfastCatchupTime()Returns the current fast catchup time.java.util.List<Peer>findPeersOfAtLeastVersion(long protocolVersion)Returns an array list of peers that implement the given protocol version or better.java.util.List<Peer>findPeersWithServiceMask(int mask)Returns an array list of peers that match the requested service bit mask.java.util.List<Peer>getConnectedPeers()Returns a newly allocated list containing the currently connected peers.PeergetDownloadPeer()Returns the currently selected download peer.longgetFastCatchupTimeSecs()Deprecated.intgetMaxConnections()The maximum number of connections that we will create to peers.intgetMaxPeersToDiscoverCount()Returns the maximum number ofPeers to discover.TxConfidenceTablegetMemoryPool()Deprecated.intgetMinBroadcastConnections()Returns the number of connections that are required before transactions will be broadcast.intgetMinRequiredProtocolVersion()The minimum protocol version required: defaults to the version required for Bloom filtering.intgetMostCommonChainHeight()Returns our peers most commonly reported chain height.static intgetMostCommonChainHeight(java.util.List<Peer> peers)Returns most commonly reported chain height from the given list ofPeers.java.util.List<Peer>getPendingPeers()Returns a list containing Peers that did not complete connection yet.longgetPingIntervalMsec()Returns the period between pings for an individual peer.booleangetUseLocalhostPeerWhenPossible()VersionMessagegetVersionMessage()Returns the version message provided by setVersionMessage or a default if none was given.protected voidhandleNewPeer(Peer peer)protected voidhandlePeerDeath(Peer peer, java.lang.Throwable exception)booleanisBloomFilteringEnabled()Returns whether the Bloom filtering protocol optimisation is in use: defaults to true.booleanisRunning()intnumConnectedPeers()Returns the number of currently connected peers.ListenableCompletableFuture<BloomFilter>recalculateFastCatchupAndFilter(PeerGroup.FilterRecalculateMode mode)Recalculates the bloom filter given to peers as well as the timestamp after which full blocks are downloaded (instead of only headers).booleanremoveBlocksDownloadedEventListener(BlocksDownloadedEventListener listener)booleanremoveChainDownloadStartedEventListener(ChainDownloadStartedEventListener listener)booleanremoveConnectedEventListener(PeerConnectedEventListener listener)The given event listener will no longer be called with events.booleanremoveDisconnectedEventListener(PeerDisconnectedEventListener listener)The given event listener will no longer be called with events.booleanremoveDiscoveredEventListener(PeerDiscoveredEventListener listener)The given event listener will no longer be called with events.booleanremoveGetDataEventListener(GetDataEventListener listener)The given event listener will no longer be called with events.booleanremoveOnTransactionBroadcastListener(OnTransactionBroadcastListener listener)The given event listener will no longer be called with events.voidremovePeerFilterProvider(PeerFilterProvider provider)Opposite ofaddPeerFilterProvider(PeerFilterProvider).booleanremovePreMessageReceivedEventListener(PreMessageReceivedEventListener listener)voidremoveWallet(Wallet wallet)Unlinks the given wallet so it no longer receives broadcast transactions or has its transactions announced.protected PeerselectDownloadPeer(java.util.List<Peer> peers)Given a list of Peers, return a Peer to be used as the download peer.voidsetBloomFilterFalsePositiveRate(double bloomFilterFPRate)Sets the false positive rate of bloom filters given to peers.voidsetBloomFilteringEnabled(boolean bloomFilteringEnabled)Can be used to disable Bloom filtering entirely, even in SPV mode.voidsetConnectTimeout(java.time.Duration connectTimeout)Sets the timeout between when a connection attempt to a peer begins and when the version message exchange completes.voidsetConnectTimeoutMillis(int connectTimeoutMillis)Deprecated.voidsetDiscoverPeersViaP2P(boolean discoverPeersViaP2P)Setting this totruewill add addresses discovered via P2Paddrandaddrv2messages to the list of potential peers to connect to.voidsetDownloadTxDependencies(int depth)Configure download of pending transaction dependencies.voidsetFastCatchupTime(java.time.Instant fastCatchupTime)Tells thePeerGroupto download only block headers before a certain time and bodies after that.voidsetFastCatchupTimeSecs(long fastCatchupTimeSecs)Deprecated.voidsetMaxConnections(int maxConnections)Adjusts the desired number of connections that we will create to peers.voidsetMaxPeersToDiscoverCount(int maxPeersToDiscoverCount)Sets the maximum number ofPeers to discover.voidsetMinBroadcastConnections(int value)voidsetMinRequiredProtocolVersion(int minRequiredProtocolVersion)If a peer is connected to that claims to speak a protocol version lower than the given version, it will be disconnected and another one will be tried instead.voidsetPeerDiscoveryTimeout(java.time.Duration peerDiscoveryTimeout)This is how long we wait for peer discoveries to return their results.voidsetPeerDiscoveryTimeoutMillis(long peerDiscoveryTimeoutMillis)Deprecated.voidsetPingIntervalMsec(long pingIntervalMsec)Sets the period between pings for an individual peer.voidsetRequiredServices(long requiredServices)Convenience for connecting only to peers that can serve specific services.voidsetStallThreshold(int periodSecs, int bytesPerSecond)Configures the stall speed: the speed at which a peer is considered to be serving us the block chain unacceptably slowly.voidsetUseLocalhostPeerWhenPossible(boolean useLocalhostPeerWhenPossible)When true (the default), PeerGroup will attempt to connect to a Bitcoin node running on localhost before attempting to use the P2P network.voidsetUserAgent(java.lang.String name, java.lang.String version)Sets information that identifies this software to remote nodes.voidsetUserAgent(java.lang.String name, java.lang.String version, java.lang.String comments)Sets information that identifies this software to remote nodes.voidsetVersionMessage(VersionMessage ver)Sets theVersionMessagethat will be announced on newly created connections.voidstart()Does a blocking startup.ListenableCompletableFuture<java.lang.Void>startAsync()Starts the PeerGroup and begins network activity.voidstartBlockChainDownload(BlockchainDownloadEventListener listener)Start downloading the blockchain.voidstop()Does a blocking stopListenableCompletableFuture<java.lang.Void>stopAsync()ListenableCompletableFuture<java.util.List<Peer>>waitForPeers(int numPeers)Returns a future that is triggered when the number of connected peers is equal to the given number of peers.ListenableCompletableFuture<java.util.List<Peer>>waitForPeersOfVersion(int numPeers, long protocolVersion)Returns a future that is triggered when there are at least the requested number of connected peers that support the given protocol version or higher.ListenableCompletableFuture<java.util.List<Peer>>waitForPeersWithServiceMask(int numPeers, int mask)Returns a future that is triggered when there are at least the requested number of connected peers that support the given protocol version or higher.
 
- 
- 
- 
Field Detail- 
lockprotected final java.util.concurrent.locks.ReentrantLock lock 
 - 
DEFAULT_CONNECTIONSpublic static final int DEFAULT_CONNECTIONS The default number of connections to the p2p network the library will try to build. This is set to 12 empirically. It used to be 4, but because we divide the connection pool in two for broadcasting transactions, that meant we were only sending transactions to two peers and sometimes this wasn't reliable enough: transactions wouldn't get through.- See Also:
- Constant Field Values
 
 - 
paramsprotected final NetworkParameters params 
 - 
chain@Nullable protected final AbstractBlockChain chain 
 - 
executorprotected final java.util.concurrent.ScheduledExecutorService executor 
 - 
peerConnectedEventListenersprotected final java.util.concurrent.CopyOnWriteArrayList<ListenerRegistration<PeerConnectedEventListener>> peerConnectedEventListeners Callbacks for events related to peers connecting
 - 
peerDiscoveredEventListenersprotected final java.util.concurrent.CopyOnWriteArrayList<ListenerRegistration<PeerDiscoveredEventListener>> peerDiscoveredEventListeners Callbacks for events related to peer connection/disconnection
 - 
peerDisconnectedEventListenersprotected final java.util.concurrent.CopyOnWriteArrayList<ListenerRegistration<PeerDisconnectedEventListener>> peerDisconnectedEventListeners Callbacks for events related to peers disconnecting
 - 
peersTransactionBroadastEventListenersprotected final java.util.concurrent.CopyOnWriteArrayList<ListenerRegistration<OnTransactionBroadcastListener>> peersTransactionBroadastEventListeners 
 - 
DEFAULT_PING_INTERVAL_MSECpublic static final long DEFAULT_PING_INTERVAL_MSEC How many milliseconds to wait after receiving a pong before sending another ping.- See Also:
- Constant Field Values
 
 - 
MAX_ADDRESSES_PER_ADDR_MESSAGEpublic static final int MAX_ADDRESSES_PER_ADDR_MESSAGE - See Also:
- Constant Field Values
 
 - 
DEFAULT_BLOOM_FILTER_FP_RATEpublic static final double DEFAULT_BLOOM_FILTER_FP_RATE The default Bloom filter false positive rate, which is selected to be extremely low such that you hardly ever download false positives. This provides maximum performance. Although this default can be overridden to push the FP rate higher, due to various complexities there are still ways a remote peer can deanonymize the users wallet. This is why the FP rate is chosen for performance rather than privacy. If a future version of bitcoinj fixes the known de-anonymization attacks this FP rate may rise again (or more likely, become expressed as a bandwidth allowance).- See Also:
- Constant Field Values
 
 - 
MAX_FP_RATE_INCREASEpublic static final double MAX_FP_RATE_INCREASE Maximum increase in FP rate before forced refresh of the bloom filter- See Also:
- Constant Field Values
 
 - 
DEFAULT_CONNECT_TIMEOUTpublic static final java.time.Duration DEFAULT_CONNECT_TIMEOUT The default timeout between when a connection attempt begins and version message exchange completes
 
- 
 - 
Constructor Detail- 
PeerGrouppublic PeerGroup(Network network) Creates a PeerGroup for the given network. No chain is provided so this node will report its chain height as zero to other peers. This constructor is useful if you just want to explore the network but aren't interested in downloading block data.- Parameters:
- network- the P2P network to connect to
 
 - 
PeerGroup@Deprecated public PeerGroup(NetworkParameters params) Deprecated.Creates a PeerGroup with the given network. No chain is provided so this node will report its chain height as zero to other peers. This constructor is useful if you just want to explore the network but aren't interested in downloading block data.
 - 
PeerGrouppublic PeerGroup(Network network, @Nullable AbstractBlockChain chain) Creates a PeerGroup for the given network and chain. Blocks will be passed to the chain as they are broadcast and downloaded. This is probably the constructor you want to use.- Parameters:
- network- the P2P network to connect to
- chain- used to process blocks
 
 - 
PeerGroup@Deprecated public PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain) Deprecated.Creates a PeerGroup for the given network and chain. Blocks will be passed to the chain as they are broadcast and downloaded.
 - 
PeerGroupprotected PeerGroup(Network network, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager) Create a PeerGroup for the given network, chain and connection manager.- Parameters:
- network- the P2P network to connect to
- chain- used to process blocks
- connectionManager- used to create new connections and keep track of existing ones.
 
 - 
PeerGroupprotected PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager) Create a PeerGroup for the given network, chain and connection manager.- Parameters:
- params- the P2P network to connect to
- chain- used to process blocks
- connectionManager- used to create new connections and keep track of existing ones.
 
 
- 
 - 
Method Detail- 
createPrivateExecutorprotected java.util.concurrent.ScheduledExecutorService createPrivateExecutor() 
 - 
setPeerDiscoveryTimeoutpublic void setPeerDiscoveryTimeout(java.time.Duration peerDiscoveryTimeout) This is how long we wait for peer discoveries to return their results.
 - 
setPeerDiscoveryTimeoutMillis@Deprecated public void setPeerDiscoveryTimeoutMillis(long peerDiscoveryTimeoutMillis) Deprecated.This is how many milliseconds we wait for peer discoveries to return their results.
 - 
setMaxConnectionspublic void setMaxConnections(int maxConnections) Adjusts the desired number of connections that we will create to peers. Note that if there are already peers open and the new value is lower than the current number of peers, those connections will be terminated. Likewise if there aren't enough current connections to meet the new requested max size, some will be added.
 - 
setDownloadTxDependenciespublic void setDownloadTxDependencies(int depth) Configure download of pending transaction dependencies. A change of values only takes effect for newly connected peers.
 - 
getMaxConnectionspublic int getMaxConnections() The maximum number of connections that we will create to peers.
 - 
setVersionMessagepublic void setVersionMessage(VersionMessage ver) Sets theVersionMessagethat will be announced on newly created connections. A version message is primarily interesting because it lets you customize the "subVer" field which is used a bit like the User-Agent field from HTTP. It means your client tells the other side what it is, see BIP 14. The VersionMessage you provide is copied and the best chain height/time filled in for each new connection, therefore you don't have to worry about setting that. The provided object is really more of a template.
 - 
getVersionMessagepublic VersionMessage getVersionMessage() Returns the version message provided by setVersionMessage or a default if none was given.
 - 
setUserAgentpublic void setUserAgent(java.lang.String name, java.lang.String version, @Nullable java.lang.String comments)Sets information that identifies this software to remote nodes. This is a convenience wrapper for creating a newVersionMessage, callingVersionMessage.appendToSubVer(String, String, String)on it, and then callingsetVersionMessage(VersionMessage)on the result of that. See the docs forVersionMessage.appendToSubVer(String, String, String)for information on what the fields should contain.
 - 
setUserAgentpublic void setUserAgent(java.lang.String name, java.lang.String version)Sets information that identifies this software to remote nodes. This is a convenience wrapper for creating a newVersionMessage, callingVersionMessage.appendToSubVer(String, String, String)on it, and then callingsetVersionMessage(VersionMessage)on the result of that. See the docs forVersionMessage.appendToSubVer(String, String, String)for information on what the fields should contain.
 - 
addBlocksDownloadedEventListenerpublic void addBlocksDownloadedEventListener(BlocksDownloadedEventListener listener) 
 - 
addBlocksDownloadedEventListenerpublic void addBlocksDownloadedEventListener(java.util.concurrent.Executor executor, BlocksDownloadedEventListener listener)Adds a listener that will be notified on the given executor when blocks are downloaded by the download peer. 
 - 
addChainDownloadStartedEventListenerpublic void addChainDownloadStartedEventListener(ChainDownloadStartedEventListener listener) 
 - 
addChainDownloadStartedEventListenerpublic void addChainDownloadStartedEventListener(java.util.concurrent.Executor executor, ChainDownloadStartedEventListener listener)Adds a listener that will be notified on the given executor when chain download starts. 
 - 
addConnectedEventListenerpublic void addConnectedEventListener(PeerConnectedEventListener listener) 
 - 
addConnectedEventListenerpublic void addConnectedEventListener(java.util.concurrent.Executor executor, PeerConnectedEventListener listener)Adds a listener that will be notified on the given executor when new peers are connected to. 
 - 
addDisconnectedEventListenerpublic void addDisconnectedEventListener(PeerDisconnectedEventListener listener) 
 - 
addDisconnectedEventListenerpublic void addDisconnectedEventListener(java.util.concurrent.Executor executor, PeerDisconnectedEventListener listener)Adds a listener that will be notified on the given executor when peers are disconnected from. 
 - 
addDiscoveredEventListenerpublic void addDiscoveredEventListener(PeerDiscoveredEventListener listener) 
 - 
addDiscoveredEventListenerpublic void addDiscoveredEventListener(java.util.concurrent.Executor executor, PeerDiscoveredEventListener listener)Adds a listener that will be notified on the given executor when new peers are discovered. 
 - 
addGetDataEventListenerpublic void addGetDataEventListener(GetDataEventListener listener) 
 - 
addGetDataEventListenerpublic void addGetDataEventListener(java.util.concurrent.Executor executor, GetDataEventListener listener)
 - 
addOnTransactionBroadcastListenerpublic void addOnTransactionBroadcastListener(OnTransactionBroadcastListener listener) 
 - 
addOnTransactionBroadcastListenerpublic void addOnTransactionBroadcastListener(java.util.concurrent.Executor executor, OnTransactionBroadcastListener listener)
 - 
addPreMessageReceivedEventListenerpublic void addPreMessageReceivedEventListener(PreMessageReceivedEventListener listener) 
 - 
addPreMessageReceivedEventListenerpublic void addPreMessageReceivedEventListener(java.util.concurrent.Executor executor, PreMessageReceivedEventListener listener)
 - 
removeBlocksDownloadedEventListenerpublic boolean removeBlocksDownloadedEventListener(BlocksDownloadedEventListener listener) 
 - 
removeChainDownloadStartedEventListenerpublic boolean removeChainDownloadStartedEventListener(ChainDownloadStartedEventListener listener) 
 - 
removeConnectedEventListenerpublic boolean removeConnectedEventListener(PeerConnectedEventListener listener) The given event listener will no longer be called with events.
 - 
removeDisconnectedEventListenerpublic boolean removeDisconnectedEventListener(PeerDisconnectedEventListener listener) The given event listener will no longer be called with events.
 - 
removeDiscoveredEventListenerpublic boolean removeDiscoveredEventListener(PeerDiscoveredEventListener listener) The given event listener will no longer be called with events.
 - 
removeGetDataEventListenerpublic boolean removeGetDataEventListener(GetDataEventListener listener) The given event listener will no longer be called with events.
 - 
removeOnTransactionBroadcastListenerpublic boolean removeOnTransactionBroadcastListener(OnTransactionBroadcastListener listener) The given event listener will no longer be called with events.
 - 
removePreMessageReceivedEventListenerpublic boolean removePreMessageReceivedEventListener(PreMessageReceivedEventListener listener) 
 - 
getConnectedPeerspublic java.util.List<Peer> getConnectedPeers() Returns a newly allocated list containing the currently connected peers. If all you care about is the count, use numConnectedPeers().
 - 
getPendingPeerspublic java.util.List<Peer> getPendingPeers() Returns a list containing Peers that did not complete connection yet.
 - 
addAddresspublic void addAddress(PeerAddress peerAddress) Add an address to the list of potential peers to connect to. It won't necessarily be used unless there's a need to build new connections to reach the max connection count.- Parameters:
- peerAddress- IP/port to use.
 
 - 
addAddresspublic void addAddress(PeerAddress peerAddress, int priority) Add an address to the list of potential peers to connect to. It won't necessarily be used unless there's a need to build new connections to reach the max connection count.- Parameters:
- peerAddress- IP/port to use.
- priority- for connecting and being picked as a download peer
 
 - 
setRequiredServicespublic void setRequiredServices(long requiredServices) Convenience for connecting only to peers that can serve specific services. It will configure suitable peer discoveries.- Parameters:
- requiredServices- Required services as a bitmask, e.g.- Services.NODE_NETWORK.
 
 - 
addAddresspublic void addAddress(java.net.InetAddress address) Convenience method foraddAddress(PeerAddress).
 - 
addAddresspublic void addAddress(java.net.InetAddress address, int priority)Convenience method foraddAddress(PeerAddress, int).
 - 
setDiscoverPeersViaP2Ppublic void setDiscoverPeersViaP2P(boolean discoverPeersViaP2P) Setting this totruewill add addresses discovered via P2Paddrandaddrv2messages to the list of potential peers to connect to. This will automatically be set to true if at least one peer discovery is added viaaddPeerDiscovery(PeerDiscovery).- Parameters:
- discoverPeersViaP2P- true if peers should be discovered from the P2P network
 
 - 
addPeerDiscoverypublic void addPeerDiscovery(PeerDiscovery peerDiscovery) Add addresses from a discovery source to the list of potential peers to connect to. If max connections has not been configured, or set to zero, then it's set to the default at this point.
 - 
discoverPeersprotected int discoverPeers() Returns number of discovered peers.
 - 
startAsyncpublic ListenableCompletableFuture<java.lang.Void> startAsync() Starts the PeerGroup and begins network activity.- Returns:
- A future that completes when first connection activity has been triggered (note: not first connection made).
 
 - 
startpublic void start() Does a blocking startup.
 - 
stopAsyncpublic ListenableCompletableFuture<java.lang.Void> stopAsync() 
 - 
stoppublic void stop() Does a blocking stop
 - 
dropAllPeerspublic void dropAllPeers() Gracefully drops all connected peers.
 - 
addWalletpublic void addWallet(Wallet wallet) Link the given wallet to this PeerGroup. This is used for three purposes: - So the wallet receives broadcast transactions.
- Announcing pending transactions that didn't get into the chain yet to our peers.
- Set the fast catchup time using setFastCatchupTimeSecs(long), to optimize chain download.
 Note that this should be done before chain download commences because if you add a wallet with keys earlier than the current chain head, the relevant parts of the chain won't be redownloaded for you. The Wallet will have an event listener registered on it, so to avoid leaks remember to use removeWallet(Wallet)on it if you wish to keep the Wallet but lose the PeerGroup.
 - 
addPeerFilterProviderpublic ListenableCompletableFuture<BloomFilter> addPeerFilterProvider(PeerFilterProvider provider) Link the given PeerFilterProvider to this PeerGroup. DO NOT use this for Wallets, use addWallet(Wallet)instead.Note that this should be done before chain download commences because if you add a listener with keys earlier than the current chain head, the relevant parts of the chain won't be redownloaded for you. This method invokes recalculateFastCatchupAndFilter(FilterRecalculateMode). The return value of this method is theListenableCompletableFuturereturned by that invocation.- Returns:
- a future that completes once each Peerin this group has had itsBloomFilter(re)set.
 
 - 
removePeerFilterProviderpublic void removePeerFilterProvider(PeerFilterProvider provider) Opposite ofaddPeerFilterProvider(PeerFilterProvider). Again, don't use this for wallets. Does not trigger recalculation of the filter.
 - 
removeWalletpublic void removeWallet(Wallet wallet) Unlinks the given wallet so it no longer receives broadcast transactions or has its transactions announced.
 - 
recalculateFastCatchupAndFilterpublic ListenableCompletableFuture<BloomFilter> recalculateFastCatchupAndFilter(PeerGroup.FilterRecalculateMode mode) Recalculates the bloom filter given to peers as well as the timestamp after which full blocks are downloaded (instead of only headers). Note that calls made one after another may return the same future, if the request wasn't processed yet (i.e. calls are deduplicated).- Parameters:
- mode- In what situations to send the filter to connected peers.
- Returns:
- a future that completes once the filter has been calculated (note: this does not mean acknowledged by remote peers).
 
 - 
setBloomFilterFalsePositiveRatepublic void setBloomFilterFalsePositiveRate(double bloomFilterFPRate) Sets the false positive rate of bloom filters given to peers. The default is DEFAULT_BLOOM_FILTER_FP_RATE.Be careful regenerating the bloom filter too often, as it decreases anonymity because remote nodes can compare transactions against both the new and old filters to significantly decrease the false positive rate. See the docs for BloomFilter(int, double, int, BloomFilter.BloomUpdate)for a brief explanation of anonymity when using bloom filters.
 - 
numConnectedPeerspublic int numConnectedPeers() Returns the number of currently connected peers. To be informed when this count changes, usePeerConnectedEventListener.onPeerConnected(org.bitcoinj.core.Peer, int)andPeerDisconnectedEventListener.onPeerDisconnected(org.bitcoinj.core.Peer, int).
 - 
connectTo@Nullable public Peer connectTo(java.net.InetSocketAddress address) Connect to a peer by creating a channel to the destination address. This should not be used normally - let the PeerGroup manage connections throughstart()- Parameters:
- address- destination IP and port.
- Returns:
- The newly created Peer object or null if the peer could not be connected.
         Use Peer.getConnectionOpenFuture()if you want a future which completes when the connection is open.
 
 - 
connectToLocalHost@Nullable public Peer connectToLocalHost() Helper for forcing a connection to localhost. Useful when using regtest mode. Returns the peer object.
 - 
connectTo@Nullable protected Peer connectTo(PeerAddress address, boolean incrementMaxConnections, java.time.Duration connectTimeout) Creates a version message to send, constructs a Peer object and attempts to connect it. Returns the peer on success or null on failure.- Parameters:
- address- Remote network address
- incrementMaxConnections- Whether to consider this connection an attempt to fill our quota, or something explicitly requested.
- connectTimeout- timeout for establishing the connection to peers
- Returns:
- Peer or null.
 
 - 
createPeerprotected Peer createPeer(PeerAddress address, VersionMessage ver) You can override this to customise the creation ofPeerobjects.
 - 
setConnectTimeoutpublic void setConnectTimeout(java.time.Duration connectTimeout) Sets the timeout between when a connection attempt to a peer begins and when the version message exchange completes. This does not apply to currently pending peers.- Parameters:
- connectTimeout- timeout for estiablishing the connection to peers
 
 - 
setConnectTimeoutMillis@Deprecated public void setConnectTimeoutMillis(int connectTimeoutMillis) Deprecated.
 - 
startBlockChainDownloadpublic void startBlockChainDownload(BlockchainDownloadEventListener listener) Start downloading the blockchain. If no peers are currently connected, the download will be started once a peer starts. If the peer dies, the download will resume with another peer. - Parameters:
- listener- a listener for chain download events, may not be null
 
 - 
downloadBlockChainpublic void downloadBlockChain() Download the blockchain from peers. Convenience that uses aDownloadProgressTrackerfor you.This method waits until the download is complete. "Complete" is defined as downloading from at least one peer all the blocks that are in that peer's inventory. 
 - 
handleNewPeerprotected void handleNewPeer(Peer peer) 
 - 
getMemoryPool@Deprecated @Nullable public TxConfidenceTable getMemoryPool() Deprecated.Use "Context.get().getConfidenceTable()" instead
 - 
setFastCatchupTimepublic void setFastCatchupTime(java.time.Instant fastCatchupTime) Tells thePeerGroupto download only block headers before a certain time and bodies after that. Call this before starting block chain download. Do not use atime > NOW - 1block, as it will break some block download logic.
 - 
setFastCatchupTimeSecs@Deprecated public void setFastCatchupTimeSecs(long fastCatchupTimeSecs) Deprecated.
 - 
fastCatchupTimepublic java.time.Instant fastCatchupTime() Returns the current fast catchup time. The contents of blocks before this time won't be downloaded as they cannot contain any interesting transactions. If you useaddWallet(Wallet)this just returns the min of the wallets earliest key times.- Returns:
- a time in seconds since the epoch
 
 - 
getFastCatchupTimeSecs@Deprecated public long getFastCatchupTimeSecs() Deprecated.
 - 
handlePeerDeathprotected void handlePeerDeath(Peer peer, @Nullable java.lang.Throwable exception) 
 - 
setStallThresholdpublic void setStallThreshold(int periodSecs, int bytesPerSecond)Configures the stall speed: the speed at which a peer is considered to be serving us the block chain unacceptably slowly. Once a peer has served us data slower than the given data rate for the given number of seconds, it is considered stalled and will be disconnected, forcing the chain download to continue from a different peer. The defaults are chosen conservatively, but if you are running on a platform that is CPU constrained or on a very slow network e.g. EDGE, the default settings may need adjustment to avoid false stalls.- Parameters:
- periodSecs- How many seconds the download speed must be below blocksPerSec, defaults to 10.
- bytesPerSecond- Download speed (only blocks/txns count) must be consistently below this for a stall, defaults to the bandwidth required for 10 block headers per second.
 
 - 
waitForPeerspublic ListenableCompletableFuture<java.util.List<Peer>> waitForPeers(int numPeers) Returns a future that is triggered when the number of connected peers is equal to the given number of peers. By using this withgetMaxConnections()you can wait until the network is fully online. To block immediately, just call get() on the result. Just callswaitForPeersOfVersion(int, long)with zero as the protocol version.- Parameters:
- numPeers- How many peers to wait for.
- Returns:
- a future that will be triggered when the number of connected peers is greater than or equals numPeers
 
 - 
waitForPeersOfVersionpublic ListenableCompletableFuture<java.util.List<Peer>> waitForPeersOfVersion(int numPeers, long protocolVersion) Returns a future that is triggered when there are at least the requested number of connected peers that support the given protocol version or higher. To block immediately, just call get() on the result.- Parameters:
- numPeers- How many peers to wait for.
- protocolVersion- The protocol version the awaited peers must implement (or better).
- Returns:
- a future that will be triggered when the number of connected peers implementing protocolVersion or higher is greater than or equals numPeers
 
 - 
findPeersOfAtLeastVersionpublic java.util.List<Peer> findPeersOfAtLeastVersion(long protocolVersion) Returns an array list of peers that implement the given protocol version or better.
 - 
waitForPeersWithServiceMaskpublic ListenableCompletableFuture<java.util.List<Peer>> waitForPeersWithServiceMask(int numPeers, int mask) Returns a future that is triggered when there are at least the requested number of connected peers that support the given protocol version or higher. To block immediately, just call get() on the result.- Parameters:
- numPeers- How many peers to wait for.
- mask- An integer representing a bit mask that will be ANDed with the peers advertised service masks.
- Returns:
- a future that will be triggered when the number of connected peers implementing protocolVersion or higher is greater than or equals numPeers
 
 - 
findPeersWithServiceMaskpublic java.util.List<Peer> findPeersWithServiceMask(int mask) Returns an array list of peers that match the requested service bit mask.
 - 
getMinBroadcastConnectionspublic int getMinBroadcastConnections() Returns the number of connections that are required before transactions will be broadcast. If there aren't enough,broadcastTransaction(Transaction)will wait until the minimum number is reached so propagation across the network can be observed. If no value has been set usingsetMinBroadcastConnections(int)a default of 80% of whatevergetMaxConnections()returns is used.
 - 
setMinBroadcastConnectionspublic void setMinBroadcastConnections(int value) 
 - 
broadcastTransactionpublic TransactionBroadcast broadcastTransaction(Transaction tx) CallsbroadcastTransaction(Transaction, int, boolean)with getMinBroadcastConnections() as the number of connections to wait for before commencing broadcast. Also, if the transaction has no broadcast confirmations yet the peers will be dropped after the transaction has been sent.- Specified by:
- broadcastTransactionin interface- TransactionBroadcaster
 
 - 
broadcastTransactionpublic TransactionBroadcast broadcastTransaction(Transaction tx, int minConnections, boolean dropPeersAfterBroadcast) Given a transaction, sends it un-announced to one peer and then waits for it to be received back from other peers. Once all connected peers have announced the transaction, the future available via the TransactionBroadcast.awaitRelayed()()} method will be completed. If anything goes wrong the exception will be thrown when get() is called, or you can receive it via a callback on theListenableCompletableFuture. This method returns immediately, so if you want it to block just call get() on the result.Optionally, peers will be dropped after they have been used for broadcasting the transaction and they have no broadcast confirmations yet. Note that if the PeerGroup is limited to only one connection (discovery is not activated) then the future will complete as soon as the transaction was successfully written to that peer. The transaction won't be sent until there are at least minConnections active connections available. A good choice for proportion would be between 0.5 and 0.8 but if you want faster transmission during initial bringup of the peer group you can lower it. The returned TransactionBroadcastobject can be used to get progress feedback, which is calculated by watching the transaction propagate across the network and be announced by peers.
 - 
getPingIntervalMsecpublic long getPingIntervalMsec() Returns the period between pings for an individual peer. Setting this lower means more accurate and timely ping times are available viaPeer.lastPingInterval()but it increases load on the remote node. It defaults toDEFAULT_PING_INTERVAL_MSEC.
 - 
setPingIntervalMsecpublic void setPingIntervalMsec(long pingIntervalMsec) Sets the period between pings for an individual peer. Setting this lower means more accurate and timely ping times are available viaPeer.lastPingInterval()but it increases load on the remote node. It defaults toDEFAULT_PING_INTERVAL_MSEC. Setting the value to be smaller or equals 0 disables pinging entirely, although you can still request one yourself usingPeer.sendPing().
 - 
setMinRequiredProtocolVersionpublic void setMinRequiredProtocolVersion(int minRequiredProtocolVersion) If a peer is connected to that claims to speak a protocol version lower than the given version, it will be disconnected and another one will be tried instead.
 - 
getMinRequiredProtocolVersionpublic int getMinRequiredProtocolVersion() The minimum protocol version required: defaults to the version required for Bloom filtering.
 - 
getMostCommonChainHeightpublic int getMostCommonChainHeight() Returns our peers most commonly reported chain height. If the most common heights are tied, or no peers are connected, returns0.
 - 
getMostCommonChainHeightpublic static int getMostCommonChainHeight(java.util.List<Peer> peers) Returns most commonly reported chain height from the given list ofPeers. If the most common heights are tied, or no peers are connected, returns0.
 - 
selectDownloadPeer@Nullable protected Peer selectDownloadPeer(java.util.List<Peer> peers) Given a list of Peers, return a Peer to be used as the download peer. If you don't want PeerGroup to manage download peer statuses for you, just override this and always return null.
 - 
getDownloadPeerpublic Peer getDownloadPeer() Returns the currently selected download peer. Bear in mind that it may have changed as soon as this method returns. Can return null if no peer was selected.
 - 
getMaxPeersToDiscoverCountpublic int getMaxPeersToDiscoverCount() Returns the maximum number ofPeers to discover. This maximum is checked after eachPeerDiscoveryso this max number can be surpassed.- Returns:
- the maximum number of peers to discover
 
 - 
setMaxPeersToDiscoverCountpublic void setMaxPeersToDiscoverCount(int maxPeersToDiscoverCount) Sets the maximum number ofPeers to discover. This maximum is checked after eachPeerDiscoveryso this max number can be surpassed.- Parameters:
- maxPeersToDiscoverCount- the maximum number of peers to discover
 
 - 
getUseLocalhostPeerWhenPossiblepublic boolean getUseLocalhostPeerWhenPossible() 
 - 
setUseLocalhostPeerWhenPossiblepublic void setUseLocalhostPeerWhenPossible(boolean useLocalhostPeerWhenPossible) When true (the default), PeerGroup will attempt to connect to a Bitcoin node running on localhost before attempting to use the P2P network. If successful, only localhost will be used. This makes for a simple and easy way for a user to upgrade a bitcoinj based app running in SPV mode to fully validating security.
 - 
isRunningpublic boolean isRunning() 
 - 
setBloomFilteringEnabledpublic void setBloomFilteringEnabled(boolean bloomFilteringEnabled) Can be used to disable Bloom filtering entirely, even in SPV mode. You are very unlikely to need this, it is an optimisation for rare cases when full validation is not required but it's still more efficient to download full blocks than filtered blocks.
 - 
isBloomFilteringEnabledpublic boolean isBloomFilteringEnabled() Returns whether the Bloom filtering protocol optimisation is in use: defaults to true.
 
- 
 
-