Skip to content

Commit

Permalink
fix uint16_t not initilized caused bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Sep 14, 2024
1 parent 09d4a3e commit 8617745
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
8 changes: 5 additions & 3 deletions cpp/ppc-framework/protocol/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
7 changes: 4 additions & 3 deletions cpp/ppc-framework/protocol/MessagePayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
8 changes: 4 additions & 4 deletions cpp/wedpr-protocol/protocol/src/v1/MessageHeaderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 3 additions & 2 deletions cpp/wedpr-transport/ppc-front/ppc-front/FrontImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ void FrontImpl::asyncSendMessageToGateway(bool responsePacket, MessagePayload::P
routeInfo->setSrcNode(m_nodeID);
auto payload = std::make_shared<bcos::bytes>();
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
}
Expand Down

0 comments on commit 8617745

Please sign in to comment.