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);
if (preferences.getBitcoinNetwork() == BitcoinNetwork.MAINNET)
UserThread.runAfter(() -> new Popup()
.warning("The application 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" +
"To limit the possible losses the maximum allowed trading amount and the security deposit are " +
"reduced to 0.01 BTC for the alpha version on Mainnet.")
.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" +
"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!")
.actionButtonText("I understand and want to stick with Mainnet")
.closeButtonText("Restart and use Testnet")
.actionButtonText("I understand and want to use Mainnet")
.closeButtonText("Use Testnet and restart")
.onClose(() -> {
UserThread.execute(() -> preferences.setBitcoinNetwork(BitcoinNetwork.TESTNET));
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");
ArrayList<NodeAddress> remainingNodeAddresses = new ArrayList<>(seedNodeAddresses);
remainingNodeAddresses.remove(nodeAddress);
Collections.shuffle(remainingNodeAddresses);
requestReportedPeers(nodeAddress, remainingNodeAddresses);
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()
.filter(peerManager::isSeedNode)
.count();
if (numberOfConnectedSeedNodes == 0)
requestReportedPeersFromRandomPeer(new ArrayList<>(seedNodeAddresses));
if (numberOfConnectedSeedNodes == 0) {
ArrayList<NodeAddress> nodeAddresses = new ArrayList<>(seedNodeAddresses);
Collections.shuffle(nodeAddresses);
requestReportedPeersFromRandomPeer(nodeAddresses);
}
// We try to get sufficient connections by connecting to reported and persisted peers
if (numberOfConnectedSeedNodes == 0) {
@ -216,6 +221,8 @@ public class PeerExchangeManager implements MessageListener, ConnectionListener
// 3. seenNodes
List<NodeAddress> list = new ArrayList<>(getFilteredAndSortedList(peerManager.getReportedPeers(), new ArrayList<>()));
list.addAll(getFilteredAndSortedList(peerManager.getPersistedPeers(), list));
ArrayList<NodeAddress> seedNodeAddresses = new ArrayList<>(this.seedNodeAddresses);
Collections.shuffle(seedNodeAddresses);
list.addAll(seedNodeAddresses.stream()
.filter(e -> !list.contains(e) &&
!peerManager.isSelf(e) &&

View File

@ -85,6 +85,7 @@ public class RequestDataManager implements MessageListener {
public void requestPreliminaryData() {
Log.traceCall();
ArrayList<NodeAddress> nodeAddresses = new ArrayList<>(seedNodeAddresses);
Collections.shuffle(nodeAddresses);
NodeAddress nextCandidate = nodeAddresses.get(0);
nodeAddresses.remove(nextCandidate);
requestData(nextCandidate, nodeAddresses);
@ -95,6 +96,7 @@ public class RequestDataManager implements MessageListener {
checkArgument(nodeOfPreliminaryDataRequest.isPresent(), "seedNodeOfPreliminaryDataRequest must be present");
dataUpdateRequested = true;
List<NodeAddress> remainingNodeAddresses = new ArrayList<>(seedNodeAddresses);
Collections.shuffle(remainingNodeAddresses);
NodeAddress candidate = nodeOfPreliminaryDataRequest.get();
remainingNodeAddresses.remove(candidate);
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
// data set
List<NodeAddress> list = new ArrayList<>(seedNodeAddresses);
Collections.shuffle(list);
list.addAll(getFilteredAndSortedList(peerManager.getReportedPeers(), list));
list.addAll(getFilteredAndSortedList(peerManager.getPersistedPeers(), list));
log.trace("Sorted and filtered list: list=" + list);