1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
//
// This file is part of the aMule Project.
//
// Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
// Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net )
// Copyright (c) 2005-2011 Dévai Tamás ( gonosztopi@amule.org )
//
// Any parts of this program derived from the xMule, lMule or eMule project,
// or contributed by third-party developers are copyrighted by their
// respective authors.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
//

#ifndef STATISTICS_H
#define STATISTICS_H

#include "Constants.h"		// Needed for StatsGraphType
#include "StatTree.h"		// Needed for CStatTreeItem* classes

#include <deque>		// Needed for std::deque

typedef struct UpdateInfo {
	double timestamp;
	float downloads[3];
	float uploads[3];
	float connections[3];
	float kadnodes[3];
} GraphUpdateInfo;

typedef struct HistoryRecord {
	double		kBytesSent;
	double		kBytesReceived;
	float		kBpsUpCur;
	float		kBpsDownCur;
	double		sTimestamp;
	uint16		cntDownloads;
	uint16		cntUploads;
	uint16		cntConnections;
	uint16		kadNodesCur;
	uint64		kadNodesTotal;
} HR;


#ifndef CLIENT_GUI

/**
 * Counts precise rate/average on added bytes/values.
 *
 * @note This class is MT-safe.
 */
class CPreciseRateCounter {
	friend class CStatistics;	// for playing dirty tricks to compute running average :P
 public:

	/**
	 * Constructor
	 *
	 * @param timespan Desired timespan for rate calculations.
	 * @param count_average Counts average instead of rate.
	 */
	CPreciseRateCounter(uint32_t timespan, bool count_average = false)
		: m_timespan(timespan), m_total(0), m_rate(0.0), m_max_rate(0.0), m_tmp_sum(0), m_count_average(count_average)
		{
			if (!count_average) {
				uint64_t cur_time = GetTickCount64();
				uint64_t target_time = cur_time - timespan;
				while (cur_time > target_time) {
					m_tick_history.push_front(cur_time);
					m_byte_history.push_front(0);
					cur_time -= 100;	// default update period
				}
				m_tick_history.push_front(cur_time);
			}
		}

	/**
	 * Calculate current rate.
	 *
	 * This function should be called reasonably often, to
	 * keep rates up-to-date, and prevent history growing
	 * to the skies.
	 */
	void	CalculateRate(uint64_t now);

	/**
	 * Get current rate.
	 *
	 * @return Current rate in bytes/second.
	 */
	double	GetRate()			{ wxMutexLocker lock(m_mutex); return m_rate; };

	/**
	 * Gets ever seen maximal rate.
	 *
	 * @return The maximal rate which occurred.
	 */
	double	GetMaxRate()			{ wxMutexLocker lock(m_mutex); return m_max_rate; }

	/**
	 * Sets desired timespan for rate calculations.
	 *
	 * If new timespan is greater than the old was, then the change
	 * takes effect with time. The exact time needed for the change
	 * to take effect is new minus old value of the timespan.
	 *
	 * If the new timespan is lower than the old, the change takes
	 * effect immediately at the next call to CalculateRate().
	 */
	void	SetTimespan(uint32_t timespan)	{ wxMutexLocker lock(m_mutex); m_timespan = timespan; }

	/**
	 * Add bytes to be tracked for rate-counting.
	 */
	void	operator+=(uint32_t bytes)	{ wxMutexLocker lock(m_mutex); m_tmp_sum += bytes; }

 protected:

	std::deque<uint32>	m_byte_history;
	std::deque<uint64>	m_tick_history;
	uint32_t	m_timespan;
	uint32_t	m_total;
	double		m_rate;
	double		m_max_rate;
	uint32_t	m_tmp_sum;
	wxMutex		m_mutex;
	bool		m_count_average;
};


class CECTag;

/**
 * Stat tree item for rates/averages.
 */
class CStatTreeItemRateCounter : public CStatTreeItemBase, public CPreciseRateCounter {
 public:

