Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Tidy the download server picker

Leonardo Lobatof5b7d4315a23
diff --git a/README.md b/README.md
index 2f48299..c564cba 100644
--- a/README.md
+++ b/README.md
@@ -348,7 +348,7 @@ build/homebrew-host/playden-homebrew --simulation --scenario signed-out
**Downloads for slow networks**: Playden then downloads 8 pieces at the same time instead of 4. On a fast connection
it can be slower, so turn it off again if downloads get slower. If downloads stay slow, open Settings › Downloads ›
**Download server**, use **Test servers** and choose the fastest server. The test downloads up to 160 MB.
- Automatic uses the server Steam lists first. Each provider chooses its nearby server through DNS or anycast,
+ Default uses the server Steam lists first. Each provider chooses its nearby server through DNS or anycast,
so your DNS resolver can affect the result.
See the [compatibility list](COMPATIBILITY.md) for what we know about each game.
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cpp
index c73bbd8..830c2e1 100644
--- a/src/homebrew/simulation.cpp
+++ b/src/homebrew/simulation.cpp
@@ -2742,7 +2742,7 @@ void Simulation::refresh_download_servers(const std::string& focus) {
if (modal.id != "download-server") continue;
const auto prior = modal.action_keys.empty() ? std::string{} :
modal.action_keys[static_cast<std::size_t>(modal.focused_action)];
- modal.action_keys = {"download-server-auto"};
+ modal.action_keys = {"download-server-test", "download-server-auto"};
for (std::size_t index = 0; index < download_servers_.servers.size(); ++index)
modal.action_keys.push_back("download-server-" + std::to_string(index));
if (download_servers_.phase == "listing" || download_servers_.phase == "idle")
@@ -2751,11 +2751,10 @@ void Simulation::refresh_download_servers(const std::string& focus) {
modal.action_keys.push_back("download-server-list-failed");
modal.action_keys.push_back("download-server-retry");
}
- modal.action_keys.push_back("download-server-test");
modal.action_keys.push_back("cancel");
const auto wanted = focus.empty() ? prior : focus;
const auto found = std::find(modal.action_keys.begin(), modal.action_keys.end(), wanted);
- modal.focused_action = found == modal.action_keys.end() ? 0 : static_cast<int>(found - modal.action_keys.begin());
+ modal.focused_action = found == modal.action_keys.end() ? 1 : static_cast<int>(found - modal.action_keys.begin());
if (&modal == &state_.navigation.modals.back())
state_.navigation.focus_key = modal.action_keys[static_cast<std::size_t>(modal.focused_action)];
}
@@ -3529,7 +3528,9 @@ bool Simulation::scenario(const std::string& name) {
{"fastly.cdn.steampipe.steamcontent.com", "Fastly"},
{"google2.cdn.steampipe.steamcontent.com", "Google Cloud"},
{"alibaba.cdn.steampipe.steamcontent.com", "Alibaba Cloud", true},
- {"edgenext.cdn.steampipe.steamcontent.com", "EdgeNext", true}};
+ {"edgenext.cdn.steampipe.steamcontent.com", "EdgeNext", true},
+ {"cache5-fra1.steamcontent.com", "Steam (Valve) · cache5-fra1"},
+ {"cache2-ams1.steamcontent.com", "Steam (Valve) · cache2-ams1"}};
download_server_test_requested_ = false;
download_server_cancel_pending_ = false;
state_.account().authentication = AuthState::SignedIn;
@@ -4132,7 +4133,7 @@ void Simulation::rebuild_view() {
item.dangerous = modal.destructive && action_key != "cancel";
if (modal.id == "download-server") {
if (action_key == "download-server-auto") {
- item.title = "Automatic";
+ item.title = "Default";
item.selected = state_.download_server.empty();
} else if (action_key == "download-server-listing" || action_key == "download-server-list-failed") {
item.title = action_key == "download-server-listing" ? "Getting the server list…" : "Could not get the server list.";
@@ -5523,7 +5524,7 @@ void Simulation::rebuild_view() {
? "8 pieces at a time. Turn it off if downloads got slower."
: "Off: 4 pieces at a time. Turn it on if downloads stay near 1 MB/s.";
auto& server = add("settings-download-server", RowKind::Action, "Download server", "download-server-picker");
- server.value = state_.download_server.empty() ? "Automatic"
+ server.value = state_.download_server.empty() ? "Default"
: download_servers_.preferred_name.empty() ? state_.download_server : download_servers_.preferred_name;
bool offered = false;
for (const auto& option : download_servers_.servers) if (option.id == state_.download_server) {
@@ -5534,7 +5535,7 @@ void Simulation::rebuild_view() {
download_servers_.phase == "tested" || download_servers_.phase == "test-failed";
server.subtitle = state_.download_server.empty()
? "Uses the server Steam lists first. Choose one if downloads are slow."
- : listed && !offered ? "Not offered on this network now. Automatic is used."
+ : listed && !offered ? "Not offered on this network now. Default is used."
: "If it stops answering, Playden uses another one.";
}
section = "Display";
@@ -8575,8 +8576,8 @@ void Simulation::tick(int ticks) {
auto progress = download_servers_;
const auto index = progress.testing_index;
if (index < progress.servers.size()) {
- constexpr double rates[] = {12.4, 41.2, 9.7, 0.0, 2.5};
- progress.rates.push_back({progress.servers[index].id, rates[index % 5], index == 3});
+ constexpr double rates[] = {12.4, 41.2, 9.7, 0.0, 2.5, 18.3, 6.1};
+ progress.rates.push_back({progress.servers[index].id, rates[index % 7], index == 3});
if (index + 1 < progress.servers.size()) ++progress.testing_index;
else progress.phase = "tested";
}
diff --git a/src/homebrew/simulation.hpp b/src/homebrew/simulation.hpp
index d91aeb9..ab2de59 100644
--- a/src/homebrew/simulation.hpp
+++ b/src/homebrew/simulation.hpp
@@ -669,7 +669,7 @@ struct State {
bool cloud_saves_auto = false; // Cloud saves move before Play, after sessions and at startup (opt-in)
bool beta_updates = false;
bool downloads_slow_network = false; // 8 download pieces at a time instead of 4 (Settings › Storage)
- std::string download_server; // empty: Automatic; otherwise the chosen provider's stable identifier
+ std::string download_server; // empty: Default (Steam's order); otherwise the chosen provider's stable identifier
bool controller_connected = true;
ControllerState controller;
bool persistence_available = true;
diff --git a/src/steam/backend/download_server_source.cpp b/src/steam/backend/download_server_source.cpp
index 0b214ab..73e05c0 100644
--- a/src/steam/backend/download_server_source.cpp
+++ b/src/steam/backend/download_server_source.cpp
@@ -7,6 +7,7 @@
#include <algorithm>
#include <array>
+#include <map>
#include <mutex>
#include <thread>
@@ -17,6 +18,13 @@ std::string Hex(const std::array<std::uint8_t, 20>& bytes) {
for (const auto byte : bytes) { result += "0123456789abcdef"[byte >> 4]; result += "0123456789abcdef"[byte & 15]; }
return result;
}
+// The part of a host that tells servers of one provider apart: cache5-fra1 for cache5-fra1.steamcontent.com.
+std::string ShortHost(const std::string& host) {
+ for (const std::string suffix : {".cdn.steampipe.steamcontent.com", ".steamcontent.com"})
+ if (host.size() > suffix.size() && host.compare(host.size() - suffix.size(), suffix.size(), suffix) == 0)
+ return host.substr(0, host.size() - suffix.size());
+ return host;
+}
}
CdnDownloadServerSource::CdnDownloadServerSource(CmClient& cm, CdnClient& cdn,
@@ -41,6 +49,11 @@ bool CdnDownloadServerSource::List(const std::atomic<bool>& cancel, std::vector<
servers_ = std::move(listed);
out->clear();
for (const auto& server : servers_) out->push_back({server.host, DisplayName(server.host), !server.https});
+ // Steam often lists several servers of one provider: name each by its host so they can be told apart.
+ std::map<std::string, int> names;
+ for (const auto& view : *out) ++names[view.name];
+ for (auto& view : *out)
+ if (names[view.name] > 1 && view.name != view.id) view.name += " · " + ShortHost(view.id);
return !out->empty();
}
DownloadServerPreparation CdnDownloadServerSource::Prepare(const StoredSession& session, const std::atomic<bool>& cancel) {
diff --git a/tests/download_server_source_test.cpp b/tests/download_server_source_test.cpp
index f5b64ad..e05aadf 100644
--- a/tests/download_server_source_test.cpp
+++ b/tests/download_server_source_test.cpp
@@ -35,6 +35,18 @@ void ListingPolicy() {
assert(servers[0].plain_http == !mixed);
assert(servers[0].name == (mixed ? "Fastly" : "http.example"));
}
+ // Servers of one provider are told apart by their host; a lone one keeps the provider name.
+ CdnClient cdn([&](const HttpRequest&, const std::atomic<bool>&) {
+ return Reply(R"({"response":{"servers":[{"type":"CDN","host":"cache5-fra1.steamcontent.com"},)"
+ R"({"type":"CDN","host":"cache2-ams1.steamcontent.com"},{"type":"CDN","host":"fastly.cdn.steampipe.steamcontent.com"},)"
+ R"({"type":"CDN","host":"google2.cdn.steampipe.steamcontent.com"},{"type":"CDN","host":"google3.cdn.steampipe.steamcontent.com"}]}})");
+ });
+ CdnDownloadServerSource source(cdn, {});
+ std::vector<DownloadServerView> servers;
+ assert(source.List(cancel, &servers) && servers.size() == 5);
+ assert(servers[0].name == "Steam (Valve) · cache5-fra1" && servers[1].name == "Steam (Valve) · cache2-ams1");
+ assert(servers[2].name == "Fastly");
+ assert(servers[3].name == "Google Cloud · google2" && servers[4].name == "Google Cloud · google3");
}
void PayloadAndTransfers(const std::string& fixtures) {
const auto manifest = Read(fixtures + "/manifest_encrypted_deflated.zip");
diff --git a/tests/homebrew_library_model_test.cpp b/tests/homebrew_library_model_test.cpp
index 687374b..97137fa 100644
--- a/tests/homebrew_library_model_test.cpp
+++ b/tests/homebrew_library_model_test.cpp
@@ -3180,18 +3180,23 @@ void live_download_server_picker() {
servers.phase = "listed";
servers.servers = {{"akamai.invalid", "Akamai"}, {"fastly.invalid", "Fastly"}, {"cache.invalid", "Network cache", true}};
model.ApplyLiveDownloadServers(servers);
- check(find_row(model, "settings-download-server")->value == "Automatic" &&
+ check(find_row(model, "settings-download-server")->value == "Default" &&
find_row(model, "settings-download-server")->subtitle ==
"Uses the server Steam lists first. Choose one if downloads are slow.",
- "the server row explains Automatic");
+ "the server row explains Default");
activate(model, "settings-download-server");
check(model.TakeDownloadServerRequests() == std::vector<DownloadServerRequest>{DownloadServerRequest::List},
"opening the picker asks the worker for a new list");
check(find_row(model, "download-server-listing")->title == "Getting the server list…" &&
model.state().navigation.focus_key == "download-server-auto" &&
model.view().subtitle == "Applies to downloads that start or resume from now.",
- "listing keeps Automatic available and explains when the choice applies");
+ "listing keeps Default available and explains when the choice applies");
model.ApplyLiveDownloadServers(servers);
+ check(model.state().navigation.modals.back().action_keys ==
+ std::vector<std::string>{"download-server-test", "download-server-auto", "download-server-0",
+ "download-server-1", "download-server-2", "cancel"} &&
+ find_row(model, "download-server-auto")->title == "Default",
+ "Test servers comes first, then Default and the listed servers");
check(find_row(model, "download-server-2")->subtitle == "HTTP", "plain HTTP servers are marked");
activate(model, "download-server-1");
check(model.state().navigation.modals.empty() && model.state().download_server == "fastly.invalid" &&
@@ -3252,7 +3257,7 @@ void live_download_server_picker() {
restarted.ApplyLiveDownloadServers(servers);
check(find_row(restarted, "settings-download-server")->value == "Akamai" &&
find_row(restarted, "settings-download-server")->subtitle ==
- "Not offered on this network now. Automatic is used.", "a missing stored server falls back visibly");
+ "Not offered on this network now. Default is used.", "a missing stored server falls back visibly");
activate(restarted, "settings-download-server");
(void)restarted.TakeDownloadServerRequests();
servers.phase = "list-failed";
@@ -3283,7 +3288,7 @@ void live_download_server_picker() {
check(find_row(restarted, "download-server-test")->enabled, "pausing the download enables measurement");
activate(restarted, "download-server-auto");
check(restarted.state().download_server.empty() && restarted.ExportPreferences().download_server.empty(),
- "Automatic clears the stored choice");
+ "Default clears the stored choice");
}
void leftover_titles_require_confirmation_and_follow_the_queue() {
diff --git a/tests/homebrew_simulation_test.cpp b/tests/homebrew_simulation_test.cpp
index 50218c3..5b3fd1a 100644
--- a/tests/homebrew_simulation_test.cpp
+++ b/tests/homebrew_simulation_test.cpp
@@ -1398,15 +1398,16 @@ void synthetic_download_servers(const std::filesystem::path& fixtures, const std
const auto press = [&simulation](const std::string& key) {
check(simulation.action("focus:" + key) && simulation.action("cross"), "synthetic server action exists");
};
- check(row("settings-download-server") && row("settings-download-server")->value == "Automatic",
+ check(row("settings-download-server") && row("settings-download-server")->value == "Default",
"the synthetic scenario shows the Settings row");
press("settings-download-server");
- check(row("download-server-4") && !row("download-server-5") && row("download-server-3")->subtitle == "HTTP",
- "five providers are shown, with HTTP marked");
+ check(row("download-server-6") && !row("download-server-7") && row("download-server-3")->subtitle == "HTTP" &&
+ row("download-server-5")->title == "Steam (Valve) · cache5-fra1",
+ "seven servers are shown, with HTTP and the host of repeated providers marked");
press("download-server-test");
- check(row("download-server-test")->title == "Testing Akamai (1 of 5)…", "synthetic test starts with the first provider");
+ check(row("download-server-test")->title == "Testing Akamai (1 of 7)…", "synthetic test starts with the first provider");
simulation.tick(1);
- check(row("download-server-test")->title == "Testing Fastly (2 of 5)…" &&
+ check(row("download-server-test")->title == "Testing Fastly (2 of 7)…" &&
row("download-server-0")->value == "12.4 MB/s", "synthetic progress produces rates");
simulation.action("circle");
check(!simulation.state().navigation.modals.empty(), "Circle cancels the synthetic test first");
@@ -1414,7 +1415,7 @@ void synthetic_download_servers(const std::filesystem::path& fixtures, const std
check(simulation.state().navigation.modals.empty(), "the next Circle closes the picker");
press("settings-download-server");
press("download-server-test");
- simulation.tick(5);
+ simulation.tick(7);
check(row("download-server-1")->value == "41.2 MB/s" && row("download-server-1")->badge == "Fastest" &&
row("download-server-3")->value == "Failed" && simulation.state().navigation.focus_key == "download-server-1" &&
simulation.state().download_server.empty(), "synthetic completion focuses the fastest without choosing it");