Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing check if capability is not empty before checking mandatory capabilities #3162

Merged
merged 3 commits into from Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/src/main/java/bisq/common/app/Capabilities.java
Expand Up @@ -118,7 +118,7 @@ public static Capabilities fromIntList(List<Integer> capabilities) {
}

public static boolean hasMandatoryCapability(Capabilities capabilities) {
return capabilities.isEmpty() || capabilities.capabilities.stream().anyMatch(c -> c == mandatoryCapability);
return capabilities.capabilities.stream().anyMatch(c -> c == mandatoryCapability);
}

@Override
Expand Down
Expand Up @@ -45,7 +45,8 @@ public enum CloseConnectionReason {
// illegal requests
RULE_VIOLATION(true, false),
PEER_BANNED(true, false),
INVALID_CLASS_RECEIVED(false, false);
INVALID_CLASS_RECEIVED(false, false),
MANDATORY_CAPABILITIES_NOT_SUPPORTED(false, false);

public final boolean sendCloseMessage;
public final boolean isIntended;
Expand Down
5 changes: 3 additions & 2 deletions p2p/src/main/java/bisq/network/p2p/network/Connection.java
Expand Up @@ -799,8 +799,9 @@ && reportInvalidRequest(RuleViolation.WRONG_NETWORK_ID)) {
Capabilities supportedCapabilities = ((SupportedCapabilitiesMessage) networkEnvelope).getSupportedCapabilities();
if (supportedCapabilities != null) {
if (!capabilities.equals(supportedCapabilities)) {
if (!Capabilities.hasMandatoryCapability(capabilities)) {
shutDown(CloseConnectionReason.RULE_VIOLATION);
// Capabilities can be empty. We only check for mandatory if we get some capabilities.
if (!capabilities.isEmpty() && !Capabilities.hasMandatoryCapability(capabilities)) {
shutDown(CloseConnectionReason.MANDATORY_CAPABILITIES_NOT_SUPPORTED);
return;
}

Expand Down