From 769a78fe52d27a4ac166022e21043286c8e37f72 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 5 Jan 2021 21:29:51 -0500 Subject: [PATCH] Behaviour change: Remove setAllowDisconnectSeedNodes method We handle it in ConnectionState by counting requests and responses and adding a timer --- .../dao/node/full/network/FullNodeNetworkService.java | 1 - .../dao/node/lite/network/LiteNodeNetworkService.java | 9 --------- .../main/java/bisq/network/p2p/peers/PeerManager.java | 8 +------- .../java/bisq/network/p2p/peers/PeerManagerTest.java | 6 +++--- 4 files changed, 4 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/node/full/network/FullNodeNetworkService.java b/core/src/main/java/bisq/core/dao/node/full/network/FullNodeNetworkService.java index 3faf2b8bac..e8b6a0483f 100644 --- a/core/src/main/java/bisq/core/dao/node/full/network/FullNodeNetworkService.java +++ b/core/src/main/java/bisq/core/dao/node/full/network/FullNodeNetworkService.java @@ -91,7 +91,6 @@ public class FullNodeNetworkService implements MessageListener, PeerManager.List public void start() { networkNode.addMessageListener(this); peerManager.addListener(this); - peerManager.setAllowDisconnectSeedNodes(true); } @SuppressWarnings("Duplicates") diff --git a/core/src/main/java/bisq/core/dao/node/lite/network/LiteNodeNetworkService.java b/core/src/main/java/bisq/core/dao/node/lite/network/LiteNodeNetworkService.java index f13d99aa8b..189afea334 100644 --- a/core/src/main/java/bisq/core/dao/node/lite/network/LiteNodeNetworkService.java +++ b/core/src/main/java/bisq/core/dao/node/lite/network/LiteNodeNetworkService.java @@ -283,9 +283,6 @@ public class LiteNodeNetworkService implements MessageListener, ConnectionListen return; } - // In case we would have had an earlier request and had set allowDisconnectSeedNodes to true we un-do that - // if we get a repeated request. - peerManager.setAllowDisconnectSeedNodes(false); RequestBlocksHandler requestBlocksHandler = new RequestBlocksHandler(networkNode, peerManager, peersNodeAddress, @@ -304,9 +301,6 @@ public class LiteNodeNetworkService implements MessageListener, ConnectionListen listeners.forEach(listener -> listener.onRequestedBlocksReceived(getBlocksResponse, () -> { - // After we received the blocks we allow to disconnect seed nodes. - // We delay 20 seconds to allow multiple requests to finish. - UserThread.runAfter(() -> peerManager.setAllowDisconnectSeedNodes(true), 20); })); } else { log.warn("We got a response which is already obsolete because we received a " + @@ -325,9 +319,6 @@ public class LiteNodeNetworkService implements MessageListener, ConnectionListen listeners.forEach(listener -> listener.onFault(errorMessage, connection)); - // We allow now to disconnect from that seed. - peerManager.setAllowDisconnectSeedNodes(true); - tryWithNewSeedNode(startBlockHeight); } }); diff --git a/p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java b/p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java index 43d6ccdf83..e7c33e10fd 100644 --- a/p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java +++ b/p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java @@ -57,7 +57,6 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import lombok.Getter; -import lombok.Setter; import lombok.extern.slf4j.Slf4j; import javax.annotation.Nullable; @@ -124,14 +123,11 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost @Getter private int minConnections; - private int disconnectFromSeedNode; private int outBoundPeerTrigger; private int initialDataExchangeTrigger; private int maxConnectionsAbsolute; @Getter private int peakNumConnections; - @Setter - private boolean allowDisconnectSeedNodes; @Getter private int numAllConnectionsLostEvents; @@ -531,8 +527,7 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost } log.info("We have exceeded initialDataExchangeTrigger of {} " + - "Lets try to remove any connection which is not " + - "of type DIRECT_MSG_PEER or INITIAL_DATA_REQUEST.", initialDataExchangeTrigger); + "Lets try to remove the oldest INITIAL_DATA_EXCHANGE connection.", initialDataExchangeTrigger); candidates = allConnections.stream() .filter(e -> e.getConnectionState().getPeerType() == PeerType.INITIAL_DATA_EXCHANGE) .sorted(Comparator.comparingLong(o -> o.getConnectionState().getLastInitialDataMsgTimeStamp())) @@ -745,7 +740,6 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost private void setConnectionLimits(int maxConnections) { this.maxConnections = maxConnections; // app node 12; seedNode 20 minConnections = Math.max(1, (int) Math.round(maxConnections * 0.7)); // app node 8; seedNode 14 - disconnectFromSeedNode = maxConnections; // app node 12; seedNode 20 outBoundPeerTrigger = Math.max(4, (int) Math.round(maxConnections * 1.3)); // app node 16; seedNode 26 initialDataExchangeTrigger = Math.max(8, (int) Math.round(maxConnections * 1.7)); // app node 20; seedNode 34 maxConnectionsAbsolute = Math.max(12, (int) Math.round(maxConnections * 2.5)); // app node 30; seedNode 50 diff --git a/p2p/src/test/java/bisq/network/p2p/peers/PeerManagerTest.java b/p2p/src/test/java/bisq/network/p2p/peers/PeerManagerTest.java index 0e1875ee77..6f04afcc57 100644 --- a/p2p/src/test/java/bisq/network/p2p/peers/PeerManagerTest.java +++ b/p2p/src/test/java/bisq/network/p2p/peers/PeerManagerTest.java @@ -154,12 +154,12 @@ public class PeerManagerTest { @Test public void testCheckMaxConnectionsNonDirectLimitExceeded() throws InterruptedException { for (int i = 0; i < maxConnectionsNonDirect + 1; i++) { - node.addOutboundConnection(PeerType.PEER); + node.addOutboundConnection(PeerType.INITIAL_DATA_EXCHANGE); } assertEquals(maxConnectionsNonDirect + 1, node.getNetworkNode().getAllConnections().size()); List sortedPeerConnections = node.getNetworkNode().getAllConnections().stream() - .filter(e -> e.getConnectionState().getPeerType() != PeerType.DIRECT_MSG_PEER && - e.getConnectionState().getPeerType() != PeerType.INITIAL_DATA_EXCHANGE) + .filter(e -> e.getConnectionState().getPeerType() != PeerType.PEER) + .filter(e -> e.getConnectionState().getPeerType() == PeerType.INITIAL_DATA_EXCHANGE) .sorted(Comparator.comparingLong(o -> o.getStatistic().getLastActivityTimestamp())) .collect(Collectors.toList()); Connection oldestConnection = sortedPeerConnections.remove(0);