Compare commits

..

8 Commits

Author SHA1 Message Date
Lion Kortlepel dad469f800 CMake: Fix typo in SANITIZE codepath 2021-09-14 14:38:18 +02:00
Lion Kortlepel c3012fcee7 CMake: Use gzipped debug info on linux 2021-09-14 13:38:00 +02:00
Lion Kortlepel 7250137935 Sentry: Properly store DSN 2021-09-14 13:03:27 +02:00
Lion Kortlepel fa3cf9f5a7 Add cryptography header for the future 2021-09-14 12:52:19 +02:00
Lion Kortlepel eed8326deb Http, Heartbeat: Process status < 0 differently, report as "Invalid
Response Code"
2021-09-14 12:34:28 +02:00
Lion Kortlepel 90c3aac0bc Http: Add Sentry error breadcrumbs on internal https POST errors 2021-09-14 12:32:30 +02:00
Lion Kortlepel 7a25377d4e Heartbeat: Dont report 200 + INVALID_KEY to Sentry 2021-09-14 12:18:31 +02:00
Lion Kortlepel f4900189c0 Config: private by default 2021-09-14 12:16:31 +02:00
2 changed files with 20 additions and 75 deletions
+20 -65
View File
@@ -3,12 +3,8 @@
#include "Client.h" #include "Client.h"
#include "Http.h" #include "Http.h"
//#include "SocketIO.h" //#include "SocketIO.h"
#include <rapidjson/document.h>
#include <rapidjson/rapidjson.h>
#include <sstream> #include <sstream>
namespace json = rapidjson;
void THeartbeatThread::operator()() { void THeartbeatThread::operator()() {
RegisterThread("Heartbeat"); RegisterThread("Heartbeat");
std::string Body; std::string Body;
@@ -45,83 +41,42 @@ void THeartbeatThread::operator()() {
{ { "response-body", T }, { { "response-body", T },
{ "request-body", Body } }); { "request-body", Body } });
Sentry.SetTransaction(transaction); Sentry.SetTransaction(transaction);
trace("sending log to sentry: " + std::to_string(status) + " for " + transaction);
Sentry.Log(SentryLevel::Error, "default", Http::Status::ToString(status) + " (" + std::to_string(status) + ")"); Sentry.Log(SentryLevel::Error, "default", Http::Status::ToString(status) + " (" + std::to_string(status) + ")");
}; };
auto Target = "/heartbeat"; auto Target = "/heartbeat";
int ResponseCode = -1; int ResponseCode = -1;
const std::vector<std::string> Urls = { T = Http::POST(Application::GetBackendHostname(), Target, {}, Body, false, &ResponseCode);
Application::GetBackendHostname(),
Application::GetBackup1Hostname(),
Application::GetBackup2Hostname(),
};
json::Document Doc; if ((T.substr(0, 2) != "20" && ResponseCode != 200) || ResponseCode != 200) {
bool Ok = false; trace("got " + T + " from backend");
for (const auto& Url : Urls) { SentryReportError(Application::GetBackendHostname() + Target, ResponseCode);
T = Http::POST(Url, Target, { { "api-v", "2" } }, Body, false, &ResponseCode);
trace(T);
Doc.Parse(T.data(), T.size());
if (Doc.HasParseError() || !Doc.IsObject()) {
error("Backend response failed to parse as valid json");
debug("Response was: `" + T + "`");
Sentry.SetContext("JSON Response", { { "reponse", T } });
SentryReportError(Url + Target, ResponseCode);
} else if (ResponseCode != 200) {
SentryReportError(Url + Target, ResponseCode);
} else {
// all ok
Ok = true;
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(500));
} T = Http::POST(Application::GetBackup1Hostname(), Target, {}, Body, false, &ResponseCode);
std::string Status {}; if ((T.substr(0, 2) != "20" && ResponseCode != 200) || ResponseCode != 200) {
std::string Code {}; SentryReportError(Application::GetBackup1Hostname() + Target, ResponseCode);
std::string Message {}; std::this_thread::sleep_for(std::chrono::milliseconds(500));
const auto StatusKey = "status"; T = Http::POST(Application::GetBackup2Hostname(), Target, {}, Body, false, &ResponseCode);
const auto CodeKey = "code"; if ((T.substr(0, 2) != "20" && ResponseCode != 200) || ResponseCode != 200) {
const auto MessageKey = "msg"; warn("Backend system refused server! Server will not show in the public server list.");
isAuth = false;
if (Ok) { SentryReportError(Application::GetBackup2Hostname() + Target, ResponseCode);
if (Doc.HasMember(StatusKey) && Doc[StatusKey].IsString()) { }
Status = Doc[StatusKey].GetString();
} else {
Sentry.SetContext("JSON Response", { { StatusKey, "invalid string / missing" } });
Ok = false;
}
if (Doc.HasMember(CodeKey) && Doc[CodeKey].IsString()) {
Code = Doc[CodeKey].GetString();
} else {
Sentry.SetContext("JSON Response", { { CodeKey, "invalid string / missing" } });
Ok = false;
}
if (Doc.HasMember(MessageKey) && Doc[MessageKey].IsString()) {
Message = Doc[MessageKey].GetString();
} else {
Sentry.SetContext("JSON Response", { { MessageKey, "invalid string / missing" } });
Ok = false;
}
if (!Ok) {
error("Missing/invalid json members in backend response");
Sentry.LogError("Missing/invalid json members in backend response", __FILE__, std::to_string(__LINE__));
} }
} }
if (Ok && !isAuth) { if (!isAuth) {
if (Status == "2000") { if (T == "2000") {
info(("Authenticated!")); info(("Authenticated!"));
isAuth = true; isAuth = true;
} else if (Status == "200") { } else if (T == "200") {
info(("Resumed authenticated session!")); info(("Resumed authenticated session!"));
isAuth = true; isAuth = true;
} else {
if (Message.empty()) {
Message = "Backend didn't provide a reason";
}
error("Backend REFUSED the auth key. " + Message);
} }
} }
//SocketIO::Get().SetAuthenticated(isAuth);
} }
} }
-10
View File
@@ -54,16 +54,6 @@ int main(int argc, char** argv) try {
Application::Console().InitializeLuaConsole(LuaEngine); Application::Console().InitializeLuaConsole(LuaEngine);
Application::CheckForUpdates(); Application::CheckForUpdates();
Sentry.LogError("test error", __FILE__, std::to_string(__LINE__));
error("goodbye, crashing now");
volatile int* a = nullptr;
// oh boy
*a = -0;
a[318008]++;
// bye now
abort();
// TODO: replace // TODO: replace
while (!Shutdown) { while (!Shutdown) {
std::this_thread::sleep_for(std::chrono::milliseconds(50)); std::this_thread::sleep_for(std::chrono::milliseconds(50));