mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Disconnect nodes which do not have the mandatory capability
This commit is contained in:
parent
ab4aa64424
commit
55092edb6c
@ -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) {
|
||||
@ -71,7 +75,7 @@ public class Capabilities {
|
||||
}
|
||||
|
||||
public void addAll(Capabilities capabilities) {
|
||||
if(capabilities != null)
|
||||
if (capabilities != null)
|
||||
this.capabilities.addAll(capabilities.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());
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user