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

Fix MRP to not happen over BTP again. #9792

Merged
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
21 changes: 7 additions & 14 deletions src/messaging/ExchangeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp
mFlags.Clear(Flags::kFlagWillSendMessage);
}

Transport::PeerConnectionState * state = nullptr;

VerifyOrReturnError(mExchangeMgr != nullptr, CHIP_ERROR_INTERNAL);
VerifyOrReturnError(mSecureSession.HasValue(), CHIP_ERROR_CONNECTION_ABORTED);

Expand All @@ -102,18 +100,13 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp
// an error arising below. at the end, we have to close it.
ExchangeHandle ref(*this);

bool reliableTransmissionRequested = true;

state = mExchangeMgr->GetSessionMgr()->GetPeerConnectionState(mSecureSession.Value());
// If sending via UDP and NoAutoRequestAck send flag is not specificed, request reliable transmission.
if (state != nullptr && state->GetPeerAddress().GetTransportType() != Transport::Type::kUdp)
{
reliableTransmissionRequested = false;
}
else
{
reliableTransmissionRequested = !sendFlags.Has(SendMessageFlags::kNoAutoRequestAck);
}
// If sending via UDP and NoAutoRequestAck send flag is not specificed,
// request reliable transmission.
const Transport::PeerAddress * peerAddress = GetSecureSession().GetPeerAddress(mExchangeMgr->GetSessionMgr());
// Treat unknown peer address as "not UDP", because we have no idea whether
// it's safe to do MRP there.
bool isUDPTransport = peerAddress && peerAddress->GetTransportType() == Transport::Type::kUdp;
bool reliableTransmissionRequested = isUDPTransport && !sendFlags.Has(SendMessageFlags::kNoAutoRequestAck);

// If a response message is expected...
if (sendFlags.Has(SendMessageFlags::kExpectResponse))
Expand Down
2 changes: 2 additions & 0 deletions src/transport/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ static_library("transport") {
"SecureSession.h",
"SecureSessionMgr.cpp",
"SecureSessionMgr.h",
"SessionHandle.cpp",
"SessionHandle.h",
"TransportMgr.h",
"TransportMgrBase.cpp",
"TransportMgrBase.h",
Expand Down
42 changes: 42 additions & 0 deletions src/transport/SessionHandle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <transport/PeerConnectionState.h>
#include <transport/SecureSessionMgr.h>
#include <transport/SessionHandle.h>

namespace chip {

using namespace Transport;

const PeerAddress * SessionHandle::GetPeerAddress(SecureSessionMgr * ssm) const
{
if (IsSecure())
{
PeerConnectionState * state = ssm->GetPeerConnectionState(*this);
if (state == nullptr)
{
return nullptr;
}

return &state->GetPeerAddress();
}

return &GetUnauthenticatedSession()->GetPeerAddress();
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
}

} // namespace chip
12 changes: 11 additions & 1 deletion src/transport/SessionHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@

#pragma once

#include <app/util/basic-types.h>
#include <lib/core/NodeId.h>
#include <lib/core/Optional.h>
#include <transport/FabricTable.h>
#include <transport/UnauthenticatedSessionTable.h>
#include <transport/raw/PeerAddress.h>

namespace chip {

Expand Down Expand Up @@ -67,7 +72,12 @@ class SessionHandle
const Optional<uint16_t> & GetPeerSessionId() const { return mPeerSessionId; }
const Optional<uint16_t> & GetLocalSessionId() const { return mLocalSessionId; }

Transport::UnauthenticatedSessionHandle GetUnauthenticatedSession() { return mUnauthenticatedSessionHandle.Value(); }
// Return the peer address for this session. May return null if the peer
// address is not known. This can happen for secure sessions that have been
// torn down, at the very least.
const Transport::PeerAddress * GetPeerAddress(SecureSessionMgr * ssm) const;

Transport::UnauthenticatedSessionHandle GetUnauthenticatedSession() const { return mUnauthenticatedSessionHandle.Value(); }

private:
friend class SecureSessionMgr;
Expand Down
2 changes: 2 additions & 0 deletions src/transport/UnauthenticatedSessionTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <lib/support/ReferenceCountedHandle.h>
#include <lib/support/logging/CHIPLogging.h>
#include <system/TimeSource.h>
#include <transport/MessageCounter.h>
#include <transport/PeerMessageCounter.h>
#include <transport/raw/PeerAddress.h>

namespace chip {
Expand Down