From 4e0f572ed9e76a230762a876c6118e21ab931895 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 18 Nov 2015 14:41:47 +0100 Subject: [PATCH] Fix peergroup --- .../io/bitsquare/p2p/peers/PeerGroup.java | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/network/src/main/java/io/bitsquare/p2p/peers/PeerGroup.java b/network/src/main/java/io/bitsquare/p2p/peers/PeerGroup.java index e7f5cb4038..659915dc76 100644 --- a/network/src/main/java/io/bitsquare/p2p/peers/PeerGroup.java +++ b/network/src/main/java/io/bitsquare/p2p/peers/PeerGroup.java @@ -279,19 +279,21 @@ public class PeerGroup implements MessageListener, ConnectionListener { } else { log.info("An authentication handshake is already created for that peerAddress ({})", peerAddress); - Optional>> tupleOptional = getRandomNotAuthPeerAndRemainingSet(remainingAddresses); - if (tupleOptional.isPresent()) { - log.info("We try to authenticate to a seed node. " + tupleOptional.get().first); - authenticateToSeedNode(tupleOptional.get().second, tupleOptional.get().first, true); - } else if (reportedPeers.size() > 0) { - log.info("We don't have any more seed nodes for connecting. Lets try the reported peers."); - authenticateToRemainingReportedPeers(true); - } else { - log.info("We don't have any more seed nodes nor reported nodes for connecting. " + - "We stop authentication attempts now, but will repeat after a few minutes."); - UserThread.runAfterRandomDelay(() -> authenticateToRemainingReportedPeers(true), - 1, 2, TimeUnit.MINUTES); - } + UserThread.runAfterRandomDelay(() -> { + Optional>> tupleOptional = getRandomNotAuthPeerAndRemainingSet(remainingAddresses); + if (tupleOptional.isPresent()) { + log.info("We try to authenticate to a seed node. " + tupleOptional.get().first); + authenticateToSeedNode(tupleOptional.get().second, tupleOptional.get().first, true); + } else if (reportedPeers.size() > 0) { + log.info("We don't have any more seed nodes for connecting. Lets try the reported peers."); + authenticateToRemainingReportedPeers(true); + } else { + log.info("We don't have any more seed nodes nor reported nodes for connecting. " + + "We stop authentication attempts now, but will repeat after a few minutes."); + authenticateToRemainingReportedPeers(true); + } + }, + 1, 2, TimeUnit.MINUTES); } } @@ -382,16 +384,17 @@ public class PeerGroup implements MessageListener, ConnectionListener { }); } else { log.info("An authentication handshake is already created for that peerAddress ({})", reportedPeer); - - if (reportedPeers.size() > 0) { - log.info("Authentication failed. Lets try again with the remaining reported peer addresses."); - authenticateToRemainingReportedPeers(false); - } else { - log.info("Authentication failed. " + - "Lets wait a bit and then try the remaining seed nodes."); - UserThread.runAfterRandomDelay(() -> authenticateToRemainingSeedNodes(), - 1, 2, TimeUnit.MINUTES); - } + UserThread.runAfterRandomDelay(() -> { + if (reportedPeers.size() > 0) { + log.info("Authentication failed. Lets try again with the remaining reported peer addresses."); + authenticateToRemainingReportedPeers(false); + } else { + log.info("Authentication failed. " + + "Lets wait a bit and then try the remaining seed nodes."); + authenticateToRemainingSeedNodes(); + } + }, + 1, 2, TimeUnit.MINUTES); } }