Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9300 in orxonox.OLD


Ignore:
Timestamp:
Jul 17, 2006, 10:15:33 AM (18 years ago)
Author:
patrick
Message:

work from this weekend in the train :D

  • the ip should now synchronize over network in the handshake (always the favorite 2 proxy server ips)
  • the network monitor now keeps track of all network nodes answers with proxy server lists if asked/needed
  • it is untested :D
Location:
branches/proxy/src
Files:
11 edited

Legend:

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

    r9296 r9300  
    2525
    2626
    27 Handshake::Handshake( int nodeType, int clientId, int networkGameManagerId, int messageManagerId )
     27 Handshake::Handshake( int nodeType, int clientId, int networkGameManagerId, int messageManagerId )
    2828  : Synchronizeable()
    2929{
     
    4646
    4747  registerVar( new SynchronizeableString( &localState.preferedNickName, &remoteState.preferedNickName, "preferedNickName", PERMISSION_ALL ) );
     48  // now synchronize only two of the available proxy server addresses
    4849  registerVar( new SynchronizeableIP( &localState.proxy1, &remoteState.proxy1, "proxy server 1", PERMISSION_ALL ) );
    4950  registerVar( new SynchronizeableIP( &localState.proxy2, &remoteState.proxy1, "proxy server 2", PERMISSION_ALL ) );
     
    6162  localState.canDel = 0;
    6263  localState.redirectProxy = 0;
     64  localState.proxy1.host = 0;
     65  localState.proxy1.port = 0;
     66  localState.proxy2.host = 0;
     67  localState.proxy2.port = 0;
    6368
     69
     70  // init the remote state
    6471  remoteState.completed = 0;
    6572  remoteState.error = 0;
     
    7380  remoteState.canDel = 0;
    7481  remoteState.redirectProxy = 0;
     82  remoteState.proxy1.host = 0;
     83  remoteState.proxy1.port = 0;
     84  remoteState.proxy2.host = 0;
     85  remoteState.proxy2.port = 0;
    7586
    7687  // activate the synchronization process
  • branches/proxy/src/lib/network/handshake.h

    r9296 r9300  
    11/*!
    22 * @file network_stream.h
    3  *  implementation of a network pipe
     3 *  implementation of a network pipe. This node handles the handshake of two network nodes and exchanges informationas
     4 * vial to the connection setup.
    45 */
    56
     
    1011#include "synchronizeable.h"
    1112
    12 
     13//!< a struct to save the handshakes to
    1314struct HandshakeState
    1415{
     
    3637};
    3738
     39
     40//!< the handshake itself with some interface functions
    3841class Handshake : public Synchronizeable
    3942{
     
    7477
    7578    /** @returns if true the local client should reconnect to a proxy server from the proxy server list */
    76     inline bool redirect() { return this->remoteState.redirectProxy;}
     79    inline bool redirect() { return this->localState.redirectProxy;}
     80    /** @param flag: indicating if the client should be redirected */
     81    inline void setRedirect(bool flag) { this->remoteState.redirectProxy = flag; }
    7782
    7883    /** @param address: the address of the proxy server 1 if any */
  • branches/proxy/src/lib/network/monitor/network_monitor.cc

    r9292 r9300  
    1919#include "debug.h"
    2020
     21#include "proxy/proxy_settings.h"
     22
    2123#include "network_monitor.h"
    2224#include "network_node.h"
     25#include "peer_info.h"
    2326#include "network_stream.h"
     27#include "netdefs.h"
     28
     29#include <vector>
    2430
    2531
     
    4551
    4652  this->setSynchronized(false);
     53
     54  // assuming that the config files are already read we get the proxy servers
     55  std::vector<IPaddress*>* proxyList = &ProxySettings::getInstance()->getProxyList();
     56  std::vector<IPaddress*>::iterator it = proxyList->begin();
     57  // create a peer info class and a network node class for each new proxy and add them to the passive list
     58  for(; it < proxyList->end(); it++)
     59  {
     60    PeerInfo* peer = new PeerInfo();
     61    peer->ip = *(*it);
     62    peer->nodeType = NET_PROXY_SERVER;
     63    peer->userId = -1;
     64
     65    NetworkNode* node = new NetworkNode(peer);
     66    this->addPassiveProxyServer( this->localNode, peer);
     67  }
    4768}
    4869
     
    86107}
    87108
     109/**
     110 * tihs adds the new network node
     111 * @param ip ip of the new node
     112 */
     113void NetworkMonitor::addNode(IPaddress ip)
     114{}
     115
    88116
    89117/**
     
    128156  else if( pInfo->isMasterServer())
    129157    node->addMasterServer(pInfo);
     158}
     159
     160
     161/**
     162 * @returns the proxy server of the first choice
     163 */
     164PeerInfo* NetworkMonitor::getFirstChoiceProxy()
     165{
     166  // return the fist proxy in the list
     167  return this->localNode->getActiveProxyServer(0);
     168}
     169
     170
     171/**
     172 * @returns the proxy server of second choice
     173 */
     174PeerInfo* NetworkMonitor::getSecondChoiceProxy()
     175{
     176  // return the second server in the list
     177  return this->localNode->getActiveProxyServer(1);
    130178}
    131179
     
    185233  }
    186234
     235  // check if a proxy server has to activated
     236
    187237  this->debug();
    188238}
  • branches/proxy/src/lib/network/monitor/network_monitor.h

    r9296 r9300  
    3434    void removeNetworkNode(NetworkNode* node);
    3535
     36    void addNode(IPaddress ip);
    3637    void addNode(PeerInfo* pInfo);
    3738    void addNode(NetworkNode* node) { this->nodeList.push_back(node); }
     
    4243    /** adds to @param node a network node @param pInfo a new proxy server */
    4344    inline void addActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addActiveProxyServer(pInfo); }
     45    /** adds to @param node a network node @param pInfo a new proxy server */
     46    inline void addPassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addPassiveProxyServer(pInfo); }
    4447    /** adds to @param node a network node @param pInfo a new master server*/
    4548    inline void addMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->addMasterServer(pInfo); }
     
    4750    inline void removeClient(NetworkNode* node, PeerInfo* pInfo) { node->removeClient(pInfo); }
    4851    inline void removeActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removeActiveProxyServer(pInfo); }
     52    inline void removePassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removePassiveProxyServer(pInfo); }
    4953    inline void removeMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->removeMasterServer(pInfo); }
    5054
     
    5761    /** @param node node to be checked for slots @returns true if there are still free network slots available at this node */
    5862    inline bool gotFreeSlots(NetworkNode* node) { return (node->getPlayerNumber() < NET_MAX_CONNECTIONS)?true:false; }
    59     void getServerWithFreeSlots() { }
     63    PeerInfo* getFirstChoiceProxy();
     64    PeerInfo* getSecondChoiceProxy();
     65    /** @returns true if the next client should be reconnected to some other proxy server with more connections */
     66    inline bool reconnectNextClient() { return (this->localNode->getPlayerNumber() >= NET_MAX_CONNECTIONS)?true:false; }
    6067
    6168
  • branches/proxy/src/lib/network/monitor/network_node.cc

    r9292 r9300  
    147147
    148148
     149/**
     150 * @param index index to the client
     151 * @return the client in the list or NULL if none
     152 */
     153PeerInfo* NetworkNode::getClient(int index)
     154{
     155  if( this->clientList.size() < index)
     156    return NULL;
     157
     158  std::list<PeerInfo*>::iterator it = this->clientList.begin();
     159  for(int i = 0; it != this->clientList.end(); it++, i++)
     160  {
     161  if( i == index)
     162    return (*it);
     163  }
     164
     165  return NULL;
     166}
     167
     168
     169/**
     170 * @param index index to the client
     171 * @return the active proxy server in the list or NULL if none
     172 */
     173PeerInfo* NetworkNode::getActiveProxyServer(int index)
     174{
     175  if( this->activeProxyServerList.size() < index)
     176    return NULL;
     177
     178  std::list<PeerInfo*>::iterator it = this->activeProxyServerList.begin();
     179  for(int i = 0; it != this->activeProxyServerList.end(); it++, i++)
     180  {
     181    if( i == index)
     182      return (*it);
     183  }
     184
     185  return NULL;
     186}
     187
     188
     189/**
     190 * @param index index to the client
     191 * @return the passive proxy server in the list or NULL if none
     192 */
     193PeerInfo* NetworkNode::getPassiveProxyServer(int index)
     194{
     195  if( this->passiveProxyServerList.size() < index)
     196    return NULL;
     197
     198  std::list<PeerInfo*>::iterator it = this->passiveProxyServerList.begin();
     199  for(int i = 0; it != this->passiveProxyServerList.end(); it++, i++)
     200  {
     201    if( i == index)
     202      return (*it);
     203  }
     204
     205  return NULL;
     206}
     207
     208
     209/**
     210 * @param index index to the client
     211 * @return the master server in the list or NULL if none
     212 */
     213PeerInfo* NetworkNode::getMasterServer(int index)
     214{
     215  if( this->masterServerList.size() < index)
     216    return NULL;
     217
     218  std::list<PeerInfo*>::iterator it = this->masterServerList.begin();
     219  for(int i = 0; it != this->masterServerList.end(); it++, i++)
     220  {
     221    if( i == index)
     222      return (*it);
     223  }
     224
     225  return NULL;
     226}
     227
    149228
    150229/**
  • branches/proxy/src/lib/network/monitor/network_node.h

    r9292 r9300  
    3232    void removeMasterServer(PeerInfo* node);
    3333
     34    PeerInfo* getClient(int index);
     35    PeerInfo* getActiveProxyServer(int index);
     36    PeerInfo* getPassiveProxyServer(int index);
     37    PeerInfo* getMasterServer(int index);
     38
    3439    /** @returns the number of players */
    3540    inline int getPlayerNumber() { return this->playerNumber; }
  • branches/proxy/src/lib/network/netdefs.h

    r9290 r9300  
    3333
    3434
    35 /* maximal connectinons for the server*/
     35//!< maximal connectinons for the server
    3636#define NET_MAX_CONNECTIONS 5
    3737
    38 /* network polling frequency */
     38//!< the amount of slots used before a proxy server is activated
     39#define NET_CONNECTION_SATURATION 0.75
     40
     41//!< network polling frequency
    3942#define NETWORK_FREQUENCY 66
    4043
    4144
    42 /* handshake settings */
     45//!< orxonox protocol id
    4346#define _ORXONOX_ID        0xF91337A0
     47//!< orxonox network version identifier
    4448#define _ORXONOX_VERSION   1
    4549
  • branches/proxy/src/lib/network/network_stream.cc

    r9296 r9300  
    8181  this->peers[0].nodeType = NET_MASTER_SERVER;
    8282  this->peers[0].connectionMonitor = new ConnectionMonitor( 0 );
     83  this->peers[0].ip = this->peers[0].socket->getDestAddress();
    8384  // and set also the localhost
    8485  this->pInfo->nodeType = NET_CLIENT;
     86  // get the local ip address
     87  SDLNet_ResolveHost( &this->pInfo->ip, "localhost", port );
     88
    8589}
    8690
     
    9599  this->serverSocket = new UdpServerSocket(port);
    96100  this->pInfo->nodeType = NET_MASTER_SERVER;
     101  // get the local ip address
     102  SDLNet_ResolveHost( &this->pInfo->ip, "localhost", port );
    97103}
    98104
     
    164170  if( this->pInfo)
    165171    delete this->pInfo;
     172
     173  if( this->networkMonitor)
     174    delete this->networkMonitor;
    166175}
    167176
     
    182191/**
    183192 * starts the network handshake
     193 * handsakes are always initialized from the client side first. this starts the handshake and therefore is only
     194 * executed as client
    184195 */
    185196void NetworkStream::startHandshake()
     
    190201  peers[0].handshake = hs;
    191202
     203  // set the preferred nick name
    192204  hs->setPreferedNickName( Preferences::getInstance()->getString( "multiplayer", "nickname", "Player" ) );
    193   //hs->set
    194205
    195206//   peers[0].handshake->setSynchronized( true );
     
    314325      peers[clientId].socket = tempNetworkSocket;
    315326      peers[clientId].handshake = new Handshake(this->pInfo->nodeType, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID() );
     327      peers[clientId].handshake->setUniqueID(clientId);
     328
     329      // get the proxy server informations and write them to the handshake, if any (proxy)
     330      PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy();
     331      if( pi != NULL)
     332        peers[clientId].handshake->setProxy1Address( pi->ip);
     333      pi = this->networkMonitor->getSecondChoiceProxy();
     334      if( pi != NULL)
     335        peers[clientId].handshake->setProxy2Address( pi->ip);
     336
     337       // check if the connecting client should reconnect to a proxy server
     338      peers[clientId].handshake->setRedirect(this->networkMonitor->reconnectNextClient());
     339
    316340      peers[clientId].connectionMonitor = new ConnectionMonitor( clientId );
    317       peers[clientId].handshake->setUniqueID(clientId);
    318341      peers[clientId].userId = clientId;
    319342      peers[clientId].nodeType = NET_CLIENT;
     
    328351
    329352      peers[clientId].socket = tempNetworkSocket;
     353      // handshake handling
    330354      peers[clientId].handshake = new Handshake(this->pInfo->nodeType, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID());
    331355      peers[clientId].handshake->setUniqueID(clientId);
     356      // get the proxy server informations and write them to the handshake, if any (proxy)
     357      PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy();
     358      if( pi != NULL)
     359        peers[clientId].handshake->setProxy1Address( pi->ip);
     360      pi = this->networkMonitor->getSecondChoiceProxy();
     361      if( pi != NULL)
     362        peers[clientId].handshake->setProxy2Address( pi->ip);
     363
     364       // check if the connecting client should reconnect to a proxy server
     365      peers[clientId].handshake->setRedirect(this->networkMonitor->reconnectNextClient());
     366
    332367      peers[clientId].connectionMonitor = new ConnectionMonitor( clientId );
    333368      peers[clientId].userId = clientId;
     
    337372    }
    338373
    339     // check if there are too many clients connected
     374    // check if there are too many clients connected (DEPRECATED: new: the masterserver sends a list of proxy servers)
    340375    if ( clientId > NET_MAX_CONNECTIONS )
    341376    {
    342       peers[clientId].handshake->doReject( "too many connections" );
     377//       peers[clientId].handshake->setRedirect(true);
     378//
     379//       peers[clientId].handshake->doReject( "too many connections" );
    343380      PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId);
    344381    }
     
    467504              this->networkMonitor->addNode(&it->second);
    468505
     506              // get proxy 1 address and add it
     507              this->networkMonitor->addNode(it->second.handshake->getProxy1Address());
     508              // get proxy 2 address and add it
     509              this->networkMonitor->addNode(it->second.handshake->getProxy2Address());
     510
     511
     512              // now check if there server accepted the connection
     513              if( it->second.handshake->redirect())
     514              {
     515                // handle the redirection
     516                PRINTF(0)("===============================================\n");
     517                PRINTF(0)("Client is redirected to the other proxy servers\n");
     518                PRINTF(0)("===============================================\n");
     519
     520                // disconnect from the current server and reconnect to proxy server
     521//                 it->second.socket->disconnectServer();
     522
     523              }
     524
     525              // create the new network game manager and init it
    469526              this->networkGameManager = NetworkGameManager::getInstance();
    470527              this->networkGameManager->setUniqueID( it->second.handshake->getNetworkGameManagerId() );
     528              // init the new message manager
    471529              MessageManager::getInstance()->setUniqueID( it->second.handshake->getMessageManagerId() );
    472530            }
  • branches/proxy/src/lib/network/proxy/proxy_settings.cc

    r9297 r9300  
    4343{
    4444  ProxySettings::singletonRef = NULL;
     45
     46  // remove all unused proxy data again
     47  for( int i = 0; i < this->proxies.size(); i++)
     48  {
     49    IPaddress* ip = this->proxies.back();
     50    this->proxies.pop_back();
     51    delete ip;
     52  }
    4553}
    4654
  • branches/proxy/src/lib/network/proxy/proxy_settings.h

    r9297 r9300  
    2929    void loadProxySettings(const TiXmlElement* root);
    3030
     31    /** @returns the max number of players */
    3132    inline void setMaxPlayer(int number) { this->maxPlayer = number; }
    3233    void setProxyAddr(const std::string& proxyAddr);
     34
     35    /** @returns the list of proxy servers from the init file */
     36    inline std::vector<IPaddress*> getProxyList() { return this->proxies; }
    3337
    3438
  • branches/proxy/src/story_entities/multi_player_world_data.cc

    r9296 r9300  
    299299ErrorMessage MultiPlayerWorldData::unloadScene()
    300300{
     301  // delete the proxy settings
     302  delete ProxySettings::getInstance();
     303
    301304  /* call underlying function */
    302305  return GameWorldData::unloadScene();
Note: See TracChangeset for help on using the changeset viewer.