Changeset 9494 in orxonox.OLD for trunk/src/lib/network/monitor
- Timestamp:
- Jul 27, 2006, 10:44:28 AM (18 years ago)
- Location:
- trunk/src/lib/network/monitor
- Files:
-
- 6 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/monitor/connection_monitor.cc
r9406 r9494 32 32 /* set the class id for the base object and add ist to class list*/ 33 33 this->setClassID(CL_CONNECTION_MONITOR, "ConnectionMonitor"); 34 34 35 35 this->userId = userId; 36 36 this->ping = 0; … … 43 43 this->nZIncomingPackets = 0; 44 44 this->nZOutgoingPackets = 0; 45 45 46 46 this->lastPacketTick = 0; 47 47 this->lastPrintTick = 0; … … 64 64 { 65 65 nOutgoingPackets++; 66 66 67 67 // for ping calculation 68 68 sentStateTicks[stateId] = tick; 69 69 70 70 // calculate bandwidth 71 71 outgoingUnzippedPacketHistory[tick] = length; 72 72 outgoingUnzippedBandWidth = calculateBandWidth( outgoingUnzippedPacketHistory, tick ); 73 73 74 74 //NETPRINTF(n)("UNZIPPED UPSTREAM: user: %d bandwidth %f\n", userId, outgoingUnzippedBandWidth ); 75 75 76 76 // count zero bytes 77 77 //int nZeroBytes = 0; 78 78 79 79 //for ( int i = 0; i < length; i++ ) 80 80 // if ( data[i] == '\0' ) 81 81 // nZeroBytes++; 82 82 83 83 //NETPRINTF(n)( "ZEROBYTES: %d (%f%%)\n", nZeroBytes, ((float)100)*nZeroBytes/length ); 84 84 } … … 94 94 { 95 95 nIncomingPackets++; 96 96 97 97 lastPacketTick = tick; 98 98 99 99 // calculate ping 100 100 if ( sentStateTicks.find( ackedState ) != sentStateTicks.end() ) … … 102 102 ackDelay.push_back( tick - sentStateTicks[ackedState] ); 103 103 } 104 104 105 105 while ( sentStateTicks.begin() != sentStateTicks.end() && sentStateTicks.begin()->first <= ackedState ) 106 106 sentStateTicks.erase( sentStateTicks.begin() ); 107 107 108 108 while ( ackDelay.size() > N_PACKETS_FOR_PING ) 109 109 ackDelay.erase( ackDelay.begin() ); 110 110 111 111 ping = 0; 112 112 113 113 for ( std::list<int>::iterator it = ackDelay.begin(); it != ackDelay.end(); it++ ) 114 114 ping += *it; 115 115 116 116 if ( ackDelay.size() == 0 ) 117 117 ping = -1; 118 118 else 119 119 ping /= ackDelay.size(); 120 120 121 121 //NETPRINTF(n)("PING: user: %d ping: %d\n", userId, ping ); 122 122 123 123 // calculate bandwidth 124 124 incomingUnzippedPacketHistory[tick] = length; 125 125 incomingUnzippedBandWidth = calculateBandWidth( incomingUnzippedPacketHistory, tick ); 126 126 127 127 //NETPRINTF(n)("UNZIPPED DOWNSTREAM: user: %d bandwidth %f\n", userId, incomingUnzippedBandWidth ); 128 128 129 129 } 130 130 131 131 /** 132 132 * remove old packets 133 * @param packetHistory 134 * @param tick 133 * @param packetHistory 134 * @param tick 135 135 */ 136 136 void ConnectionMonitor::removeOldPackets( std::map< int, int > & packetHistory, int tick ) … … 149 149 { 150 150 removeOldPackets( packetHistory, tick ); 151 151 152 152 float res = 0.0f; 153 153 #if 0 … … 157 157 res += it->second; 158 158 } 159 159 160 160 if ( packetHistory.size() <= 1 || tick - packetHistory.begin()->first == 0 ) 161 161 res = 0.0f; 162 162 else 163 163 res /= (float)(tick - packetHistory.begin()->first); 164 164 165 165 res *= 1000.0f; 166 166 #endif 167 167 168 for ( std::map<int,int>:: iterator it = packetHistory.begin(); it != packetHistory.end(); it++ )168 for ( std::map<int,int>::const_iterator it = packetHistory.begin(); it != packetHistory.end(); it++ ) 169 169 { 170 170 res += it->second; 171 171 } 172 172 173 173 if ( packetHistory.size() <= 1 ) 174 174 res = 0.0f; 175 175 else 176 176 res /= (float)(tick - packetHistory.begin()->first); 177 177 178 178 res *= 1000.0f; 179 179 … … 191 191 { 192 192 nZOutgoingPackets++; 193 193 194 194 // calculate bandwidth 195 195 outgoingZippedPacketHistory[tick] = length; 196 196 outgoingZippedBandWidth = calculateBandWidth( outgoingZippedPacketHistory, tick ); 197 197 198 198 //NETPRINTF(n)("UPSTREAM: user: %d bandwidth %f nOutgoingPackets %d\n", userId, outgoingZippedBandWidth, nOutgoingPackets ); 199 199 … … 216 216 { 217 217 nZIncomingPackets++; 218 218 219 219 // calculate bandwidth 220 220 incomingZippedPacketHistory[tick] = length; 221 221 incomingZippedBandWidth = calculateBandWidth( incomingZippedPacketHistory, tick ); 222 222 223 223 //NETPRINTF(n)("DOWNSTREAM: user: %d bandwidth %f nIncomingPackets %d\n", userId, incomingZippedBandWidth, nIncomingPackets ); 224 224 225 225 } 226 226 … … 230 230 * @return true if last packet recieved \< NOW() - SECS_TO_TIMEOUT 231 231 */ 232 bool ConnectionMonitor::hasTimedOut( ) 232 bool ConnectionMonitor::hasTimedOut( ) const 233 233 { 234 234 if ( lastPacketTick + SECS_TO_TIMEOUT*1000 < SDL_GetTicks() && nIncomingPackets > 0 ) 235 235 return true; 236 236 237 237 if ( nIncomingPackets == 0 && nOutgoingPackets >= NETWORK_FREQUENCY*SECS_TO_TIMEOUT ) 238 238 return true; 239 239 240 240 return false; 241 241 } … … 246 246 * prints bandwith usage, ping and other important things to telnet-console 247 247 */ 248 void ConnectionMonitor::printStatis( ) 248 void ConnectionMonitor::printStatis( ) const 249 249 { 250 250 NETPRINT(n)("============NETWORKSTATS FOR USER %d============\n", userId); -
trunk/src/lib/network/monitor/connection_monitor.h
r9406 r9494 31 31 void calculatePing(); 32 32 33 bool hasTimedOut() ;33 bool hasTimedOut() const; 34 34 35 void printStatis(); 35 void printStatis() const; 36 float getIncomingUnzippedBandWidth() const { return incomingUnzippedBandWidth; } 37 float getOutgoingUnzippedBandWidth() const { return outgoingUnzippedBandWidth; } 38 float getIncomingZippedBandWidth() const { return incomingZippedBandWidth; } 39 float getOutgoingZippedBandWidth() const { return outgoingZippedBandWidth; } 36 40 37 41 private: -
trunk/src/lib/network/monitor/network_monitor.cc
r9406 r9494 31 31 32 32 33 SHELL_COMMAND(showGUI, NetworkMonitor, showGUI); 34 SHELL_COMMAND(hideGUI, NetworkMonitor, hideGUI); 33 #include "network_stats_widget.h" 34 35 SHELL_COMMAND(gui, NetworkMonitor, toggleGUI) 36 ->setAlias("ProxyGui"); 35 37 SHELL_COMMAND(debug, NetworkMonitor, debug); 36 38 … … 57 59 { 58 60 // assuming that the config files are already read we get the proxy servers 59 std::vector<IP address*>* proxyList = NetworkSettings::getInstance()->getProxyList();60 std::vector<IP address*>::iterator it = proxyList->begin();61 std::vector<IP>* proxyList = NetworkSettings::getInstance()->getProxyList(); 62 std::vector<IP>::iterator it = proxyList->begin(); 61 63 // create a peer info class and a network node class for each new proxy and add them to the passive list 62 64 for(; it < proxyList->end(); it++) 63 65 { 64 66 PeerInfo* peer = new PeerInfo(); 65 peer->ip = *(*it);67 peer->ip = (*it); 66 68 peer->nodeType = NET_PROXY_SERVER_ACTIVE; 67 69 peer->userId = -1; … … 72 74 } 73 75 } 76 this->box = NULL; 74 77 } 75 78 … … 119 122 * @param ip ip of the new node 120 123 */ 121 void NetworkMonitor::addNode( IPip, int nodeType)124 void NetworkMonitor::addNode(const IP& ip, int nodeType) 122 125 { 123 126 PeerInfo* pInfo = new PeerInfo(); … … 140 143 if( pInfo->isClient()) 141 144 this->localNode->addClient(pInfo); 142 else if( pInfo->isProxyServer ())145 else if( pInfo->isProxyServerActive()) 143 146 { 144 147 this->localNode->addActiveProxyServer(pInfo); … … 166 169 if( pInfo->isClient()) 167 170 node->addClient(pInfo); 168 else if( pInfo->isProxyServer ())171 else if( pInfo->isProxyServerActive()) 169 172 node->addActiveProxyServer(pInfo); 170 173 else if( pInfo->isMasterServer()) … … 176 179 * @returns the proxy server of the first choice 177 180 */ 178 PeerInfo* NetworkMonitor::getFirstChoiceProxy() 181 PeerInfo* NetworkMonitor::getFirstChoiceProxy() const 179 182 { 180 183 // return the fist proxy in the list … … 186 189 * @returns the proxy server of second choice 187 190 */ 188 PeerInfo* NetworkMonitor::getSecondChoiceProxy() 191 PeerInfo* NetworkMonitor::getSecondChoiceProxy() const 189 192 { 190 193 // return the second server in the list … … 196 199 * this displays the network monitor gui 197 200 */ 198 void NetworkMonitor:: showGUI()201 void NetworkMonitor::toggleGUI() 199 202 { 200 203 if (this->box == NULL) … … 202 205 this->box = new OrxGui::GLGuiBox(OrxGui::Vertical); 203 206 { 204 OrxGui::GLGuiBox* waterColorBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); 205 { 206 OrxGui::GLGuiText* waterColorText = new OrxGui::GLGuiText(); 207 waterColorText->setText("NetworkMonitor"); 208 waterColorBox->pack(waterColorText); 209 } 210 this->box->pack(waterColorBox); 207 NetworkStatsWidget* netStats = new NetworkStatsWidget(this); 208 this->box->pack(netStats); 209 211 210 } 212 211 213 212 this->box->showAll(); 214 213 this->box->setAbsCoor2D(300, 40); 215 OrxGui::GLGuiHandler::getInstance()->activate(); 216 // OrxGui::GLGuiHandler::getInstance()->activateCursor(); 217 } 218 } 219 220 221 /** 222 * hides the network monitor gui again 223 */ 224 void NetworkMonitor::hideGUI() 225 { 226 if( this->box == NULL) 227 return; 228 229 OrxGui::GLGuiHandler::getInstance()->deactivate(); 230 // OrxGui::GLGuiHandler::getInstance()->deactivateCursor(); 231 232 delete this->box; 233 this->box = NULL; 234 } 235 214 } 215 else 216 { 217 delete this->box; 218 this->box = NULL; 219 } 220 } 236 221 237 222 /** … … 255 240 * prints out the debug informations 256 241 */ 257 void NetworkMonitor::debug() 242 void NetworkMonitor::debug() const 258 243 { 259 244 PRINT(0)("================================= Network Monitor::debug() =====\n"); 260 245 PRINT(0)(" I am: %s\n", this->localNode->getPeerInfo()->getNodeTypeString().c_str()); 261 PRINT(0)(" Total count of network connections: %i\n", this->playerNumber); 246 PRINT(0)(" Total count of network connections: %i\n", this->connectionNumber); 247 PRINT(0)(" Total count of players: %i\n", this->playerNumber); 262 248 PRINT(0)(" Max players on this server: %i\n", SharedNetworkData::getInstance()->getMaxPlayer()); 263 249 264 std::list<NetworkNode*>:: iterator it = this->nodeList.begin();250 std::list<NetworkNode*>::const_iterator it = this->nodeList.begin(); 265 251 for(; it != this->nodeList.end(); it++) 266 252 { -
trunk/src/lib/network/monitor/network_monitor.h
r9406 r9494 37 37 38 38 void addNode(PeerInfo* pInfo); 39 void addNode( IPip, int nodeType);39 void addNode(const IP& ip, int nodeType); 40 40 void addNode(NetworkNode* node) { this->nodeList.push_back(node); } 41 41 void addNode(NetworkNode* node, PeerInfo* pInfo); … … 55 55 inline void removeMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->removeMasterServer(pInfo); } 56 56 57 PeerInfo* getFirstChoiceProxy(); 58 PeerInfo* getSecondChoiceProxy(); 57 PeerInfo* getFirstChoiceProxy() const; 58 PeerInfo* getSecondChoiceProxy() const; 59 /** @returns the local node */ 60 inline NetworkNode* getLocalNode() const { return this->localNode; }; 59 61 60 62 /** @returns the active proxy server list of the localnode */ 61 inline std::list<PeerInfo*> getActiveProxyServer() { return this->localNode->getActiveProxyServer(); }63 inline std::list<PeerInfo*> getActiveProxyServer() const { return this->localNode->getActiveProxyServer(); } 62 64 63 65 /* slots admin and info interface */ 64 66 /** @returns the total number of players in this game (including all proxy servers etc)*/ 65 inline int getPlayerNumber() { return this->playerNumber; }67 inline int getPlayerNumber() const { return this->playerNumber; } 66 68 67 69 /** @returns true if there are still free network slots available at the local node*/ 68 inline bool gotFreeSlots() { return (this->localNode->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer())?true:false; }70 inline bool gotFreeSlots() const { return (this->localNode->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer()); } 69 71 /** @param node node to be checked for slots @returns true if there are still free network slots available at this node */ 70 inline bool gotFreeSlots(NetworkNode* node) { return (node->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer())?true:false; }72 inline bool gotFreeSlots(NetworkNode* node) const { return (node->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer()); } 71 73 72 74 /** @returns true if the next client should be reconnected to some other proxy server with more connections */ 73 inline bool isReconnectNextClient() { return (this->localNode->getPlayerNumber() >= SharedNetworkData::getInstance()->getMaxPlayer())?true:false; }75 inline bool isReconnectNextClient() const { return (this->localNode->getPlayerNumber() >= SharedNetworkData::getInstance()->getMaxPlayer()); } 74 76 77 inline const std::list<NetworkNode*>& getNodeList() const { return this->nodeList; }; 75 78 76 void showGUI(); 77 void hideGUI(); 79 void toggleGUI(); 78 80 79 81 void process(); 80 void debug() ;82 void debug() const; 81 83 82 84 -
trunk/src/lib/network/monitor/network_node.cc
r9406 r9494 152 152 * @return the client in the list or NULL if none 153 153 */ 154 PeerInfo* NetworkNode::getClient(int index) 154 PeerInfo* NetworkNode::getClient(int index) const 155 155 { 156 156 if( this->clientList.size() < index) 157 157 return NULL; 158 158 159 std::list<PeerInfo*>:: iterator it = this->clientList.begin();159 std::list<PeerInfo*>::const_iterator it = this->clientList.begin(); 160 160 for(int i = 0; it != this->clientList.end(); it++, i++) 161 161 { … … 172 172 * @return the active proxy server in the list or NULL if none 173 173 */ 174 PeerInfo* NetworkNode::getActiveProxyServer(int index) 174 PeerInfo* NetworkNode::getActiveProxyServer(int index) const 175 175 { 176 176 if( this->activeProxyServerList.size() < index) 177 177 return NULL; 178 178 179 std::list<PeerInfo*>:: iterator it = this->activeProxyServerList.begin();179 std::list<PeerInfo*>::const_iterator it = this->activeProxyServerList.begin(); 180 180 for(int i = 0; it != this->activeProxyServerList.end(); it++, i++) 181 181 { … … 192 192 * @return the passive proxy server in the list or NULL if none 193 193 */ 194 PeerInfo* NetworkNode::getPassiveProxyServer(int index) 194 PeerInfo* NetworkNode::getPassiveProxyServer(int index) const 195 195 { 196 196 if( this->passiveProxyServerList.size() < index) 197 197 return NULL; 198 198 199 std::list<PeerInfo*>:: iterator it = this->passiveProxyServerList.begin();199 std::list<PeerInfo*>::const_iterator it = this->passiveProxyServerList.begin(); 200 200 for(int i = 0; it != this->passiveProxyServerList.end(); it++, i++) 201 201 { … … 212 212 * @return the master server in the list or NULL if none 213 213 */ 214 PeerInfo* NetworkNode::getMasterServer(int index) 214 PeerInfo* NetworkNode::getMasterServer(int index) const 215 215 { 216 216 if( this->masterServerList.size() < index) 217 217 return NULL; 218 218 219 std::list<PeerInfo*>:: iterator it = this->masterServerList.begin();219 std::list<PeerInfo*>::const_iterator it = this->masterServerList.begin(); 220 220 for(int i = 0; it != this->masterServerList.end(); it++, i++) 221 221 { … … 232 232 * @param depth: depth in the tree 233 233 */ 234 void NetworkNode::debug(int depth) 234 void NetworkNode::debug(int depth) const 235 235 { 236 236 PRINT(0)(" = %s\n", this->peerInfo->getNodeTypeString().c_str()); 237 237 238 238 PRINT(0)(" master servers: %i\n", this->masterServerList.size()); 239 std::list<PeerInfo*>:: iterator it = this->masterServerList.begin();239 std::list<PeerInfo*>::const_iterator it = this->masterServerList.begin(); 240 240 for(; it != this->masterServerList.end(); it++) 241 241 { -
trunk/src/lib/network/monitor/network_node.h
r9406 r9494 32 32 void removeMasterServer(PeerInfo* node); 33 33 34 PeerInfo* getClient(int index) ;35 PeerInfo* getActiveProxyServer(int index) ;36 PeerInfo* getPassiveProxyServer(int index) ;37 PeerInfo* getMasterServer(int index) ;34 PeerInfo* getClient(int index) const; 35 PeerInfo* getActiveProxyServer(int index) const; 36 PeerInfo* getPassiveProxyServer(int index) const; 37 PeerInfo* getMasterServer(int index) const; 38 38 39 39 /** @returns the master server list */ 40 inline std::list<PeerInfo*> getMasterServer() { return this->masterServerList; }40 inline std::list<PeerInfo*> getMasterServer() const { return this->masterServerList; } 41 41 /** @returns the active proxy server list */ 42 inline std::list<PeerInfo*> getActiveProxyServer() { return this->activeProxyServerList; }42 inline std::list<PeerInfo*> getActiveProxyServer() const { return this->activeProxyServerList; } 43 43 /** @returns the passive proxy server list */ 44 inline std::list<PeerInfo*> getPassiveProxyServer() { return this->passiveProxyServerList; }44 inline std::list<PeerInfo*> getPassiveProxyServer() const { return this->passiveProxyServerList; } 45 45 /** @returns the client list */ 46 inline std::list<PeerInfo*> getClient() { return this->clientList; }46 inline std::list<PeerInfo*> getClient() const { return this->clientList; } 47 47 48 48 49 49 /** @returns the number of players */ 50 inline int getPlayerNumber() { return this->playerNumber; }50 inline int getPlayerNumber() const { return this->playerNumber; } 51 51 /** @returns the node type of this node */ 52 inline int getNodeType() { return this->peerInfo->nodeType; }52 inline int getNodeType() const { return this->peerInfo->nodeType; } 53 53 /** @returns the peer info of this node */ 54 inline PeerInfo* getPeerInfo() { return this->peerInfo; }54 inline PeerInfo* getPeerInfo() const { return this->peerInfo; } 55 55 56 void debug(int depth) ;56 void debug(int depth) const; 57 57 58 58 … … 60 60 int playerNumber; //!< localy direct connected player number 61 61 int connectionNumber; //!< number of connections ( can but musn't be equal players) 62 PeerInfo* peerInfo; //!< the peer information aabout this node62 PeerInfo* peerInfo; //!< the peer information about this node 63 63 64 64 /* network nodes directly connected to this node */
Note: See TracChangeset
for help on using the changeset viewer.