Play your Steam library's Windows games on a jailbroken PS5.
C++
Log curl's error code with Cloud and CDN failures
Leonardo Lobato475ba4222262
diff --git a/src/steam/backend/cdn_client.cpp b/src/steam/backend/cdn_client.cppindex 15bf676..4d95f7c 100644--- a/src/steam/backend/cdn_client.cpp+++ b/src/steam/backend/cdn_client.cpp@@ -61,7 +61,7 @@ CdnError CdnClient::Get(const std::string& url, std::size_t max_bytes, std::uint*out = std::move(response.body);} else {last_failure_ = response.ok() ? "http=" + std::to_string(response.status_code)- : std::string("transport=") + HttpErrorName(response.error);+ : std::string("transport=") + HttpFailureName(response);}return error;}diff --git a/src/steam/backend/cloud_sync.cpp b/src/steam/backend/cloud_sync.cppindex 7ffdaf3..e4ef97c 100644--- a/src/steam/backend/cloud_sync.cpp+++ b/src/steam/backend/cloud_sync.cpp@@ -803,7 +803,7 @@ CloudOutcome CloudSync::Apply(const StoredSession& session, const GameSaveLocaticonst auto response = hooks_.http(request, cancel);if (!response.ok() || response.status_code != 200) {failure = "A Cloud save could not be downloaded. Try again.";- detail = named + " http error=" + HttpErrorName(response.error) + " status=" + std::to_string(response.status_code) ++ detail = named + " http error=" + HttpFailureName(response) + " status=" + std::to_string(response.status_code) +" host=" + ticket->host + " file_size=" + std::to_string(ticket->file_size) +" raw_size=" + std::to_string(ticket->raw_file_size) + " body=" + std::to_string(response.body.size());return std::nullopt;@@ -938,7 +938,7 @@ CloudOutcome CloudSync::Apply(const StoredSession& session, const GameSaveLocatidata.begin() + static_cast<std::ptrdiff_t>(block.offset + block.length));const auto response = hooks_.http(request, cancel);if (!response.ok() || response.status_code < 200 || response.status_code >= 300) {- detail = "file=" + decision.remote_name + " upload http error=" + HttpErrorName(response.error) ++ detail = "file=" + decision.remote_name + " upload http error=" + HttpFailureName(response) +" status=" + std::to_string(response.status_code) + " host=" + block.host +" bytes=" + std::to_string(request.body.size());transferred = false;diff --git a/src/steam/backend/http_client.cpp b/src/steam/backend/http_client.cppindex 2fdab10..69f3c78 100644--- a/src/steam/backend/http_client.cpp+++ b/src/steam/backend/http_client.cpp@@ -207,6 +207,12 @@ const char* HttpErrorName(HttpError error) {return "protocol_error";}+std::string HttpFailureName(const HttpResponse& response) {+ std::string name = HttpErrorName(response.error);+ if (response.transport_code != 0) name += " curl=" + std::to_string(response.transport_code);+ return name;+}+class HttpClient::Impl {public:explicit Impl(std::string ca_bundle) : ca_bundle_(std::move(ca_bundle)) {@@ -386,6 +392,7 @@ class HttpClient::Impl {curl_slist_free_all(request_headers);transfer.response.error = MapError(result, transfer, canceled);if (!transfer.response.ok()) {+ transfer.response.transport_code = result == CURLE_OK ? 0 : static_cast<int>(result);// Clearing both caches covers transport failure and abandonment before curl consumes// staged DNS removals. Successful GETs retain their multi connection and DNS caches.resolution_cache_.ResetTransport(multi_);diff --git a/src/steam/backend/http_client.h b/src/steam/backend/http_client.hindex dda3987..ce7f3a7 100644--- a/src/steam/backend/http_client.h+++ b/src/steam/backend/http_client.h@@ -67,10 +67,16 @@ struct HttpResponse {std::vector<std::uint8_t> body;HttpTiming timing; // Retained when a failed response discards its payload.+ // The transport library's numeric result code when the transfer failed (0 otherwise), for logs:+ // several codes share one HttpError, such as a TLS handshake failure and kProtocolError.+ int transport_code = 0;bool ok() const { return error == HttpError::kNone; }};+// HttpErrorName plus the transport code when there is one, such as "protocol_error curl=35".+std::string HttpFailureName(const HttpResponse& response);+// One worker thread owns each instance and calls Perform synchronously. The cancel flag may be// changed by another thread. Responses contain stable categories and never expose URLs, headers,// bodies, or transport-library error text.diff --git a/tests/http_client_test.cpp b/tests/http_client_test.cppindex 1abbd4f..26fdf55 100644--- a/tests/http_client_test.cpp+++ b/tests/http_client_test.cpp@@ -143,6 +143,8 @@ int main(int argc, char** argv) {post.body = {'p', 'a', 'y', 'l', 'o', 'a', 'd'};response = client.Perform(post, cancel);Check(response.ok() && response.status_code == 201, "verified POST should succeed");+ Check(response.transport_code == 0 && playden::steam::HttpFailureName(response) == "none",+ "a successful transfer has no transport code");Check(Text(response.body) == "present:payload", "POST should send headers and bytes");HttpRequest timeout;@@ -223,6 +225,10 @@ int main(int argc, char** argv) {HttpClient untrusted(wrong_ca_bundle);response = untrusted.Perform(get, cancel);Check(response.error == HttpError::kTlsVerificationFailed, "wrong CA should fail verification");+ // 60 is CURLE_PEER_FAILED_VERIFICATION.+ Check(response.transport_code == 60 &&+ playden::steam::HttpFailureName(response) == "tls_verification_failed curl=60",+ "a transport failure should keep curl's code for diagnostics");HttpRequest invalid_header = get;invalid_header.headers.emplace_back("Bad\r\nInjected", "value");diff --git a/tests/steam_cloud_test.cpp b/tests/steam_cloud_test.cppindex 249be2d..f478339 100644--- a/tests/steam_cloud_test.cpp+++ b/tests/steam_cloud_test.cpp@@ -143,6 +143,7 @@ struct FakeCloud {bool declares_ufs = true;bool corrupt_downloads = false;long download_status = 200; // another status refuses every download+ int download_transport_code = 0; // nonzero fails every download in transport with this curl codestd::uint64_t next_batch = 700;std::map<std::string, std::vector<std::uint8_t>> pending; // uploads in the open batchstd::vector<std::string> pending_deletes;@@ -258,6 +259,12 @@ struct FakeCloud {response.status_code = download_status;response.body.clear();}+ if (download_transport_code != 0) {+ response.error = HttpError::kProtocolError;+ response.transport_code = download_transport_code;+ response.status_code = 0;+ response.body.clear();+ }} else if (path.rfind("/up/", 0) == 0) {CHECK(request.method == HttpMethod::kPut);pending[path.substr(4)] = request.body;@@ -533,6 +540,14 @@ void SyncEndToEnd() {outcome.detail.find(" status=403 ") != std::string::npos && outcome.detail.find("x-test-signature") == std::string::npos);cloud.download_status = 200;+ // A download that fails in transport: the log names curl's code, which several failures share one error for.+ plan = sync.Check(session, location, cancel);+ cloud.download_transport_code = 35;+ outcome = sync.Apply(session, location, plan, Resolution::kUseCloud, true, cancel);+ CHECK(!outcome.ok && outcome.message == "A Cloud save could not be downloaded. Try again.");+ CHECK(outcome.detail.find(" http error=protocol_error curl=35 status=0 ") != std::string::npos);+ cloud.download_transport_code = 0;+// A game without Steam Cloud says so.cloud.declares_ufs = false;plan = sync.Check(session, location, cancel);