feat(traffic): count traffic by peer and by connection

Every server now splits its packet counts by peer: its own connections
(players on auth and worlds), its master link, or other servers (the
worlds on chat, every server on master, a world's chat link, which is
now counted too). HTTP requests carrying X-Darkflame-Server count as
another server's, the dashboard counts its own requests to the UGC
server, and each HTTP client address is counted. The report also gets
each RakNet connection's statistics (worlds name the player on it),
trimmed to the 32 busiest with the rest summed. Counting stays on the
main loop, except the dashboard's UGC fetches, which only touch the
locked recorder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-29 18:23:31 -05:00
parent 8a53562629
commit 9e8f161dd8
10 changed files with 273 additions and 27 deletions

View File

@@ -4,10 +4,17 @@
#include "BitStreamUtils.h"
#include "Game.h"
#include "RakPeerInterface.h"
#include "TrafficStats.h"
void ChatServerLink::Send(const LUBitStream& msg, const PacketPriority priority, const PacketReliability reliability) {
if (!Game::chatServer) return;
RakNet::BitStream bitStream;
msg.WritePacket(bitStream);
const auto bytes = bitStream.GetNumberOfBytesUsed();
TrafficStats::Local().Packet(TrafficStats::Now(), TrafficStats::KeyOf(bitStream.GetData(), bytes, true), bytes, 1, TrafficStats::Peer::SERVERS);
Game::chatServer->Send(&bitStream, priority, reliability, 0, Game::chatSysAddr, false);
}
void ChatServerLink::CountReceived(const unsigned char* data, unsigned int length) {
TrafficStats::Local().Packet(TrafficStats::Now(), TrafficStats::KeyOf(data, length, false), length, 1, TrafficStats::Peer::SERVERS);
}