Skip to content

Commit

Permalink
Merge pull request #3162 from chimp1984/fix-mandatory-capability-check
Browse files Browse the repository at this point in the history
Add missing check if capability is not empty before checking mandatory capabilities
  • Loading branch information
sqrrm authored Aug 29, 2019
2 parents 4e7cb04 + adac3bd commit 9a2dfda
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions common/src/main/java/bisq/common/app/Capabilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
import java.util.stream.Collectors;

import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;

/**
* hold a set of capabilities and offers appropriate comparison methods.
*
* @author Florian Reimair
*/
@EqualsAndHashCode
@Slf4j
public class Capabilities {

/**
Expand Down
Original file line number Diff line number Diff line change
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
8 changes: 5 additions & 3 deletions p2p/src/main/java/bisq/network/p2p/network/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -799,12 +799,14 @@ && 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.set(supportedCapabilities);

// 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;
}

capabilities.set(supportedCapabilities);
capabilitiesListeners.forEach(weakListener -> {
SupportedCapabilitiesListener supportedCapabilitiesListener = weakListener.get();
if (supportedCapabilitiesListener != null) {
Expand Down

0 comments on commit 9a2dfda

Please sign in to comment.