- Timestamp:
- Jul 25, 2006, 11:27:48 AM (18 years ago)
- Location:
- branches/proxy/src/lib/network
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/network/handshake.h
r9406 r9454 49 49 /* functions indicating states of the handshake */ 50 50 /** @returns true if the handshake is completed */ 51 inline bool completed() { return localState.completed != 0 && remoteState.completed != 0; }51 inline bool completed() const { return localState.completed != 0 && remoteState.completed != 0; } 52 52 /** @returns true if no error has occured until now */ 53 inline bool ok() { return localState.error == 0 && remoteState.error == 0; }53 inline bool ok() const { return localState.error == 0 && remoteState.error == 0; } 54 54 /** stops the handshake and reject the other side with @param reason: string describing the reason */ 55 55 inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; } 56 56 /** @returns true if the handshake is finished and the instances can be deleted */ 57 inline bool canDel() { return localState.canDel == 1 && remoteState.canDel == 1; }57 inline bool canDel() const { return localState.canDel == 1 && remoteState.canDel == 1; } 58 58 /** @returns true if the local state can be removed*/ 59 inline bool allowDel() { return localState.canDel == 1; }59 inline bool allowDel() const { return localState.canDel == 1; } 60 60 /** marks the handshake to be deleted */ 61 inline void del() { localState.canDel = 1; }61 inline void del() { localState.canDel = 1; } 62 62 63 63 64 64 /* the actual informations exchanged in the handshake */ 65 65 /** @returns the host id of the remote host */ 66 inline int getHostId() { return remoteState.hostId; }66 inline int getHostId() const { return remoteState.hostId; } 67 67 /** @returns the unique id of the network game manager*/ 68 inline int getNetworkGameManagerId() { return remoteState.networkManagerId; }68 inline int getNetworkGameManagerId() const { return remoteState.networkManagerId; } 69 69 /** @returns the unique id of the message manager */ 70 inline int getMessageManagerId() { return remoteState.messageManagerId; }70 inline int getMessageManagerId() const { return remoteState.messageManagerId; } 71 71 /** @returns the node type of the remote host */ 72 inline int getRemoteNodeType() { return this->remoteState.nodeType; }72 inline int getRemoteNodeType() const { return this->remoteState.nodeType; } 73 73 74 74 /** sets @param nick the prefereded nick name */ 75 75 inline void setPreferedNickName( const std::string & nick ){ localState.preferedNickName = nick; } 76 76 /** @returns the prefered nick name */ 77 inline std::string getPreferedNickName(){ return remoteState.preferedNickName; }77 inline const std::string& getPreferedNickName() const { return remoteState.preferedNickName; } 78 78 79 79 /** @returns if true the local client should reconnect to a proxy server from the proxy server list */ 80 inline bool redirect() { return this->redirectProxy;}80 inline bool redirect() const { return this->redirectProxy; } 81 81 /** @param flag: indicating if the client should be redirected */ 82 82 inline void setRedirect(bool flag) { if( SharedNetworkData::getInstance()->isClient()) return; this->redirectProxy = (int)flag; } … … 85 85 inline void setProxy1Address(IP address) { if( SharedNetworkData::getInstance()->isClient()) return; this->proxy1 = address; } 86 86 /** @returns the address of the proxy server 1 if any */ 87 inline IP getProxy1Address() { return this->proxy1; }87 inline IP getProxy1Address() const { return this->proxy1; } 88 88 /** @param address: the address of the proxy server 2 if any */ 89 89 inline void setProxy2Address(IP address) { if( SharedNetworkData::getInstance()->isClient()) return; this->proxy2 = address; } 90 90 /** @returns the address of the proxy server 2 if any */ 91 inline IP getProxy2Address() { return this->proxy2; }91 inline IP getProxy2Address() const { return this->proxy2; } 92 92 93 93 -
branches/proxy/src/lib/network/message_manager.h
r9008 r9454 26 26 27 27 28 enum MessageId 28 enum MessageId 29 29 { 30 30 TESTMESSAGEID = 1, … … 52 52 MP_HIGHBANDWIDTH = 1, //!< fast and reliable but uses a lot of bandwidth 53 53 MP_LOWBANDWIDTH, //!< may take a long time to arrive. reliable 54 MP_UNRELIABLE //!< unreliable. low bandwidth 54 MP_UNRELIABLE //!< unreliable. low bandwidth 55 55 }; 56 56 … … 88 88 public: 89 89 inline static MessageManager * getInstance(){ if (!singletonRef) singletonRef = new MessageManager(); return singletonRef; } 90 90 91 91 virtual ~MessageManager(); 92 92 93 93 bool registerMessageHandler( MessageId messageId, MessageCallback cb, void * someData ); 94 94 95 95 void sendMessage( MessageId messageId, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority ); 96 96 … … 100 100 virtual void handleSentState( int userId, int stateId, int fromStateId ){} 101 101 virtual void handleRecvState( int userId, int stateId, int fromStateId ){} 102 102 103 103 void initUser( int userId ); 104 104 … … 110 110 111 111 int newNumber; //!< used to create unique message numbers 112 std::list<NetworkMessage> incomingMessageBuffer; 112 std::list<NetworkMessage> incomingMessageBuffer; 113 113 114 114 }; -
branches/proxy/src/lib/network/monitor/connection_monitor.cc
r9406 r9454 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); -
branches/proxy/src/lib/network/monitor/connection_monitor.h
r9431 r9454 31 31 void calculatePing(); 32 32 33 bool hasTimedOut() ;33 bool hasTimedOut() const; 34 34 35 void printStatis() ;35 void printStatis() const; 36 36 float getIncomingUnzippedBandWidth() const { return incomingUnzippedBandWidth; } 37 37 float getOutgoingUnzippedBandWidth() const { return outgoingUnzippedBandWidth; } -
branches/proxy/src/lib/network/proxy/network_settings.h
r9426 r9454 37 37 inline void setMaxPlayer(int number) { this->maxPlayer = number; } 38 38 /** @returns teh max number of players */ 39 int getMaxPlayer() { return this->maxPlayer; }39 int getMaxPlayer() const { return this->maxPlayer; } 40 40 /** sets the @param saturation: a threshold in percente when the proxy servers should be activated to be able to redirect the clients */ 41 41 inline void setMaxPlayerSaturation(float saturation) { this->maxPlayerSaturation = saturation; } … … 44 44 void setMasterAddr(const std::string& masterAddr); 45 45 /** @returns the address of the master server read from the network config file */ 46 inline IP getMasterAddr(){ return this->masterServer; }46 inline const IP& getMasterAddr() const { return this->masterServer; } 47 47 48 48 void setProxyAddr(const std::string& proxyAddr);
Note: See TracChangeset
for help on using the changeset viewer.