Changeset 9656 in orxonox.OLD for trunk/src/lib/network/monitor
- Timestamp:
- Aug 4, 2006, 11:01:28 PM (18 years ago)
- Location:
- trunk/src/lib/network/monitor
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/monitor/network_monitor.cc
r9494 r9656 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()); … … 66 67 PeerInfo* peer = new PeerInfo(); 67 68 peer->ip = (*it); 68 peer->nodeType = NET_PROXY_SERVER_ ACTIVE;69 peer->nodeType = NET_PROXY_SERVER_PASSIVE; 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)); 181 } 182 183 184 185 /** 186 * removes a node from the network monitor 187 * @param pInfo the node to remove 188 */ 189 void 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 */ 200 void 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); 175 211 } 176 212 … … 197 233 198 234 /** 235 * @param userId of the searched node 236 * @returns the PeerInfo of the userId peer 237 */ 238 PeerInfo* 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 */ 252 NetworkNode* 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 /** 199 268 * this displays the network monitor gui 200 269 */ … … 203 272 if (this->box == NULL) 204 273 { 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); 212 275 this->box->showAll(); 213 this->box->setAbsCoor2D(300, 40);214 276 } 215 277 else … … 251 313 for(; it != this->nodeList.end(); it++) 252 314 { 253 (*it)->debug( 0);315 (*it)->debug(1); 254 316 } 255 317 -
trunk/src/lib/network/monitor/network_monitor.h
r9494 r9656 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 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); } 56 59 57 60 PeerInfo* getFirstChoiceProxy() const; … … 61 64 62 65 /** @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(); } 64 67 65 68 /* slots admin and info interface */ … … 76 79 77 80 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 78 89 79 90 void toggleGUI(); … … 92 103 int playerNumber; //!< total number of players in the game 93 104 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 94 108 }; 95 109 -
trunk/src/lib/network/monitor/network_node.cc
r9494 r9656 18 18 #include "debug.h" 19 19 20 21 20 /** 22 21 * constructor … … 39 38 * adds a client 40 39 */ 41 void NetworkNode::addClient( PeerInfo* node)40 void NetworkNode::addClient(NetworkNode* node) 42 41 { 43 42 this->clientList.push_back(node); … … 49 48 * adds a proxy server 50 49 */ 51 void NetworkNode::addActiveProxyServer( PeerInfo* node)50 void NetworkNode::addActiveProxyServer(NetworkNode* node) 52 51 { 53 52 this->activeProxyServerList.push_back(node); … … 58 57 * adds a proxy server 59 58 */ 60 void NetworkNode::addPassiveProxyServer( PeerInfo* node)59 void NetworkNode::addPassiveProxyServer(NetworkNode* node) 61 60 { 62 61 this->passiveProxyServerList.push_back(node); … … 66 65 * adds a master server 67 66 */ 68 void NetworkNode::addMasterServer( PeerInfo* node)67 void NetworkNode::addMasterServer(NetworkNode* node) 69 68 { 70 69 this->masterServerList.push_back(node); … … 75 74 * removes a client 76 75 */ 77 void NetworkNode::removeClient( PeerInfo* node)78 { 79 std::list< PeerInfo*>::iterator it = this->clientList.begin();76 void NetworkNode::removeClient(NetworkNode* node) 77 { 78 std::list<NetworkNode*>::iterator it = this->clientList.begin(); 80 79 for(; it != this->clientList.end(); it++) 81 80 { … … 94 93 * removes a proxy server 95 94 */ 96 void NetworkNode::removeActiveProxyServer( PeerInfo* node)97 { 98 std::list< PeerInfo*>::iterator it = this->activeProxyServerList.begin();95 void NetworkNode::removeActiveProxyServer(NetworkNode* node) 96 { 97 std::list<NetworkNode*>::iterator it = this->activeProxyServerList.begin(); 99 98 for(; it != this->activeProxyServerList.end(); it++) 100 99 { … … 113 112 * removes a proxy server 114 113 */ 115 void NetworkNode::removePassiveProxyServer( PeerInfo* node)116 { 117 std::list< PeerInfo*>::iterator it = this->passiveProxyServerList.begin();114 void NetworkNode::removePassiveProxyServer(NetworkNode* node) 115 { 116 std::list<NetworkNode*>::iterator it = this->passiveProxyServerList.begin(); 118 117 for(; it != this->passiveProxyServerList.end(); it++) 119 118 { … … 131 130 * removes a master server 132 131 */ 133 void NetworkNode::removeMasterServer( PeerInfo* node)134 { 135 std::list< PeerInfo*>::iterator it = this->masterServerList.begin();132 void NetworkNode::removeMasterServer(NetworkNode* node) 133 { 134 std::list<NetworkNode*>::iterator it = this->masterServerList.begin(); 136 135 for(; it != this->masterServerList.end(); it++) 137 136 { … … 145 144 146 145 PRINTF(2)("Could not remove client from the list, very strange..."); 146 } 147 148 149 150 151 /** 152 * removes a client 153 */ 154 void 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 */ 173 void 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 */ 192 void 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 */ 210 void 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 */ 235 PeerInfo* 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; 147 270 } 148 271 … … 154 277 PeerInfo* NetworkNode::getClient(int index) const 155 278 { 156 if( this->clientList.size() < index)279 if( (int)this->clientList.size() < index) 157 280 return NULL; 158 281 159 std::list< PeerInfo*>::const_iterator it = this->clientList.begin();282 std::list<NetworkNode*>::const_iterator it = this->clientList.begin(); 160 283 for(int i = 0; it != this->clientList.end(); it++, i++) 161 284 { 162 285 if( i == index) 163 return (*it) ;286 return (*it)->getPeerInfo(); 164 287 } 165 288 … … 174 297 PeerInfo* NetworkNode::getActiveProxyServer(int index) const 175 298 { 176 if( this->activeProxyServerList.size() < index)299 if( (int)this->activeProxyServerList.size() < index) 177 300 return NULL; 178 301 179 std::list< PeerInfo*>::const_iterator it = this->activeProxyServerList.begin();302 std::list<NetworkNode*>::const_iterator it = this->activeProxyServerList.begin(); 180 303 for(int i = 0; it != this->activeProxyServerList.end(); it++, i++) 181 304 { 182 305 if( i == index) 183 return (*it) ;306 return (*it)->getPeerInfo(); 184 307 } 185 308 … … 194 317 PeerInfo* NetworkNode::getPassiveProxyServer(int index) const 195 318 { 196 if( this->passiveProxyServerList.size() < index)319 if( (int)this->passiveProxyServerList.size() < index) 197 320 return NULL; 198 321 199 std::list< PeerInfo*>::const_iterator it = this->passiveProxyServerList.begin();322 std::list<NetworkNode*>::const_iterator it = this->passiveProxyServerList.begin(); 200 323 for(int i = 0; it != this->passiveProxyServerList.end(); it++, i++) 201 324 { 202 325 if( i == index) 203 return (*it) ;326 return (*it)->getPeerInfo(); 204 327 } 205 328 … … 214 337 PeerInfo* NetworkNode::getMasterServer(int index) const 215 338 { 216 if( this->masterServerList.size() < index)339 if( (int)this->masterServerList.size() < index) 217 340 return NULL; 218 341 219 std::list< PeerInfo*>::const_iterator it = this->masterServerList.begin();342 std::list<NetworkNode*>::const_iterator it = this->masterServerList.begin(); 220 343 for(int i = 0; it != this->masterServerList.end(); it++, i++) 221 344 { 222 345 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 */ 359 NetworkNode* 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; 224 397 } 225 398 … … 234 407 void NetworkNode::debug(int depth) const 235 408 { 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 13 13 #include <list> 14 14 15 16 15 //!< a class representing a node in the network (this can be a MASTER_SERVER, PROXY_SERVER or a CLIENT 17 16 class NetworkNode … … 22 21 23 22 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); 28 27 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 33 38 34 39 PeerInfo* getClient(int index) const; … … 38 43 39 44 /** @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; } 41 46 /** @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; } 43 48 /** @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; } 45 50 /** @returns the client list */ 46 inline std::list< PeerInfo*> getClient() const { return this->clientList; }51 inline std::list<NetworkNode*> getClients() const { return this->clientList; } 47 52 53 PeerInfo* getPeerByUserId( int userId); 48 54 49 55 /** @returns the number of players */ … … 53 59 /** @returns the peer info of this node */ 54 60 inline PeerInfo* getPeerInfo() const { return this->peerInfo; } 61 62 NetworkNode* getNodeByUserId( int userId); 55 63 56 64 void debug(int depth) const; … … 63 71 64 72 /* network nodes directly connected to this node */ 65 std::list< PeerInfo*> clientList; //!< list of all clients in the network66 std::list< PeerInfo*> activeProxyServerList; //!< list of all proxy servers in the network67 std::list< PeerInfo*> passiveProxyServerList; //!< list of all proxy servers in the network68 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) 69 77 70 78 }; -
trunk/src/lib/network/monitor/network_stats_widget.cc
r9494 r9656 18 18 #include "network_stats_widget.h" 19 19 #include "network_monitor.h" 20 #include "peer_info.h" 20 21 21 22 #include "multi_type.h" … … 23 24 #include "shell_command.h" 24 25 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"); 27 31 28 32 … … 30 34 : GLGuiBox(OrxGui::Horizontal) 31 35 { 36 this->init(); 37 32 38 this->setName(name); 33 39 this->setIP(ip); 34 40 41 } 42 43 HostWidget::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 56 void 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 35 66 this->pack(&this->_name); 36 67 this->pack(&this->_ip); … … 49 80 } 50 81 82 Font* HostWidget::_font = NULL; 83 84 51 85 52 86 … … 54 88 55 89 56 ProxyWidget::ProxyWidget(const std::string& proxyName, const IP& ip)90 NodeWidget::NodeWidget(const std::string& proxyName, const IP& ip) 57 91 : _proxyWidget(proxyName, ip) 58 92 { 59 this->_ clientNameWidth = 100.0f;93 this->_nodeNameWidth = 100.0f; 60 94 this->pack(&_proxyWidget); 61 95 } 62 96 63 void ProxyWidget::addClient(const std::string& name, const IP& ip) 97 NodeWidget::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 123 void 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 131 void NodeWidget::addNode(const std::string& name, const IP& ip) 64 132 { 65 133 HostWidget* newClient = new HostWidget(name, ip); 66 newClient->setNameWidth(this->_ clientNameWidth);134 newClient->setNameWidth(this->_nodeNameWidth); 67 135 68 136 this->pack(newClient); … … 72 140 } 73 141 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()142 bool 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 157 bool 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 173 bool 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 189 void 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 196 void NodeWidget::hiding() 129 197 { 130 198 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 203 void NodeWidget::showing() 136 204 { 137 205 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(); 140 208 } 141 209 … … 147 215 */ 148 216 NetworkStatsWidget::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)) 150 218 { 151 219 this->_monitor = monitor; 220 this->_passedTime = 0.0f; 152 221 153 222 /* … … 169 238 this->_bar.setChangedValueColor(Color::black); 170 239 */ 240 this->_thisHostIs.setText(std::string("I am ") + _monitor->getLocalNode()->getPeerInfo()->getNodeTypeString()); 241 242 this->pack(&this->_thisHostIs); 243 171 244 this->pack(&this->_thisHost); 245 246 this->pack(&this->_serverBox); 172 247 173 248 this->pack(&this->_upstreamText); 174 249 this->pack(&this->_downstreamText); 175 250 176 this->pack(&this->_serverIP); 251 252 this->rebuild(); 177 253 } 178 254 … … 183 259 NetworkStatsWidget::~NetworkStatsWidget () 184 260 {} 261 262 263 void 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 273 NetworkStatsWidget* NetworkStatsWidget::_statsWidget = NULL; 274 275 #include "class_list.h" 276 277 void 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 } 185 295 186 296 … … 204 314 205 315 316 void NetworkStatsWidget::addProxy(const std::string& name, const IP& proxy) 317 {} 318 319 void NetworkStatsWidget::clearProxies() 320 {} 321 322 323 void 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 206 343 void NetworkStatsWidget::tick(float dt) 207 344 { 345 346 if ((_passedTime+= dt) > 1.0f) 347 { 348 this->_passedTime = 0.0f; 349 this->rebuild(); 350 } 351 208 352 assert (this->_monitor->getLocalNode() != NULL); 209 353 assert(this->_monitor->getLocalNode()->getPeerInfo() != NULL); … … 220 364 void NetworkStatsWidget::resize() 221 365 { 222 GLGui Box::resize();366 GLGuiFixedpositionBox::resize(); 223 367 } 224 368 -
trunk/src/lib/network/monitor/network_stats_widget.h
r9494 r9656 2 2 * @file network_stats_widget.h 3 3 * @brief Definition of an EnergyWidget, that displays a bar and a Text 4 */4 */ 5 5 6 6 #ifndef _NETWORK_STATS_WIDGET_H 7 7 #define _NETWORK_STATS_WIDGET_H 8 8 9 #include "glgui_ box.h"9 #include "glgui_fixedposition_box.h" 10 10 #include "glgui_bar.h" 11 11 #include "glgui_text.h" 12 #include "glgui_pushbutton.h" 12 13 13 14 #include "network/ip.h" 14 15 15 16 class NetworkMonitor; 16 17 class NetworkNode; 18 class PeerInfo; 17 19 18 20 class HostWidget : public OrxGui::GLGuiBox … … 20 22 public: 21 23 HostWidget(const std::string& name, const IP& ip); 22 ~HostWidget() {};24 HostWidget(const PeerInfo* peerInfo); 23 25 24 26 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; }; 26 28 27 29 void setNameWidth(float width) { this->_name.setLineWidth(width); }; … … 35 37 36 38 private: 39 void init(); 40 private: 37 41 OrxGui::GLGuiText _name; //!< The Name of the Proxy server to be displayed. 38 42 OrxGui::GLGuiText _ip; //!< The IP of the proxy server. 39 43 IP _storedIP; //!< The ip to compare. 44 45 static Font* _font; 40 46 }; 41 47 42 48 43 class ProxyWidget : public OrxGui::GLGuiBox49 class NodeWidget : public OrxGui::GLGuiBox 44 50 { 45 51 public: 46 ProxyWidget(const std::string& proxyName, const IP& ip); 52 NodeWidget(const std::string& proxyName, const IP& ip); 53 NodeWidget(const NetworkNode* node); 47 54 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); 49 57 50 bool remove Client(const IP& ip);51 bool remove Client(const std::string& name);52 bool remove Client(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); 53 61 54 void set ClientNameWidths(float width);62 void setNodeNameWidths(float width); 55 63 56 64 … … 63 71 HostWidget _proxyWidget; 64 72 65 std::vector< HostWidget*> _clients;66 float _ clientNameWidth;73 std::vector<NodeWidget*> _nodes; 74 float _nodeNameWidth; 67 75 }; 68 76 … … 71 79 72 80 //! A class to display network Statistics. 73 class NetworkStatsWidget : public OrxGui::GLGui Box81 class NetworkStatsWidget : public OrxGui::GLGuiFixedpositionBox 74 82 { 75 83 public: 84 static void toggleGUI(); 85 76 86 NetworkStatsWidget(const NetworkMonitor* monitor); 77 87 virtual ~NetworkStatsWidget(); … … 84 94 85 95 void addProxy(const std::string& name, const IP& proxy); 96 void addNode(const NetworkNode* node); 86 97 98 void clearProxies(); 99 100 void rebuild(); 87 101 88 102 //void rebuildConnectedHosts(std::vector<hosts> hosts); … … 101 115 const NetworkMonitor* _monitor; 102 116 117 OrxGui::GLGuiText _thisHostIs; 103 118 HostWidget _thisHost; 104 119 … … 106 121 OrxGui::GLGuiText _downstreamText; 107 122 108 std::vector<HostWidget*>_connectedProxies;123 OrxGui::GLGuiBox _serverBox; 109 124 110 OrxGui::GLGuiText _serverIP;125 std::vector<NodeWidget*> _proxies; 111 126 112 127 128 static NetworkStatsWidget* _statsWidget; 129 130 131 float _passedTime; 113 132 //OrxGui::GLGuiText _valueText; 114 133 //OrxGui::GLGuiBar _bar;
Note: See TracChangeset
for help on using the changeset viewer.