Skip to content

Commit

Permalink
Change order used to connect to peers (DNM, seeds, dns seeders) (#518)
Browse files Browse the repository at this point in the history
* Change order that is used to connect to peers (DNM, seeds, dns seeders)
  • Loading branch information
HashEngineering authored Oct 2, 2020
1 parent 702c87b commit aad73a6
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions wallet/src/de/schildbach/wallet/service/BlockchainServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public class BlockchainServiceImpl extends LifecycleService implements Blockchai
private final SeedPeers seedPeerDiscovery = new SeedPeers(Constants.NETWORK_PARAMETERS);
private final DnsDiscovery dnsDiscovery = new DnsDiscovery(Constants.DNS_SEED, Constants.NETWORK_PARAMETERS);
ArrayList<PeerDiscovery> peerDiscoveryList = new ArrayList<>(2);

private final static int MINIMUM_PEER_COUNT = 16;

private static final int MIN_COLLECT_HISTORY = 2;
private static final int IDLE_BLOCK_TIMEOUT_MIN = 2;
Expand Down Expand Up @@ -518,34 +518,36 @@ public InetSocketAddress[] getPeers(final long services, final long timeoutValue
}

if (!connectTrustedPeerOnly) {
// First use the masternode list that is included
try {
peers.addAll(
Arrays.asList(normalPeerDiscovery.getPeers(services, timeoutValue, timeoutUnit)));
SimplifiedMasternodeList mnlist = org.bitcoinj.core.Context.get().masternodeListManager.getListAtChainTip();
MasternodePeerDiscovery discovery = new MasternodePeerDiscovery(mnlist);
peers.addAll(Arrays.asList(discovery.getPeers(services, timeoutValue, timeoutUnit)));
} catch (PeerDiscoveryException x) {
//swallow and continue with another method of connection.
log.info("DNS peer discovery failed: "+ x.getMessage());
if(x.getCause() != null)
log.info( "cause: " + x.getCause().getMessage());
//swallow and continue with another method of connection
log.info("DMN List peer discovery failed: "+ x.getMessage());
}
if(peers.size() < 10) {
log.info("DNS peer discovery returned less than 10 nodes. Adding DMN peers to the list to increase connections");
try {
SimplifiedMasternodeList mnlist = org.bitcoinj.core.Context.get().masternodeListManager.getListAtChainTip();
MasternodePeerDiscovery discovery = new MasternodePeerDiscovery(mnlist);
peers.addAll(Arrays.asList(discovery.getPeers(services, timeoutValue, timeoutUnit)));
} catch (PeerDiscoveryException x) {
//swallow and continue with another method of connection
log.info("DMN List peer discovery failed: "+ x.getMessage());

if(peers.size() < MINIMUM_PEER_COUNT) {
if (Constants.NETWORK_PARAMETERS.getAddrSeeds() != null) {
log.info("DNM peer discovery returned less than 16 nodes. Adding seed peers to the list to increase connections");
peers.addAll(Arrays.asList(seedPeerDiscovery.getPeers(services, timeoutValue, timeoutUnit)));
} else {
log.info("DNS peer discovery returned less than 16 nodes. Unable to add seed peers (it is not specified for this network).");
}
}

if(peers.size() < 10) {
if (Constants.NETWORK_PARAMETERS.getAddrSeeds() != null) {
log.info("DNS peer discovery returned less than 10 nodes. Adding seed peers to the list to increase connections");
peers.addAll(Arrays.asList(seedPeerDiscovery.getPeers(services, timeoutValue, timeoutUnit)));
} else {
log.info("DNS peer discovery returned less than 10 nodes. Unable to add seed peers (it is not specified for this network).");
}
if(peers.size() < MINIMUM_PEER_COUNT) {
log.info("Masternode peer discovery returned less than 16 nodes. Adding DMN peers to the list to increase connections");

try {
peers.addAll(
Arrays.asList(normalPeerDiscovery.getPeers(services, timeoutValue, timeoutUnit)));
} catch (PeerDiscoveryException x) {
//swallow and continue with another method of connection, if one exists.
log.info("DNS peer discovery failed: "+ x.getMessage());
if(x.getCause() != null)
log.info( "cause: " + x.getCause().getMessage());
}
}
}
Expand Down

0 comments on commit aad73a6

Please sign in to comment.