	/**
	 * @see CStatTreeItemBase::CStatTreeItemBase, CPreciseRateCounter::CPreciseRateCounter
	 *
	 * @param show_maxrate If true, shows max rate instead of current rate.
	 */
	CStatTreeItemRateCounter(const wxString& label, bool show_maxrate, uint32_t timespan, bool count_average = false)
		: CStatTreeItemBase(label, stNone), CPreciseRateCounter(timespan, count_average), m_show_maxrate(show_maxrate)
		{}

#ifndef AMULE_DAEMON
	/**
	 * @see CStatTreeItemBase::GetDisplayString()
	 */
	virtual wxString GetDisplayString() const;<--- Function in derived class
#endif

 protected:
	/**
	 * Add values to EC tag being generated.
	 *
	 * @param tag The tag to which values should be added.
	 *
	 * @see CStatTreeItemBase::AddECValues
	 */
	virtual	void	AddECValues(CECTag* tag) const;<--- Function in derived class

	//! Whether to show max rate instead of actual rate.
	bool	m_show_maxrate;
};


/**
 * Stat tree item for Peak Connections.
 */
class CStatTreeItemPeakConnections : public CStatTreeItemBase {
 public:

	/**
	 * @see CStatTreeItemBase::CStatTreeItemBase
	 */
	CStatTreeItemPeakConnections(const wxString& label)
		: CStatTreeItemBase(label)
		{}

#ifndef AMULE_DAEMON
	/**
	 * @see CStatTreeItemBase::GetDisplayString()
	 */
	virtual wxString GetDisplayString() const;<--- Function in derived class
#endif

 protected:
	/**
	 * Add values to EC tag being generated.
	 *
	 * @param tag The tag to which values should be added.
	 *
	 * @see CStatTreeItemBase::AddECValues
	 */
	virtual	void	AddECValues(CECTag* tag) const;<--- Function in derived class
};


class CUpDownClient;

class CStatistics {
	friend class CStatisticsDlg;	// to access CStatistics::GetTreeRoot()
 public:
	CStatistics();
	~CStatistics();

	static void	Load();
	static void	Save();

	/* Statistics graph functions */

	void	 RecordHistory();
	unsigned GetHistoryForWeb(unsigned cntPoints, double sStep, double *sStart, uint32 **graphData);
	unsigned GetHistory(unsigned cntPoints, double sStep, double sFinal, const std::vector<float *> &ppf, StatsGraphType which_graph);
	GraphUpdateInfo GetPointsForUpdate();

	/* Statistics tree functions */

	void UpdateStatsTree();

	/* Access to the tree */

	// uptime
	static	uint64	GetUptimeMillis()			{ return s_uptime->GetTimerValue(); }
	static	uint64	GetUptimeSeconds()			{ return s_uptime->GetTimerSeconds(); }
	static	uint64	GetStartTime()				{ return s_uptime->GetTimerStart(); }

	// Upload
	static	uint64	GetTotalSentBytes()			{ return s_totalSent; }
	static	uint64	GetSessionSentBytes()			{ return (*s_sessionUpload); }
	static	void	AddUpOverheadFileRequest(uint32 size)	{ (*s_fileReqUpOverhead) += size; (*s_upOverheadRate) += size; }
	static	void	AddUpOverheadSourceExchange(uint32 size){ (*s_sourceXchgUpOverhead) += size; (*s_upOverheadRate) += size; }
	static	void	AddUpOverheadServer(uint32 size)	{ (*s_serverUpOverhead) += size; (*s_upOverheadRate) += size; }
	static	void	AddUpOverheadKad(uint32 size)		{ (*s_kadUpOverhead) += size; (*s_upOverheadRate) += size; }
	static	void	AddUpOverheadCrypt(uint32_t size)	{ (*s_cryptUpOverhead) += size; }
	static	void	AddUpOverheadOther(uint32 size)		{ (*s_totalUpOverhead) += size; (*s_upOverheadRate) += size; }
	static	double	GetUpOverheadRate()			{ return s_upOverheadRate->GetRate(); }
	static	void	AddSuccessfulUpload()			{ ++(*s_totalSuccUploads); }
	static	void	AddFailedUpload()			{ ++(*s_totalFailedUploads); }
	static	void	AddUploadTime(uint32 time)		{ (*s_totalUploadTime) += time; }
	static	void	AddUploadingClient()			{ ++(*s_activeUploads); }
	static	void	RemoveUploadingClient()			{ --(*s_activeUploads); }
	static	uint32	GetActiveUploadsCount()			{ return (*s_activeUploads); }
	static	void	AddWaitingClient()			{ ++(*s_waitingUploads); }
	static	void	RemoveWaitingClient()			{ --(*s_waitingUploads); }
	static	uint32	GetWaitingUserCount()			{ return (*s_waitingUploads); }
	static	double	GetUploadRate()				{ return s_uploadrate->GetRate(); }

