Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9494 in orxonox.OLD for trunk/src/lib/network/monitor


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

merged the proxy back

Location:
trunk/src/lib/network/monitor
Files:
6 edited
2 copied

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);
  • trunk/src/lib/network/monitor/connection_monitor.h

    r9406 r9494  
    3131    void calculatePing();
    3232
    33     bool hasTimedOut();
     33    bool hasTimedOut() const;
    3434
    35     void printStatis();
     35    void printStatis() const;
     36    float getIncomingUnzippedBandWidth() const { return incomingUnzippedBandWidth; }
     37    float getOutgoingUnzippedBandWidth() const { return outgoingUnzippedBandWidth; }
     38    float getIncomingZippedBandWidth() const { return incomingZippedBandWidth; }
     39    float getOutgoingZippedBandWidth() const { return outgoingZippedBandWidth; }
    3640
    3741  private:
  • trunk/src/lib/network/monitor/network_monitor.cc

    r9406 r9494  
    3131
    3232
    33 SHELL_COMMAND(showGUI, NetworkMonitor, showGUI);
    34 SHELL_COMMAND(hideGUI, NetworkMonitor, hideGUI);
     33#include "network_stats_widget.h"
     34
     35SHELL_COMMAND(gui, NetworkMonitor, toggleGUI)
     36 ->setAlias("ProxyGui");
    3537SHELL_COMMAND(debug, NetworkMonitor, debug);
    3638
     
    5759  {
    5860    // assuming that the config files are already read we get the proxy servers
    59     std::vector<IPaddress*>* proxyList = NetworkSettings::getInstance()->getProxyList();
    60     std::vector<IPaddress*>::iterator it = proxyList->begin();
     61    std::vector<IP>* proxyList = NetworkSettings::getInstance()->getProxyList();
     62    std::vector<IP>::iterator it = proxyList->begin();
    6163    // create a peer info class and a network node class for each new proxy and add them to the passive list
    6264    for(; it < proxyList->end(); it++)
    6365    {
    6466      PeerInfo* peer = new PeerInfo();
    65       peer->ip = *(*it);
     67      peer->ip = (*it);
    6668      peer->nodeType = NET_PROXY_SERVER_ACTIVE;
    6769      peer->userId = -1;
     
    7274    }
    7375  }
     76  this->box = NULL;
    7477}
    7578
     
    119122 * @param ip ip of the new node
    120123 */
    121 void NetworkMonitor::addNode(IP ip, int nodeType)
     124void NetworkMonitor::addNode(const IP& ip, int nodeType)
    122125{
    123126  PeerInfo* pInfo = new PeerInfo();
     
    140143  if( pInfo->isClient())
    141144    this->localNode->addClient(pInfo);
    142   else if( pInfo->isProxyServer())
     145  else if( pInfo->isProxyServerActive())
    143146  {
    144147    this->localNode->addActiveProxyServer(pInfo);
     
    166169  if( pInfo->isClient())
    167170    node->addClient(pInfo);
    168   else if( pInfo->isProxyServer())
     171  else if( pInfo->isProxyServerActive())
    169172    node->addActiveProxyServer(pInfo);
    170173  else if( pInfo->isMasterServer())
     
    176179 * @returns the proxy server of the first choice
    177180 */
    178 PeerInfo* NetworkMonitor::getFirstChoiceProxy()
     181PeerInfo* NetworkMonitor::getFirstChoiceProxy() const
    179182{
    180183  // return the fist proxy in the list
     
    186189 * @returns the proxy server of second choice
    187190 */
    188 PeerInfo* NetworkMonitor::getSecondChoiceProxy()
     191PeerInfo* NetworkMonitor::getSecondChoiceProxy() const
    189192{
    190193  // return the second server in the list
     
    196199 * this displays the network monitor gui
    197200 */
    198 void NetworkMonitor::showGUI()
     201void NetworkMonitor::toggleGUI()
    199202{
    200203  if (this->box == NULL)
     
    202205    this->box = new OrxGui::GLGuiBox(OrxGui::Vertical);
    203206    {
    204       OrxGui::GLGuiBox* waterColorBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
    205       {
    206         OrxGui::GLGuiText* waterColorText = new OrxGui::GLGuiText();
    207         waterColorText->setText("NetworkMonitor");
    208         waterColorBox->pack(waterColorText);
    209       }
    210       this->box->pack(waterColorBox);
     207      NetworkStatsWidget* netStats = new NetworkStatsWidget(this);
     208      this->box->pack(netStats);
     209
    211210    }
    212211
    213212    this->box->showAll();
    214213    this->box->setAbsCoor2D(300, 40);
    215     OrxGui::GLGuiHandler::getInstance()->activate();
    216 //     OrxGui::GLGuiHandler::getInstance()->activateCursor();
    217   }
    218 }
    219 
    220 
    221 /**
    222  * hides the network monitor gui again
    223  */
    224 void NetworkMonitor::hideGUI()
    225 {
    226   if( this->box == NULL)
    227     return;
    228 
    229   OrxGui::GLGuiHandler::getInstance()->deactivate();
    230 //   OrxGui::GLGuiHandler::getInstance()->deactivateCursor();
    231 
    232   delete this->box;
    233   this->box = NULL;
    234 }
    235 
     214  }
     215  else
     216  {
     217    delete this->box;
     218    this->box = NULL;
     219  }
     220}
    236221
    237222/**
     
    255240 * prints out the debug informations
    256241 */
    257 void NetworkMonitor::debug()
     242void NetworkMonitor::debug() const
    258243{
    259244  PRINT(0)("================================= Network Monitor::debug() =====\n");
    260245  PRINT(0)(" I am: %s\n", this->localNode->getPeerInfo()->getNodeTypeString().c_str());
    261   PRINT(0)(" Total count of network connections: %i\n", this->playerNumber);
     246  PRINT(0)(" Total count of network connections: %i\n", this->connectionNumber);
     247  PRINT(0)(" Total count of players: %i\n", this->playerNumber);
    262248  PRINT(0)(" Max players on this server: %i\n", SharedNetworkData::getInstance()->getMaxPlayer());
    263249
    264   std::list<NetworkNode*>::iterator it = this->nodeList.begin();
     250  std::list<NetworkNode*>::const_iterator it = this->nodeList.begin();
    265251  for(; it != this->nodeList.end(); it++)
    266252  {
  • trunk/src/lib/network/monitor/network_monitor.h

    r9406 r9494  
    3737
    3838    void addNode(PeerInfo* pInfo);
    39     void addNode(IP ip, int nodeType);
     39    void addNode(const IP& ip, int nodeType);
    4040    void addNode(NetworkNode* node) { this->nodeList.push_back(node); }
    4141    void addNode(NetworkNode* node, PeerInfo* pInfo);
     
    5555    inline void removeMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->removeMasterServer(pInfo); }
    5656
    57     PeerInfo* getFirstChoiceProxy();
    58     PeerInfo* getSecondChoiceProxy();
     57    PeerInfo* getFirstChoiceProxy() const;
     58    PeerInfo* getSecondChoiceProxy() const;
     59    /** @returns the local node */
     60    inline NetworkNode* getLocalNode() const { return this->localNode; };
    5961
    6062    /** @returns the active proxy server list of the localnode */
    61     inline std::list<PeerInfo*> getActiveProxyServer() { return this->localNode->getActiveProxyServer(); }
     63    inline std::list<PeerInfo*> getActiveProxyServer() const { return this->localNode->getActiveProxyServer(); }
    6264
    6365    /* slots admin and info interface */
    6466    /** @returns the total number of players in this game (including all proxy servers etc)*/
    65     inline int getPlayerNumber() { return this->playerNumber; }
     67    inline int getPlayerNumber() const { return this->playerNumber; }
    6668
    6769    /** @returns true if there are still free network slots available at the local node*/
    68     inline bool gotFreeSlots() { return (this->localNode->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer())?true:false; }
     70    inline bool gotFreeSlots() const { return (this->localNode->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer()); }
    6971    /** @param node node to be checked for slots @returns true if there are still free network slots available at this node */
    70     inline bool gotFreeSlots(NetworkNode* node) { return (node->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer())?true:false; }
     72    inline bool gotFreeSlots(NetworkNode* node) const { return (node->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer()); }
    7173
    7274    /** @returns true if the next client should be reconnected to some other proxy server with more connections */
    73     inline bool isReconnectNextClient() { return (this->localNode->getPlayerNumber() >= SharedNetworkData::getInstance()->getMaxPlayer())?true:false; }
     75    inline bool isReconnectNextClient() const { return (this->localNode->getPlayerNumber() >= SharedNetworkData::getInstance()->getMaxPlayer()); }
    7476
     77    inline const std::list<NetworkNode*>& getNodeList() const { return this->nodeList; };
    7578
    76     void showGUI();
    77     void hideGUI();
     79    void toggleGUI();
    7880
    7981    void process();
    80     void debug();
     82    void debug() const;
    8183
    8284
  • trunk/src/lib/network/monitor/network_node.cc

    r9406 r9494  
    152152 * @return the client in the list or NULL if none
    153153 */
    154 PeerInfo* NetworkNode::getClient(int index)
     154PeerInfo* NetworkNode::getClient(int index) const
    155155{
    156156  if( this->clientList.size() < index)
    157157    return NULL;
    158158
    159   std::list<PeerInfo*>::iterator it = this->clientList.begin();
     159  std::list<PeerInfo*>::const_iterator it = this->clientList.begin();
    160160  for(int i = 0; it != this->clientList.end(); it++, i++)
    161161  {
     
    172172 * @return the active proxy server in the list or NULL if none
    173173 */
    174 PeerInfo* NetworkNode::getActiveProxyServer(int index)
     174PeerInfo* NetworkNode::getActiveProxyServer(int index) const
    175175{
    176176  if( this->activeProxyServerList.size() < index)
    177177    return NULL;
    178178
    179   std::list<PeerInfo*>::iterator it = this->activeProxyServerList.begin();
     179  std::list<PeerInfo*>::const_iterator it = this->activeProxyServerList.begin();
    180180  for(int i = 0; it != this->activeProxyServerList.end(); it++, i++)
    181181  {
     
    192192 * @return the passive proxy server in the list or NULL if none
    193193 */
    194 PeerInfo* NetworkNode::getPassiveProxyServer(int index)
     194PeerInfo* NetworkNode::getPassiveProxyServer(int index) const
    195195{
    196196  if( this->passiveProxyServerList.size() < index)
    197197    return NULL;
    198198
    199   std::list<PeerInfo*>::iterator it = this->passiveProxyServerList.begin();
     199  std::list<PeerInfo*>::const_iterator it = this->passiveProxyServerList.begin();
    200200  for(int i = 0; it != this->passiveProxyServerList.end(); it++, i++)
    201201  {
     
    212212 * @return the master server in the list or NULL if none
    213213 */
    214 PeerInfo* NetworkNode::getMasterServer(int index)
     214PeerInfo* NetworkNode::getMasterServer(int index) const
    215215{
    216216  if( this->masterServerList.size() < index)
    217217    return NULL;
    218218
    219   std::list<PeerInfo*>::iterator it = this->masterServerList.begin();
     219  std::list<PeerInfo*>::const_iterator it = this->masterServerList.begin();
    220220  for(int i = 0; it != this->masterServerList.end(); it++, i++)
    221221  {
     
    232232 * @param depth: depth in the tree
    233233 */
    234 void NetworkNode::debug(int depth)
     234void NetworkNode::debug(int depth) const
    235235{
    236236  PRINT(0)(" = %s\n", this->peerInfo->getNodeTypeString().c_str());
    237237
    238238  PRINT(0)("    master servers: %i\n", this->masterServerList.size());
    239   std::list<PeerInfo*>::iterator it = this->masterServerList.begin();
     239  std::list<PeerInfo*>::const_iterator it = this->masterServerList.begin();
    240240  for(; it != this->masterServerList.end(); it++)
    241241  {
  • trunk/src/lib/network/monitor/network_node.h

    r9406 r9494  
    3232    void removeMasterServer(PeerInfo* node);
    3333
    34     PeerInfo* getClient(int index);
    35     PeerInfo* getActiveProxyServer(int index);
    36     PeerInfo* getPassiveProxyServer(int index);
    37     PeerInfo* getMasterServer(int index);
     34    PeerInfo* getClient(int index) const;
     35    PeerInfo* getActiveProxyServer(int index) const;
     36    PeerInfo* getPassiveProxyServer(int index) const;
     37    PeerInfo* getMasterServer(int index) const;
    3838
    3939    /** @returns the master server list */
    40     inline std::list<PeerInfo*> getMasterServer() { return this->masterServerList; }
     40    inline std::list<PeerInfo*> getMasterServer() const { return this->masterServerList; }
    4141    /** @returns the active proxy server list */
    42     inline std::list<PeerInfo*> getActiveProxyServer() { return this->activeProxyServerList; }
     42    inline std::list<PeerInfo*> getActiveProxyServer() const { return this->activeProxyServerList; }
    4343    /** @returns the passive proxy server list */
    44     inline std::list<PeerInfo*> getPassiveProxyServer() { return this->passiveProxyServerList; }
     44    inline std::list<PeerInfo*> getPassiveProxyServer() const { return this->passiveProxyServerList; }
    4545    /** @returns the client list */
    46     inline std::list<PeerInfo*> getClient() { return this->clientList; }
     46    inline std::list<PeerInfo*> getClient() const { return this->clientList; }
    4747
    4848
    4949    /** @returns the number of players */
    50     inline int getPlayerNumber() { return this->playerNumber; }
     50    inline int getPlayerNumber() const { return this->playerNumber; }
    5151    /** @returns the node type of this node */
    52     inline int getNodeType() { return this->peerInfo->nodeType; }
     52    inline int getNodeType() const { return this->peerInfo->nodeType; }
    5353    /** @returns the peer info of this node */
    54     inline PeerInfo* getPeerInfo() { return this->peerInfo; }
     54    inline PeerInfo* getPeerInfo() const { return this->peerInfo; }
    5555
    56     void debug(int depth);
     56    void debug(int depth) const;
    5757
    5858
     
    6060    int                          playerNumber;                 //!< localy direct connected player number
    6161    int                          connectionNumber;             //!< number of connections ( can but musn't be equal players)
    62     PeerInfo*                    peerInfo;                     //!< the peer informationa about this node
     62    PeerInfo*                    peerInfo;                     //!< the peer information about this node
    6363
    6464    /* network nodes directly connected to this node */
Note: See TracChangeset for help on using the changeset viewer.