Class MultiplexingDiscovery

java.lang.Object
org.bitcoinj.net.discovery.MultiplexingDiscovery
All Implemented Interfaces:
PeerDiscovery
Direct Known Subclasses:
DnsDiscovery

public class MultiplexingDiscovery extends 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 Details

  • Constructor Details

    • MultiplexingDiscovery

      public MultiplexingDiscovery(NetworkParameters params, List<PeerDiscovery> seeds)
      Will query the given seeds in parallel before producing a merged response.
  • Method Details

    • 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. If specific services are required, DNS is not used as the protocol can't handle it.
      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. If specific services are required, DNS is not used as the protocol can't handle it.
      Parameters:
      params - Network to use.
      services - Required services as a bitmask, e.g. VersionMessage.NODE_NETWORK.
      parallelQueries - When true, seeds are queried in parallel
      shufflePeers - When true, queried peers are shuffled
    • getPeers

      public List<InetSocketAddress> getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException
      Description copied from interface: PeerDiscovery
      Queries the addresses. This method may block.
      Specified by:
      getPeers in interface PeerDiscovery
      Parameters:
      services - Required services as a bitmask, e.g. VersionMessage.NODE_NETWORK.
      Throws:
      PeerDiscoveryException
    • createExecutor

      protected ExecutorService createExecutor()
    • shutdown

      public void shutdown()
      Description copied from interface: PeerDiscovery
      Stops any discovery in progress when we want to shut down quickly.
      Specified by:
      shutdown in interface PeerDiscovery