	// Download
	static	uint64	GetTotalReceivedBytes()			{ return s_totalReceived; }
	static	uint64	GetSessionReceivedBytes()		{ return (*s_sessionDownload); }
	static	void	AddDownOverheadFileRequest(uint32 size)	{ (*s_fileReqDownOverhead) += size; (*s_downOverheadRate) += size; }
	static	void	AddDownOverheadSourceExchange(uint32 size){ (*s_sourceXchgDownOverhead) += size; (*s_downOverheadRate) += size; }
	static	void	AddDownOverheadServer(uint32 size)	{ (*s_serverDownOverhead) += size; (*s_downOverheadRate) += size; }
	static	void	AddDownOverheadKad(uint32 size)		{ (*s_kadDownOverhead) += size; (*s_downOverheadRate) += size; }
	static	void	AddDownOverheadCrypt(uint32_t size)	{ (*s_cryptDownOverhead) += size; }
	static	void	AddDownOverheadOther(uint32 size)	{ (*s_totalDownOverhead) += size; (*s_downOverheadRate) += size; }
	static	double	GetDownOverheadRate()			{ return s_downOverheadRate->GetRate(); }
	static	void	AddFoundSource()			{ ++(*s_foundSources); }
	static	void	RemoveFoundSource()			{ --(*s_foundSources); }
	static	uint32	GetFoundSources()			{ return (*s_foundSources); }
	static	void	AddSourceOrigin(unsigned origin);
	static	void	RemoveSourceOrigin(unsigned origin);
	static	void	AddDownloadingSource()			{ ++(*s_activeDownloads); }
	static	void	RemoveDownloadingSource()		{ --(*s_activeDownloads); }
	static	uint32	GetDownloadingSources()			{ return (*s_activeDownloads); }
	static	double	GetDownloadRate()			{ return s_downloadrate->GetRate(); }

	// Connection
	static	CStatTreeItemTimer* GetServerConnectTimer()	{ return s_sinceConnected; }
	static	void	AddReconnect()				{ ++(*s_reconnects); }
	static	void	AddActiveConnection()			{ ++(*s_activeConnections); }
	static	void	RemoveActiveConnection()		{ --(*s_activeConnections); }
	static	uint32	GetActiveConnections()			{ return s_activeConnections->GetValue(); }
	static	uint32	GetPeakConnections()			{ return s_activeConnections->GetMaxValue(); }
	static	void	AddMaxConnectionLimitReached()		{ ++(*s_limitReached); }

	// Clients
	static	void	AddFilteredClient()			{ ++(*s_filtered); }
	static	void	AddUnknownClient()			{ ++(*s_unknown); }
	static	void	RemoveUnknownClient()			{ --(*s_unknown); }
	static	void	AddKnownClient(CUpDownClient *pClient);
	static	void	RemoveKnownClient(uint32 clientSoft, uint32 clientVersion, const wxString& OSInfo);
#ifdef __DEBUG__
	static	void	SocketAssignedToClient()		{ ++(*s_hasSocket); }
	static	void	SocketUnassignedFromClient()		{ --(*s_hasSocket); }
#endif
	static	uint32	GetBannedCount()			{ return (*s_banned); }
	static	void	AddBannedClient()			{ ++(*s_banned); }
	static	void	RemoveBannedClient()			{ --(*s_banned); }

