From 32f6909e8f98a3d4aa841e2f6c0a10821b7fdfe0 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 10 Apr 2025 19:24:37 +0100 Subject: [PATCH] Codechange: Simplify requesting content by ContentID. This function takes the number of elements and a pointer to an array of content IDs. However the only caller only ever passes a pointer to a single content ID. Remove the unnecessary logic for splitting a large array into MTU-size chunks. --- src/network/network_content.cpp | 31 ++++++++----------------------- src/network/network_content.h | 2 +- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp index cc41d9e920..8f4e8eb28f 100644 --- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -232,32 +232,17 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentType type) } /** - * Request the content list for a given number of content IDs. - * @param count The number of IDs to request. - * @param content_ids The unique identifiers of the content to request information about. + * Request the content list for a given content ID. + * @param content_id The unique identifier of the content to request information about. */ -void ClientNetworkContentSocketHandler::RequestContentList(uint count, const ContentID *content_ids) +void ClientNetworkContentSocketHandler::RequestContentList(ContentID content_id) { this->Connect(); - while (count > 0) { - /* We can "only" send a limited number of IDs in a single packet. - * A packet begins with the packet size and a byte for the type. - * Then this packet adds a uint16_t for the count in this packet. - * The rest of the packet can be used for the IDs. */ - uint p_count = std::min(count, (TCP_MTU - sizeof(PacketSize) - sizeof(uint8_t) - sizeof(uint16_t)) / sizeof(uint32_t)); - - auto p = std::make_unique(this, PACKET_CONTENT_CLIENT_INFO_ID, TCP_MTU); - p->Send_uint16(p_count); - - for (uint i = 0; i < p_count; i++) { - p->Send_uint32(content_ids[i]); - } - - this->SendPacket(std::move(p)); - count -= p_count; - content_ids += p_count; - } + auto p = std::make_unique(this, PACKET_CONTENT_CLIENT_INFO_ID, TCP_MTU); + p->Send_uint16(1); // Number of content IDs. We only ever send one. + p->Send_uint32(content_id); + this->SendPacket(std::move(p)); } /** @@ -855,7 +840,7 @@ void ClientNetworkContentSocketHandler::DownloadContentInfo(ContentID cid) if (std::ranges::find(this->requested, cid) != this->requested.end()) return; this->requested.push_back(cid); - this->RequestContentList(1, &cid); + this->RequestContentList(cid); } /** diff --git a/src/network/network_content.h b/src/network/network_content.h index ee145ff6a4..af2b15509b 100644 --- a/src/network/network_content.h +++ b/src/network/network_content.h @@ -116,7 +116,7 @@ public: void Cancel(); void RequestContentList(ContentType type); - void RequestContentList(uint count, const ContentID *content_ids); + void RequestContentList(ContentID content_id); void RequestContentList(ContentVector *cv, bool send_md5sum = true); void DownloadSelectedContent(uint &files, uint &bytes, bool fallback = false);