Add shuffling to seednodes

This commit is contained in:
Manfred Karrer 2016-01-27 22:48:19 +01:00
parent d8086ffba9
commit 43047b3727
3 changed files with 20 additions and 8 deletions

View file

@ -392,13 +392,15 @@ public class MainViewModel implements ViewModel {
preferences.setTacAccepted(true); preferences.setTacAccepted(true);
if (preferences.getBitcoinNetwork() == BitcoinNetwork.MAINNET) if (preferences.getBitcoinNetwork() == BitcoinNetwork.MAINNET)
UserThread.runAfter(() -> new Popup() UserThread.runAfter(() -> new Popup()
.warning("The application is still in alpha version.\n" + .warning("This software is still in alpha version.\n" +
"Please be aware that using Mainnet comes with the risk to lose funds in case of software bugs.\n" + "Please be aware that using Mainnet comes with the risk to lose funds " +
"To limit the possible losses the maximum allowed trading amount and the security deposit are " + "in case of software bugs.\n" +
"reduced to 0.01 BTC for the alpha version on Mainnet.") "To limit the possible losses the maximum allowed trading amount and the " +
"security deposit have been reduced to 0.01 BTC for the alpha version " +
"when using Mainnet.")
.headLine("Important information!") .headLine("Important information!")
.actionButtonText("I understand and want to stick with Mainnet") .actionButtonText("I understand and want to use Mainnet")
.closeButtonText("Restart and use Testnet") .closeButtonText("Use Testnet and restart")
.onClose(() -> { .onClose(() -> {
UserThread.execute(() -> preferences.setBitcoinNetwork(BitcoinNetwork.TESTNET)); UserThread.execute(() -> preferences.setBitcoinNetwork(BitcoinNetwork.TESTNET));
UserThread.runAfter(BitsquareApp.shutDownHandler::run, 300, TimeUnit.MILLISECONDS); UserThread.runAfter(BitsquareApp.shutDownHandler::run, 300, TimeUnit.MILLISECONDS);

View file

@ -63,6 +63,7 @@ public class PeerExchangeManager implements MessageListener, ConnectionListener
checkNotNull(networkNode.getNodeAddress(), "My node address must not be null at requestReportedPeers"); checkNotNull(networkNode.getNodeAddress(), "My node address must not be null at requestReportedPeers");
ArrayList<NodeAddress> remainingNodeAddresses = new ArrayList<>(seedNodeAddresses); ArrayList<NodeAddress> remainingNodeAddresses = new ArrayList<>(seedNodeAddresses);
remainingNodeAddresses.remove(nodeAddress); remainingNodeAddresses.remove(nodeAddress);
Collections.shuffle(remainingNodeAddresses);
requestReportedPeers(nodeAddress, remainingNodeAddresses); requestReportedPeers(nodeAddress, remainingNodeAddresses);
int delay = new Random().nextInt(60) + 60 * 3; // 3-4 min int delay = new Random().nextInt(60) + 60 * 3; // 3-4 min
@ -180,8 +181,12 @@ public class PeerExchangeManager implements MessageListener, ConnectionListener
long numberOfConnectedSeedNodes = confirmedConnections.stream() long numberOfConnectedSeedNodes = confirmedConnections.stream()
.filter(peerManager::isSeedNode) .filter(peerManager::isSeedNode)
.count(); .count();
if (numberOfConnectedSeedNodes == 0) if (numberOfConnectedSeedNodes == 0) {
requestReportedPeersFromRandomPeer(new ArrayList<>(seedNodeAddresses)); ArrayList<NodeAddress> nodeAddresses = new ArrayList<>(seedNodeAddresses);
Collections.shuffle(nodeAddresses);
requestReportedPeersFromRandomPeer(nodeAddresses);
}
// We try to get sufficient connections by connecting to reported and persisted peers // We try to get sufficient connections by connecting to reported and persisted peers
if (numberOfConnectedSeedNodes == 0) { if (numberOfConnectedSeedNodes == 0) {
@ -216,6 +221,8 @@ public class PeerExchangeManager implements MessageListener, ConnectionListener
// 3. seenNodes // 3. seenNodes
List<NodeAddress> list = new ArrayList<>(getFilteredAndSortedList(peerManager.getReportedPeers(), new ArrayList<>())); List<NodeAddress> list = new ArrayList<>(getFilteredAndSortedList(peerManager.getReportedPeers(), new ArrayList<>()));
list.addAll(getFilteredAndSortedList(peerManager.getPersistedPeers(), list)); list.addAll(getFilteredAndSortedList(peerManager.getPersistedPeers(), list));
ArrayList<NodeAddress> seedNodeAddresses = new ArrayList<>(this.seedNodeAddresses);
Collections.shuffle(seedNodeAddresses);
list.addAll(seedNodeAddresses.stream() list.addAll(seedNodeAddresses.stream()
.filter(e -> !list.contains(e) && .filter(e -> !list.contains(e) &&
!peerManager.isSelf(e) && !peerManager.isSelf(e) &&

View file

@ -85,6 +85,7 @@ public class RequestDataManager implements MessageListener {
public void requestPreliminaryData() { public void requestPreliminaryData() {
Log.traceCall(); Log.traceCall();
ArrayList<NodeAddress> nodeAddresses = new ArrayList<>(seedNodeAddresses); ArrayList<NodeAddress> nodeAddresses = new ArrayList<>(seedNodeAddresses);
Collections.shuffle(nodeAddresses);
NodeAddress nextCandidate = nodeAddresses.get(0); NodeAddress nextCandidate = nodeAddresses.get(0);
nodeAddresses.remove(nextCandidate); nodeAddresses.remove(nextCandidate);
requestData(nextCandidate, nodeAddresses); requestData(nextCandidate, nodeAddresses);
@ -95,6 +96,7 @@ public class RequestDataManager implements MessageListener {
checkArgument(nodeOfPreliminaryDataRequest.isPresent(), "seedNodeOfPreliminaryDataRequest must be present"); checkArgument(nodeOfPreliminaryDataRequest.isPresent(), "seedNodeOfPreliminaryDataRequest must be present");
dataUpdateRequested = true; dataUpdateRequested = true;
List<NodeAddress> remainingNodeAddresses = new ArrayList<>(seedNodeAddresses); List<NodeAddress> remainingNodeAddresses = new ArrayList<>(seedNodeAddresses);
Collections.shuffle(remainingNodeAddresses);
NodeAddress candidate = nodeOfPreliminaryDataRequest.get(); NodeAddress candidate = nodeOfPreliminaryDataRequest.get();
remainingNodeAddresses.remove(candidate); remainingNodeAddresses.remove(candidate);
requestData(candidate, remainingNodeAddresses); requestData(candidate, remainingNodeAddresses);
@ -189,6 +191,7 @@ public class RequestDataManager implements MessageListener {
// we got from the other seed node contacted but we still have not requested the initial // we got from the other seed node contacted but we still have not requested the initial
// data set // data set
List<NodeAddress> list = new ArrayList<>(seedNodeAddresses); List<NodeAddress> list = new ArrayList<>(seedNodeAddresses);
Collections.shuffle(list);
list.addAll(getFilteredAndSortedList(peerManager.getReportedPeers(), list)); list.addAll(getFilteredAndSortedList(peerManager.getReportedPeers(), list));
list.addAll(getFilteredAndSortedList(peerManager.getPersistedPeers(), list)); list.addAll(getFilteredAndSortedList(peerManager.getPersistedPeers(), list));
log.trace("Sorted and filtered list: list=" + list); log.trace("Sorted and filtered list: list=" + list);