	// Servers
	static	void	AddServer()				{ ++(*s_totalServers); }
	static	void	DeleteServer()				{ ++(*s_deletedServers); --(*s_totalServers); }
	static	void	DeleteAllServers()			{ (*s_deletedServers) += (*s_totalServers); (*s_totalServers) = 0; }
	static	void	AddFilteredServer()			{ ++(*s_filteredServers); }

	// Shared files
	static	void	ClearSharedFilesInfo()			{ (*s_numberOfShared) = 0; (*s_sizeOfShare) = 0; }
	static	void	AddSharedFile(uint64 size)		{ ++(*s_numberOfShared); (*s_sizeOfShare) += size; }
	static	void	RemoveSharedFile(uint64 size)		{ --(*s_numberOfShared); (*s_sizeOfShare) -= size; }
	static	uint32	GetSharedFileCount()			{ return (*s_numberOfShared); }

	// Kad nodes
	static void	AddKadNode()				{ ++s_kadNodesCur; }
	static void	RemoveKadNode()				{ --s_kadNodesCur; }
	static uint16_t GetKadNodes()			{ return s_kadNodesCur; }


	// Other
	static	void	CalculateRates();

	static	void	AddReceivedBytes(uint32 bytes)
		{
			if (!s_sinceFirstTransfer->IsRunning()) {
				s_sinceFirstTransfer->StartTimer();
			}

			(*s_sessionDownload) += bytes;
			(*s_downloadrate) += bytes;
			s_totalReceived += bytes;
			s_statsNeedSave = true;
		}

	static	void	AddSentBytes(uint32 bytes)
		{
			if (!s_sinceFirstTransfer->IsRunning()) {
				s_sinceFirstTransfer->StartTimer();
			}

			(*s_sessionUpload) += bytes;
			(*s_uploadrate) += bytes;
			s_totalSent += bytes;
			s_statsNeedSave = true;
		}

	static	void	AddDownloadFromSoft(uint8 SoftType, uint32 bytes);
	static	void	AddUploadToSoft(uint8 SoftType, uint32 bytes);

	// EC
	static	CECTag*	GetECStatTree(uint8 tree_capping_value)	{ return s_statTree->CreateECTag(tree_capping_value); }

	void SetAverageMinutes(uint8 minutes) { average_minutes = minutes; }

 private:
	std::list<HR>	listHR;
	typedef std::list<HR>::iterator		listPOS;
	typedef std::list<HR>::reverse_iterator	listRPOS;

	/* Graph-related functions */

	void ComputeAverages(HR **pphr, listRPOS pos, unsigned cntFilled,
		double sStep, const std::vector<float *> &ppf, StatsGraphType which_graph);

	int GetPointsPerRange()
	{
		return (1280/2) - 80; // This used to be a calc. based on GUI width
	}

	/* Graphs-related vars */

	CPreciseRateCounter	m_graphRunningAvgDown;
	CPreciseRateCounter	m_graphRunningAvgUp;
	CPreciseRateCounter	m_graphRunningAvgKad;


	uint8 average_minutes;
	int	nHistRanges;
	int	bitsHistClockMask;
	int	nPointsPerRange;
	listPOS*	aposRecycle;

	HR hrInit;

	/* Rate/Average counters */
	static	CPreciseRateCounter*		s_upOverheadRate;
	static	CPreciseRateCounter*		s_downOverheadRate;
	static	CStatTreeItemRateCounter*	s_uploadrate;
	static	CStatTreeItemRateCounter*	s_downloadrate;

	/* Tree-related functions */

	static	void	InitStatsTree();

	static	CStatTreeItemBase*	GetTreeRoot()	{ return s_statTree; }

	/* Tree-related vars */

	// the tree
	static	CStatTreeItemBase*		s_statTree;

