Remove check for not empty seednodes (can be empty in some cases)

This commit is contained in:
Manfred Karrer 2016-03-20 19:23:17 +01:00
parent e7967cc0e1
commit 605cf27eaf
4 changed files with 24 additions and 19 deletions

View File

@ -93,6 +93,7 @@ public class PeerManager implements ConnectionListener {
public PeerManager(NetworkNode networkNode, Set<NodeAddress> seedNodeAddresses, File storageDir, Clock clock) {
this.networkNode = networkNode;
this.clock = clock;
// seedNodeAddresses can be empty (in case there is only 1 seed node, the seed node starting up has no other seed nodes)
this.seedNodeAddresses = new HashSet<>(seedNodeAddresses);
networkNode.addConnectionListener(this);
dbStorage = new Storage<>(storageDir);

View File

@ -69,10 +69,10 @@ public class RequestDataManager implements MessageListener, ConnectionListener,
this.networkNode = networkNode;
this.dataStorage = dataStorage;
this.peerManager = peerManager;
// seedNodeAddresses can be empty (in case there is only 1 seed node, the seed node starting up has no other seed nodes)
this.seedNodeAddresses = new HashSet<>(seedNodeAddresses);
this.listener = listener;
checkArgument(!seedNodeAddresses.isEmpty(), "seedNodeAddresses must not be empty.");
networkNode.addMessageListener(this);
peerManager.addListener(this);
}
@ -94,10 +94,12 @@ public class RequestDataManager implements MessageListener, ConnectionListener,
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);
if (!nodeAddresses.isEmpty()) {
Collections.shuffle(nodeAddresses);
NodeAddress nextCandidate = nodeAddresses.get(0);
nodeAddresses.remove(nextCandidate);
requestData(nextCandidate, nodeAddresses);
}
}
public void requestUpdateData() {
@ -105,10 +107,12 @@ public class RequestDataManager implements MessageListener, ConnectionListener,
checkArgument(nodeAddressOfPreliminaryDataRequest.isPresent(), "seedNodeOfPreliminaryDataRequest must be present");
dataUpdateRequested = true;
List<NodeAddress> remainingNodeAddresses = new ArrayList<>(seedNodeAddresses);
Collections.shuffle(remainingNodeAddresses);
NodeAddress candidate = nodeAddressOfPreliminaryDataRequest.get();
remainingNodeAddresses.remove(candidate);
requestData(candidate, remainingNodeAddresses);
if (!remainingNodeAddresses.isEmpty()) {
Collections.shuffle(remainingNodeAddresses);
NodeAddress candidate = nodeAddressOfPreliminaryDataRequest.get();
remainingNodeAddresses.remove(candidate);
requestData(candidate, remainingNodeAddresses);
}
}
public Optional<NodeAddress> getNodeAddressOfPreliminaryDataRequest() {
@ -315,10 +319,11 @@ public class RequestDataManager implements MessageListener, ConnectionListener,
List<NodeAddress> filteredPersistedPeers = getFilteredNonSeedNodeList(getSortedNodeAddresses(peerManager.getPersistedPeers()), list);
list.addAll(filteredPersistedPeers);
checkArgument(!list.isEmpty(), "seedNodeAddresses must not be empty.");
NodeAddress nextCandidate = list.get(0);
list.remove(nextCandidate);
requestData(nextCandidate, list);
if (!list.isEmpty()) {
NodeAddress nextCandidate = list.get(0);
list.remove(nextCandidate);
requestData(nextCandidate, list);
}
},
RETRY_DELAY_SEC);
}

View File

@ -16,7 +16,6 @@ import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
public class PeerExchangeManager implements MessageListener, ConnectionListener, PeerManager.Listener {
@ -41,7 +40,7 @@ public class PeerExchangeManager implements MessageListener, ConnectionListener,
public PeerExchangeManager(NetworkNode networkNode, PeerManager peerManager, Set<NodeAddress> seedNodeAddresses) {
this.networkNode = networkNode;
this.peerManager = peerManager;
checkArgument(!seedNodeAddresses.isEmpty(), "seedNodeAddresses must not be empty");
// seedNodeAddresses can be empty (in case there is only 1 seed node, the seed node starting up has no other seed nodes)
this.seedNodeAddresses = new HashSet<>(seedNodeAddresses);
networkNode.addMessageListener(this);

View File

@ -32,15 +32,15 @@ public class SeedNodesRepository {
new NodeAddress("izs5oz7i5ta7c2ir.onion:8000"),*/
// v0.3.5, v0.3.6 (backwards compatible)
new NodeAddress("hulvbm5xjn7b7ku4.onion:8000"),
/*new NodeAddress("hulvbm5xjn7b7ku4.onion:8000"),
new NodeAddress("3efgjjbdvhbvck3x.onion:8000"),
new NodeAddress("3unfcshgwipxhxfm.onion:8000"),
new NodeAddress("3unfcshgwipxhxfm.onion:8000"),*/
// v0.3.7
/* new NodeAddress("ybmi4iaesugslxrw.onion:8000"),
new NodeAddress("ybmi4iaesugslxrw.onion:8000"),
new NodeAddress("ufwnvo775jfnjeux.onion:8000"),
new NodeAddress("b66vnevaljo6xt5a.onion:8000"),*/
new NodeAddress("b66vnevaljo6xt5a.onion:8000"),
// testnet
new NodeAddress("znmy44wcstn2rkva.onion:8001"),