mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 02:43:44 +00:00
feat(web): API key traffic is its own Network row, named after the key
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -208,9 +208,12 @@ namespace TrafficStats {
|
||||
if (list.size() > limit) list.resize(limit);
|
||||
}
|
||||
|
||||
void Recorder::HttpClient(const std::string& address, bool fromServer, uint64_t bytesIn, uint64_t bytesOut, uint32_t accountId, const std::string& user) {
|
||||
// One entry per address and signed-in account: people sharing an address (behind one NAT or proxy) stay apart
|
||||
const auto key = accountId ? address + '\n' + std::to_string(accountId) : address;
|
||||
void Recorder::HttpClient(const std::string& address, bool fromServer, uint64_t bytesIn, uint64_t bytesOut, uint32_t accountId, const std::string& user,
|
||||
const std::string& apiKeyName) {
|
||||
// One entry per address and signed-in account: people sharing an address (behind one NAT or proxy) stay apart.
|
||||
// An API key is its own entry, named after the key, apart from its owner's browser sessions
|
||||
const auto key = accountId ? address + '\n' + std::to_string(accountId) + (apiKeyName.empty() ? std::string() : "\nkey:" + apiKeyName) : address;
|
||||
const auto label = apiKeyName.empty() || user.empty() ? user : user + " (API key \"" + apiKeyName + "\")";
|
||||
std::lock_guard lock(m_Mutex);
|
||||
auto it = m_HttpClients.find(key);
|
||||
if (it == m_HttpClients.end()) {
|
||||
@@ -220,11 +223,11 @@ namespace TrafficStats {
|
||||
it->second.http = true;
|
||||
if (!full) {
|
||||
it->second.accountId = accountId;
|
||||
it->second.account = user;
|
||||
it->second.account = label;
|
||||
}
|
||||
}
|
||||
auto& client = it->second;
|
||||
if (client.account.empty() && !user.empty() && client.accountId == accountId) client.account = user; // a WebSocket upgrade knows only the account
|
||||
if (client.account.empty() && !label.empty() && client.accountId == accountId) client.account = label; // a WebSocket upgrade knows only the account
|
||||
if (fromServer) client.peer = Peer::SERVERS;
|
||||
client.packetsIn++;
|
||||
client.packetsOut++;
|
||||
|
||||
@@ -201,7 +201,8 @@ namespace TrafficStats {
|
||||
// An HTTP client's request by its address (bytes of the request and of the answer's body). `accountId` and `user`:
|
||||
// the account the request was signed in as (the dashboard's session or API key), 0 and "" when none; each
|
||||
// signed-in account on an address is counted apart
|
||||
void HttpClient(const std::string& address, bool fromServer, uint64_t bytesIn, uint64_t bytesOut, uint32_t accountId = 0, const std::string& user = {});
|
||||
void HttpClient(const std::string& address, bool fromServer, uint64_t bytesIn, uint64_t bytesOut, uint32_t accountId = 0, const std::string& user = {},
|
||||
const std::string& apiKeyName = {});
|
||||
|
||||
// Evaluated when a report is taken (on the thread that takes it)
|
||||
void SetGauge(const std::string& name, std::function<double()> source);
|
||||
|
||||
Reference in New Issue
Block a user