	// Uptime
	static	CStatTreeItemTimer*		s_uptime;

	// Upload
	static	CStatTreeItemUlDlCounter*	s_sessionUpload;
	static	CStatTreeItemPacketTotals*	s_totalUpOverhead;
	static	CStatTreeItemPackets*		s_fileReqUpOverhead;
	static	CStatTreeItemPackets*		s_sourceXchgUpOverhead;
	static	CStatTreeItemPackets*		s_serverUpOverhead;
	static	CStatTreeItemPackets*		s_kadUpOverhead;
	static	CStatTreeItemCounter*		s_cryptUpOverhead;
	static	CStatTreeItemNativeCounter*	s_activeUploads;
	static	CStatTreeItemNativeCounter*	s_waitingUploads;
	static	CStatTreeItemCounter*		s_totalSuccUploads;
	static	CStatTreeItemCounter*		s_totalFailedUploads;
	static	CStatTreeItemCounter*		s_totalUploadTime;

	// Download
	static	CStatTreeItemUlDlCounter*	s_sessionDownload;
	static	CStatTreeItemPacketTotals*	s_totalDownOverhead;
	static	CStatTreeItemPackets*		s_fileReqDownOverhead;
	static	CStatTreeItemPackets*		s_sourceXchgDownOverhead;
	static	CStatTreeItemPackets*		s_serverDownOverhead;
	static	CStatTreeItemPackets*		s_kadDownOverhead;
	static	CStatTreeItemCounter*		s_cryptDownOverhead;
	static	CStatTreeItemCounter*		s_foundSources;
	static	CStatTreeItemNativeCounter*	s_activeDownloads;

	// Connection
	static	CStatTreeItemReconnects*	s_reconnects;
	static	CStatTreeItemTimer*		s_sinceFirstTransfer;
	static	CStatTreeItemTimer*		s_sinceConnected;
	static	CStatTreeItemCounterMax*	s_activeConnections;
	static	CStatTreeItemMaxConnLimitReached* s_limitReached;
	static	CStatTreeItemSimple*		s_avgConnections;

	// Clients
	static	CStatTreeItemHiddenCounter*	s_clients;
	static	CStatTreeItemCounter*		s_unknown;
	//static	CStatTreeItem			s_lowID;
	//static	CStatTreeItem			s_secIdentOnOff;
#ifdef __DEBUG__
	static	CStatTreeItemNativeCounter*	s_hasSocket;
#endif
	static	CStatTreeItemNativeCounter*	s_filtered;
	static	CStatTreeItemNativeCounter*	s_banned;

	// Servers
	static	CStatTreeItemSimple*		s_workingServers;
	static	CStatTreeItemSimple*		s_failedServers;
	static	CStatTreeItemNativeCounter*	s_totalServers;
	static	CStatTreeItemNativeCounter*	s_deletedServers;
	static	CStatTreeItemNativeCounter*	s_filteredServers;
	static	CStatTreeItemSimple*		s_usersOnWorking;
	static	CStatTreeItemSimple*		s_filesOnWorking;
	static	CStatTreeItemSimple*		s_totalUsers;
	static	CStatTreeItemSimple*		s_totalFiles;
	static	CStatTreeItemSimple*		s_serverOccupation;

	// Shared files
	static	CStatTreeItemCounter*		s_numberOfShared;
	static	CStatTreeItemCounter*		s_sizeOfShare;

	// Kad nodes
	static	uint64_t	s_kadNodesTotal;
	static	uint16_t	s_kadNodesCur;

	// Total sent/received bytes
	static	uint64_t	s_totalSent;
	static	uint64_t	s_totalReceived;

	static	bool		s_statsNeedSave;
};

#else /* CLIENT_GUI */

class CECPacket;
class CRemoteConnect;

