@@ -222,6 +222,48 @@ struct RSTrafficClue : RsSerializable
222222 }
223223};
224224
225+ /* !
226+ * \brief Cumulative traffic statistics for tracking all-time data transfer
227+ * Used to persist and display per-peer and per-service data usage
228+ */
229+ struct RsCumulativeTrafficStats : RsSerializable
230+ {
231+ uint64_t bytesIn; // < Total bytes received
232+ uint64_t bytesOut; // < Total bytes sent
233+ uint32_t countIn; // < Number of incoming packets
234+ uint32_t countOut; // < Number of outgoing packets
235+ rstime_t firstSeen; // < Timestamp of first recorded traffic
236+ rstime_t lastSeen; // < Timestamp of most recent traffic
237+
238+ RsCumulativeTrafficStats () :
239+ bytesIn (0 ), bytesOut(0 ), countIn(0 ), countOut(0 ),
240+ firstSeen (0 ), lastSeen(0 ) {}
241+
242+ RsCumulativeTrafficStats& operator +=(const RsCumulativeTrafficStats& other) {
243+ bytesIn += other.bytesIn ;
244+ bytesOut += other.bytesOut ;
245+ countIn += other.countIn ;
246+ countOut += other.countOut ;
247+ if (firstSeen == 0 || (other.firstSeen != 0 && other.firstSeen < firstSeen))
248+ firstSeen = other.firstSeen ;
249+ if (other.lastSeen > lastSeen)
250+ lastSeen = other.lastSeen ;
251+ return *this ;
252+ }
253+
254+ void clear () { bytesIn = bytesOut = countIn = countOut = 0 ; firstSeen = lastSeen = 0 ; }
255+
256+ // RsSerializable interface
257+ void serial_process (RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) {
258+ RS_SERIAL_PROCESS (bytesIn);
259+ RS_SERIAL_PROCESS (bytesOut);
260+ RS_SERIAL_PROCESS (countIn);
261+ RS_SERIAL_PROCESS (countOut);
262+ RS_SERIAL_PROCESS (firstSeen);
263+ RS_SERIAL_PROCESS (lastSeen);
264+ }
265+ };
266+
225267struct RsConfigNetStatus : RsSerializable
226268{
227269 RsConfigNetStatus () : netLocalOk(true )
@@ -348,6 +390,39 @@ class RsServerConfig
348390 */
349391 virtual int getTrafficInfo (std::list<RSTrafficClue>& out_lst,std::list<RSTrafficClue>& in_lst) = 0 ;
350392
393+ /* *
394+ * @brief getCumulativeTrafficByPeer returns cumulative traffic stats grouped by peer
395+ * @jsonapi{development}
396+ * @param[out] stats map of peer ID to cumulative traffic stats
397+ * @return returns true on success
398+ */
399+ virtual bool getCumulativeTrafficByPeer (std::map<RsPeerId, RsCumulativeTrafficStats>& stats) = 0;
400+
401+ /* *
402+ * @brief getCumulativeTrafficByService returns cumulative traffic stats grouped by service
403+ * @jsonapi{development}
404+ * @param[out] stats map of service ID to cumulative traffic stats
405+ * @return returns true on success
406+ */
407+ virtual bool getCumulativeTrafficByService (std::map<uint16_t , RsCumulativeTrafficStats>& stats) = 0;
408+
409+ /* *
410+ * @brief clearCumulativeTraffic clears all cumulative traffic statistics
411+ * @jsonapi{development}
412+ * @param[in] clearPeerStats if true, clears per-peer stats
413+ * @param[in] clearServiceStats if true, clears per-service stats
414+ * @return returns true on success
415+ */
416+ virtual bool clearCumulativeTraffic (bool clearPeerStats = true , bool clearServiceStats = true ) = 0;
417+
418+ /* *
419+ * @brief getTotalCumulativeTraffic returns the total cumulative traffic across all peers/services
420+ * @jsonapi{development}
421+ * @param[out] stats total cumulative traffic stats
422+ * @return returns true on success
423+ */
424+ virtual bool getTotalCumulativeTraffic (RsCumulativeTrafficStats& stats) = 0;
425+
351426 /* From RsInit */
352427
353428 // NOT IMPLEMENTED YET!
0 commit comments