Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 27, 2006, 10:44:28 AM (18 years ago)
Author:
bensch
Message:

merged the proxy back

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/network/monitor/connection_monitor.cc

    r9406 r9494  
    3232  /* set the class id for the base object and add ist to class list*/
    3333  this->setClassID(CL_CONNECTION_MONITOR, "ConnectionMonitor");
    34  
     34
    3535  this->userId = userId;
    3636  this->ping = 0;
     
    4343  this->nZIncomingPackets = 0;
    4444  this->nZOutgoingPackets = 0;
    45  
     45
    4646  this->lastPacketTick = 0;
    4747  this->lastPrintTick = 0;
     
    6464{
    6565  nOutgoingPackets++;
    66  
     66
    6767  // for ping calculation
    6868  sentStateTicks[stateId] = tick;
    69  
     69
    7070  // calculate bandwidth
    7171  outgoingUnzippedPacketHistory[tick] = length;
    7272  outgoingUnzippedBandWidth = calculateBandWidth( outgoingUnzippedPacketHistory, tick );
    73  
     73
    7474  //NETPRINTF(n)("UNZIPPED UPSTREAM: user: %d bandwidth %f\n", userId, outgoingUnzippedBandWidth );
    75  
     75
    7676  // count zero bytes
    7777  //int nZeroBytes = 0;
    78  
     78
    7979  //for ( int i = 0; i < length; i++ )
    8080  //  if ( data[i] == '\0' )
    8181  //    nZeroBytes++;
    82  
     82
    8383  //NETPRINTF(n)( "ZEROBYTES: %d (%f%%)\n", nZeroBytes, ((float)100)*nZeroBytes/length );
    8484}
     
    9494{
    9595  nIncomingPackets++;
    96  
     96
    9797  lastPacketTick = tick;
    98  
     98
    9999  // calculate ping
    100100  if ( sentStateTicks.find( ackedState ) != sentStateTicks.end() )
     
    102102    ackDelay.push_back( tick - sentStateTicks[ackedState] );
    103103  }
    104  
     104
    105105  while ( sentStateTicks.begin() != sentStateTicks.end() && sentStateTicks.begin()->first <= ackedState )
    106106    sentStateTicks.erase( sentStateTicks.begin() );
    107      
     107
    108108  while ( ackDelay.size() > N_PACKETS_FOR_PING )
    109109    ackDelay.erase( ackDelay.begin() );
    110      
     110
    111111  ping = 0;
    112      
     112
    113113  for ( std::list<int>::iterator it = ackDelay.begin(); it != ackDelay.end(); it++ )
    114114    ping += *it;
    115      
     115
    116116  if ( ackDelay.size() == 0 )
    117117    ping = -1;
    118118  else
    119119    ping /= ackDelay.size();
    120      
     120
    121121  //NETPRINTF(n)("PING: user: %d ping: %d\n", userId, ping );
    122  
     122
    123123  // calculate bandwidth
    124124  incomingUnzippedPacketHistory[tick] = length;
    125125  incomingUnzippedBandWidth = calculateBandWidth( incomingUnzippedPacketHistory, tick );
    126  
     126
    127127  //NETPRINTF(n)("UNZIPPED DOWNSTREAM: user: %d bandwidth %f\n", userId, incomingUnzippedBandWidth );
    128  
     128
    129129}
    130130
    131131/**
    132132 * remove old packets
    133  * @param packetHistory 
    134  * @param tick 
     133 * @param packetHistory
     134 * @param tick
    135135 */
    136136void ConnectionMonitor::removeOldPackets( std::map< int, int > & packetHistory, int tick )
     
    149149{
    150150  removeOldPackets( packetHistory, tick );
    151  
     151
    152152  float res = 0.0f;
    153153#if 0
     
    157157      res += it->second;
    158158  }
    159  
     159
    160160  if ( packetHistory.size() <= 1 || tick - packetHistory.begin()->first == 0 )
    161161    res = 0.0f;
    162162  else
    163163    res /= (float)(tick - packetHistory.begin()->first);
    164  
     164
    165165  res *= 1000.0f;
    166166#endif
    167167
    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++ )
    169169  {
    170170    res += it->second;
    171171  }
    172  
     172
    173173  if ( packetHistory.size() <= 1 )
    174174    res = 0.0f;
    175175  else
    176176    res /= (float)(tick - packetHistory.begin()->first);
    177  
     177
    178178  res *= 1000.0f;
    179179
     
    191191{
    192192  nZOutgoingPackets++;
    193  
     193
    194194  // calculate bandwidth
    195195  outgoingZippedPacketHistory[tick] = length;
    196196  outgoingZippedBandWidth = calculateBandWidth( outgoingZippedPacketHistory, tick );
    197  
     197
    198198  //NETPRINTF(n)("UPSTREAM: user: %d bandwidth %f nOutgoingPackets %d\n", userId, outgoingZippedBandWidth, nOutgoingPackets );
    199199
     
    216216{
    217217  nZIncomingPackets++;
    218  
     218
    219219  // calculate bandwidth
    220220  incomingZippedPacketHistory[tick] = length;
    221221  incomingZippedBandWidth = calculateBandWidth( incomingZippedPacketHistory, tick );
    222  
     222
    223223  //NETPRINTF(n)("DOWNSTREAM: user: %d bandwidth %f nIncomingPackets %d\n", userId, incomingZippedBandWidth, nIncomingPackets );
    224  
     224
    225225}
    226226
     
    230230 * @return true if last packet recieved \< NOW() - SECS_TO_TIMEOUT
    231231 */
    232 bool ConnectionMonitor::hasTimedOut( )
     232bool ConnectionMonitor::hasTimedOut( ) const
    233233{
    234234  if ( lastPacketTick + SECS_TO_TIMEOUT*1000 < SDL_GetTicks() && nIncomingPackets > 0 )
    235235    return true;
    236  
     236
    237237  if ( nIncomingPackets == 0 && nOutgoingPackets >= NETWORK_FREQUENCY*SECS_TO_TIMEOUT )
    238238    return true;
    239  
     239
    240240  return false;
    241241}
     
    246246 * prints bandwith usage, ping and other important things to telnet-console
    247247 */
    248 void ConnectionMonitor::printStatis( )
     248void ConnectionMonitor::printStatis( ) const
    249249{
    250250  NETPRINT(n)("============NETWORKSTATS FOR USER %d============\n", userId);
Note: See TracChangeset for help on using the changeset viewer.