lichao
2021-06-29 6c07fe29a5185835f28059f627a1d30e462da28b
src/proto.cpp
@@ -17,6 +17,10 @@
 */
#include "proto.h"
#include <boost/uuid/uuid_generators.hpp>
#include <chrono>
namespace
{
std::string RandId()
{
@@ -24,18 +28,27 @@
   return std::string((char *) &id, sizeof(id));
}
BHMsgHead InitMsgHead(const MsgType type, const std::string &proc_id)
} // namespace
std::string NewMsgId() { return RandId(); }
BHMsgHead InitMsgHead(const MsgType type, const std::string &proc_id, const uint64_t ssn_id)
{
   return InitMsgHead(type, proc_id, RandId());
   return InitMsgHead(type, proc_id, ssn_id, RandId());
}
BHMsgHead InitMsgHead(const MsgType type, const std::string &proc_id, const std::string &msgid)
BHMsgHead InitMsgHead(const MsgType type, const std::string &proc_id, const uint64_t ssn_id, const std::string &msgid)
{
   BHMsgHead msg;
   msg.set_msg_id(msgid);
   msg.set_type(type);
   msg.set_proc_id(proc_id);
   time_t tm = 0;
   msg.set_timestamp(time(&tm));
   msg.set_ssn_id(ssn_id);
   msg.set_timestamp(NowSec());
   return msg;
}
bool IsMsgExpired(const BHMsgHead &head)
{
   return NowSec() > head.timestamp() + 10;
}