From 26c1793d857feb8cdc00da9492118ba40a0a056c Mon Sep 17 00:00:00 2001 From: CalDescent Date: Mon, 10 May 2021 09:00:42 +0100 Subject: [PATCH] Added "allowConnectionsWithOlderPeerVersions" setting (default: true) This controls whether to allow connections with peers below minPeerVersion. If true, we won't sync with them but they can still sync with us, and will show in the peers list. This is the default, which allows older nodes to continue functioning, but prevents them from interfering with the sync behaviour of updated nodes. If false, sync will be blocked both ways, and they will not appear in the peers list at all. --- src/main/java/org/qortal/network/Handshake.java | 9 +++++++++ src/main/java/org/qortal/settings/Settings.java | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/org/qortal/network/Handshake.java b/src/main/java/org/qortal/network/Handshake.java index ed6d02db..8bee63a2 100644 --- a/src/main/java/org/qortal/network/Handshake.java +++ b/src/main/java/org/qortal/network/Handshake.java @@ -71,6 +71,15 @@ public enum Handshake { peer.setPeersConnectionTimestamp(peersConnectionTimestamp); peer.setPeersVersion(versionString, version); + if (Settings.getInstance().getAllowConnectionsWithOlderPeerVersions() == false) { + // Ensure the peer is running at least the minimum version allowed for connections + final String minPeerVersion = Settings.getInstance().getMinPeerVersion(); + if (peer.isAtLeastVersion(minPeerVersion) == false) { + LOGGER.info(String.format("Ignoring peer %s because it is on an old version (%s)", peer, versionString)); + return null; + } + } + return CHALLENGE; } diff --git a/src/main/java/org/qortal/settings/Settings.java b/src/main/java/org/qortal/settings/Settings.java index f94db927..164223c9 100644 --- a/src/main/java/org/qortal/settings/Settings.java +++ b/src/main/java/org/qortal/settings/Settings.java @@ -124,8 +124,13 @@ public class Settings { private int networkPoWComputePoolSize = 2; /** Maximum number of retry attempts if a peer fails to respond with the requested data */ private int maxRetries = 2; + /** Minimum peer version number required in order to sync with them */ private String minPeerVersion = "1.5.0"; + /** Whether to allow connections with peers below minPeerVersion + * If true, we won't sync with them but they can still sync with us, and will show in the peers list + * If false, sync will be blocked both ways, and they will not appear in the peers list */ + private boolean allowConnectionsWithOlderPeerVersions = true; // Which blockchains this node is running private String blockchainConfig = null; // use default from resources @@ -416,6 +421,8 @@ public class Settings { public String getMinPeerVersion() { return this.minPeerVersion; } + public boolean getAllowConnectionsWithOlderPeerVersions() { return this.allowConnectionsWithOlderPeerVersions; } + public String getBlockchainConfig() { return this.blockchainConfig; }