summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorfearlessTobi <thm.frey@gmail.com>2018-09-16 20:05:51 +0200
committerfearlessTobi <thm.frey@gmail.com>2018-10-02 15:30:48 +0200
commit4d139943f2407144d5f8e3dc5a673f24850d43d0 (patch)
treebe24285a32c2b72b9756b69fd614f3d45c70ff41 /src/core
parentAdd submodules (diff)
downloadyuzu-4d139943f2407144d5f8e3dc5a673f24850d43d0.tar
yuzu-4d139943f2407144d5f8e3dc5a673f24850d43d0.tar.gz
yuzu-4d139943f2407144d5f8e3dc5a673f24850d43d0.tar.bz2
yuzu-4d139943f2407144d5f8e3dc5a673f24850d43d0.tar.lz
yuzu-4d139943f2407144d5f8e3dc5a673f24850d43d0.tar.xz
yuzu-4d139943f2407144d5f8e3dc5a673f24850d43d0.tar.zst
yuzu-4d139943f2407144d5f8e3dc5a673f24850d43d0.zip
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt3
-rw-r--r--src/core/settings.h6
-rw-r--r--src/core/telemetry_session.cpp51
-rw-r--r--src/core/telemetry_session.h5
4 files changed, 51 insertions, 14 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 23fd6e920..95f8b5d4a 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -394,6 +394,9 @@ create_target_directory_groups(core)
target_link_libraries(core PUBLIC common PRIVATE audio_core video_core)
target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt lz4_static mbedtls opus unicorn open_source_archives)
+if (ENABLE_WEB_SERVICE)
+ target_link_libraries(core PUBLIC json-headers web_service)
+endif()
if (ARCHITECTURE_x86_64)
target_sources(core PRIVATE
diff --git a/src/core/settings.h b/src/core/settings.h
index 0318d019c..1808f5937 100644
--- a/src/core/settings.h
+++ b/src/core/settings.h
@@ -155,6 +155,12 @@ struct Values {
// Debugging
bool use_gdbstub;
u16 gdbstub_port;
+
+ // WebService
+ bool enable_telemetry;
+ std::string web_api_url;
+ std::string yuzu_username;
+ std::string yuzu_token;
} extern values;
void Apply();
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp
index b0df154ca..09c85297a 100644
--- a/src/core/telemetry_session.cpp
+++ b/src/core/telemetry_session.cpp
@@ -6,6 +6,8 @@
#include "common/common_types.h"
#include "common/file_util.h"
+#include <mbedtls/ctr_drbg.h>
+#include <mbedtls/entropy.h>
#include "core/core.h"
#include "core/file_sys/control_metadata.h"
#include "core/file_sys/patch_manager.h"
@@ -13,10 +15,30 @@
#include "core/settings.h"
#include "core/telemetry_session.h"
+#ifdef ENABLE_WEB_SERVICE
+#include "web_service/telemetry_json.h"
+#include "web_service/verify_login.h"
+#endif
+
namespace Core {
static u64 GenerateTelemetryId() {
u64 telemetry_id{};
+
+ mbedtls_entropy_context entropy;
+ mbedtls_entropy_init(&entropy);
+ mbedtls_ctr_drbg_context ctr_drbg;
+ const char* personalization = "yuzu Telemetry ID";
+
+ mbedtls_ctr_drbg_init(&ctr_drbg);
+ mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
+ (const unsigned char*)personalization, strlen(personalization));
+ ASSERT(mbedtls_ctr_drbg_random(&ctr_drbg, reinterpret_cast<unsigned char*>(&telemetry_id),
+ sizeof(u64)) == 0);
+
+ mbedtls_ctr_drbg_free(&ctr_drbg);
+ mbedtls_entropy_free(&entropy);
+
return telemetry_id;
}
@@ -25,14 +47,21 @@ u64 GetTelemetryId() {
const std::string filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) +
"telemetry_id"};
- if (FileUtil::Exists(filename)) {
+ bool generate_new_id = !FileUtil::Exists(filename);
+ if (!generate_new_id) {
FileUtil::IOFile file(filename, "rb");
if (!file.IsOpen()) {
LOG_ERROR(Core, "failed to open telemetry_id: {}", filename);
return {};
}
file.ReadBytes(&telemetry_id, sizeof(u64));
- } else {
+ if (telemetry_id == 0) {
+ LOG_ERROR(Frontend, "telemetry_id is 0. Generating a new one.", telemetry_id);
+ generate_new_id = true;
+ }
+ }
+
+ if (generate_new_id) {
FileUtil::IOFile file(filename, "wb");
if (!file.IsOpen()) {
LOG_ERROR(Core, "failed to open telemetry_id: {}", filename);
@@ -59,23 +88,20 @@ u64 RegenerateTelemetryId() {
return new_telemetry_id;
}
-std::future<bool> VerifyLogin(std::string username, std::string token, std::function<void()> func) {
+bool VerifyLogin(std::string username, std::string token) {
#ifdef ENABLE_WEB_SERVICE
- return WebService::VerifyLogin(username, token, Settings::values.verify_endpoint_url, func);
+ return WebService::VerifyLogin(Settings::values.web_api_url, username, token);
#else
- return std::async(std::launch::async, [func{std::move(func)}]() {
- func();
- return false;
- });
+ return false;
#endif
}
TelemetrySession::TelemetrySession() {
#ifdef ENABLE_WEB_SERVICE
if (Settings::values.enable_telemetry) {
- backend = std::make_unique<WebService::TelemetryJson>(
- Settings::values.telemetry_endpoint_url, Settings::values.yuzu_username,
- Settings::values.yuzu_token);
+ backend = std::make_unique<WebService::TelemetryJson>(Settings::values.web_api_url,
+ Settings::values.yuzu_username,
+ Settings::values.yuzu_token);
} else {
backend = std::make_unique<Telemetry::NullVisitor>();
}
@@ -94,7 +120,8 @@ TelemetrySession::TelemetrySession() {
u64 program_id{};
const Loader::ResultStatus res{System::GetInstance().GetAppLoader().ReadProgramId(program_id)};
if (res == Loader::ResultStatus::Success) {
- AddField(Telemetry::FieldType::Session, "ProgramId", program_id);
+ std::string formatted_program_id{fmt::format("{:016X}", program_id)};
+ AddField(Telemetry::FieldType::Session, "ProgramId", formatted_program_id);
std::string name;
System::GetInstance().GetAppLoader().ReadTitle(name);
diff --git a/src/core/telemetry_session.h b/src/core/telemetry_session.h
index dbc4f8bd4..e6976ad45 100644
--- a/src/core/telemetry_session.h
+++ b/src/core/telemetry_session.h
@@ -4,7 +4,6 @@
#pragma once
-#include <future>
#include <memory>
#include "common/telemetry.h"
@@ -31,6 +30,8 @@ public:
field_collection.AddField(type, name, std::move(value));
}
+ static void FinalizeAsyncJob();
+
private:
Telemetry::FieldCollection field_collection; ///< Tracks all added fields for the session
std::unique_ptr<Telemetry::VisitorInterface> backend; ///< Backend interface that logs fields
@@ -55,6 +56,6 @@ u64 RegenerateTelemetryId();
* @param func A function that gets exectued when the verification is finished
* @returns Future with bool indicating whether the verification succeeded
*/
-std::future<bool> VerifyLogin(std::string username, std::string token, std::function<void()> func);
+bool VerifyLogin(std::string username, std::string token);
} // namespace Core