Disconnect nodes which do not have the mandatory capability

This commit is contained in:
chimp1984 2019-08-28 21:06:17 +02:00
parent ab4aa64424
commit 55092edb6c
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3
2 changed files with 14 additions and 1 deletions

View File

@ -39,6 +39,10 @@ public class Capabilities {
*/
public static final Capabilities app = new Capabilities();
// Defines which most recent capability any node need to support.
// This helps to clean network from very old inactive but still running nodes.
private static final Capability mandatoryCapability = Capability.DAO_STATE;
protected final Set<Capability> capabilities = new HashSet<>();
public Capabilities(Capability... capabilities) {
@ -111,6 +115,10 @@ public class Capabilities {
.collect(Collectors.toSet()));
}
public static boolean hasMandatoryCapability(Capabilities capabilities) {
return capabilities.capabilities.stream().anyMatch(c -> c == mandatoryCapability);
}
@Override
public String toString() {
return Arrays.toString(Capabilities.toIntList(this).toArray());

View File

@ -799,6 +799,11 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
Capabilities supportedCapabilities = ((SupportedCapabilitiesMessage) networkEnvelope).getSupportedCapabilities();
if (supportedCapabilities != null) {
if (!capabilities.equals(supportedCapabilities)) {
if (!Capabilities.hasMandatoryCapability(capabilities)) {
shutDown(CloseConnectionReason.RULE_VIOLATION);
return;
}
capabilities.set(supportedCapabilities);
capabilitiesListeners.forEach(weakListener -> {
SupportedCapabilitiesListener supportedCapabilitiesListener = weakListener.get();