summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwangmenglan <[email protected]>2024-11-28 15:18:30 +0800
committerwangmenglan <[email protected]>2024-11-28 15:22:23 +0800
commit59e7f7a6a30383f75c0bf9ac5487a00dec2133b3 (patch)
tree6f5e3cf1978102d7dcb3462cf3e2d0c6438578e3
parentdd4e2e6d66fcd20b29e6733ef2f10d7c1dfad942 (diff)
TSG-23932: Support parsing session_uuid field
-rw-r--r--common/src/tfe_ctrl_packet.cpp22
-rw-r--r--common/src/tfe_packet_io.cpp2
-rw-r--r--common/test/test_mpack.cpp8
3 files changed, 29 insertions, 3 deletions
diff --git a/common/src/tfe_ctrl_packet.cpp b/common/src/tfe_ctrl_packet.cpp
index 94f4ba5..3cb19cb 100644
--- a/common/src/tfe_ctrl_packet.cpp
+++ b/common/src/tfe_ctrl_packet.cpp
@@ -390,6 +390,16 @@ static int proxy_parse_messagepack(mpack_node_t node, void *ctx, void *logger)
break;
}
}
+
+ mpack_node_t node_session_uuid;
+ uuid_t session_uuid;
+ if (mpack_node_is_nil(mpack_node_map_cstr(node, "session_uuid")))
+ goto done;
+
+ node_session_uuid = mpack_node_map_cstr(node, "session_uuid");
+ if (mpack_parse_uuid(node_session_uuid, session_uuid) != -1)
+ tfe_cmsg_set(handler->cmsg, TFE_CMSG_STREAM_TRACE_ID, (const unsigned char*)session_uuid, UUID_LEN);
+done:
return 0;
}
@@ -570,6 +580,7 @@ void ctrl_packet_parser_dump(struct ctrl_pkt_parser *handler, void *logger)
int map_index = 0;
char *log_str = NULL;
uuid_t tags_ids_array[128];
+ uuid_t session_uuid;
int log_len = 0;
log_str = (char *)calloc(1, LOG_STR_LEN);
@@ -684,6 +695,17 @@ void ctrl_packet_parser_dump(struct ctrl_pkt_parser *handler, void *logger)
}
}
}
+
+ ret = tfe_cmsg_get_value(handler->cmsg, TFE_CMSG_STREAM_TRACE_ID, (unsigned char *)session_uuid, UUID_LEN, &size);
+ if (ret < 0) {
+ log_len += snprintf(log_str + log_len, LOG_STR_LEN - log_len, ", session_uuid:null");
+ }
+ else {
+ char str_session_uuid[UUID_STRING_SIZE] = {0};
+ uuid_unparse(session_uuid, str_session_uuid);
+ log_len += snprintf(log_str + log_len, LOG_STR_LEN - log_len, ", session_uuid:%s", str_session_uuid);
+ }
+
TFE_LOG_DEBUG(logger, "%s", log_str);
free(log_str);
log_str = NULL;
diff --git a/common/src/tfe_packet_io.cpp b/common/src/tfe_packet_io.cpp
index 0d69082..045406e 100644
--- a/common/src/tfe_packet_io.cpp
+++ b/common/src/tfe_packet_io.cpp
@@ -1255,8 +1255,6 @@ static int handle_session_opening(struct metadata *meta, marsio_buff_t *rx_buff,
stream_common_direction = meta->is_e2i_dir ? 'I' : 'E';
tfe_cmsg_set(parser->cmsg, TFE_CMSG_COMMON_DIRECTION, (const uint8_t *)&stream_common_direction, sizeof(stream_common_direction));
- snprintf(stream_traceid, 24, "%" PRIu64, meta->session_id);
- tfe_cmsg_set(parser->cmsg, TFE_CMSG_STREAM_TRACE_ID, (const uint8_t *)stream_traceid, strlen(stream_traceid));
tfe_cmsg_dup(parser->cmsg);
// 为避免 packet IO thread 与 worker 访问 cmsg 时出现竞争,packet IO thread 必须在调用 tfe_proxy_fds_accept 之前 set cmsg
diff --git a/common/test/test_mpack.cpp b/common/test/test_mpack.cpp
index c1e225b..037a5a0 100644
--- a/common/test/test_mpack.cpp
+++ b/common/test/test_mpack.cpp
@@ -170,8 +170,14 @@ void build_mpack_data(char **data, size_t *size)
mpack_write_bin(&writer, (const char*)seq_header, sizeof(seq_header));
mpack_write_bin(&writer, (const char*)ack_header, sizeof(ack_header));
mpack_write_u8(&writer, tfe_flag);
-
mpack_complete_array(&writer);
+
+ mpack_write_cstr(&writer, "session_uuid");
+ uuid_generate(uuid);
+ uuid_unparse(uuid, str_uuid);
+ printf("session_uuid:%s\n", str_uuid);
+ mpack_write_bin(&writer, (const char*)uuid, sizeof(uuid));
+
mpack_complete_map(&writer);
mpack_complete_map(&writer);
mpack_complete_map(&writer);