Handle Capabilities for encrypted messages (offer availibility request/response)

We did check in Connection for SupportedCapabilitiesMessage and if a message is of that type we set the capability.
But encrypted messages are wrapped in a PrefixedSealedAndSignedMessage so the payload is not visible as SupportedCapabilitiesMessage without decrypting it.
We need to call maybeHandleSupportedCapabilitiesMessage at decrypting the message. We do that only for direct messages not for mailbox messages as we likely do not have a connection open to the peer in that case (otherwise it would not be a mailbox msg) and as we don't have the connection available (we get is as AddDataMessage broadcast from an peer, so could could not apply it to the Connection of the sender.
This commit is contained in:
chimp1984 2020-10-16 11:07:36 -05:00
parent bac1e7b04c
commit 6b4d77fb1b
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3
2 changed files with 9 additions and 6 deletions

View File

@ -419,6 +419,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
connection.setPeerType(Connection.PeerType.DIRECT_MSG_PEER); connection.setPeerType(Connection.PeerType.DIRECT_MSG_PEER);
try { try {
DecryptedMessageWithPubKey decryptedMsg = encryptionService.decryptAndVerify(sealedMsg.getSealedAndSigned()); DecryptedMessageWithPubKey decryptedMsg = encryptionService.decryptAndVerify(sealedMsg.getSealedAndSigned());
connection.maybeHandleSupportedCapabilitiesMessage(decryptedMsg.getNetworkEnvelope());
connection.getPeersNodeAddressOptional().ifPresentOrElse(nodeAddress -> connection.getPeersNodeAddressOptional().ifPresentOrElse(nodeAddress ->
decryptedDirectMessageListeners.forEach(e -> e.onDirectMessage(decryptedMsg, nodeAddress)), decryptedDirectMessageListeners.forEach(e -> e.onDirectMessage(decryptedMsg, nodeAddress)),
() -> { () -> {

View File

@ -785,12 +785,10 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
return; return;
} }
if (networkEnvelope instanceof SupportedCapabilitiesMessage) { boolean causedShutDown = maybeHandleSupportedCapabilitiesMessage(networkEnvelope);
boolean causedShutDown = handleSupportedCapabilitiesMessage(networkEnvelope);
if (causedShutDown) { if (causedShutDown) {
return; return;
} }
}
if (networkEnvelope instanceof CloseConnectionMessage) { if (networkEnvelope instanceof CloseConnectionMessage) {
// If we get a CloseConnectionMessage we shut down // If we get a CloseConnectionMessage we shut down
@ -865,7 +863,11 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
} }
} }
protected boolean handleSupportedCapabilitiesMessage(NetworkEnvelope networkEnvelope) { public boolean maybeHandleSupportedCapabilitiesMessage(NetworkEnvelope networkEnvelope) {
if (!(networkEnvelope instanceof SupportedCapabilitiesMessage)) {
return false;
}
Capabilities supportedCapabilities = ((SupportedCapabilitiesMessage) networkEnvelope).getSupportedCapabilities(); Capabilities supportedCapabilities = ((SupportedCapabilitiesMessage) networkEnvelope).getSupportedCapabilities();
if (supportedCapabilities == null || supportedCapabilities.isEmpty()) { if (supportedCapabilities == null || supportedCapabilities.isEmpty()) {
return false; return false;