Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9454 in orxonox.OLD


Ignore:
Timestamp:
Jul 25, 2006, 11:27:48 AM (18 years ago)
Author:
bensch
Message:

some consts added

Location:
branches/proxy/src/lib/network
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/proxy/src/lib/network/handshake.h

    r9406 r9454  
    4949    /* functions indicating states of the handshake */
    5050    /** @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; }
    5252    /** @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; }
    5454    /** stops the handshake and reject the other side with @param reason: string describing the reason */
    5555    inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; }
    5656    /** @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; }
    5858    /** @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; }
    6060    /** marks the handshake to be deleted */
    61     inline void del(){ localState.canDel = 1; }
     61    inline void del() { localState.canDel = 1; }
    6262
    6363
    6464    /* the actual informations exchanged in the handshake */
    6565    /** @returns the host id of the remote host */
    66     inline int  getHostId(){ return remoteState.hostId; }
     66    inline int  getHostId() const { return remoteState.hostId; }
    6767    /** @returns the unique id of the network game manager*/
    68     inline int  getNetworkGameManagerId(){ return remoteState.networkManagerId; }
     68    inline int  getNetworkGameManagerId() const { return remoteState.networkManagerId; }
    6969    /** @returns the unique id of the message manager */
    70     inline int  getMessageManagerId(){ return remoteState.messageManagerId; }
     70    inline int  getMessageManagerId() const { return remoteState.messageManagerId; }
    7171    /** @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; }
    7373
    7474    /** sets @param nick the prefereded nick name */
    7575    inline void setPreferedNickName( const std::string & nick ){ localState.preferedNickName = nick; }
    7676    /** @returns the prefered nick name */
    77     inline std::string getPreferedNickName(){ return remoteState.preferedNickName; }
     77    inline const std::string& getPreferedNickName() const { return remoteState.preferedNickName; }
    7878
    7979    /** @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; }
    8181    /** @param flag: indicating if the client should be redirected */
    8282    inline void setRedirect(bool flag) { if( SharedNetworkData::getInstance()->isClient()) return; this->redirectProxy = (int)flag; }
     
    8585    inline void setProxy1Address(IP address) { if( SharedNetworkData::getInstance()->isClient()) return; this->proxy1 = address; }
    8686    /** @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; }
    8888    /** @param address: the address of the proxy server 2 if any */
    8989    inline void setProxy2Address(IP address) { if( SharedNetworkData::getInstance()->isClient()) return; this->proxy2 = address; }
    9090    /** @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; }
    9292
    9393
  • branches/proxy/src/lib/network/message_manager.h

    r9008 r9454  
    2626
    2727
    28 enum MessageId 
     28enum MessageId
    2929{
    3030  TESTMESSAGEID = 1,
     
    5252  MP_HIGHBANDWIDTH = 1,  //!< fast and reliable but uses a lot of bandwidth
    5353  MP_LOWBANDWIDTH,       //!< may take a long time to arrive. reliable
    54   MP_UNRELIABLE          //!< unreliable. low bandwidth 
     54  MP_UNRELIABLE          //!< unreliable. low bandwidth
    5555};
    5656
     
    8888 public:
    8989   inline static MessageManager * getInstance(){ if (!singletonRef) singletonRef = new MessageManager();  return singletonRef; }
    90    
     90
    9191   virtual ~MessageManager();
    92    
     92
    9393   bool registerMessageHandler( MessageId messageId, MessageCallback cb, void * someData );
    94    
     94
    9595   void sendMessage( MessageId messageId, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority );
    9696
     
    100100   virtual void handleSentState( int userId, int stateId, int fromStateId ){}
    101101   virtual void handleRecvState( int userId, int stateId, int fromStateId ){}
    102    
     102
    103103   void initUser( int userId );
    104104
     
    110110
    111111   int                       newNumber;              //!< used to create unique message numbers
    112    std::list<NetworkMessage> incomingMessageBuffer; 
     112   std::list<NetworkMessage> incomingMessageBuffer;
    113113
    114114};
  • branches/proxy/src/lib/network/monitor/connection_monitor.cc

    r9406 r9454  
    3232  /* set the class id for the base object and add ist to class list*/
    3333  this->setClassID(CL_CONNECTION_MONITOR, "ConnectionMonitor");
    34  
     34
    3535  this->userId = userId;
    3636  this->ping = 0;
     
    4343  this->nZIncomingPackets = 0;
    4444  this->nZOutgoingPackets = 0;
    45  
     45
    4646  this->lastPacketTick = 0;
    4747  this->lastPrintTick = 0;
     
    6464{
    6565  nOutgoingPackets++;
    66  
     66
    6767  // for ping calculation
    6868  sentStateTicks[stateId] = tick;
    69  
     69
    7070  // calculate bandwidth
    7171  outgoingUnzippedPacketHistory[tick] = length;
    7272  outgoingUnzippedBandWidth = calculateBandWidth( outgoingUnzippedPacketHistory, tick );
    73  
     73
    7474  //NETPRINTF(n)("UNZIPPED UPSTREAM: user: %d bandwidth %f\n", userId, outgoingUnzippedBandWidth );
    75  
     75
    7676  // count zero bytes
    7777  //int nZeroBytes = 0;
    78  
     78
    7979  //for ( int i = 0; i < length; i++ )
    8080  //  if ( data[i] == '\0' )
    8181  //    nZeroBytes++;
    82  
     82
    8383  //NETPRINTF(n)( "ZEROBYTES: %d (%f%%)\n", nZeroBytes, ((float)100)*nZeroBytes/length );
    8484}
     
    9494{
    9595  nIncomingPackets++;
    96  
     96
    9797  lastPacketTick = tick;
    98  
     98
    9999  // calculate ping
    100100  if ( sentStateTicks.find( ackedState ) != sentStateTicks.end() )
     
    102102    ackDelay.push_back( tick - sentStateTicks[ackedState] );
    103103  }
    104  
     104
    105105  while ( sentStateTicks.begin() != sentStateTicks.end() && sentStateTicks.begin()->first <= ackedState )
    106106    sentStateTicks.erase( sentStateTicks.begin() );
    107      
     107
    108108  while ( ackDelay.size() > N_PACKETS_FOR_PING )
    109109    ackDelay.erase( ackDelay.begin() );
    110      
     110
    111111  ping = 0;
    112      
     112
    113113  for ( std::list<int>::iterator it = ackDelay.begin(); it != ackDelay.end(); it++ )
    114114    ping += *it;
    115      
     115
    116116  if ( ackDelay.size() == 0 )
    117117    ping = -1;
    118118  else
    119119    ping /= ackDelay.size();
    120      
     120
    121121  //NETPRINTF(n)("PING: user: %d ping: %d\n", userId, ping );
    122  
     122
    123123  // calculate bandwidth
    124124  incomingUnzippedPacketHistory[tick] = length;
    125125  incomingUnzippedBandWidth = calculateBandWidth( incomingUnzippedPacketHistory, tick );
    126  
     126
    127127  //NETPRINTF(n)("UNZIPPED DOWNSTREAM: user: %d bandwidth %f\n", userId, incomingUnzippedBandWidth );
    128  
     128
    129129}
    130130
    131131/**
    132132 * remove old packets
    133  * @param packetHistory 
    134  * @param tick 
     133 * @param packetHistory
     134 * @param tick
    135135 */
    136136void ConnectionMonitor::removeOldPackets( std::map< int, int > & packetHistory, int tick )
     
    149149{
    150150  removeOldPackets( packetHistory, tick );
    151  
     151
    152152  float res = 0.0f;
    153153#if 0
     
    157157      res += it->second;
    158158  }
    159  
     159
    160160  if ( packetHistory.size() <= 1 || tick - packetHistory.begin()->first == 0 )
    161161    res = 0.0f;
    162162  else
    163163    res /= (float)(tick - packetHistory.begin()->first);
    164  
     164
    165165  res *= 1000.0f;
    166166#endif
    167167
    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++ )
    169169  {
    170170    res += it->second;
    171171  }
    172  
     172
    173173  if ( packetHistory.size() <= 1 )
    174174    res = 0.0f;
    175175  else
    176176    res /= (float)(tick - packetHistory.begin()->first);
    177  
     177
    178178  res *= 1000.0f;
    179179
     
    191191{
    192192  nZOutgoingPackets++;
    193  
     193
    194194  // calculate bandwidth
    195195  outgoingZippedPacketHistory[tick] = length;
    196196  outgoingZippedBandWidth = calculateBandWidth( outgoingZippedPacketHistory, tick );
    197  
     197
    198198  //NETPRINTF(n)("UPSTREAM: user: %d bandwidth %f nOutgoingPackets %d\n", userId, outgoingZippedBandWidth, nOutgoingPackets );
    199199
     
    216216{
    217217  nZIncomingPackets++;
    218  
     218
    219219  // calculate bandwidth
    220220  incomingZippedPacketHistory[tick] = length;
    221221  incomingZippedBandWidth = calculateBandWidth( incomingZippedPacketHistory, tick );
    222  
     222
    223223  //NETPRINTF(n)("DOWNSTREAM: user: %d bandwidth %f nIncomingPackets %d\n", userId, incomingZippedBandWidth, nIncomingPackets );
    224  
     224
    225225}
    226226
     
    230230 * @return true if last packet recieved \< NOW() - SECS_TO_TIMEOUT
    231231 */
    232 bool ConnectionMonitor::hasTimedOut( )
     232bool ConnectionMonitor::hasTimedOut( ) const
    233233{
    234234  if ( lastPacketTick + SECS_TO_TIMEOUT*1000 < SDL_GetTicks() && nIncomingPackets > 0 )
    235235    return true;
    236  
     236
    237237  if ( nIncomingPackets == 0 && nOutgoingPackets >= NETWORK_FREQUENCY*SECS_TO_TIMEOUT )
    238238    return true;
    239  
     239
    240240  return false;
    241241}
     
    246246 * prints bandwith usage, ping and other important things to telnet-console
    247247 */
    248 void ConnectionMonitor::printStatis( )
     248void ConnectionMonitor::printStatis( ) const
    249249{
    250250  NETPRINT(n)("============NETWORKSTATS FOR USER %d============\n", userId);
  • branches/proxy/src/lib/network/monitor/connection_monitor.h

    r9431 r9454  
    3131    void calculatePing();
    3232
    33     bool hasTimedOut();
     33    bool hasTimedOut() const;
    3434
    35     void printStatis();
     35    void printStatis() const;
    3636    float getIncomingUnzippedBandWidth() const { return incomingUnzippedBandWidth; }
    3737    float getOutgoingUnzippedBandWidth() const { return outgoingUnzippedBandWidth; }
  • branches/proxy/src/lib/network/proxy/network_settings.h

    r9426 r9454  
    3737    inline void setMaxPlayer(int number) { this->maxPlayer = number; }
    3838    /** @returns teh max number of players */
    39     int getMaxPlayer() { return this->maxPlayer; }
     39    int getMaxPlayer() const { return this->maxPlayer; }
    4040    /** sets the @param saturation: a threshold in percente when the proxy servers should be activated to be able to redirect the clients */
    4141    inline void setMaxPlayerSaturation(float saturation) { this->maxPlayerSaturation = saturation; }
     
    4444    void setMasterAddr(const std::string& masterAddr);
    4545    /** @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; }
    4747
    4848    void setProxyAddr(const std::string& proxyAddr);
Note: See TracChangeset for help on using the changeset viewer.