From 86177456cf44a73fb3e38b703eb2895a80ba9845 Mon Sep 17 00:00:00 2001 From: cyjseagull Date: Sat, 14 Sep 2024 13:47:51 +0800 Subject: [PATCH] fix uint16_t not initilized caused bug --- cpp/ppc-framework/protocol/Message.h | 8 +++++--- cpp/ppc-framework/protocol/MessagePayload.h | 7 ++++--- cpp/wedpr-protocol/protocol/src/v1/MessageHeaderImpl.cpp | 8 ++++---- cpp/wedpr-transport/ppc-front/ppc-front/FrontImpl.cpp | 5 +++-- .../ppc-gateway/gateway/router/LocalRouter.cpp | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/cpp/ppc-framework/protocol/Message.h b/cpp/ppc-framework/protocol/Message.h index 2988fc4b..291b1d2e 100644 --- a/cpp/ppc-framework/protocol/Message.h +++ b/cpp/ppc-framework/protocol/Message.h @@ -159,6 +159,7 @@ class MessageHeader virtual bool hasOptionalField() const = 0; protected: + // Note: must init here to 0, otherwise, it will be unexpected value in some other platform // the msg version, used to support compatibility uint8_t m_version = 0; // the traceID @@ -168,11 +169,11 @@ class MessageHeader // the dstGwNode std::string m_dstGwNode; // the packetType - uint16_t m_packetType; + uint16_t m_packetType = 0; // the ttl int16_t m_ttl = 0; // the ext(contains the router policy and response flag) - uint16_t m_ext; + uint16_t m_ext = 0; //// the optional field(used to route between components and nodes) MessageOptionalHeader::Ptr m_optionalField; uint16_t mutable m_length; @@ -324,7 +325,8 @@ inline std::string printWsMessage(bcos::boostssl::MessageFace::Ptr const& _msg) } std::ostringstream stringstream; stringstream << LOG_KV("rsp", _msg->isRespPacket()) << LOG_KV("traceID", _msg->seq()) - << LOG_KV("packetType", _msg->packetType()) << LOG_KV("length", _msg->length()); + << LOG_KV("packetType", _msg->packetType()) << LOG_KV("length", _msg->length()) + << LOG_KV("ext", _msg->ext()); return stringstream.str(); } diff --git a/cpp/ppc-framework/protocol/MessagePayload.h b/cpp/ppc-framework/protocol/MessagePayload.h index a8e6a57c..0a612a97 100644 --- a/cpp/ppc-framework/protocol/MessagePayload.h +++ b/cpp/ppc-framework/protocol/MessagePayload.h @@ -69,13 +69,14 @@ class MessagePayload protected: // the front payload version, used to support compatibility - uint8_t m_version; + // Note: must init here to 0, otherwise, it will be unexpected value in some other platform + uint8_t m_version = 0; // the seq - uint16_t m_seq; + uint16_t m_seq = 0; // the traceID std::string m_traceID; bcos::bytes m_data; - uint16_t m_ext; + uint16_t m_ext = 0; int64_t mutable m_length; }; diff --git a/cpp/wedpr-protocol/protocol/src/v1/MessageHeaderImpl.cpp b/cpp/wedpr-protocol/protocol/src/v1/MessageHeaderImpl.cpp index 6690dd07..8dc17520 100644 --- a/cpp/wedpr-protocol/protocol/src/v1/MessageHeaderImpl.cpp +++ b/cpp/wedpr-protocol/protocol/src/v1/MessageHeaderImpl.cpp @@ -167,13 +167,13 @@ int64_t MessageHeaderImpl::decode(bcos::bytesConstRef data) uint16_t MessageHeaderImpl::routeType() const { - if (m_ext & (uint16_t)ppc::gateway::GatewayMsgExtFlag::RouteByComponent) + if (m_ext & (uint16_t)ppc::gateway::GatewayMsgExtFlag::RouteByNodeID) { - return (uint16_t)RouteType::ROUTE_THROUGH_COMPONENT; + return (uint16_t)RouteType::ROUTE_THROUGH_NODEID; } - if (m_ext & (uint16_t)ppc::gateway::GatewayMsgExtFlag::RouteByAgency) + if (m_ext & (uint16_t)ppc::gateway::GatewayMsgExtFlag::RouteByComponent) { - return (uint16_t)RouteType::ROUTE_THROUGH_AGENCY; + return (uint16_t)RouteType::ROUTE_THROUGH_COMPONENT; } if (m_ext & (uint16_t)ppc::gateway::GatewayMsgExtFlag::RouteByAgency) { diff --git a/cpp/wedpr-transport/ppc-front/ppc-front/FrontImpl.cpp b/cpp/wedpr-transport/ppc-front/ppc-front/FrontImpl.cpp index 58aae243..ca774092 100644 --- a/cpp/wedpr-transport/ppc-front/ppc-front/FrontImpl.cpp +++ b/cpp/wedpr-transport/ppc-front/ppc-front/FrontImpl.cpp @@ -224,8 +224,9 @@ void FrontImpl::asyncSendMessageToGateway(bool responsePacket, MessagePayload::P routeInfo->setSrcNode(m_nodeID); auto payload = std::make_shared(); frontMessage->encode(*payload); - FRONT_LOG(TRACE) << LOG_DESC("asyncSendMessageToGateway") << LOG_KV("traceID", traceID) - << LOG_KV("route", printOptionalField(routeInfo)); + FRONT_LOG(TRACE) << LOG_DESC("asyncSendMessageToGateway") << LOG_KV("routeType", routeType) + << LOG_KV("traceID", traceID) << printOptionalField(routeInfo) + << LOG_KV("payloadSize", frontMessage->length()); m_gatewayClient->asyncSendMessage( routeType, routeInfo, traceID, std::move(*payload), timeout, callback); } diff --git a/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/LocalRouter.cpp b/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/LocalRouter.cpp index 513f6b5f..9b910408 100644 --- a/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/LocalRouter.cpp +++ b/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/LocalRouter.cpp @@ -98,7 +98,7 @@ bool LocalRouter::dispatcherMessage(Message::Ptr const& msg, ReceiveMsgFunc call return; } LOCAL_ROUTER_LOG(WARNING) << LOG_DESC("dispatcherMessage to front failed") - << LOG_KV("code", error->errorMessage()) + << LOG_KV("code", error->errorCode()) << LOG_KV("msg", error->errorMessage()); }); }