diff options
Diffstat (limited to 'src/core/telemetry_session.cpp')
| -rw-r--r-- | src/core/telemetry_session.cpp | 86 |
1 files changed, 85 insertions, 1 deletions
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index 841d6cfa1..ca517ff44 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp | |||
| @@ -3,15 +3,19 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include <cryptopp/osrng.h> | ||
| 6 | 7 | ||
| 7 | #include "common/assert.h" | 8 | #include "common/assert.h" |
| 9 | #include "common/file_util.h" | ||
| 8 | #include "common/scm_rev.h" | 10 | #include "common/scm_rev.h" |
| 9 | #include "common/x64/cpu_detect.h" | 11 | #include "common/x64/cpu_detect.h" |
| 12 | #include "core/core.h" | ||
| 10 | #include "core/settings.h" | 13 | #include "core/settings.h" |
| 11 | #include "core/telemetry_session.h" | 14 | #include "core/telemetry_session.h" |
| 12 | 15 | ||
| 13 | #ifdef ENABLE_WEB_SERVICE | 16 | #ifdef ENABLE_WEB_SERVICE |
| 14 | #include "web_service/telemetry_json.h" | 17 | #include "web_service/telemetry_json.h" |
| 18 | #include "web_service/verify_login.h" | ||
| 15 | #endif | 19 | #endif |
| 16 | 20 | ||
| 17 | namespace Core { | 21 | namespace Core { |
| @@ -28,23 +32,94 @@ static const char* CpuVendorToStr(Common::CPUVendor vendor) { | |||
| 28 | UNREACHABLE(); | 32 | UNREACHABLE(); |
| 29 | } | 33 | } |
| 30 | 34 | ||
| 35 | static u64 GenerateTelemetryId() { | ||
| 36 | u64 telemetry_id{}; | ||
| 37 | CryptoPP::AutoSeededRandomPool rng; | ||
| 38 | rng.GenerateBlock(reinterpret_cast<CryptoPP::byte*>(&telemetry_id), sizeof(u64)); | ||
| 39 | return telemetry_id; | ||
| 40 | } | ||
| 41 | |||
| 42 | u64 GetTelemetryId() { | ||
| 43 | u64 telemetry_id{}; | ||
| 44 | static const std::string& filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"}; | ||
| 45 | |||
| 46 | if (FileUtil::Exists(filename)) { | ||
| 47 | FileUtil::IOFile file(filename, "rb"); | ||
| 48 | if (!file.IsOpen()) { | ||
| 49 | LOG_ERROR(Core, "failed to open telemetry_id: %s", filename.c_str()); | ||
| 50 | return {}; | ||
| 51 | } | ||
| 52 | file.ReadBytes(&telemetry_id, sizeof(u64)); | ||
| 53 | } else { | ||
| 54 | FileUtil::IOFile file(filename, "wb"); | ||
| 55 | if (!file.IsOpen()) { | ||
| 56 | LOG_ERROR(Core, "failed to open telemetry_id: %s", filename.c_str()); | ||
| 57 | return {}; | ||
| 58 | } | ||
| 59 | telemetry_id = GenerateTelemetryId(); | ||
| 60 | file.WriteBytes(&telemetry_id, sizeof(u64)); | ||
| 61 | } | ||
| 62 | |||
| 63 | return telemetry_id; | ||
| 64 | } | ||
| 65 | |||
| 66 | u64 RegenerateTelemetryId() { | ||
| 67 | const u64 new_telemetry_id{GenerateTelemetryId()}; | ||
| 68 | static const std::string& filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"}; | ||
| 69 | |||
| 70 | FileUtil::IOFile file(filename, "wb"); | ||
| 71 | if (!file.IsOpen()) { | ||
| 72 | LOG_ERROR(Core, "failed to open telemetry_id: %s", filename.c_str()); | ||
| 73 | return {}; | ||
| 74 | } | ||
| 75 | file.WriteBytes(&new_telemetry_id, sizeof(u64)); | ||
| 76 | return new_telemetry_id; | ||
| 77 | } | ||
| 78 | |||
| 79 | std::future<bool> VerifyLogin(std::string username, std::string token, std::function<void()> func) { | ||
| 80 | #ifdef ENABLE_WEB_SERVICE | ||
| 81 | return WebService::VerifyLogin(username, token, Settings::values.verify_endpoint_url, func); | ||
| 82 | #else | ||
| 83 | return std::async(std::launch::async, [func{std::move(func)}]() { | ||
| 84 | func(); | ||
| 85 | return false; | ||
| 86 | }); | ||
| 87 | #endif | ||
| 88 | } | ||
| 89 | |||
| 31 | TelemetrySession::TelemetrySession() { | 90 | TelemetrySession::TelemetrySession() { |
| 32 | #ifdef ENABLE_WEB_SERVICE | 91 | #ifdef ENABLE_WEB_SERVICE |
| 33 | backend = std::make_unique<WebService::TelemetryJson>(); | 92 | if (Settings::values.enable_telemetry) { |
| 93 | backend = std::make_unique<WebService::TelemetryJson>( | ||
| 94 | Settings::values.telemetry_endpoint_url, Settings::values.citra_username, | ||
| 95 | Settings::values.citra_token); | ||
| 96 | } else { | ||
| 97 | backend = std::make_unique<Telemetry::NullVisitor>(); | ||
| 98 | } | ||
| 34 | #else | 99 | #else |
| 35 | backend = std::make_unique<Telemetry::NullVisitor>(); | 100 | backend = std::make_unique<Telemetry::NullVisitor>(); |
| 36 | #endif | 101 | #endif |
| 102 | // Log one-time top-level information | ||
| 103 | AddField(Telemetry::FieldType::None, "TelemetryId", GetTelemetryId()); | ||
| 104 | |||
| 37 | // Log one-time session start information | 105 | // Log one-time session start information |
| 38 | const s64 init_time{std::chrono::duration_cast<std::chrono::milliseconds>( | 106 | const s64 init_time{std::chrono::duration_cast<std::chrono::milliseconds>( |
| 39 | std::chrono::system_clock::now().time_since_epoch()) | 107 | std::chrono::system_clock::now().time_since_epoch()) |
| 40 | .count()}; | 108 | .count()}; |
| 41 | AddField(Telemetry::FieldType::Session, "Init_Time", init_time); | 109 | AddField(Telemetry::FieldType::Session, "Init_Time", init_time); |
| 110 | std::string program_name; | ||
| 111 | const Loader::ResultStatus res{System::GetInstance().GetAppLoader().ReadTitle(program_name)}; | ||
| 112 | if (res == Loader::ResultStatus::Success) { | ||
| 113 | AddField(Telemetry::FieldType::Session, "ProgramName", program_name); | ||
| 114 | } | ||
| 42 | 115 | ||
| 43 | // Log application information | 116 | // Log application information |
| 44 | const bool is_git_dirty{std::strstr(Common::g_scm_desc, "dirty") != nullptr}; | 117 | const bool is_git_dirty{std::strstr(Common::g_scm_desc, "dirty") != nullptr}; |
| 45 | AddField(Telemetry::FieldType::App, "Git_IsDirty", is_git_dirty); | 118 | AddField(Telemetry::FieldType::App, "Git_IsDirty", is_git_dirty); |
| 46 | AddField(Telemetry::FieldType::App, "Git_Branch", Common::g_scm_branch); | 119 | AddField(Telemetry::FieldType::App, "Git_Branch", Common::g_scm_branch); |
| 47 | AddField(Telemetry::FieldType::App, "Git_Revision", Common::g_scm_rev); | 120 | AddField(Telemetry::FieldType::App, "Git_Revision", Common::g_scm_rev); |
| 121 | AddField(Telemetry::FieldType::App, "BuildDate", Common::g_build_date); | ||
| 122 | AddField(Telemetry::FieldType::App, "BuildName", Common::g_build_name); | ||
| 48 | 123 | ||
| 49 | // Log user system information | 124 | // Log user system information |
| 50 | AddField(Telemetry::FieldType::UserSystem, "CPU_Model", Common::GetCPUCaps().cpu_string); | 125 | AddField(Telemetry::FieldType::UserSystem, "CPU_Model", Common::GetCPUCaps().cpu_string); |
| @@ -68,6 +143,15 @@ TelemetrySession::TelemetrySession() { | |||
| 68 | Common::GetCPUCaps().sse4_1); | 143 | Common::GetCPUCaps().sse4_1); |
| 69 | AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_SSE42", | 144 | AddField(Telemetry::FieldType::UserSystem, "CPU_Extension_x64_SSE42", |
| 70 | Common::GetCPUCaps().sse4_2); | 145 | Common::GetCPUCaps().sse4_2); |
| 146 | #ifdef __APPLE__ | ||
| 147 | AddField(Telemetry::FieldType::UserSystem, "OsPlatform", "Apple"); | ||
| 148 | #elif defined(_WIN32) | ||
| 149 | AddField(Telemetry::FieldType::UserSystem, "OsPlatform", "Windows"); | ||
| 150 | #elif defined(__linux__) || defined(linux) || defined(__linux) | ||
| 151 | AddField(Telemetry::FieldType::UserSystem, "OsPlatform", "Linux"); | ||
| 152 | #else | ||
| 153 | AddField(Telemetry::FieldType::UserSystem, "OsPlatform", "Unknown"); | ||
| 154 | #endif | ||
| 71 | 155 | ||
| 72 | // Log user configuration information | 156 | // Log user configuration information |
| 73 | AddField(Telemetry::FieldType::UserConfig, "Audio_EnableAudioStretching", | 157 | AddField(Telemetry::FieldType::UserConfig, "Audio_EnableAudioStretching", |