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 | ObjectListDeclaration(ConnectionMonitor); |
---|
22 | public: |
---|
23 | ConnectionMonitor( int userId ); |
---|
24 | virtual ~ConnectionMonitor(); |
---|
25 | |
---|
26 | void processUnzippedOutgoingPacket( int tick, byte * data, int length, int stateId ); |
---|
27 | void processUnzippedIncomingPacket( int tick, byte * data, int length, int stateId, int ackedState ); |
---|
28 | |
---|
29 | void processZippedOutgoingPacket( int tick, byte * data, int length, int stateId ); |
---|
30 | void processZippedIncomingPacket( int tick, byte * data, int length ); |
---|
31 | |
---|
32 | void calculatePing(); |
---|
33 | |
---|
34 | bool hasTimedOut() const; |
---|
35 | |
---|
36 | void printStatis() const; |
---|
37 | float getIncomingUnzippedBandWidth() const { return incomingUnzippedBandWidth; } |
---|
38 | float getOutgoingUnzippedBandWidth() const { return outgoingUnzippedBandWidth; } |
---|
39 | float getIncomingZippedBandWidth() const { return incomingZippedBandWidth; } |
---|
40 | float getOutgoingZippedBandWidth() const { return outgoingZippedBandWidth; } |
---|
41 | |
---|
42 | private: |
---|
43 | float calculateBandWidth( std::map<int,int> & packetHistory, int tick ); |
---|
44 | void removeOldPackets( std::map<int,int> & packetHistory, int tick ); |
---|
45 | |
---|
46 | int userId; //!< user's id |
---|
47 | |
---|
48 | std::map<int,int> sentStateTicks; |
---|
49 | |
---|
50 | std::map<int,int> incomingUnzippedPacketHistory; |
---|
51 | std::map<int,int> outgoingUnzippedPacketHistory; |
---|
52 | |
---|
53 | std::map<int,int> incomingZippedPacketHistory; |
---|
54 | std::map<int,int> outgoingZippedPacketHistory; |
---|
55 | |
---|
56 | std::list<int> ackDelay; |
---|
57 | int ping; |
---|
58 | |
---|
59 | float incomingUnzippedBandWidth; |
---|
60 | float outgoingUnzippedBandWidth; |
---|
61 | |
---|
62 | float incomingZippedBandWidth; |
---|
63 | float outgoingZippedBandWidth; |
---|
64 | |
---|
65 | int nIncomingPackets; |
---|
66 | int nOutgoingPackets; |
---|
67 | |
---|
68 | int nZIncomingPackets; |
---|
69 | int nZOutgoingPackets; |
---|
70 | |
---|
71 | int lastPacketTick; |
---|
72 | |
---|
73 | int lastPrintTick; |
---|
74 | }; |
---|
75 | |
---|
76 | #endif |
---|