mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 01:41:11 +01:00
Behaviour change: Remove setAllowDisconnectSeedNodes method
We handle it in ConnectionState by counting requests and responses and adding a timer
This commit is contained in:
parent
7414df0951
commit
769a78fe52
@ -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")
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
@ -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
|
||||
|
@ -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<Connection> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user