From 67af9585d8ba1e6da54eb83475fd2290f33a8654 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Tue, 12 Dec 2023 20:29:44 +0800 Subject: [PATCH] proto fetch storage ids add field allow_empty --- tracker/fdfs_server_id_func.c | 15 +++++---- tracker/tracker_proto.h | 7 +++++ tracker/tracker_service.c | 57 ++++++++++++++++++++--------------- 3 files changed, 47 insertions(+), 32 deletions(-) diff --git a/tracker/fdfs_server_id_func.c b/tracker/fdfs_server_id_func.c index 58ac23f..f8d9823 100644 --- a/tracker/fdfs_server_id_func.c +++ b/tracker/fdfs_server_id_func.c @@ -406,18 +406,17 @@ int fdfs_load_storage_ids(char *content, const char *pStorageIdsFilename) } pHost = group_name; - while (!(*pHost == ' ' || *pHost == '\t' \ - || *pHost == '\0')) + while (!(*pHost == ' ' || *pHost == '\t' || *pHost == '\0')) { pHost++; } if (*pHost == '\0') { - logError("file: "__FILE__", line: %d, " \ - "config file: %s, line no: %d, " \ - "content: %s, invalid format, " \ - "expect ip address!", __LINE__, \ + logError("file: "__FILE__", line: %d, " + "config file: %s, line no: %d, " + "content: %s, invalid format, " + "expect ip address!", __LINE__, pStorageIdsFilename, i + 1, line); result = EINVAL; break; @@ -567,7 +566,7 @@ int fdfs_get_storage_ids_from_tracker_server(TrackerServerInfo *pTrackerServer) #define MAX_REQUEST_LOOP 32 TrackerHeader *pHeader; ConnectionInfo *conn; - char out_buff[sizeof(TrackerHeader) + sizeof(int)]; + char out_buff[sizeof(TrackerHeader) + sizeof(FDFSFetchStorageIdsBody)]; char *p; char *response; struct data_info { @@ -593,7 +592,7 @@ int fdfs_get_storage_ids_from_tracker_server(TrackerServerInfo *pTrackerServer) pHeader = (TrackerHeader *)out_buff; p = out_buff + sizeof(TrackerHeader); pHeader->cmd = TRACKER_PROTO_CMD_STORAGE_FETCH_STORAGE_IDS; - long2buff(sizeof(int), pHeader->pkg_len); + long2buff(sizeof(FDFSFetchStorageIdsBody), pHeader->pkg_len); start_index = 0; list_count = 0; diff --git a/tracker/tracker_proto.h b/tracker/tracker_proto.h index 8fefb93..e7ab47b 100644 --- a/tracker/tracker_proto.h +++ b/tracker/tracker_proto.h @@ -213,6 +213,13 @@ typedef struct char size[4]; } FDFSTrunkInfoBuff; + +typedef struct +{ + char start_index[4]; + char allow_empty; +} FDFSFetchStorageIdsBody; + #ifdef __cplusplus extern "C" { #endif diff --git a/tracker/tracker_service.c b/tracker/tracker_service.c index d9bc23f..9ce5a35 100644 --- a/tracker/tracker_service.c +++ b/tracker/tracker_service.c @@ -1054,6 +1054,7 @@ static int tracker_deal_get_storage_group_name(struct fast_task_info *pTask) static int tracker_deal_fetch_storage_ids(struct fast_task_info *pTask) { + FDFSFetchStorageIdsBody *req_body; FDFSStorageIdInfo *pIdsStart; FDFSStorageIdInfo *pIdsEnd; FDFSStorageIdInfo *pIdInfo; @@ -1063,37 +1064,45 @@ static int tracker_deal_fetch_storage_ids(struct fast_task_info *pTask) int start_index; char ip_str[256]; - if (!g_use_storage_id) + nPkgLen = pTask->recv.ptr->length - sizeof(TrackerHeader); + if (nPkgLen != sizeof(*req_body)) { - logError("file: "__FILE__", line: %d, " \ - "client ip addr: %s, operation not supported", \ + logError("file: "__FILE__", line: %d, " + "cmd=%d, client ip addr: %s, package size %d " + "is not correct, expect %d bytes", __LINE__, + TRACKER_PROTO_CMD_STORAGE_FETCH_STORAGE_IDS, + pTask->client_ip, nPkgLen, (int)sizeof(*req_body)); + pTask->send.ptr->length = sizeof(TrackerHeader); + return EINVAL; + } + + req_body = (FDFSFetchStorageIdsBody *)(pTask->recv.ptr->data + + sizeof(TrackerHeader)); + if (!g_use_storage_id) + { + if (req_body->allow_empty) + { + pTask->send.ptr->length = sizeof(TrackerHeader) + 8; + memset(pTask->send.ptr->data + sizeof(TrackerHeader), 0, 8); + return 0; + } + + logError("file: "__FILE__", line: %d, " + "client ip addr: %s, operation not supported", __LINE__, pTask->client_ip); pTask->send.ptr->length = sizeof(TrackerHeader); return EOPNOTSUPP; } - nPkgLen = pTask->recv.ptr->length - sizeof(TrackerHeader); - if (nPkgLen != sizeof(int)) - { - logError("file: "__FILE__", line: %d, " \ - "cmd=%d, client ip addr: %s, " \ - "package size %d is not correct, " \ - "expect %d bytes", __LINE__, \ - TRACKER_PROTO_CMD_STORAGE_FETCH_STORAGE_IDS, \ - pTask->client_ip, nPkgLen, (int)sizeof(int)); - pTask->send.ptr->length = sizeof(TrackerHeader); - return EINVAL; - } - - start_index = buff2int(pTask->recv.ptr->data + sizeof(TrackerHeader)); + start_index = buff2int(req_body->start_index); if (start_index < 0 || start_index >= g_storage_ids_by_id.count) - { - logError("file: "__FILE__", line: %d, " \ - "client ip addr: %s, invalid offset: %d", \ - __LINE__, pTask->client_ip, start_index); - pTask->send.ptr->length = sizeof(TrackerHeader); - return EINVAL; - } + { + logError("file: "__FILE__", line: %d, " + "client ip addr: %s, invalid offset: %d", + __LINE__, pTask->client_ip, start_index); + pTask->send.ptr->length = sizeof(TrackerHeader); + return EINVAL; + } p = pTask->send.ptr->data + sizeof(TrackerHeader); int2buff(g_storage_ids_by_id.count, p);