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 "Http.h"
//#include "SocketIO.h"
#include <rapidjson/document.h>
#include <rapidjson/rapidjson.h>
#include <sstream>
namespace json = rapidjson;
void THeartbeatThread::operator()() {
RegisterThread("Heartbeat");
std::string Body;
@@ -45,83 +41,42 @@ void THeartbeatThread::operator()() {
{ { "response-body", T },
{ "request-body", Body } });
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) + ")");
};
auto Target = "/heartbeat";
int ResponseCode = -1;
const std::vector<std::string> Urls = {
Application::GetBackendHostname(),
Application::GetBackup1Hostname(),
Application::GetBackup2Hostname(),
};
T = Http::POST(Application::GetBackendHostname(), Target, {}, Body, false, &ResponseCode);
json::Document Doc;
bool Ok = false;
for (const auto& Url : Urls) {
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;
}
if ((T.substr(0, 2) != "20" && ResponseCode != 200) || ResponseCode != 200) {
trace("got " + T + " from backend");
SentryReportError(Application::GetBackendHostname() + Target, ResponseCode);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
std::string Status {};
std::string Code {};
std::string Message {};
const auto StatusKey = "status";
const auto CodeKey = "code";
const auto MessageKey = "msg";
if (Ok) {
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__));
T = Http::POST(Application::GetBackup1Hostname(), Target, {}, Body, false, &ResponseCode);
if ((T.substr(0, 2) != "20" && ResponseCode != 200) || ResponseCode != 200) {
SentryReportError(Application::GetBackup1Hostname() + Target, ResponseCode);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
T = Http::POST(Application::GetBackup2Hostname(), Target, {}, Body, false, &ResponseCode);
if ((T.substr(0, 2) != "20" && ResponseCode != 200) || ResponseCode != 200) {
warn("Backend system refused server! Server will not show in the public server list.");
isAuth = false;
SentryReportError(Application::GetBackup2Hostname() + Target, ResponseCode);
}
}
}
if (Ok && !isAuth) {
if (Status == "2000") {
if (!isAuth) {
if (T == "2000") {
info(("Authenticated!"));
isAuth = true;
} else if (Status == "200") {
} else if (T == "200") {
info(("Resumed authenticated session!"));
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::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
while (!Shutdown) {
std::this_thread::sleep_for(std::chrono::milliseconds(50));