Changeset 9625 in orxonox.OLD for branches/proxy/src/lib/network/monitor
- Timestamp:
- Jul 30, 2006, 11:19:24 PM (19 years ago)
- Location:
- branches/proxy/src/lib/network/monitor
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/network/monitor/network_monitor.cc
r9589 r9625 10 10 11 11 ### File Specific: 12 main-programmer: Patrick Boenzli 12 main-programmer: Patrick Boenzli (patrick@orxonox.ethz.ch) 13 13 */ 14 14 … … 49 49 this->networkStream = networkStream; 50 50 this->playerNumber = 0; 51 this->connectionNumber = 0; 51 52 // create the localnode, init it and add it to the nodes list 52 53 this->localNode = new NetworkNode( this->networkStream->getPeerInfo()); … … 69 70 peer->userId = -1; 70 71 71 NetworkNode* node = new NetworkNode(peer);72 this->addNode( node);73 72 this->addActiveProxyServer( this->localNode, peer); 74 73 } … … 141 140 return; 142 141 142 PRINTF(0)("^^^^^^^^^^^^^^^^^^^^^^^^^^ adding node: %i with type: %s\n\n", pInfo->userId, pInfo->getNodeTypeString().c_str()); 143 143 144 if( pInfo->isClient()) 144 this->localNode->addClient(pInfo); 145 { 146 this->localNode->addClient(new NetworkNode(pInfo)); 147 } 145 148 else if( pInfo->isProxyServerActive()) 146 149 { 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)); 151 155 } 152 156 else if( pInfo->isMasterServer()) 153 157 { 154 this->localNode->addMasterServer(pInfo); 155 } 158 this->localNode->addMasterServer(new NetworkNode(pInfo)); 159 } 160 else 161 assert(false); 156 162 } 157 163 … … 168 174 169 175 if( pInfo->isClient()) 170 node->addClient( pInfo);176 node->addClient(new NetworkNode(pInfo)); 171 177 else if( pInfo->isProxyServerActive()) 172 node->addActiveProxyServer( pInfo);178 node->addActiveProxyServer(new NetworkNode(pInfo)); 173 179 else if( pInfo->isMasterServer()) 174 node->addMasterServer( pInfo);180 node->addMasterServer(new NetworkNode(pInfo)); 175 181 } 176 182 … … 198 204 199 205 if( pInfo->isClient()) 200 node->removeClient(pInfo );206 node->removeClient(pInfo->userId); 201 207 else if( pInfo->isProxyServerActive()) 202 node->removeActiveProxyServer(pInfo );208 node->removeActiveProxyServer(pInfo->userId); 203 209 else if( pInfo->isMasterServer()) 204 node->removeMasterServer(pInfo );210 node->removeMasterServer(pInfo->userId); 205 211 } 206 212 … … 253 259 for(; it != this->nodeList.end(); it++) 254 260 { 261 PRINTF(0)("comparing %i to %i\n", (*it)->getPeerInfo()->userId, userId); 255 262 if( (*it)->getPeerInfo()->userId == userId) 256 263 return (*it); … … 308 315 for(; it != this->nodeList.end(); it++) 309 316 { 310 (*it)->debug( 0);317 (*it)->debug(1); 311 318 } 312 319 -
branches/proxy/src/lib/network/monitor/network_monitor.h
r9601 r9625 42 42 43 43 /** 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)); } 45 45 /** 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)); } 47 47 /** 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)); } 49 49 /** 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)); } 51 51 52 52 void removeNode(PeerInfo* pInfo); 53 53 void removeNode(NetworkNode* node, PeerInfo* pInfo); 54 54 55 inline void removeClient(NetworkNode* node, PeerInfo* pInfo) { node->removeClient(pInfo); }56 inline void removeActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removeActiveProxyServer(pInfo); }57 inline void removePassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removePassiveProxyServer(pInfo); }58 inline void removeMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->removeMasterServer(pInfo); }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); } 59 59 60 60 PeerInfo* getFirstChoiceProxy() const; … … 64 64 65 65 /** @returns the active proxy server list of the localnode */ 66 inline std::list< PeerInfo*> getActiveProxyServer() const { return this->localNode->getActiveProxyServer(); }66 inline std::list<NetworkNode*> getActiveProxyServer() const { return this->localNode->getActiveProxyServer(); } 67 67 68 68 /* slots admin and info interface */ -
branches/proxy/src/lib/network/monitor/network_node.cc
r9583 r9625 39 39 * adds a client 40 40 */ 41 void NetworkNode::addClient( PeerInfo* node)41 void NetworkNode::addClient(NetworkNode* node) 42 42 { 43 43 this->clientList.push_back(node); … … 49 49 * adds a proxy server 50 50 */ 51 void NetworkNode::addActiveProxyServer( PeerInfo* node)51 void NetworkNode::addActiveProxyServer(NetworkNode* node) 52 52 { 53 53 this->activeProxyServerList.push_back(node); … … 58 58 * adds a proxy server 59 59 */ 60 void NetworkNode::addPassiveProxyServer( PeerInfo* node)60 void NetworkNode::addPassiveProxyServer(NetworkNode* node) 61 61 { 62 62 this->passiveProxyServerList.push_back(node); … … 66 66 * adds a master server 67 67 */ 68 void NetworkNode::addMasterServer( PeerInfo* node)68 void NetworkNode::addMasterServer(NetworkNode* node) 69 69 { 70 70 this->masterServerList.push_back(node); … … 75 75 * removes a client 76 76 */ 77 void NetworkNode::removeClient( PeerInfo* node)78 { 79 std::list< PeerInfo*>::iterator it = this->clientList.begin();77 void NetworkNode::removeClient(NetworkNode* node) 78 { 79 std::list<NetworkNode*>::iterator it = this->clientList.begin(); 80 80 for(; it != this->clientList.end(); it++) 81 81 { … … 94 94 * removes a proxy server 95 95 */ 96 void NetworkNode::removeActiveProxyServer( PeerInfo* node)97 { 98 std::list< PeerInfo*>::iterator it = this->activeProxyServerList.begin();96 void NetworkNode::removeActiveProxyServer(NetworkNode* node) 97 { 98 std::list<NetworkNode*>::iterator it = this->activeProxyServerList.begin(); 99 99 for(; it != this->activeProxyServerList.end(); it++) 100 100 { … … 113 113 * removes a proxy server 114 114 */ 115 void NetworkNode::removePassiveProxyServer( PeerInfo* node)116 { 117 std::list< PeerInfo*>::iterator it = this->passiveProxyServerList.begin();115 void NetworkNode::removePassiveProxyServer(NetworkNode* node) 116 { 117 std::list<NetworkNode*>::iterator it = this->passiveProxyServerList.begin(); 118 118 for(; it != this->passiveProxyServerList.end(); it++) 119 119 { … … 131 131 * removes a master server 132 132 */ 133 void NetworkNode::removeMasterServer( PeerInfo* node)134 { 135 std::list< PeerInfo*>::iterator it = this->masterServerList.begin();133 void NetworkNode::removeMasterServer(NetworkNode* node) 134 { 135 std::list<NetworkNode*>::iterator it = this->masterServerList.begin(); 136 136 for(; it != this->masterServerList.end(); it++) 137 137 { … … 146 146 PRINTF(2)("Could not remove client from the list, very strange..."); 147 147 } 148 149 150 151 152 /** 153 * removes a client 154 */ 155 void NetworkNode::removeClient(int userId) 156 { 157 std::list<NetworkNode*>::iterator it = this->clientList.begin(); 158 for(; it != this->clientList.end(); it++) 159 { 160 if( (*it)->getPeerInfo()->userId == userId) 161 { 162 this->clientList.erase(it); 163 this->playerNumber--; 164 return; 165 } 166 } 167 168 PRINTF(2)("Could not remove client from the list, very strange..."); 169 } 170 171 /** 172 * removes a proxy server 173 */ 174 void NetworkNode::removeActiveProxyServer(int userId) 175 { 176 std::list<NetworkNode*>::iterator it = this->activeProxyServerList.begin(); 177 for(; it != this->activeProxyServerList.end(); it++) 178 { 179 if( (*it)->getPeerInfo()->userId == userId) 180 { 181 this->activeProxyServerList.erase(it); 182 this->playerNumber--; 183 return; 184 } 185 } 186 187 PRINTF(2)("Could not remove proxy server from the list, very strange..."); 188 } 189 190 /** 191 * removes a proxy server 192 */ 193 void NetworkNode::removePassiveProxyServer(int userId) 194 { 195 std::list<NetworkNode*>::iterator it = this->passiveProxyServerList.begin(); 196 for(; it != this->passiveProxyServerList.end(); it++) 197 { 198 if( (*it)->getPeerInfo()->userId == userId) 199 { 200 this->passiveProxyServerList.erase(it); 201 return; 202 } 203 } 204 205 PRINTF(2)("Could not remove proxy server from the list, very strange..."); 206 } 207 208 /** 209 * removes a master server 210 */ 211 void NetworkNode::removeMasterServer(int userId) 212 { 213 std::list<NetworkNode*>::iterator it = this->masterServerList.begin(); 214 for(; it != this->masterServerList.end(); it++) 215 { 216 if( (*it)->getPeerInfo()->userId == userId) 217 { 218 this->masterServerList.erase(it); 219 this->playerNumber--; 220 return; 221 } 222 } 223 224 PRINTF(2)("Could not remove client from the list, very strange..."); 225 } 226 227 148 228 149 229 … … 157 237 { 158 238 // look through the master server lists 159 std::list< PeerInfo*>::const_iterator it = this->masterServerList.begin();239 std::list<NetworkNode*>::const_iterator it = this->masterServerList.begin(); 160 240 for( ;it != this->masterServerList.end(); it++) 161 241 { 162 if( (*it)-> userId == userId)163 return (*it) ;242 if( (*it)->getPeerInfo()->userId == userId) 243 return (*it)->getPeerInfo(); 164 244 } 165 245 … … 168 248 for( ; it != this->activeProxyServerList.end(); it++) 169 249 { 170 if( (*it)-> userId == userId)171 return (*it) ;250 if( (*it)->getPeerInfo()->userId == userId) 251 return (*it)->getPeerInfo(); 172 252 } 173 253 … … 176 256 for( ; it != this->passiveProxyServerList.end(); it++) 177 257 { 178 if( (*it)-> userId == userId)179 return (*it) ;258 if( (*it)->getPeerInfo()->userId == userId) 259 return (*it)->getPeerInfo(); 180 260 } 181 261 … … 184 264 for( ; it != this->clientList.end(); it++) 185 265 { 186 if( (*it)-> userId == userId)187 return (*it) ;266 if( (*it)->getPeerInfo()->userId == userId) 267 return (*it)->getPeerInfo(); 188 268 } 189 269 … … 201 281 return NULL; 202 282 203 std::list< PeerInfo*>::const_iterator it = this->clientList.begin();283 std::list<NetworkNode*>::const_iterator it = this->clientList.begin(); 204 284 for(int i = 0; it != this->clientList.end(); it++, i++) 205 285 { 206 286 if( i == index) 207 return (*it) ;287 return (*it)->getPeerInfo(); 208 288 } 209 289 … … 221 301 return NULL; 222 302 223 std::list< PeerInfo*>::const_iterator it = this->activeProxyServerList.begin();303 std::list<NetworkNode*>::const_iterator it = this->activeProxyServerList.begin(); 224 304 for(int i = 0; it != this->activeProxyServerList.end(); it++, i++) 225 305 { 226 306 if( i == index) 227 return (*it) ;307 return (*it)->getPeerInfo(); 228 308 } 229 309 … … 241 321 return NULL; 242 322 243 std::list< PeerInfo*>::const_iterator it = this->passiveProxyServerList.begin();323 std::list<NetworkNode*>::const_iterator it = this->passiveProxyServerList.begin(); 244 324 for(int i = 0; it != this->passiveProxyServerList.end(); it++, i++) 245 325 { 246 326 if( i == index) 247 return (*it) ;327 return (*it)->getPeerInfo(); 248 328 } 249 329 … … 261 341 return NULL; 262 342 263 std::list< PeerInfo*>::const_iterator it = this->masterServerList.begin();343 std::list<NetworkNode*>::const_iterator it = this->masterServerList.begin(); 264 344 for(int i = 0; it != this->masterServerList.end(); it++, i++) 265 345 { 266 346 if( i == index) 267 return (*it) ;347 return (*it)->getPeerInfo(); 268 348 } 269 349 … … 278 358 void NetworkNode::debug(int depth) const 279 359 { 280 PRINT(0)(" = %s\n", this->peerInfo->getNodeTypeString().c_str()); 281 282 PRINT(0)(" master servers: %i\n", this->masterServerList.size()); 283 std::list<PeerInfo*>::const_iterator it = this->masterServerList.begin(); 284 for(; it != this->masterServerList.end(); it++) 285 { 286 IP* ip = &(*it)->ip; 287 PRINT(0)(" - ms, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); 288 } 289 290 PRINT(0)(" proxy servers active: %i\n", this->activeProxyServerList.size()); 291 it = this->activeProxyServerList.begin(); 292 for(; it != this->activeProxyServerList.end(); it++) 293 { 294 IP* ip = &(*it)->ip; 295 PRINT(0)(" - ps-a, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); 296 } 297 298 PRINT(0)(" proxy servers passive: %i\n", this->passiveProxyServerList.size()); 299 it = this->passiveProxyServerList.begin(); 300 for(; it != this->passiveProxyServerList.end(); it++) 301 { 302 IP* ip = &(*it)->ip; 303 PRINT(0)(" - ps-p, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); 304 } 305 306 PRINT(0)(" clients: %i\n", this->clientList.size()); 307 it = this->clientList.begin(); 308 for(; it != this->clientList.end(); it++) 309 { 310 IP* ip = &(*it)->ip; 311 PRINT(0)(" - client, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); 312 } 313 } 314 360 char indent[depth +1]; 361 for( int i = 0; i < depth; i++) { indent[i] = ' '; } 362 indent[depth] = '\0'; 363 364 PRINT(0)("%s + %s, with ip: %s\n", indent, this->peerInfo->getNodeTypeString().c_str(), this->peerInfo->ip.ipString().c_str()); 365 std::list<NetworkNode*>::const_iterator it; 366 if( !this->masterServerList.empty()) 367 { 368 // PRINT(0)("%s + master servers: %i\n", indent, this->masterServerList.size()); 369 it = this->masterServerList.begin(); 370 371 for(; it != this->masterServerList.end(); it++) 372 { 373 // IP* ip = &(*it)->getPeerInfo()->ip; 374 // PRINT(0)("%s - ms, id: %i (%s)\n", indent, (*it)->getPeerInfo()->userId, ip->ipString().c_str()); 375 (*it)->debug(depth+1); 376 } 377 } 378 379 if( !this->activeProxyServerList.empty()) 380 { 381 // PRINT(0)("%s + proxy servers active: %i\n", indent, this->activeProxyServerList.size()); 382 it = this->activeProxyServerList.begin(); 383 384 for(; it != this->activeProxyServerList.end(); it++) 385 { 386 // IP* ip = &(*it)->getPeerInfo()->ip; 387 // PRINT(0)("%s - ps-a, id: %i (%s)\n", indent, (*it)->getPeerInfo()->userId, ip->ipString().c_str()); 388 (*it)->debug(depth+1); 389 } 390 } 391 392 393 if( !this->passiveProxyServerList.empty()) 394 { 395 // PRINT(0)("%s proxy servers passive: %i\n", indent, this->passiveProxyServerList.size()); 396 it = this->passiveProxyServerList.begin(); 397 398 for(; it != this->passiveProxyServerList.end(); it++) 399 { 400 // IP* ip = &(*it)->getPeerInfo()->ip; 401 // PRINT(0)("%s - ps-p, id: %i (%s)\n", indent, (*it)->getPeerInfo()->userId, ip->ipString().c_str()); 402 (*it)->debug(depth+1); 403 } 404 } 405 406 if( !this->clientList.empty()) 407 { 408 // PRINT(0)("%s clients: %i\n", indent, this->clientList.size()); 409 it = this->clientList.begin(); 410 411 for(; it != this->clientList.end(); it++) 412 { 413 // IP* ip = &(*it)->getPeerInfo()->ip; 414 // PRINT(0)("%s - client, id: %i (%s)\n", indent, (*it)->getPeerInfo()->userId, ip->ipString().c_str()); 415 (*it)->debug(depth+1); 416 } 417 } 418 } 419 -
branches/proxy/src/lib/network/monitor/network_node.h
r9583 r9625 22 22 23 23 24 void addClient( PeerInfo* node);25 void addActiveProxyServer( PeerInfo* node);26 void addPassiveProxyServer( PeerInfo* node);27 void addMasterServer( PeerInfo* node);24 void addClient(NetworkNode* node); 25 void addActiveProxyServer(NetworkNode* node); 26 void addPassiveProxyServer(NetworkNode* node); 27 void addMasterServer(NetworkNode* node); 28 28 29 void removeClient(PeerInfo* node); 30 void removeActiveProxyServer(PeerInfo* node); 31 void removePassiveProxyServer(PeerInfo* node); 32 void removeMasterServer(PeerInfo* node); 29 void removeClient(NetworkNode* node); 30 void removeActiveProxyServer(NetworkNode* node); 31 void removePassiveProxyServer(NetworkNode* node); 32 void removeMasterServer(NetworkNode* node); 33 34 void removeClient(int userId); 35 void removeActiveProxyServer(int userId); 36 void removePassiveProxyServer(int userId); 37 void removeMasterServer(int userId); 38 33 39 34 40 PeerInfo* getClient(int index) const; … … 38 44 39 45 /** @returns the master server list */ 40 inline std::list< PeerInfo*> getMasterServer() const { return this->masterServerList; }46 inline std::list<NetworkNode*> getMasterServer() const { return this->masterServerList; } 41 47 /** @returns the active proxy server list */ 42 inline std::list< PeerInfo*> getActiveProxyServer() const { return this->activeProxyServerList; }48 inline std::list<NetworkNode*> getActiveProxyServer() const { return this->activeProxyServerList; } 43 49 /** @returns the passive proxy server list */ 44 inline std::list< PeerInfo*> getPassiveProxyServer() const { return this->passiveProxyServerList; }50 inline std::list<NetworkNode*> getPassiveProxyServer() const { return this->passiveProxyServerList; } 45 51 /** @returns the client list */ 46 inline std::list< PeerInfo*> getClient() const { return this->clientList; }52 inline std::list<NetworkNode*> getClient() const { return this->clientList; } 47 53 48 54 PeerInfo* getPeerByUserId( int userId); … … 64 70 65 71 /* network nodes directly connected to this node */ 66 std::list< PeerInfo*> clientList; //!< list of all clients in the network67 std::list< PeerInfo*> activeProxyServerList; //!< list of all proxy servers in the network68 std::list< PeerInfo*> passiveProxyServerList; //!< list of all proxy servers in the network69 std::list< PeerInfo*> masterServerList; //!< list of all master servers in the network (should be 1!! :D)72 std::list<NetworkNode*> clientList; //!< list of all clients in the network 73 std::list<NetworkNode*> activeProxyServerList; //!< list of all proxy servers in the network 74 std::list<NetworkNode*> passiveProxyServerList; //!< list of all proxy servers in the network 75 std::list<NetworkNode*> masterServerList; //!< list of all master servers in the network (should be 1!! :D) 70 76 71 77 };
Note: See TracChangeset
for help on using the changeset viewer.