Package org.bitcoinj.net.discovery
Class MultiplexingDiscovery
- java.lang.Object
-
- org.bitcoinj.net.discovery.MultiplexingDiscovery
-
- All Implemented Interfaces:
PeerDiscovery
- Direct Known Subclasses:
DnsDiscovery
public class MultiplexingDiscovery extends java.lang.Object implements PeerDiscovery
MultiplexingDiscovery queries multiple PeerDiscovery objects, optionally shuffles their responses and then returns the results, thus selecting randomly between them and reducing the influence of any particular seed. Any that don't respond within the timeout are ignored. Backends are queried in parallel or serially. Backends may block.
-
-
Field Summary
Fields Modifier and Type Field Description protected NetworkParametersnetParamsprotected java.util.List<PeerDiscovery>seeds
-
Constructor Summary
Constructors Constructor Description MultiplexingDiscovery(NetworkParameters params, java.util.List<PeerDiscovery> seeds)Will query the given seeds in parallel before producing a merged response.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.concurrent.ExecutorServicecreateExecutor()static MultiplexingDiscoveryforServices(NetworkParameters params, long services)Builds a suitable set of peer discoveries.static MultiplexingDiscoveryforServices(NetworkParameters params, long services, boolean parallelQueries, boolean shufflePeers)Builds a suitable set of peer discoveries.java.util.List<java.net.InetSocketAddress>getPeers(long services, java.time.Duration timeout)Queries for addresses.voidshutdown()Stops any discovery in progress when we want to shut down quickly.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.bitcoinj.net.discovery.PeerDiscovery
getPeers
-
-
-
-
Field Detail
-
seeds
protected final java.util.List<PeerDiscovery> seeds
-
netParams
protected final NetworkParameters netParams
-
-
Constructor Detail
-
MultiplexingDiscovery
public MultiplexingDiscovery(NetworkParameters params, java.util.List<PeerDiscovery> seeds)
Will query the given seeds in parallel before producing a merged response.
-
-
Method Detail
-
forServices
public static MultiplexingDiscovery forServices(NetworkParameters params, long services)
Builds a suitable set of peer discoveries. Will query them in parallel before producing a merged response.- Parameters:
params- Network to use.services- Required services as a bitmask, e.g.VersionMessage.NODE_NETWORK.
-
forServices
public static MultiplexingDiscovery forServices(NetworkParameters params, long services, boolean parallelQueries, boolean shufflePeers)
Builds a suitable set of peer discoveries.- Parameters:
params- Network to use.services- Required services as a bitmask, e.g.VersionMessage.NODE_NETWORK.parallelQueries- When true, seeds are queried in parallelshufflePeers- When true, queried peers are shuffled
-
getPeers
public java.util.List<java.net.InetSocketAddress> getPeers(long services, java.time.Duration timeout) throws PeerDiscoveryExceptionDescription copied from interface:PeerDiscoveryQueries for addresses. This method may block.- Specified by:
getPeersin interfacePeerDiscovery- Parameters:
services- required services as a bitmask, e.g.VersionMessage.NODE_NETWORKtimeout- query timeout- Returns:
- found addresses
- Throws:
PeerDiscoveryException
-
createExecutor
protected java.util.concurrent.ExecutorService createExecutor()
-
shutdown
public void shutdown()
Description copied from interface:PeerDiscoveryStops any discovery in progress when we want to shut down quickly.- Specified by:
shutdownin interfacePeerDiscovery
-
-