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

Disable CRMP if we send/receive messages not over UDP transport #6407

Merged
merged 2 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/messaging/ExchangeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,17 @@ CHIP_ERROR ExchangeContext::SendMessageImpl(Protocols::Id protocolId, uint8_t ms
// an error arising below. at the end, we have to close it.
Retain();

bool reliableTransmissionRequested = !sendFlags.Has(SendMessageFlags::kNoAutoRequestAck);
bool reliableTransmissionRequested = true;

// If sending via UDP and NoAutoRequestAck send flag is not specificed, request reliable transmission.
yufengwangca marked this conversation as resolved.
Show resolved Hide resolved
if (state && state->GetPeerAddress().GetTransportType() != Transport::Type::kUdp)
{
reliableTransmissionRequested = false;
}
else
{
reliableTransmissionRequested = !sendFlags.Has(SendMessageFlags::kNoAutoRequestAck);
}

ExchangeMessageDispatch * dispatch = GetMessageDispatch();
ApplicationExchangeDispatch defaultDispatch;
Expand Down
4 changes: 2 additions & 2 deletions src/messaging/ExchangeMessageDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ CHIP_ERROR ExchangeMessageDispatch::SendMessage(SecureSessionHandle session, uin
#endif
}

if (!IsTransportReliable() && reliableMessageContext->AutoRequestAck() && mReliableMessageMgr != nullptr &&
if (IsReliableTransmissionAllowed() && reliableMessageContext->AutoRequestAck() && mReliableMessageMgr != nullptr &&
isReliableTransmission)
{
payloadHeader.SetNeedsAck(true);
Expand Down Expand Up @@ -105,7 +105,7 @@ CHIP_ERROR ExchangeMessageDispatch::OnMessageReceived(const PayloadHeader & payl
ReturnErrorCodeIf(!MessagePermitted(payloadHeader.GetProtocolID().GetProtocolId(), payloadHeader.GetMessageType()),
CHIP_ERROR_INVALID_ARGUMENT);

if (!IsTransportReliable())
if (IsReliableTransmissionAllowed())
{
if (payloadHeader.IsAckMsg() && payloadHeader.GetAckId().HasValue())
{
Expand Down
2 changes: 1 addition & 1 deletion src/messaging/ExchangeMessageDispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ExchangeMessageDispatch
virtual CHIP_ERROR SendMessageImpl(SecureSessionHandle session, PayloadHeader & payloadHeader,
System::PacketBufferHandle && message, EncryptedPacketBufferHandle * retainedMessage) = 0;

virtual bool IsTransportReliable() { return false; }
virtual bool IsReliableTransmissionAllowed() { return true; }

private:
ReliableMessageMgr * mReliableMessageMgr = nullptr;
Expand Down
6 changes: 3 additions & 3 deletions src/messaging/ReliableMessageMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,11 @@ CHIP_ERROR ReliableMessageMgr::SendFromRetransTable(RetransTableEntry * entry)

VerifyOrReturnError(rc != nullptr, err);

const ExchangeMessageDispatch * transport = rc->GetExchangeContext()->GetMessageDispatch();
VerifyOrExit(transport != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
const ExchangeMessageDispatch * dispatcher = rc->GetExchangeContext()->GetMessageDispatch();
VerifyOrExit(dispatcher != nullptr, err = CHIP_ERROR_INCORRECT_STATE);

err =
transport->ResendMessage(rc->GetExchangeContext()->GetSecureSession(), std::move(entry->retainedBuf), &entry->retainedBuf);
dispatcher->ResendMessage(rc->GetExchangeContext()->GetSecureSession(), std::move(entry->retainedBuf), &entry->retainedBuf);
SuccessOrExit(err);

// Update the counters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class SessionEstablishmentExchangeDispatch : public Messaging::ExchangeMessageDi

bool MessagePermitted(uint16_t protocol, uint8_t type) override;

bool IsTransportReliable() override
bool IsReliableTransmissionAllowed() override
{
// If the underlying transport is not UDP.
return (mPeerAddress.GetTransportType() != Transport::Type::kUdp);
// If the underlying transport is UDP.
return (mPeerAddress.GetTransportType() == Transport::Type::kUdp);
}

private:
Expand Down