1 | /*! |
---|
2 | * @file connection_monitor.h |
---|
3 | \brief provides information about the quality of a connection. |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _CONNECTION_MONITOR_H |
---|
7 | #define _CONNECTION_MONITOR_H |
---|
8 | |
---|
9 | #include "base_object.h" |
---|
10 | #include "netdefs.h" |
---|
11 | |
---|
12 | #include <map> |
---|
13 | #include <list> |
---|
14 | |
---|
15 | #define N_PACKETS_FOR_PING 20 |
---|
16 | #define MSECS_TO_CALC_BWIDTH 1000 |
---|
17 | #define SECS_TO_TIMEOUT 30 |
---|
18 | |
---|
19 | class ConnectionMonitor : virtual public BaseObject |
---|
20 | { |
---|
21 | public: |
---|
22 | ConnectionMonitor( int userId ); |
---|
23 | virtual ~ConnectionMonitor(); |
---|
24 | |
---|
25 | void processUnzippedOutgoingPacket( int tick, byte * data, int length, int stateId ); |
---|
26 | void processUnzippedIncomingPacket( int tick, byte * data, int length, int stateId, int ackedState ); |
---|
27 | |
---|
28 | void processZippedOutgoingPacket( int tick, byte * data, int length, int stateId ); |
---|
29 | void processZippedIncomingPacket( int tick, byte * data, int length ); |
---|
30 | |
---|
31 | void calculatePing(); |
---|
32 | |
---|
33 | bool hasTimedOut(); |
---|
34 | |
---|
35 | void printStatis(); |
---|
36 | |
---|
37 | private: |
---|
38 | float calculateBandWidth( std::map<int,int> & packetHistory, int tick ); |
---|
39 | void removeOldPackets( std::map<int,int> & packetHistory, int tick ); |
---|
40 | |
---|
41 | int userId; //!< user's id |
---|
42 | |
---|
43 | std::map<int,int> sentStateTicks; |
---|
44 | |
---|
45 | std::map<int,int> incomingUnzippedPacketHistory; |
---|
46 | std::map<int,int> outgoingUnzippedPacketHistory; |
---|
47 | |
---|
48 | std::map<int,int> incomingZippedPacketHistory; |
---|
49 | std::map<int,int> outgoingZippedPacketHistory; |
---|
50 | |
---|
51 | std::list<int> ackDelay; |
---|
52 | int ping; |
---|
53 | |
---|
54 | float incomingUnzippedBandWidth; |
---|
55 | float outgoingUnzippedBandWidth; |
---|
56 | |
---|
57 | float incomingZippedBandWidth; |
---|
58 | float outgoingZippedBandWidth; |
---|
59 | |
---|
60 | int nIncomingPackets; |
---|
61 | int nOutgoingPackets; |
---|
62 | |
---|
63 | int nZIncomingPackets; |
---|
64 | int nZOutgoingPackets; |
---|
65 | |
---|
66 | int lastPacketTick; |
---|
67 | |
---|
68 | int lastPrintTick; |
---|
69 | }; |
---|
70 | |
---|
71 | #endif |
---|