enum StatDataIndex {
	sdUpload,
	sdUpOverhead,
	sdDownload,
	sdDownOverhead,
	sdWaitingClients,
	sdBannedClients,
	sdED2KUsers,
	sdKadUsers,
	sdED2KFiles,
	sdKadFiles,
	sdKadFirewalledUDP,
	sdKadIndexedSources,
	sdKadIndexedKeywords,
	sdKadIndexedNotes,
	sdKadIndexedLoad,
	sdKadIPAdress,
	sdKadNodes,
	sdBuddyStatus,
	sdBuddyIP,
	sdBuddyPort,
	sdKadInLanMode,
	sdTotalSentBytes,
	sdTotalReceivedBytes,
	sdSharedFileCount,

	sdTotalItems
};

class CStatistics {
	friend class CStatisticsDlg;	// to access CStatistics::GetTreeRoot()

private:
	CRemoteConnect &m_conn;
	static CStatTreeItemBase* s_statTree;
	static uint64 s_start_time;
	static uint64 s_statData[sdTotalItems];
	uint8 average_minutes;

 public:
	CStatistics(CRemoteConnect &conn);
	~CStatistics();

	static	uint64	GetUptimeMillis();
	static	uint64	GetUptimeSeconds();

	static	uint64	GetTotalSentBytes()			{ return s_statData[sdTotalSentBytes]; }
	static	double	GetUploadRate()				{ return (double)s_statData[sdUpload]; }
	static	double	GetUpOverheadRate()			{ return (double)s_statData[sdUpOverhead]; }

	static	uint64	GetTotalReceivedBytes()			{ return s_statData[sdTotalReceivedBytes]; }
	static	double	GetDownloadRate()			{ return (double)s_statData[sdDownload]; }
	static	double	GetDownOverheadRate()			{ return (double)s_statData[sdDownOverhead]; }

	static	uint32	GetWaitingUserCount()			{ return s_statData[sdWaitingClients]; }
	static	uint32	GetBannedCount()			{ return s_statData[sdBannedClients]; }

	static	uint32	GetSharedFileCount()			{ return s_statData[sdSharedFileCount]; }

	static	uint32	GetED2KUsers()			{ return s_statData[sdED2KUsers]; }
	static	uint32	GetKadUsers()			{ return s_statData[sdKadUsers]; }
	static	uint32	GetED2KFiles()			{ return s_statData[sdED2KFiles]; }
	static	uint32	GetKadFiles()			{ return s_statData[sdKadFiles]; }

	static	bool	IsFirewalledKadUDP()	{ return s_statData[sdKadFirewalledUDP] != 0; }
	static	uint32	GetKadIndexedSources()	{ return s_statData[sdKadIndexedSources]; }
	static	uint32	GetKadIndexedKeywords()	{ return s_statData[sdKadIndexedKeywords]; }
	static	uint32	GetKadIndexedNotes()	{ return s_statData[sdKadIndexedNotes]; }
	static	uint32	GetKadIndexedLoad()		{ return s_statData[sdKadIndexedLoad]; }
	static	uint32	GetKadIPAdress()		{ return s_statData[sdKadIPAdress]; }
	static	uint8	GetBuddyStatus()		{ return s_statData[sdBuddyStatus]; }
	static	uint32	GetBuddyIP()			{ return s_statData[sdBuddyIP]; }
	static	uint32	GetBuddyPort()			{ return s_statData[sdBuddyPort]; }
	static	bool	IsKadRunningInLanMode()	{ return s_statData[sdKadInLanMode] != 0; }
	static	uint32	GetKadNodes()			{ return s_statData[sdKadNodes]; }

	static	void	UpdateStats(const CECPacket* stats);

	void	UpdateStatsTree();
	void	RebuildStatTreeRemote(const CECTag *);
	void	SetAverageMinutes(uint8 minutes)	{ average_minutes = minutes; }

 private:
	static	CStatTreeItemBase*	GetTreeRoot()		{ return s_statTree; }
};

#endif /* !CLIENT_GUI / CLIENT_GUI */


/**
 * Shortcut for CStatistics
 */
typedef	CStatistics	theStats;

#endif // STATISTICS_H
// File_checked_for_headers