mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-15 09:04:10 +00:00
feat(net): count every server's packets and send a traffic report every 5 seconds
TrafficStats keeps packets and bytes in and out per second and the busiest packet and game message types. dServer counts at its send and receive calls and adds RakNet's connection statistics (datagrams, resends, ping); the report goes to master as SERVER_TRAFFIC (appended), which passes it to the dashboard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,12 +3,14 @@
|
||||
#include <chrono>
|
||||
#include <csignal>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include "RakPeerInterface.h"
|
||||
#include "ReplicaManager.h"
|
||||
#include "NetworkIDManager.h"
|
||||
|
||||
class Logger;
|
||||
class dConfig;
|
||||
struct ServerTraffic;
|
||||
enum class eServerDisconnectIdentifiers : uint32_t;
|
||||
enum class ServiceType : uint16_t;
|
||||
|
||||
@@ -51,6 +53,11 @@ public:
|
||||
|
||||
void Disconnect(const SystemAddress& sysAddr, eServerDisconnectIdentifiers disconNotifyID);
|
||||
|
||||
// Where this server's traffic report goes every few seconds (see ServerTraffic.h). By default it is sent to
|
||||
// master; master sends its own to the dashboard, the dashboard keeps its own.
|
||||
using TrafficSink = std::function<void(ServerTraffic& report)>;
|
||||
void SetTrafficSink(TrafficSink sink) { mTrafficSink = std::move(sink); }
|
||||
|
||||
bool IsConnected(const SystemAddress& sysAddr);
|
||||
const std::string& GetIP() const { return mIP; }
|
||||
const int GetPort() const { return mPort; }
|
||||
@@ -80,7 +87,16 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
struct LinkCounters {
|
||||
uint64_t datagramsSent{}, datagramsReceived{}, bitsSent{}, bitsReceived{}, resends{};
|
||||
};
|
||||
bool Startup();
|
||||
// Traffic diagnostics (TrafficStats): count one packet, and send the report when it is due
|
||||
void CountTraffic(const Packet* packet);
|
||||
void CountTraffic(const RakNet::BitStream& bitStream, bool broadcast, const SystemAddress& sysAddr);
|
||||
void ReportTraffic();
|
||||
// Adds the peer's connections to the report's link statistics (changes since the last report)
|
||||
void AddLinkStats(RakPeerInterface* peer, uint64_t peerIndex, ServerTraffic& report, uint64_t& pingSum, std::map<uint64_t, LinkCounters>& seen);
|
||||
void Shutdown();
|
||||
void SetupForMasterConnection();
|
||||
bool ConnectToMaster();
|
||||
@@ -118,4 +134,8 @@ protected:
|
||||
std::chrono::steady_clock::time_point mStartTime = std::chrono::steady_clock::now();
|
||||
std::string mMasterPassword;
|
||||
SendObserver mSendObserver;
|
||||
|
||||
TrafficSink mTrafficSink;
|
||||
// RakNet's per-connection statistics are totals since the connection opened; the last ones seen, for deltas
|
||||
std::map<uint64_t, LinkCounters> mLinkCounters;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user