From 0647188b866c62073fab9d0f72258a26b20e10c7 Mon Sep 17 00:00:00 2001 From: Zang MingJie Date: Thu, 21 Apr 2022 11:28:57 +0800 Subject: [PATCH] Remove address argument on ExchangeManager::OnMessageReceived --- src/messaging/ExchangeContext.cpp | 6 ++---- src/messaging/ExchangeContext.h | 4 +--- src/messaging/ExchangeMessageDispatch.cpp | 3 +-- src/messaging/ExchangeMessageDispatch.h | 3 +-- src/messaging/ExchangeMgr.cpp | 8 ++++---- src/messaging/ExchangeMgr.h | 4 +--- src/transport/SessionManager.cpp | 6 +++--- src/transport/SessionMessageDelegate.h | 5 ++--- src/transport/tests/TestSessionManager.cpp | 3 +-- 9 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/messaging/ExchangeContext.cpp b/src/messaging/ExchangeContext.cpp index a89bf15ed2bc2c..3af9f00450ded1 100644 --- a/src/messaging/ExchangeContext.cpp +++ b/src/messaging/ExchangeContext.cpp @@ -415,8 +415,7 @@ void ExchangeContext::NotifyResponseTimeout() MessageHandled(); } -CHIP_ERROR ExchangeContext::HandleMessage(uint32_t messageCounter, const PayloadHeader & payloadHeader, - const Transport::PeerAddress & peerAddress, MessageFlags msgFlags, +CHIP_ERROR ExchangeContext::HandleMessage(uint32_t messageCounter, const PayloadHeader & payloadHeader, MessageFlags msgFlags, PacketBufferHandle && msgBuf) { // We hold a reference to the ExchangeContext here to @@ -457,8 +456,7 @@ CHIP_ERROR ExchangeContext::HandleMessage(uint32_t messageCounter, const Payload MessageHandled(); }); - ReturnErrorOnFailure( - mDispatch.OnMessageReceived(messageCounter, payloadHeader, peerAddress, msgFlags, GetReliableMessageContext())); + ReturnErrorOnFailure(mDispatch.OnMessageReceived(messageCounter, payloadHeader, msgFlags, GetReliableMessageContext())); if (IsAckPending() && !mDelegate) { diff --git a/src/messaging/ExchangeContext.h b/src/messaging/ExchangeContext.h index 4e616194584037..94a75200f3500b 100644 --- a/src/messaging/ExchangeContext.h +++ b/src/messaging/ExchangeContext.h @@ -135,7 +135,6 @@ class DLL_EXPORT ExchangeContext : public ReliableMessageContext, * * @param[in] messageCounter The message counter of the packet. * @param[in] payloadHeader A reference to the PayloadHeader object. - * @param[in] peerAddress The address of the sender * @param[in] msgFlags The message flags corresponding to the received message * @param[in] msgBuf A handle to the packet buffer holding the CHIP message. * @@ -144,8 +143,7 @@ class DLL_EXPORT ExchangeContext : public ReliableMessageContext, * @retval #CHIP_NO_ERROR if the CHIP layer successfully delivered the message up to the * protocol layer. */ - CHIP_ERROR HandleMessage(uint32_t messageCounter, const PayloadHeader & payloadHeader, - const Transport::PeerAddress & peerAddress, MessageFlags msgFlags, + CHIP_ERROR HandleMessage(uint32_t messageCounter, const PayloadHeader & payloadHeader, MessageFlags msgFlags, System::PacketBufferHandle && msgBuf); ExchangeDelegate * GetDelegate() const { return mDelegate; } diff --git a/src/messaging/ExchangeMessageDispatch.cpp b/src/messaging/ExchangeMessageDispatch.cpp index 7ca2e5b59901c9..3e318a72d247af 100644 --- a/src/messaging/ExchangeMessageDispatch.cpp +++ b/src/messaging/ExchangeMessageDispatch.cpp @@ -114,8 +114,7 @@ CHIP_ERROR ExchangeMessageDispatch::SendMessage(SessionManager * sessionManager, } CHIP_ERROR ExchangeMessageDispatch::OnMessageReceived(uint32_t messageCounter, const PayloadHeader & payloadHeader, - const Transport::PeerAddress & peerAddress, MessageFlags msgFlags, - ReliableMessageContext * reliableMessageContext) + MessageFlags msgFlags, ReliableMessageContext * reliableMessageContext) { ReturnErrorCodeIf(!MessagePermitted(payloadHeader.GetProtocolID().GetProtocolId(), payloadHeader.GetMessageType()), CHIP_ERROR_INVALID_ARGUMENT); diff --git a/src/messaging/ExchangeMessageDispatch.h b/src/messaging/ExchangeMessageDispatch.h index 464387f4e05ff9..6c6fefb24fcdeb 100644 --- a/src/messaging/ExchangeMessageDispatch.h +++ b/src/messaging/ExchangeMessageDispatch.h @@ -42,8 +42,7 @@ class ExchangeMessageDispatch CHIP_ERROR SendMessage(SessionManager * sessionManager, const SessionHandle & session, uint16_t exchangeId, bool isInitiator, ReliableMessageContext * reliableMessageContext, bool isReliableTransmission, Protocols::Id protocol, uint8_t type, System::PacketBufferHandle && message); - CHIP_ERROR OnMessageReceived(uint32_t messageCounter, const PayloadHeader & payloadHeader, - const Transport::PeerAddress & peerAddress, MessageFlags msgFlags, + CHIP_ERROR OnMessageReceived(uint32_t messageCounter, const PayloadHeader & payloadHeader, MessageFlags msgFlags, ReliableMessageContext * reliableMessageContext); protected: diff --git a/src/messaging/ExchangeMgr.cpp b/src/messaging/ExchangeMgr.cpp index adfc214db89a46..c59f2e7932e060 100644 --- a/src/messaging/ExchangeMgr.cpp +++ b/src/messaging/ExchangeMgr.cpp @@ -182,8 +182,8 @@ CHIP_ERROR ExchangeManager::UnregisterUMH(Protocols::Id protocolId, int16_t msgT } void ExchangeManager::OnMessageReceived(const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - const SessionHandle & session, const Transport::PeerAddress & source, - DuplicateMessage isDuplicate, System::PacketBufferHandle && msgBuf) + const SessionHandle & session, DuplicateMessage isDuplicate, + System::PacketBufferHandle && msgBuf) { UnsolicitedMessageHandlerSlot * matchingUMH = nullptr; @@ -219,7 +219,7 @@ void ExchangeManager::OnMessageReceived(const PacketHeader & packetHeader, const ChipLogValueExchange(ec), ec->GetDelegate()); // Matched ExchangeContext; send to message handler. - ec->HandleMessage(packetHeader.GetMessageCounter(), payloadHeader, source, msgFlags, std::move(msgBuf)); + ec->HandleMessage(packetHeader.GetMessageCounter(), payloadHeader, msgFlags, std::move(msgBuf)); found = true; return Loop::Break; } @@ -317,7 +317,7 @@ void ExchangeManager::OnMessageReceived(const PacketHeader & packetHeader, const return; } - CHIP_ERROR err = ec->HandleMessage(packetHeader.GetMessageCounter(), payloadHeader, source, msgFlags, std::move(msgBuf)); + CHIP_ERROR err = ec->HandleMessage(packetHeader.GetMessageCounter(), payloadHeader, msgFlags, std::move(msgBuf)); if (err != CHIP_NO_ERROR) { // Using same error message for all errors to reduce code size. diff --git a/src/messaging/ExchangeMgr.h b/src/messaging/ExchangeMgr.h index a52e24024f468a..7d5bbcad126d1c 100644 --- a/src/messaging/ExchangeMgr.h +++ b/src/messaging/ExchangeMgr.h @@ -33,7 +33,6 @@ #include #include #include -#include namespace chip { namespace Messaging { @@ -240,8 +239,7 @@ class DLL_EXPORT ExchangeManager : public SessionMessageDelegate CHIP_ERROR UnregisterUMH(Protocols::Id protocolId, int16_t msgType); void OnMessageReceived(const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, const SessionHandle & session, - const Transport::PeerAddress & source, DuplicateMessage isDuplicate, - System::PacketBufferHandle && msgBuf) override; + DuplicateMessage isDuplicate, System::PacketBufferHandle && msgBuf) override; }; } // namespace Messaging diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp index 5acaccf3cc8dd4..e9727af26b8aa3 100644 --- a/src/transport/SessionManager.cpp +++ b/src/transport/SessionManager.cpp @@ -548,7 +548,7 @@ void SessionManager::UnauthenticatedMessageDispatch(const PacketHeader & packetH if (mCB != nullptr) { CHIP_TRACE_MESSAGE_RECEIVED(payloadHeader, packetHeader, unsecuredSession, peerAddress, msg->Start(), msg->TotalLength()); - mCB->OnMessageReceived(packetHeader, payloadHeader, session, peerAddress, isDuplicate, std::move(msg)); + mCB->OnMessageReceived(packetHeader, payloadHeader, session, isDuplicate, std::move(msg)); } } @@ -631,7 +631,7 @@ void SessionManager::SecureUnicastMessageDispatch(const PacketHeader & packetHea if (mCB != nullptr) { CHIP_TRACE_MESSAGE_RECEIVED(payloadHeader, packetHeader, secureSession, peerAddress, msg->Start(), msg->TotalLength()); - mCB->OnMessageReceived(packetHeader, payloadHeader, session.Value(), peerAddress, isDuplicate, std::move(msg)); + mCB->OnMessageReceived(packetHeader, payloadHeader, session.Value(), isDuplicate, std::move(msg)); } } @@ -763,7 +763,7 @@ void SessionManager::SecureGroupMessageDispatch(const PacketHeader & packetHeade Transport::IncomingGroupSession groupSession(groupContext.group_id, groupContext.fabric_index, packetHeader.GetSourceNodeId().Value()); CHIP_TRACE_MESSAGE_RECEIVED(payloadHeader, packetHeader, &groupSession, peerAddress, msg->Start(), msg->TotalLength()); - mCB->OnMessageReceived(packetHeader, payloadHeader, SessionHandle(groupSession), peerAddress, + mCB->OnMessageReceived(packetHeader, payloadHeader, SessionHandle(groupSession), SessionMessageDelegate::DuplicateMessage::No, std::move(msg)); } } diff --git a/src/transport/SessionMessageDelegate.h b/src/transport/SessionMessageDelegate.h index d4aa40ef9d2a8c..dee29514dfc020 100644 --- a/src/transport/SessionMessageDelegate.h +++ b/src/transport/SessionMessageDelegate.h @@ -46,13 +46,12 @@ class DLL_EXPORT SessionMessageDelegate * @param packetHeader The message header * @param payloadHeader The payload header * @param session The handle to the secure session - * @param source The sender's address * @param isDuplicate The message is a duplicate of previously received message * @param msgBuf The received message */ virtual void OnMessageReceived(const PacketHeader & packetHeader, const PayloadHeader & payloadHeader, - const SessionHandle & session, const Transport::PeerAddress & source, - DuplicateMessage isDuplicate, System::PacketBufferHandle && msgBuf) = 0; + const SessionHandle & session, DuplicateMessage isDuplicate, + System::PacketBufferHandle && msgBuf) = 0; }; } // namespace chip diff --git a/src/transport/tests/TestSessionManager.cpp b/src/transport/tests/TestSessionManager.cpp index 9f5cb44ea0bd80..eeb73c75aa70bd 100644 --- a/src/transport/tests/TestSessionManager.cpp +++ b/src/transport/tests/TestSessionManager.cpp @@ -70,8 +70,7 @@ class TestSessMgrCallback : public SessionMessageDelegate { public: void OnMessageReceived(const PacketHeader & header, const PayloadHeader & payloadHeader, const SessionHandle & session, - const Transport::PeerAddress & source, DuplicateMessage isDuplicate, - System::PacketBufferHandle && msgBuf) override + DuplicateMessage isDuplicate, System::PacketBufferHandle && msgBuf) override { size_t data_len = msgBuf->DataLength();