From 605cf27eaf333dd759af471773d5ac298d6abdfe Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sun, 20 Mar 2016 19:23:17 +0100 Subject: [PATCH] Remove check for not empty seednodes (can be empty in some cases) --- .../io/bitsquare/p2p/peers/PeerManager.java | 1 + .../p2p/peers/getdata/RequestDataManager.java | 31 +++++++++++-------- .../peerexchange/PeerExchangeManager.java | 3 +- .../p2p/seed/SeedNodesRepository.java | 8 ++--- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/network/src/main/java/io/bitsquare/p2p/peers/PeerManager.java b/network/src/main/java/io/bitsquare/p2p/peers/PeerManager.java index bb78ea938d..eeafda7901 100644 --- a/network/src/main/java/io/bitsquare/p2p/peers/PeerManager.java +++ b/network/src/main/java/io/bitsquare/p2p/peers/PeerManager.java @@ -93,6 +93,7 @@ public class PeerManager implements ConnectionListener { public PeerManager(NetworkNode networkNode, Set 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); diff --git a/network/src/main/java/io/bitsquare/p2p/peers/getdata/RequestDataManager.java b/network/src/main/java/io/bitsquare/p2p/peers/getdata/RequestDataManager.java index 29bf92f5b7..8c5d6ecaea 100644 --- a/network/src/main/java/io/bitsquare/p2p/peers/getdata/RequestDataManager.java +++ b/network/src/main/java/io/bitsquare/p2p/peers/getdata/RequestDataManager.java @@ -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 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 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 getNodeAddressOfPreliminaryDataRequest() { @@ -315,10 +319,11 @@ public class RequestDataManager implements MessageListener, ConnectionListener, List 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); } diff --git a/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/PeerExchangeManager.java b/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/PeerExchangeManager.java index 4d023d5b0c..12ae6162d6 100644 --- a/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/PeerExchangeManager.java +++ b/network/src/main/java/io/bitsquare/p2p/peers/peerexchange/PeerExchangeManager.java @@ -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 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); diff --git a/network/src/main/java/io/bitsquare/p2p/seed/SeedNodesRepository.java b/network/src/main/java/io/bitsquare/p2p/seed/SeedNodesRepository.java index 1d0aa02c08..12eb358170 100644 --- a/network/src/main/java/io/bitsquare/p2p/seed/SeedNodesRepository.java +++ b/network/src/main/java/io/bitsquare/p2p/seed/SeedNodesRepository.java @@ -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"),