Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Aug 4, 2006, 11:01:28 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the proxy bache back with no conflicts

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

Legend:

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

    r9494 r9656  
    1010
    1111### File Specific:
    12    main-programmer: Patrick Boenzli
     12   main-programmer: Patrick Boenzli (patrick@orxonox.ethz.ch)
    1313*/
    1414
     
    4949  this->networkStream = networkStream;
    5050  this->playerNumber = 0;
     51  this->connectionNumber = 0;
    5152  // create the localnode, init it and add it to the nodes list
    5253  this->localNode = new NetworkNode( this->networkStream->getPeerInfo());
     
    6667      PeerInfo* peer = new PeerInfo();
    6768      peer->ip = (*it);
    68       peer->nodeType = NET_PROXY_SERVER_ACTIVE;
     69      peer->nodeType = NET_PROXY_SERVER_PASSIVE;
    6970      peer->userId = -1;
    7071
    71       NetworkNode* node = new NetworkNode(peer);
    72       this->addNode( node);
    7372      this->addActiveProxyServer( this->localNode, peer);
    7473    }
     
    141140    return;
    142141
     142  PRINTF(0)("^^^^^^^^^^^^^^^^^^^^^^^^^^ adding node: %i with type: %s\n\n", pInfo->userId, pInfo->getNodeTypeString().c_str());
     143
    143144  if( pInfo->isClient())
    144     this->localNode->addClient(pInfo);
     145  {
     146    this->localNode->addClient(new NetworkNode(pInfo));
     147  }
    145148  else if( pInfo->isProxyServerActive())
    146149  {
    147     this->localNode->addActiveProxyServer(pInfo);
    148     // create a new node, since a proxy can connect clients again
    149     NetworkNode* node = new NetworkNode(pInfo);
    150     this->nodeList.push_back(node);
     150    this->localNode->addActiveProxyServer(new NetworkNode(pInfo));
     151  }
     152  else if( pInfo->isProxyServerActivePassive())
     153  {
     154    this->localNode->addPassiveProxyServer(new NetworkNode(pInfo));
    151155  }
    152156  else if( pInfo->isMasterServer())
    153157  {
    154     this->localNode->addMasterServer(pInfo);
    155   }
     158    this->localNode->addMasterServer(new NetworkNode(pInfo));
     159  }
     160  else
     161    assert(false);
    156162}
    157163
     
    168174
    169175  if( pInfo->isClient())
    170     node->addClient(pInfo);
     176    node->addClient(new NetworkNode(pInfo));
    171177  else if( pInfo->isProxyServerActive())
    172     node->addActiveProxyServer(pInfo);
     178    node->addActiveProxyServer(new NetworkNode(pInfo));
    173179  else if( pInfo->isMasterServer())
    174     node->addMasterServer(pInfo);
     180    node->addMasterServer(new NetworkNode(pInfo));
     181}
     182
     183
     184
     185/**
     186 * removes a node from the network monitor
     187 * @param pInfo the node to remove
     188 */
     189void NetworkMonitor::removeNode(PeerInfo* pInfo)
     190{
     191  this->removeNode(this->localNode, pInfo);
     192}
     193
     194
     195/**
     196 * removes the network node
     197 * @param node the network node where the PeerInfo node is connected to
     198 * @param pInfo the PeerInfo to remove
     199 */
     200void NetworkMonitor::removeNode(NetworkNode* node, PeerInfo* pInfo)
     201{
     202  if( node == NULL || pInfo == NULL)
     203    return;
     204
     205  if( pInfo->isClient())
     206    node->removeClient(pInfo->userId);
     207  else if( pInfo->isProxyServerActive())
     208    node->removeActiveProxyServer(pInfo->userId);
     209  else if( pInfo->isMasterServer())
     210    node->removeMasterServer(pInfo->userId);
    175211}
    176212
     
    197233
    198234/**
     235 * @param userId of the searched node
     236 * @returns the PeerInfo of the userId peer
     237 */
     238PeerInfo* NetworkMonitor::getPeerByUserId( int userId)
     239{
     240  NetworkNode* node = this->getNodeByUserId(userId);
     241  if( node != NULL)
     242    return node->getPeerInfo();
     243
     244  return NULL;
     245}
     246
     247/**
     248 * searches for a given NetworkNode
     249 * @param userId of the searched node
     250 * @returns the PeerInfo of the userId peer
     251 */
     252NetworkNode* NetworkMonitor::getNodeByUserId( int userId)
     253{
     254  std::list<NetworkNode*>::iterator it = this->nodeList.begin();
     255  NetworkNode* node = NULL;
     256  for(; it != this->nodeList.end(); it++)
     257  {
     258    node = (*it)->getNodeByUserId(userId);
     259    if( node != NULL)
     260      return node;
     261  }
     262
     263  return NULL;
     264}
     265
     266
     267/**
    199268 * this displays the network monitor gui
    200269 */
     
    203272  if (this->box == NULL)
    204273  {
    205     this->box = new OrxGui::GLGuiBox(OrxGui::Vertical);
    206     {
    207       NetworkStatsWidget* netStats = new NetworkStatsWidget(this);
    208       this->box->pack(netStats);
    209 
    210     }
    211 
     274    this->box = new NetworkStatsWidget(this);
    212275    this->box->showAll();
    213     this->box->setAbsCoor2D(300, 40);
    214276  }
    215277  else
     
    251313  for(; it != this->nodeList.end(); it++)
    252314  {
    253     (*it)->debug(0);
     315    (*it)->debug(1);
    254316  }
    255317
  • trunk/src/lib/network/monitor/network_monitor.h

    r9494 r9656  
    4242
    4343    /** adds to @param node a network node @param pInfo a new client */
    44     inline void addClient(NetworkNode* node, PeerInfo* pInfo) { node->addClient(pInfo); }
     44    inline void addClient(NetworkNode* node, PeerInfo* pInfo) { node->addClient(new NetworkNode(pInfo)); }
    4545    /** adds to @param node a network node @param pInfo a new proxy server */
    46     inline void addActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addActiveProxyServer(pInfo); }
     46    inline void addActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addActiveProxyServer(new NetworkNode(pInfo)); }
    4747    /** adds to @param node a network node @param pInfo a new proxy server */
    48     inline void addPassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addPassiveProxyServer(pInfo); }
     48    inline void addPassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addPassiveProxyServer(new NetworkNode(pInfo)); }
    4949    /** adds to @param node a network node @param pInfo a new master server*/
    50     inline void addMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->addMasterServer(pInfo); }
     50    inline void addMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->addMasterServer(new NetworkNode(pInfo)); }
    5151
    52     inline void removeClient(NetworkNode* node, PeerInfo* pInfo) { node->removeClient(pInfo); }
    53     inline void removeActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removeActiveProxyServer(pInfo); }
    54     inline void removePassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removePassiveProxyServer(pInfo); }
    55     inline void removeMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->removeMasterServer(pInfo); }
     52    void removeNode(PeerInfo* pInfo);
     53    void removeNode(NetworkNode* node, PeerInfo* pInfo);
     54
     55    inline void removeClient(NetworkNode* node, int userId) { node->removeClient(userId); }
     56    inline void removeActiveProxyServer(NetworkNode* node, int userId) { node->removeActiveProxyServer(userId); }
     57    inline void removePassiveProxyServer(NetworkNode* node, int userId) { node->removePassiveProxyServer(userId); }
     58    inline void removeMasterServer(NetworkNode* node, int userId) { node->removeMasterServer(userId); }
    5659
    5760    PeerInfo* getFirstChoiceProxy() const;
     
    6164
    6265    /** @returns the active proxy server list of the localnode */
    63     inline std::list<PeerInfo*> getActiveProxyServer() const { return this->localNode->getActiveProxyServer(); }
     66    inline std::list<NetworkNode*> getActiveProxyServers() const { return this->localNode->getActiveProxyServers(); }
    6467
    6568    /* slots admin and info interface */
     
    7679
    7780    inline const std::list<NetworkNode*>& getNodeList() const { return this->nodeList; };
     81    PeerInfo* getPeerByUserId( int userId);
     82    NetworkNode* getNodeByUserId( int userId);
     83
     84    /* forced reconnection interface */
     85    inline void setForcedReconnection(IP address) { this->bForcedRecon = true; this->forcedReconnection = address;}
     86    inline bool isForcedReconnection() const { return this->bForcedRecon; }
     87    inline IP getForcedReconnectionIP() { this->bForcedRecon = false; return this->forcedReconnection; }
     88
    7889
    7990    void toggleGUI();
     
    92103    int                          playerNumber;                 //!< total number of players in the game
    93104    int                          connectionNumber;             //!< total number of connections at this localhost
     105
     106    IP                           forcedReconnection;           //!< ip of a forced reconnection
     107    bool                         bForcedRecon;                 //!< true if there is a forced recon
    94108};
    95109
  • trunk/src/lib/network/monitor/network_node.cc

    r9494 r9656  
    1818#include "debug.h"
    1919
    20 
    2120/**
    2221 * constructor
     
    3938 * adds a client
    4039 */
    41 void NetworkNode::addClient(PeerInfo* node)
     40void NetworkNode::addClient(NetworkNode* node)
    4241{
    4342  this->clientList.push_back(node);
     
    4948 * adds a proxy server
    5049 */
    51 void NetworkNode::addActiveProxyServer(PeerInfo* node)
     50void NetworkNode::addActiveProxyServer(NetworkNode* node)
    5251{
    5352  this->activeProxyServerList.push_back(node);
     
    5857 * adds a proxy server
    5958 */
    60 void NetworkNode::addPassiveProxyServer(PeerInfo* node)
     59void NetworkNode::addPassiveProxyServer(NetworkNode* node)
    6160{
    6261  this->passiveProxyServerList.push_back(node);
     
    6665 * adds a master server
    6766 */
    68 void NetworkNode::addMasterServer(PeerInfo* node)
     67void NetworkNode::addMasterServer(NetworkNode* node)
    6968{
    7069  this->masterServerList.push_back(node);
     
    7574 * removes a client
    7675 */
    77 void NetworkNode::removeClient(PeerInfo* node)
    78 {
    79   std::list<PeerInfo*>::iterator it = this->clientList.begin();
     76void NetworkNode::removeClient(NetworkNode* node)
     77{
     78  std::list<NetworkNode*>::iterator it = this->clientList.begin();
    8079  for(; it != this->clientList.end(); it++)
    8180  {
     
    9493 * removes a proxy server
    9594 */
    96 void NetworkNode::removeActiveProxyServer(PeerInfo* node)
    97 {
    98   std::list<PeerInfo*>::iterator it = this->activeProxyServerList.begin();
     95void NetworkNode::removeActiveProxyServer(NetworkNode* node)
     96{
     97  std::list<NetworkNode*>::iterator it = this->activeProxyServerList.begin();
    9998  for(; it != this->activeProxyServerList.end(); it++)
    10099  {
     
    113112 * removes a proxy server
    114113 */
    115 void NetworkNode::removePassiveProxyServer(PeerInfo* node)
    116 {
    117   std::list<PeerInfo*>::iterator it = this->passiveProxyServerList.begin();
     114void NetworkNode::removePassiveProxyServer(NetworkNode* node)
     115{
     116  std::list<NetworkNode*>::iterator it = this->passiveProxyServerList.begin();
    118117  for(; it != this->passiveProxyServerList.end(); it++)
    119118  {
     
    131130 * removes a master server
    132131 */
    133 void NetworkNode::removeMasterServer(PeerInfo* node)
    134 {
    135   std::list<PeerInfo*>::iterator it = this->masterServerList.begin();
     132void NetworkNode::removeMasterServer(NetworkNode* node)
     133{
     134  std::list<NetworkNode*>::iterator it = this->masterServerList.begin();
    136135  for(; it != this->masterServerList.end(); it++)
    137136  {
     
    145144
    146145  PRINTF(2)("Could not remove client from the list, very strange...");
     146}
     147
     148
     149
     150
     151/**
     152 * removes a client
     153 */
     154void NetworkNode::removeClient(int userId)
     155{
     156  std::list<NetworkNode*>::iterator it = this->clientList.begin();
     157  for(; it != this->clientList.end(); it++)
     158  {
     159    if( (*it)->getPeerInfo()->userId == userId)
     160    {
     161      this->clientList.erase(it);
     162      this->playerNumber--;
     163      return;
     164    }
     165  }
     166
     167  PRINTF(2)("Could not remove client from the list, very strange...");
     168}
     169
     170/**
     171 * removes a proxy server
     172 */
     173void NetworkNode::removeActiveProxyServer(int userId)
     174{
     175  std::list<NetworkNode*>::iterator it = this->activeProxyServerList.begin();
     176  for(; it != this->activeProxyServerList.end(); it++)
     177  {
     178    if( (*it)->getPeerInfo()->userId == userId)
     179    {
     180      this->activeProxyServerList.erase(it);
     181      this->playerNumber--;
     182      return;
     183    }
     184  }
     185
     186  PRINTF(2)("Could not remove proxy server from the list, very strange...");
     187}
     188
     189/**
     190 * removes a proxy server
     191 */
     192void NetworkNode::removePassiveProxyServer(int userId)
     193{
     194  std::list<NetworkNode*>::iterator it = this->passiveProxyServerList.begin();
     195  for(; it != this->passiveProxyServerList.end(); it++)
     196  {
     197    if( (*it)->getPeerInfo()->userId == userId)
     198    {
     199      this->passiveProxyServerList.erase(it);
     200      return;
     201    }
     202  }
     203
     204  PRINTF(2)("Could not remove proxy server from the list, very strange...");
     205}
     206
     207/**
     208 * removes a master server
     209 */
     210void NetworkNode::removeMasterServer(int userId)
     211{
     212  std::list<NetworkNode*>::iterator it = this->masterServerList.begin();
     213  for(; it != this->masterServerList.end(); it++)
     214  {
     215    if( (*it)->getPeerInfo()->userId == userId)
     216    {
     217      this->masterServerList.erase(it);
     218      this->playerNumber--;
     219      return;
     220    }
     221  }
     222
     223  PRINTF(2)("Could not remove client from the list, very strange...");
     224}
     225
     226
     227
     228
     229
     230/**
     231 *  gets the peer info by user id
     232 * @param userId  the user id of the node to look up
     233 * @return the peer info of this node NULL if nothing found
     234 */
     235PeerInfo* NetworkNode::getPeerByUserId( int userId)
     236{
     237  // look through the master server lists
     238  std::list<NetworkNode*>::const_iterator it = this->masterServerList.begin();
     239  for( ;it != this->masterServerList.end(); it++)
     240  {
     241    if( (*it)->getPeerInfo()->userId == userId)
     242      return (*it)->getPeerInfo();
     243  }
     244
     245  // look through the active proxy server list
     246  it = this->activeProxyServerList.begin();
     247  for( ; it != this->activeProxyServerList.end(); it++)
     248  {
     249    if( (*it)->getPeerInfo()->userId == userId)
     250      return (*it)->getPeerInfo();
     251  }
     252
     253  // look through the passive server list
     254  it = this->passiveProxyServerList.begin();
     255  for( ; it != this->passiveProxyServerList.end(); it++)
     256  {
     257    if( (*it)->getPeerInfo()->userId == userId)
     258      return (*it)->getPeerInfo();
     259  }
     260
     261  // look through the client list
     262  it = this->clientList.begin();
     263  for( ; it != this->clientList.end(); it++)
     264  {
     265    if( (*it)->getPeerInfo()->userId == userId)
     266      return (*it)->getPeerInfo();
     267  }
     268
     269  return NULL;
    147270}
    148271
     
    154277PeerInfo* NetworkNode::getClient(int index) const
    155278{
    156   if( this->clientList.size() < index)
     279  if( (int)this->clientList.size() < index)
    157280    return NULL;
    158281
    159   std::list<PeerInfo*>::const_iterator it = this->clientList.begin();
     282  std::list<NetworkNode*>::const_iterator it = this->clientList.begin();
    160283  for(int i = 0; it != this->clientList.end(); it++, i++)
    161284  {
    162285  if( i == index)
    163     return (*it);
     286    return (*it)->getPeerInfo();
    164287  }
    165288
     
    174297PeerInfo* NetworkNode::getActiveProxyServer(int index) const
    175298{
    176   if( this->activeProxyServerList.size() < index)
     299  if( (int)this->activeProxyServerList.size() < index)
    177300    return NULL;
    178301
    179   std::list<PeerInfo*>::const_iterator it = this->activeProxyServerList.begin();
     302  std::list<NetworkNode*>::const_iterator it = this->activeProxyServerList.begin();
    180303  for(int i = 0; it != this->activeProxyServerList.end(); it++, i++)
    181304  {
    182305    if( i == index)
    183       return (*it);
     306      return (*it)->getPeerInfo();
    184307  }
    185308
     
    194317PeerInfo* NetworkNode::getPassiveProxyServer(int index) const
    195318{
    196   if( this->passiveProxyServerList.size() < index)
     319  if( (int)this->passiveProxyServerList.size() < index)
    197320    return NULL;
    198321
    199   std::list<PeerInfo*>::const_iterator it = this->passiveProxyServerList.begin();
     322  std::list<NetworkNode*>::const_iterator it = this->passiveProxyServerList.begin();
    200323  for(int i = 0; it != this->passiveProxyServerList.end(); it++, i++)
    201324  {
    202325    if( i == index)
    203       return (*it);
     326      return (*it)->getPeerInfo();
    204327  }
    205328
     
    214337PeerInfo* NetworkNode::getMasterServer(int index) const
    215338{
    216   if( this->masterServerList.size() < index)
     339  if( (int)this->masterServerList.size() < index)
    217340    return NULL;
    218341
    219   std::list<PeerInfo*>::const_iterator it = this->masterServerList.begin();
     342  std::list<NetworkNode*>::const_iterator it = this->masterServerList.begin();
    220343  for(int i = 0; it != this->masterServerList.end(); it++, i++)
    221344  {
    222345    if( i == index)
    223       return (*it);
     346      return (*it)->getPeerInfo();
     347  }
     348
     349  return NULL;
     350}
     351
     352
     353
     354/**
     355 * searches for a given NetworkNode
     356 * @param userId of the searched node
     357 * @returns the PeerInfo of the userId peer
     358 */
     359NetworkNode* NetworkNode::getNodeByUserId( int userId)
     360{
     361  if( this->peerInfo->userId == userId)
     362    return this;
     363
     364
     365  NetworkNode* node = NULL;
     366  std::list<NetworkNode*>::const_iterator it = this->masterServerList.begin();
     367
     368  for(; it != this->masterServerList.end(); it++)
     369  {
     370    node = (*it)->getNodeByUserId(userId);
     371    if( node != NULL)
     372      return node;
     373  }
     374
     375  it = this->activeProxyServerList.begin();
     376  for(; it != this->activeProxyServerList.end(); it++)
     377  {
     378    node = (*it)->getNodeByUserId(userId);
     379    if( node != NULL)
     380      return node;
     381  }
     382
     383  it = this->passiveProxyServerList.begin();
     384  for(; it != this->passiveProxyServerList.end(); it++)
     385  {
     386    node = (*it)->getNodeByUserId(userId);
     387    if( node != NULL)
     388      return node;
     389  }
     390
     391  it = this->clientList.begin();
     392  for(; it != this->clientList.end(); it++)
     393  {
     394    node = (*it)->getNodeByUserId(userId);
     395    if( node != NULL)
     396      return node;
    224397  }
    225398
     
    234407void NetworkNode::debug(int depth) const
    235408{
    236   PRINT(0)(" = %s\n", this->peerInfo->getNodeTypeString().c_str());
    237 
    238   PRINT(0)("    master servers: %i\n", this->masterServerList.size());
    239   std::list<PeerInfo*>::const_iterator it = this->masterServerList.begin();
    240   for(; it != this->masterServerList.end(); it++)
    241   {
    242     IP* ip = &(*it)->ip;
    243     PRINT(0)("     - ms, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str());
    244   }
    245 
    246   PRINT(0)("    proxy servers active: %i\n", this->activeProxyServerList.size());
    247   it = this->activeProxyServerList.begin();
    248   for(; it != this->activeProxyServerList.end(); it++)
    249   {
    250     IP* ip = &(*it)->ip;
    251     PRINT(0)("     - ps-a, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str());
    252   }
    253 
    254   PRINT(0)("    proxy servers passive: %i\n", this->passiveProxyServerList.size());
    255   it = this->passiveProxyServerList.begin();
    256   for(; it != this->passiveProxyServerList.end(); it++)
    257   {
    258     IP* ip = &(*it)->ip;
    259     PRINT(0)("     - ps-p, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str());
    260   }
    261 
    262   PRINT(0)("    clients: %i\n", this->clientList.size());
    263   it = this->clientList.begin();
    264   for(; it != this->clientList.end(); it++)
    265   {
    266     IP* ip = &(*it)->ip;
    267     PRINT(0)("     - client, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str());
    268   }
    269 }
    270 
     409  char indent[depth +1];
     410  for( int i = 0; i < depth; i++) {     indent[i] = ' ';  }
     411  indent[depth] = '\0';
     412
     413  PRINT(0)("%s + %s, with id %i and ip: %s\n", indent, this->peerInfo->getNodeTypeString().c_str(), this->peerInfo->userId, this->peerInfo->ip.ipString().c_str());
     414
     415
     416
     417  std::list<NetworkNode*>::const_iterator it;
     418  if( !this->masterServerList.empty())
     419  {
     420    it = this->masterServerList.begin();
     421
     422    for(; it != this->masterServerList.end(); it++)
     423    {
     424      (*it)->debug(depth+1);
     425    }
     426  }
     427
     428  if( !this->activeProxyServerList.empty())
     429  {
     430    it = this->activeProxyServerList.begin();
     431
     432    for(; it != this->activeProxyServerList.end(); it++)
     433    {
     434      (*it)->debug(depth+1);
     435    }
     436  }
     437
     438
     439  if( !this->passiveProxyServerList.empty())
     440  {
     441    it = this->passiveProxyServerList.begin();
     442
     443    for(; it != this->passiveProxyServerList.end(); it++)
     444    {
     445      (*it)->debug(depth+1);
     446    }
     447  }
     448
     449  if( !this->clientList.empty())
     450  {
     451    it = this->clientList.begin();
     452
     453    for(; it != this->clientList.end(); it++)
     454    {
     455      (*it)->debug(depth+1);
     456    }
     457  }
     458}
     459
  • trunk/src/lib/network/monitor/network_node.h

    r9494 r9656  
    1313#include <list>
    1414
    15 
    1615//!< a class representing a node in the network (this can be a MASTER_SERVER, PROXY_SERVER or a CLIENT
    1716class NetworkNode
     
    2221
    2322
    24     void addClient(PeerInfo* node);
    25     void addActiveProxyServer(PeerInfo* node);
    26     void addPassiveProxyServer(PeerInfo* node);
    27     void addMasterServer(PeerInfo* node);
     23    void addClient(NetworkNode* node);
     24    void addActiveProxyServer(NetworkNode* node);
     25    void addPassiveProxyServer(NetworkNode* node);
     26    void addMasterServer(NetworkNode* node);
    2827
    29     void removeClient(PeerInfo* node);
    30     void removeActiveProxyServer(PeerInfo* node);
    31     void removePassiveProxyServer(PeerInfo* node);
    32     void removeMasterServer(PeerInfo* node);
     28    void removeClient(NetworkNode* node);
     29    void removeActiveProxyServer(NetworkNode* node);
     30    void removePassiveProxyServer(NetworkNode* node);
     31    void removeMasterServer(NetworkNode* node);
     32
     33    void removeClient(int userId);
     34    void removeActiveProxyServer(int userId);
     35    void removePassiveProxyServer(int userId);
     36    void removeMasterServer(int userId);
     37
    3338
    3439    PeerInfo* getClient(int index) const;
     
    3843
    3944    /** @returns the master server list */
    40     inline std::list<PeerInfo*> getMasterServer() const { return this->masterServerList; }
     45    inline std::list<NetworkNode*> getMasterServers() const { return this->masterServerList; }
    4146    /** @returns the active proxy server list */
    42     inline std::list<PeerInfo*> getActiveProxyServer() const { return this->activeProxyServerList; }
     47    inline std::list<NetworkNode*> getActiveProxyServers() const { return this->activeProxyServerList; }
    4348    /** @returns the passive proxy server list */
    44     inline std::list<PeerInfo*> getPassiveProxyServer() const { return this->passiveProxyServerList; }
     49    inline std::list<NetworkNode*> getPassiveProxyServers() const { return this->passiveProxyServerList; }
    4550    /** @returns the client list */
    46     inline std::list<PeerInfo*> getClient() const { return this->clientList; }
     51    inline std::list<NetworkNode*> getClients() const { return this->clientList; }
    4752
     53    PeerInfo* getPeerByUserId( int userId);
    4854
    4955    /** @returns the number of players */
     
    5359    /** @returns the peer info of this node */
    5460    inline PeerInfo* getPeerInfo() const { return this->peerInfo; }
     61
     62    NetworkNode* getNodeByUserId( int userId);
    5563
    5664    void debug(int depth) const;
     
    6371
    6472    /* network nodes directly connected to this node */
    65     std::list<PeerInfo*>         clientList;                   //!< list of all clients in the network
    66     std::list<PeerInfo*>         activeProxyServerList;        //!< list of all proxy servers in the network
    67     std::list<PeerInfo*>         passiveProxyServerList;       //!< list of all proxy servers in the network
    68     std::list<PeerInfo*>         masterServerList;             //!< list of all master servers in the network (should be 1!! :D)
     73    std::list<NetworkNode*>         clientList;                   //!< list of all clients in the network
     74    std::list<NetworkNode*>         activeProxyServerList;        //!< list of all proxy servers in the network
     75    std::list<NetworkNode*>         passiveProxyServerList;       //!< list of all proxy servers in the network
     76    std::list<NetworkNode*>         masterServerList;             //!< list of all master servers in the network (should be 1!! :D)
    6977
    7078};
  • trunk/src/lib/network/monitor/network_stats_widget.cc

    r9494 r9656  
    1818#include "network_stats_widget.h"
    1919#include "network_monitor.h"
     20#include "peer_info.h"
    2021
    2122#include "multi_type.h"
     
    2324#include "shell_command.h"
    2425
    25 // SHELL_COMMAND(gui, NetworkMonitor, toggleGUI)
    26 //  ->setAlias("ProxyGui");
     26#include "loading/resource_manager.h"
     27
     28// this fcuk does not work!
     29// SHELL_COMMAND(gui, NetworkStatsWidget, toggleGUI)
     30// ->setAlias("ProxyGui");
    2731
    2832
     
    3034    : GLGuiBox(OrxGui::Horizontal)
    3135{
     36  this->init();
     37
    3238  this->setName(name);
    3339  this->setIP(ip);
    3440
     41}
     42
     43HostWidget::HostWidget(const PeerInfo* peerInfo)
     44    : GLGuiBox(OrxGui::Horizontal)
     45{
     46  this->init();
     47  if (peerInfo == NULL)
     48  {
     49    this->setName("INVALID");
     50    return;
     51  }
     52  this->setName(peerInfo->getNodeTypeString() + "ID: " + MultiType(peerInfo->userId).getString());
     53  this->setIP(peerInfo->ip);
     54}
     55
     56void HostWidget::init()
     57{
     58  if(_font == NULL)
     59    _font = new Font(ResourceManager::getInstance()->getDataDir() + "/fonts/arial.ttf", 20);
     60
     61  //this->_name.setFont(*_font);
     62  this->_name.setTextSize(15);
     63  //this->_ip.setFont(*_font);
     64  this->_ip.setTextSize(15);
     65
    3566  this->pack(&this->_name);
    3667  this->pack(&this->_ip);
     
    4980}
    5081
     82Font* HostWidget::_font = NULL;
     83
     84
    5185
    5286
     
    5488
    5589
    56 ProxyWidget::ProxyWidget(const std::string& proxyName, const IP& ip)
     90NodeWidget::NodeWidget(const std::string& proxyName, const IP& ip)
    5791    : _proxyWidget(proxyName, ip)
    5892{
    59   this->_clientNameWidth = 100.0f;
     93  this->_nodeNameWidth = 100.0f;
    6094  this->pack(&_proxyWidget);
    6195}
    6296
    63 void ProxyWidget::addClient(const std::string& name, const IP& ip)
     97NodeWidget::NodeWidget(const NetworkNode* node)
     98    : _proxyWidget(node->getPeerInfo())// "node", node->getPeerInfo()->ip)
     99{
     100  this->_nodeNameWidth = 100.0f;
     101  this->pack(&_proxyWidget);
     102
     103  std::list<NetworkNode*> list = node->getMasterServers();
     104  std::list<NetworkNode*>::const_iterator it;
     105
     106  for(it = list.begin(); it != list.end(); it++)
     107    this->addNode(*it);
     108
     109  list = node->getActiveProxyServers();
     110  for(it = list.begin(); it != list.end(); it++)
     111    this->addNode(*it);
     112
     113  list = node->getPassiveProxyServers();
     114  for(it = list.begin(); it != list.end(); it++)
     115    this->addNode(*it);
     116
     117  list = node->getClients();
     118  for(it = list.begin(); it != list.end(); it++)
     119    this->addNode(*it);
     120}
     121
     122
     123void NodeWidget::addNode(const NetworkNode* node)
     124{
     125  this->_nodes.push_back(new NodeWidget(node));
     126  this->pack(this->_nodes.back());
     127  this->_nodes.back()->show();
     128}
     129
     130
     131void NodeWidget::addNode(const std::string& name, const IP& ip)
    64132{
    65133  HostWidget* newClient = new HostWidget(name, ip);
    66   newClient->setNameWidth(this->_clientNameWidth);
     134  newClient->setNameWidth(this->_nodeNameWidth);
    67135
    68136  this->pack(newClient);
     
    72140}
    73141
    74 bool ProxyWidget::removeClient(const IP& ip)
    75 {
    76   std::vector<HostWidget*>::iterator rmIt;
    77   for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
    78   {
    79     if (*(*rmIt) == ip)
    80     {
    81       delete (*rmIt);
    82       this->_clients.erase(rmIt);
    83       return true;
    84     }
    85   }
    86   return false;
    87 }
    88 
    89 bool ProxyWidget::removeClient(const std::string& name)
    90 {
    91   std::vector<HostWidget*>::iterator rmIt;
    92   for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
    93   {
    94     if (*(*rmIt) == name)
    95     {
    96       delete (*rmIt);
    97       this->_clients.erase(rmIt);
    98       return true;
    99     }
    100   }
    101   return false;
    102 
    103 }
    104 
    105 bool ProxyWidget::removeClient(const std::string& name, const IP& ip)
    106 {
    107   std::vector<HostWidget*>::iterator rmIt;
    108   for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
    109   {
    110     if (*(*rmIt) == ip && *(*rmIt) == name)
    111     {
    112       delete (*rmIt);
    113       this->_clients.erase(rmIt);
    114       return true;
    115     }
    116   }
    117   return false;
    118 }
    119 
    120 
    121 void ProxyWidget::setClientNameWidths(float width)
    122 {
    123   this->_clientNameWidth = width;
    124   for (unsigned int i = 0; i < this->_clients.size(); ++i)
    125     this->_clients[i]->setNameWidth(width);
    126 }
    127 
    128 void ProxyWidget::hiding()
     142bool NodeWidget::removeNode(const IP& ip)
     143{
     144//   std::vector<HostWidget*>::iterator rmIt;
     145//   for(rmIt = this->_nodes.begin(); rmIt != this->_nodes.end(); ++rmIt)
     146//   {
     147//     if (*(*rmIt) == ip)
     148//     {
     149//       delete (*rmIt);
     150//       this->_nodes.erase(rmIt);
     151//       return true;
     152//     }
     153//   }
     154//   return false;
     155}
     156
     157bool NodeWidget::removeNode(const std::string& name)
     158{
     159//   std::vector<HostWidget*>::iterator rmIt;
     160//   for(rmIt = this->_nodes.begin(); rmIt != this->_nodes.end(); ++rmIt)
     161//   {
     162//     if (*(*rmIt) == name)
     163//     {
     164//       delete (*rmIt);
     165//       this->_nodes.erase(rmIt);
     166//       return true;
     167//     }
     168//   }
     169//   return false;
     170
     171}
     172
     173bool NodeWidget::removeNode(const std::string& name, const IP& ip)
     174{
     175//   std::vector<HostWidget*>::iterator rmIt;
     176//   for(rmIt = this->_nodes.begin(); rmIt != this->_nodes.end(); ++rmIt)
     177//   {
     178//     if (*(*rmIt) == ip && *(*rmIt) == name)
     179//     {
     180//       delete (*rmIt);
     181//       this->_nodes.erase(rmIt);
     182//       return true;
     183//     }
     184//   }
     185//   return false;
     186}
     187
     188
     189void NodeWidget::setNodeNameWidths(float width)
     190{
     191/*  this->_nodeNameWidth = width;
     192  for (unsigned int i = 0; i < this->_nodes.size(); ++i)
     193    this->_nodes[i]->setNameWidth(width);*/
     194}
     195
     196void NodeWidget::hiding()
    129197{
    130198  this->_proxyWidget.hide();
    131   for (unsigned int i = 0; i < this->_clients.size(); ++i)
    132     this->_clients[i]->hide();
    133 }
    134 
    135 void ProxyWidget::showing()
     199  for (unsigned int i = 0; i < this->_nodes.size(); ++i)
     200    this->_nodes[i]->hide();
     201}
     202
     203void NodeWidget::showing()
    136204{
    137205  this->_proxyWidget.show();
    138   for (unsigned int i = 0; i < this->_clients.size(); ++i)
    139     this->_clients[i]->show();
     206  for (unsigned int i = 0; i < this->_nodes.size(); ++i)
     207    this->_nodes[i]->show();
    140208}
    141209
     
    147215 */
    148216NetworkStatsWidget::NetworkStatsWidget(const NetworkMonitor* monitor)
    149     : GLGuiBox(OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 1))
     217    : OrxGui::GLGuiFixedpositionBox(OrxGui::Center, OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 1))
    150218{
    151219  this->_monitor = monitor;
     220  this->_passedTime = 0.0f;
    152221
    153222  /*
     
    169238  this->_bar.setChangedValueColor(Color::black);
    170239  */
     240  this->_thisHostIs.setText(std::string("I am ") + _monitor->getLocalNode()->getPeerInfo()->getNodeTypeString());
     241
     242  this->pack(&this->_thisHostIs);
     243
    171244  this->pack(&this->_thisHost);
     245
     246  this->pack(&this->_serverBox);
    172247
    173248  this->pack(&this->_upstreamText);
    174249  this->pack(&this->_downstreamText);
    175250
    176   this->pack(&this->_serverIP);
     251
     252  this->rebuild();
    177253}
    178254
     
    183259NetworkStatsWidget::~NetworkStatsWidget ()
    184260{}
     261
     262
     263void NetworkStatsWidget::addNode(const NetworkNode* node)
     264{
     265  this->_proxies.push_back(new NodeWidget(node));
     266  this->_serverBox.pack(this->_proxies.back());
     267  this->_proxies.back()->show();
     268}
     269
     270
     271
     272
     273NetworkStatsWidget* NetworkStatsWidget::_statsWidget = NULL;
     274
     275#include "class_list.h"
     276
     277void NetworkStatsWidget::toggleGUI()
     278{
     279  BaseObject* bo = NULL;
     280  const std::list<BaseObject*>* ls = ClassList::getList(CL_NETWORK_MONITOR);
     281  if (ls != NULL && !ls->empty())
     282    bo = ls->front();
     283
     284  if (bo != NULL && NetworkStatsWidget::_statsWidget == NULL)
     285  {
     286    NetworkStatsWidget::_statsWidget = new NetworkStatsWidget(dynamic_cast<NetworkMonitor*> (bo));
     287    NetworkStatsWidget::_statsWidget->showAll();
     288  }
     289  else
     290  {
     291    delete NetworkStatsWidget::_statsWidget;
     292    NetworkStatsWidget::_statsWidget = NULL;
     293  }
     294}
    185295
    186296
     
    204314
    205315
     316void NetworkStatsWidget::addProxy(const std::string& name, const IP& proxy)
     317{}
     318
     319void NetworkStatsWidget::clearProxies()
     320{}
     321
     322
     323void NetworkStatsWidget::rebuild()
     324{
     325  while (!this->_proxies.empty())
     326  {
     327    delete this->_proxies.back();
     328    this->_proxies.pop_back();
     329  }
     330
     331  const NetworkNode* node = this->_monitor->getLocalNode();
     332  if (node == NULL)
     333  {
     334    printf("NO NODE\n");
     335    return;
     336  }
     337
     338  this->addNode(node);
     339}
     340
     341
     342
    206343void NetworkStatsWidget::tick(float dt)
    207344{
     345
     346  if ((_passedTime+= dt) > 1.0f)
     347  {
     348    this->_passedTime = 0.0f;
     349    this->rebuild();
     350  }
     351
    208352  assert (this->_monitor->getLocalNode() != NULL);
    209353  assert(this->_monitor->getLocalNode()->getPeerInfo() != NULL);
     
    220364void NetworkStatsWidget::resize()
    221365{
    222   GLGuiBox::resize();
     366  GLGuiFixedpositionBox::resize();
    223367}
    224368
  • trunk/src/lib/network/monitor/network_stats_widget.h

    r9494 r9656  
    22 * @file network_stats_widget.h
    33 * @brief Definition of an EnergyWidget, that displays a bar and a Text
    4 */
     4 */
    55
    66#ifndef _NETWORK_STATS_WIDGET_H
    77#define _NETWORK_STATS_WIDGET_H
    88
    9 #include "glgui_box.h"
     9#include "glgui_fixedposition_box.h"
    1010#include "glgui_bar.h"
    1111#include "glgui_text.h"
     12#include "glgui_pushbutton.h"
    1213
    1314#include "network/ip.h"
    1415
    1516class NetworkMonitor;
    16 
     17class NetworkNode;
     18class PeerInfo;
    1719
    1820class HostWidget : public OrxGui::GLGuiBox
     
    2022  public:
    2123    HostWidget(const std::string& name, const IP& ip);
    22     ~HostWidget() {};
     24    HostWidget(const PeerInfo* peerInfo);
    2325
    2426    void setName(const std::string& name) { this->_name.setText(name); };
    25     void setIP(const IP& ip) { this->_ip.setText(ip.ipString()); this->_storedIP = ip; };
     27    void setIP(const IP& ip) { this->_ip.setText(std::string("at ") + ip.ipString()); this->_storedIP = ip; };
    2628
    2729    void setNameWidth(float width) { this->_name.setLineWidth(width); };
     
    3537
    3638  private:
     39    void init();
     40  private:
    3741    OrxGui::GLGuiText _name;           //!< The Name of the Proxy server to be displayed.
    3842    OrxGui::GLGuiText _ip;             //!< The IP of the proxy server.
    3943    IP                _storedIP;       //!< The ip to compare.
     44
     45    static Font*      _font;
    4046};
    4147
    4248
    43 class ProxyWidget : public OrxGui::GLGuiBox
     49class NodeWidget : public OrxGui::GLGuiBox
    4450{
    4551  public:
    46     ProxyWidget(const std::string& proxyName, const IP& ip);
     52    NodeWidget(const std::string& proxyName, const IP& ip);
     53    NodeWidget(const NetworkNode* node);
    4754
    48     void addClient(const std::string& name, const IP& ip);
     55    void addNode(const NetworkNode* node);
     56    void addNode(const std::string& name, const IP& ip);
    4957
    50     bool removeClient(const IP& ip);
    51     bool removeClient(const std::string& name);
    52     bool removeClient(const std::string& name, const IP& ip);
     58    bool removeNode(const IP& ip);
     59    bool removeNode(const std::string& name);
     60    bool removeNode(const std::string& name, const IP& ip);
    5361
    54     void setClientNameWidths(float width);
     62    void setNodeNameWidths(float width);
    5563
    5664
     
    6371    HostWidget                _proxyWidget;
    6472
    65     std::vector<HostWidget*>  _clients;
    66     float                     _clientNameWidth;
     73    std::vector<NodeWidget*>  _nodes;
     74    float                     _nodeNameWidth;
    6775};
    6876
     
    7179
    7280//! A class to display network Statistics.
    73 class NetworkStatsWidget : public OrxGui::GLGuiBox
     81class NetworkStatsWidget : public OrxGui::GLGuiFixedpositionBox
    7482{
    7583  public:
     84    static void toggleGUI();
     85
    7686    NetworkStatsWidget(const NetworkMonitor* monitor);
    7787    virtual ~NetworkStatsWidget();
     
    8494
    8595    void addProxy(const std::string& name, const IP& proxy);
     96    void addNode(const NetworkNode* node);
    8697
     98    void clearProxies();
     99
     100    void rebuild();
    87101
    88102    //void rebuildConnectedHosts(std::vector<hosts> hosts);
     
    101115    const NetworkMonitor*  _monitor;
    102116
     117    OrxGui::GLGuiText      _thisHostIs;
    103118    HostWidget             _thisHost;
    104119
     
    106121    OrxGui::GLGuiText      _downstreamText;
    107122
    108     std::vector<HostWidget*>_connectedProxies;
     123    OrxGui::GLGuiBox       _serverBox;
    109124
    110     OrxGui::GLGuiText       _serverIP;
     125    std::vector<NodeWidget*> _proxies;
    111126
    112127
     128    static NetworkStatsWidget*    _statsWidget;
     129
     130
     131    float                   _passedTime;
    113132    //OrxGui::GLGuiText       _valueText;
    114133    //OrxGui::GLGuiBar        _bar;
Note: See TracChangeset for help on using the changeset viewer.