Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.