Changeset 9494 in orxonox.OLD for trunk/src/lib/network/monitor/connection_monitor.cc
- Timestamp:
- Jul 27, 2006, 10:44:28 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/monitor/connection_monitor.cc
r9406 r9494 32 32 /* set the class id for the base object and add ist to class list*/ 33 33 this->setClassID(CL_CONNECTION_MONITOR, "ConnectionMonitor"); 34 34 35 35 this->userId = userId; 36 36 this->ping = 0; … … 43 43 this->nZIncomingPackets = 0; 44 44 this->nZOutgoingPackets = 0; 45 45 46 46 this->lastPacketTick = 0; 47 47 this->lastPrintTick = 0; … … 64 64 { 65 65 nOutgoingPackets++; 66 66 67 67 // for ping calculation 68 68 sentStateTicks[stateId] = tick; 69 69 70 70 // calculate bandwidth 71 71 outgoingUnzippedPacketHistory[tick] = length; 72 72 outgoingUnzippedBandWidth = calculateBandWidth( outgoingUnzippedPacketHistory, tick ); 73 73 74 74 //NETPRINTF(n)("UNZIPPED UPSTREAM: user: %d bandwidth %f\n", userId, outgoingUnzippedBandWidth ); 75 75 76 76 // count zero bytes 77 77 //int nZeroBytes = 0; 78 78 79 79 //for ( int i = 0; i < length; i++ ) 80 80 // if ( data[i] == '\0' ) 81 81 // nZeroBytes++; 82 82 83 83 //NETPRINTF(n)( "ZEROBYTES: %d (%f%%)\n", nZeroBytes, ((float)100)*nZeroBytes/length ); 84 84 } … … 94 94 { 95 95 nIncomingPackets++; 96 96 97 97 lastPacketTick = tick; 98 98 99 99 // calculate ping 100 100 if ( sentStateTicks.find( ackedState ) != sentStateTicks.end() ) … … 102 102 ackDelay.push_back( tick - sentStateTicks[ackedState] ); 103 103 } 104 104 105 105 while ( sentStateTicks.begin() != sentStateTicks.end() && sentStateTicks.begin()->first <= ackedState ) 106 106 sentStateTicks.erase( sentStateTicks.begin() ); 107 107 108 108 while ( ackDelay.size() > N_PACKETS_FOR_PING ) 109 109 ackDelay.erase( ackDelay.begin() ); 110 110 111 111 ping = 0; 112 112 113 113 for ( std::list<int>::iterator it = ackDelay.begin(); it != ackDelay.end(); it++ ) 114 114 ping += *it; 115 115 116 116 if ( ackDelay.size() == 0 ) 117 117 ping = -1; 118 118 else 119 119 ping /= ackDelay.size(); 120 120 121 121 //NETPRINTF(n)("PING: user: %d ping: %d\n", userId, ping ); 122 122 123 123 // calculate bandwidth 124 124 incomingUnzippedPacketHistory[tick] = length; 125 125 incomingUnzippedBandWidth = calculateBandWidth( incomingUnzippedPacketHistory, tick ); 126 126 127 127 //NETPRINTF(n)("UNZIPPED DOWNSTREAM: user: %d bandwidth %f\n", userId, incomingUnzippedBandWidth ); 128 128 129 129 } 130 130 131 131 /** 132 132 * remove old packets 133 * @param packetHistory 134 * @param tick 133 * @param packetHistory 134 * @param tick 135 135 */ 136 136 void ConnectionMonitor::removeOldPackets( std::map< int, int > & packetHistory, int tick ) … … 149 149 { 150 150 removeOldPackets( packetHistory, tick ); 151 151 152 152 float res = 0.0f; 153 153 #if 0 … … 157 157 res += it->second; 158 158 } 159 159 160 160 if ( packetHistory.size() <= 1 || tick - packetHistory.begin()->first == 0 ) 161 161 res = 0.0f; 162 162 else 163 163 res /= (float)(tick - packetHistory.begin()->first); 164 164 165 165 res *= 1000.0f; 166 166 #endif 167 167 168 for ( std::map<int,int>:: iterator it = packetHistory.begin(); it != packetHistory.end(); it++ )168 for ( std::map<int,int>::const_iterator it = packetHistory.begin(); it != packetHistory.end(); it++ ) 169 169 { 170 170 res += it->second; 171 171 } 172 172 173 173 if ( packetHistory.size() <= 1 ) 174 174 res = 0.0f; 175 175 else 176 176 res /= (float)(tick - packetHistory.begin()->first); 177 177 178 178 res *= 1000.0f; 179 179 … … 191 191 { 192 192 nZOutgoingPackets++; 193 193 194 194 // calculate bandwidth 195 195 outgoingZippedPacketHistory[tick] = length; 196 196 outgoingZippedBandWidth = calculateBandWidth( outgoingZippedPacketHistory, tick ); 197 197 198 198 //NETPRINTF(n)("UPSTREAM: user: %d bandwidth %f nOutgoingPackets %d\n", userId, outgoingZippedBandWidth, nOutgoingPackets ); 199 199 … … 216 216 { 217 217 nZIncomingPackets++; 218 218 219 219 // calculate bandwidth 220 220 incomingZippedPacketHistory[tick] = length; 221 221 incomingZippedBandWidth = calculateBandWidth( incomingZippedPacketHistory, tick ); 222 222 223 223 //NETPRINTF(n)("DOWNSTREAM: user: %d bandwidth %f nIncomingPackets %d\n", userId, incomingZippedBandWidth, nIncomingPackets ); 224 224 225 225 } 226 226 … … 230 230 * @return true if last packet recieved \< NOW() - SECS_TO_TIMEOUT 231 231 */ 232 bool ConnectionMonitor::hasTimedOut( ) 232 bool ConnectionMonitor::hasTimedOut( ) const 233 233 { 234 234 if ( lastPacketTick + SECS_TO_TIMEOUT*1000 < SDL_GetTicks() && nIncomingPackets > 0 ) 235 235 return true; 236 236 237 237 if ( nIncomingPackets == 0 && nOutgoingPackets >= NETWORK_FREQUENCY*SECS_TO_TIMEOUT ) 238 238 return true; 239 239 240 240 return false; 241 241 } … … 246 246 * prints bandwith usage, ping and other important things to telnet-console 247 247 */ 248 void ConnectionMonitor::printStatis( ) 248 void ConnectionMonitor::printStatis( ) const 249 249 { 250 250 NETPRINT(n)("============NETWORKSTATS FOR USER %d============\n", userId);
Note: See TracChangeset
for help on using the changeset viewer.