Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9334 in orxonox.OLD


Ignore:
Timestamp:
Jul 19, 2006, 10:29:14 PM (18 years ago)
Author:
patrick
Message:

work of the day in one commit:D

  • switched whole network framework to ip sturcture
  • extended ip structrue a little bit
  • reimplemented the disconnection/reconnection algorithm
  • synchronizeable ip bug discovered and solved
Location:
branches/proxy/src
Files:
21 edited

Legend:

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

    r9327 r9334  
    6363  localState.canDel = 0;
    6464  localState.redirectProxy = 0;
    65   localState.proxy1.host = 0;
    66   localState.proxy1.port = 0;
    67   localState.proxy2.host = 0;
    68   localState.proxy2.port = 0;
     65  localState.proxy1 = IP(0, 0);
     66  localState.proxy2 = IP (0, 0);
    6967
    7068
     
    8179  remoteState.canDel = 0;
    8280  remoteState.redirectProxy = 0;
    83   remoteState.proxy1.host = 0;
    84   remoteState.proxy1.port = 0;
    85   remoteState.proxy2.host = 0;
    86   remoteState.proxy2.port = 0;
     81  remoteState.proxy1 = IP(0, 0);
     82  remoteState.proxy2 = IP(0, 0);
    8783
    8884  // activate the synchronization process
  • branches/proxy/src/lib/network/handshake.h

    r9300 r9334  
    99
    1010#include "base_object.h"
     11#include "ip.h"
    1112#include "synchronizeable.h"
    1213
     
    3334
    3435  int           redirectProxy;                 //!< true if the client should reconnect to a proxy server (either 1 or 2 )
    35   IPaddress     proxy1;                        //!< ip address of the first proxy (0.0.0.0 of not available)
    36   IPaddress     proxy2;                        //!< ip address of the second proxy (0.0.0.0 of not available)
     36  IP            proxy1;                        //!< ip address of the first proxy (0.0.0.0 of not available)
     37  IP            proxy2;                        //!< ip address of the second proxy (0.0.0.0 of not available)
    3738};
    3839
     
    8283
    8384    /** @param address: the address of the proxy server 1 if any */
    84     inline void setProxy1Address(IPaddress address) { this->localState.proxy1 = address; }
     85    inline void setProxy1Address(IP address) { this->localState.proxy1 = address; }
    8586    /** @returns the address of the proxy server 1 if any */
    86     inline IPaddress getProxy1Address() { return this->localState.proxy1; }
     87    inline IP getProxy1Address() { return this->localState.proxy1; }
    8788    /** @param address: the address of the proxy server 2 if any */
    88     inline void setProxy2Address(IPaddress address) { this->localState.proxy2 = address; }
     89    inline void setProxy2Address(IP address) { this->localState.proxy2 = address; }
    8990    /** @returns the address of the proxy server 2 if any */
    90     inline IPaddress getProxy2Address() { return this->localState.proxy2; }
     91    inline IP getProxy2Address() { return this->localState.proxy2; }
    9192
    9293
  • branches/proxy/src/lib/network/ip.cc

    r9321 r9334  
    44 *
    55 * code taken from audiere.
     6 *
     7 *
     8   orxonox - the future of 3D-vertical-scrollers
     9
     10   Copyright (C) 2004 orx
     11
     12   This program is free software; you can redistribute it and/or modify
     13   it under the terms of the GNU General Public License as published by
     14   the Free Software Foundation; either version 2, or (at your option)
     15   any later version.
     16
     17### File Specific:
     18   main-programmer: Benjamin Grauer
     19 * co-programmer: Patrick Boenzli
    620 */
    721
     
    97111}
    98112
     113
     114/**
     115 * @brief copy operator
     116 * @param ip the IP to copy.
     117 * @return self.
     118 */
     119const IP& IP::operator=(const IPaddress& ip)
     120{
     121  this->_ip = ip.host;
     122  this->_port = ip.port;
     123  return *this;
     124}
     125
     126
    99127/**
    100128 * @brief comparison operator
     
    106134  return (this->_ip == ip.ip() &&
    107135          this->_port == ip.port());
     136}
     137
     138
     139/**
     140 * @brief comparison operator
     141 * @param ip the IP to compare
     142 * @return true if ip _and_ port do not match.
     143 */
     144bool IP::operator!=(const IP& ip)
     145{
     146  return (this->_ip != ip.ip() ||
     147      this->_port != ip.port());
    108148}
    109149
  • branches/proxy/src/lib/network/ip.h

    r9323 r9334  
    2929    /// OPERATORS
    3030    const IP& operator=(const IP& ip);
     31    const IP& operator=(const IPaddress& ip);
    3132    bool operator==(const IP& ip);
     33    bool operator!=(const IP& up);
    3234
    3335    /// RETRIVEAL
     
    3638    /** @returns the Port */
    3739    short port() const { return this->_port; };
     40    inline IPaddress getSDLNotation() { IPaddress sdlIP; sdlIP.host = this->_ip; sdlIP.port = this->_port; return sdlIP; }
    3841
    3942    int ipPart(unsigned int part) const;
  • branches/proxy/src/lib/network/monitor/network_monitor.cc

    r9308 r9334  
    117117 * @param ip ip of the new node
    118118 */
    119 void NetworkMonitor::addNode(IPaddress ip, int nodeType)
     119void NetworkMonitor::addNode(IP ip, int nodeType)
    120120{
    121121  PeerInfo* pInfo = new PeerInfo();
  • branches/proxy/src/lib/network/monitor/network_monitor.h

    r9327 r9334  
    1010#include "synchronizeable.h"
    1111#include "shared_network_data.h"
     12#include "ip.h"
    1213
    1314#include "network_node.h"
     
    3637
    3738    void addNode(PeerInfo* pInfo);
    38     void addNode(IPaddress ip, int nodeType);
     39    void addNode(IP ip, int nodeType);
    3940    void addNode(NetworkNode* node) { this->nodeList.push_back(node); }
    4041    void addNode(NetworkNode* node, PeerInfo* pInfo);
     
    6566    PeerInfo* getSecondChoiceProxy();
    6667    /** @returns true if the next client should be reconnected to some other proxy server with more connections */
    67     inline bool reconnectNextClient() { return (this->localNode->getPlayerNumber() >= SharedNetworkData::getInstance()->getMaxPlayer())?true:false; }
     68    inline bool isReconnectNextClient() { return (this->localNode->getPlayerNumber() >= SharedNetworkData::getInstance()->getMaxPlayer())?true:false; }
    6869
    6970
  • branches/proxy/src/lib/network/monitor/network_node.cc

    r9308 r9334  
    239239  for(; it != this->masterServerList.end(); it++)
    240240  {
    241     int ip = (*it)->ip.host;
    242     PRINT(0)("     - ms, id: %i (%d.%d.%d.%d:9999)\n", (*it)->userId, (ip & 0x000000FF), (ip & 0x0000FF00) >> 8, (ip & 0x00FF0000) >> 16, (ip & 0xFF000000)>>24);
     241    IP* ip = &(*it)->ip;
     242    PRINT(0)("     - ms, id: %i (%s:9999)\n", (*it)->userId, ip->ipString().c_str());
    243243  }
    244244
     
    247247  for(; it != this->activeProxyServerList.end(); it++)
    248248  {
    249     int ip = (*it)->ip.host;
    250     PRINT(0)("     - ps-a, id: %i (%d.%d.%d.%d:9999)\n", (*it)->userId, (ip & 0x000000FF), (ip & 0x0000FF00) >> 8, (ip & 0x00FF0000) >> 16, (ip & 0xFF000000)>>24);
     249    IP* ip = &(*it)->ip;
     250    PRINT(0)("     - ps-a, id: %i (%s:9999)\n", (*it)->userId, ip->ipString().c_str());
    251251  }
    252252
     
    255255  for(; it != this->passiveProxyServerList.end(); it++)
    256256  {
    257     int ip = (*it)->ip.host;
    258     PRINT(0)("     - ps-p, id: %i (%d.%d.%d.%d:9999)\n", (*it)->userId, (ip & 0x000000FF), (ip & 0x0000FF00) >> 8, (ip & 0x00FF0000) >> 16, (ip & 0xFF000000)>>24);
     257    IP* ip = &(*it)->ip;
     258    PRINT(0)("     - ps-p, id: %i (%s:9999)\n", (*it)->userId, ip->ipString().c_str());
    259259  }
    260260
     
    263263  for(; it != this->clientList.end(); it++)
    264264  {
    265     int ip = (*it)->ip.host;
    266     PRINT(0)("     - client, id: %i (%d.%d.%d.%d:9999)\n", (*it)->userId, (ip & 0x000000FF), (ip & 0x0000FF00) >> 8, (ip & 0x00FF0000) >> 16, (ip & 0xFF000000)>>24);
    267   }
    268 }
    269 
     265    IP* ip = &(*it)->ip;
     266    PRINT(0)("     - client, id: %i (%s:9999)\n", (*it)->userId, ip->ipString().c_str());
     267  }
     268}
     269
  • branches/proxy/src/lib/network/netdefs.h

    r9304 r9334  
    2424#ifndef _NETDEFS
    2525#define _NETDEFS
     26
    2627
    2728#ifdef HAVE_SDL_NET_H
  • branches/proxy/src/lib/network/network_socket.h

    r9308 r9334  
    3232     */
    3333    virtual void disconnectServer() = 0;
     34
     35    /**
     36     * reconnecting to another server by terminating old connection and init a new connection
     37     */
     38    virtual void reconnectToServer( std::string host, int port) = 0;
     39
     40    /**
     41     * reconnecting to anoter server softly
     42     */
     43    virtual void reconnectToServerSoft( std::string host, int port) = 0;
    3444
    3545    /**
  • branches/proxy/src/lib/network/network_stream.cc

    r9327 r9334  
    2828#include "monitor/network_monitor.h"
    2929#include "synchronizeable.h"
     30#include "ip.h"
    3031#include "network_game_manager.h"
    3132#include "shared_network_data.h"
     
    8586  this->pInfo->nodeType = NET_CLIENT;
    8687  // get the local ip address
    87   SDLNet_ResolveHost( &this->pInfo->ip, NULL, port );
     88  IPaddress ip;
     89  SDLNet_ResolveHost( &ip, NULL, port );
     90  this->pInfo->ip = ip;
    8891}
    8992
     
    99102  this->pInfo->nodeType = NET_MASTER_SERVER;
    100103  // get the local ip address
    101   SDLNet_ResolveHost( &this->pInfo->ip, NULL, port );
     104  IPaddress ip;
     105  SDLNet_ResolveHost( &ip, NULL, port );
     106  this->pInfo->ip = ip;
    102107}
    103108
     
    356361
    357362    // check if the connecting client should reconnect to a proxy server
    358     peers[clientId].handshake->setRedirect(this->networkMonitor->reconnectNextClient());
     363    peers[clientId].handshake->setRedirect(this->networkMonitor->isReconnectNextClient());
    359364
    360365
     
    364369
    365370    // check if there are too many clients connected (DEPRECATED: new: the masterserver sends a list of proxy servers)
    366     if ( clientId > SharedNetworkData::getInstance()->getMaxPlayer() )
    367     {
    368 //       peers[clientId].handshake->setRedirect(true);
    369 //
    370 //       peers[clientId].handshake->doReject( "too many connections" );
    371       PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId);
    372     }
    373     else
    374     {
    375       PRINTF(0)("New Client: %d\n", clientId);
    376     }
    377 
    378     //this->connectSynchronizeable(*handshakes[clientId]);
     371//     if ( clientId > SharedNetworkData::getInstance()->getMaxPlayer() )
     372//     {
     373// //       peers[clientId].handshake->setRedirect(true);
     374// //
     375// //       peers[clientId].handshake->doReject( "too many connections" );
     376//       PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId);
     377//     }
     378//     else
     379//     {
     380//       PRINTF(0)("New Client: %d\n", clientId);
     381//     }
     382    PRINTF(0)("New Client: %d\n", clientId);
     383
     384
    379385  }
    380386
     
    493499              it->second.nodeType = it->second.handshake->getRemoteNodeType();
    494500              it->second.ip = it->second.socket->getRemoteAddress();
     501              // add the new server to the nodes list (it can be a NET_MASTER_SERVER or NET_PROXY_SERVER)
    495502              this->networkMonitor->addNode(&it->second);
    496 
    497503              // get proxy 1 address and add it
    498504              this->networkMonitor->addNode(it->second.handshake->getProxy1Address(), NET_PROXY_SERVER_ACTIVE);
     
    500506              this->networkMonitor->addNode(it->second.handshake->getProxy2Address(), NET_PROXY_SERVER_ACTIVE);
    501507
    502 
    503               // now check if there server accepted the connection
     508              // now check if the server accepted the connection
    504509              if( it->second.handshake->redirect())
    505               {
    506                 // handle the redirection
    507                 PRINTF(0)("===============================================\n");
    508                 PRINTF(0)("Client is redirected to the other proxy servers\n");
    509                 PRINTF(0)("===============================================\n");
    510 
    511                 // disconnect from the current server and reconnect to proxy server
    512 //                 it->second.socket->disconnectServer();
    513               }
     510                this->handleReconnect( it->second.userId);
    514511
    515512              // create the new network game manager and init it
     
    537534                this->networkMonitor->addNode(&it->second);
    538535
    539                 handleNewClient( it->second.userId );
     536                this->handleNewClient( it->second.userId );
    540537
    541538                if ( PlayerStats::getStats( it->second.userId ) && it->second.handshake->getPreferedNickName() != "" )
     
    560557    }
    561558  }
     559}
     560
     561
     562/**
     563 * this functions handles a reconnect event received from the a NET_MASTER_SERVER or NET_PROXY_SERVER
     564 */
     565void NetworkStream::handleReconnect(int userId)
     566{
     567  PRINTF(0)("===============================================\n");
     568  PRINTF(0)("Client is redirected to the other proxy servers\n");
     569  PRINTF(0)("===============================================\n");
     570
     571  PeerInfo* pInfo = &this->peers[userId];
     572
     573  // reject the server
     574  pInfo->handshake->doReject( "redirected to different server");
     575
     576  // flush the old synchronization states, since the numbering could be completely different
     577  pInfo->lastAckedState = 0;
     578  pInfo->lastRecvedState = 0;
     579  // not sure if this works as expected
     580  if( pInfo->handshake)
     581    delete pInfo->handshake;
     582
     583  // disconnect from the current server and reconnect to proxy server
     584  pInfo->socket->reconnectToServer( pInfo->handshake->getProxy1Address().ipString(), pInfo->handshake->getProxy1Address().port());
     585
     586  // and restart the handshake
     587  this->startHandshake();
    562588}
    563589
  • branches/proxy/src/lib/network/network_stream.h

    r9327 r9334  
    8282
    8383    void updateConnectionList();
    84 
     84    /* handle processes */
    8585    void handleHandshakes();
    8686    void handleUpstream( int tick );
    8787    void handleDownstream(int tick );
     88
     89    /* handle events*/
    8890    void handleNewClient( int userId );
    89 
     91    void handleReconnect( int userId );
    9092
    9193    void writeToNewDict( byte * data, int length, bool upstream );
  • branches/proxy/src/lib/network/peer_info.cc

    r9308 r9334  
    5050  this->connectionMonitor = NULL;
    5151
    52   this->ip.host = 0;
    53   this->ip.port = 0;
     52  this->ip = IP(0,0);
    5453}
    5554
  • branches/proxy/src/lib/network/peer_info.h

    r9303 r9334  
    3232    int                 userId;
    3333    int                 nodeType;
    34     IPaddress           ip;
     34    IP                  ip;
    3535
    3636    NetworkSocket *     socket;
  • branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_ip.cc

    r9308 r9334  
    1616#include "synchronizeable_ip.h"
    1717#include "converter.h"
    18 
     18// #include "ip.h"
    1919
    2020/**
     
    2222 * @todo this constructor is not jet implemented - do it
    2323*/
    24 SynchronizeableIP::SynchronizeableIP( IPaddress * ptrIn, IPaddress * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 2*INTSIZE, permission, priority )
     24SynchronizeableIP::SynchronizeableIP( IP * ptrIn, IP * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 2*INTSIZE, permission, priority )
    2525{
    2626  this->vPtrIn = ptrIn;
     
    4747  int res;
    4848
    49   res = Converter::intToByteArray( (int)vPtrIn->host, buf, maxLength );
     49  res = Converter::intToByteArray( (int)vPtrIn->ip(), buf, maxLength );
    5050  assert(res > 0);
    5151  n += res;
    5252
    53   res = Converter::intToByteArray( (int)vPtrIn->port, buf, maxLength);
     53  res = Converter::intToByteArray( (int)vPtrIn->port(), buf, maxLength);
    5454  assert(res > 0);
    5555  n += res;
     
    7575  int n = 0;
    7676
    77   IPaddress oldIP = *vPtrOut;
    78   IPaddress newIP;
     77  IP oldIP = *vPtrOut;
    7978
    8079  res = Converter::byteArrayToInt( buf + n, &host);
     
    8786  n += res;
    8887
    89   newIP.host = host;
    90   newIP.port = port;
     88  *this->vPtrOut = IP(host, port);
    9189
    92   setHasChanged( (newIP.host != oldIP.host || newIP.port != oldIP.port) );
     90  setHasChanged( *this->vPtrOut != oldIP);
    9391
    9492  assert( n == 2 * INTSIZE);
     
    103101void SynchronizeableIP::SynchronizeableIP::debug( )
    104102{
    105   printf("SYNCHRONIZEABLE_VAR: %s IN: %i, %i OUT: %i, %i\n", name.c_str(), vPtrIn->host, vPtrIn->port, vPtrOut->host, vPtrOut->port);
     103  printf("SYNCHRONIZEABLE_VAR: %s IN: %i, %i OUT: %i, %i\n", name.c_str(), vPtrIn->ip(), vPtrIn->port(), vPtrOut->ip(), vPtrOut->port());
    106104}
    107105
  • branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_ip.h

    r9293 r9334  
    1212
    1313#include "netdefs.h"
     14#include "ip.h"
    1415
    1516class SynchronizeableIP : public SynchronizeableVar {
    1617
    1718  public:
    18     SynchronizeableIP( IPaddress *ptrIn, IPaddress * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );
     19    SynchronizeableIP( IP *ptrIn, IP * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );
    1920    virtual ~SynchronizeableIP();
    2021
     
    3233
    3334  private:
    34     IPaddress * vPtrIn;       //!< pointer to data (read)
    35     IPaddress * vPtrOut;      //!< pointer to data (write)
     35    IP * vPtrIn;       //!< pointer to data (read)
     36    IP * vPtrOut;      //!< pointer to data (write)
    3637
    3738};
  • branches/proxy/src/lib/network/tcp_server_socket.cc

    r7954 r9334  
    136136  _isListening = false;
    137137}
     138
  • branches/proxy/src/lib/network/tcp_server_socket.h

    r7954 r9334  
    2828    virtual void close();
    2929    virtual void update() {};
    30    
     30
    3131  private:
    3232    TCPsocket listenSocket;
     
    3636
    3737    void init();
    38  
     38
    3939};
    4040
  • branches/proxy/src/lib/network/tcp_socket.h

    r7954 r9334  
    11/*!
    2  * @file network_socket.h
    3   *  Main interface for the network module. Manages all the modules
     2 * @file tcp_socket.h
     3  *  tcp socket network interface
    44
    55*/
     
    4747
    4848    virtual void connectToServer( std::string host, int port );
    49    
     49
    5050    virtual void disconnectServer();
     51    virtual void reconnectToServer( std::string host, int port);
     52    virtual void reconnectToServerSoft( std::string host, int port);
    5153
    5254    virtual bool writePacket(byte * data, int length);
  • branches/proxy/src/lib/network/udp_socket.cc

    r9319 r9334  
    151151}
    152152
     153
     154/**
     155 * reconnects to
     156 * @param host new server address
     157 * @param port new port number
     158 *
     159 * this terminates the current connection and starts a new connection to the new server
     160 */
     161void UdpSocket::reconnectToServer( std::string host, int port)
     162{
     163  // first disconnect the old server
     164  this->disconnectServer();
     165
     166  // now connect to the new
     167  this->connectToServer( host, port);
     168}
     169
     170
     171/**
     172 * reconnects to
     173 * @param host new server address
     174 * @param port new port number
     175 *
     176 * this terminates the current connection and starts a new connection to the new server
     177 */
     178void UdpSocket::reconnectToServerSoft( std::string host, int port)
     179{}
     180
     181
    153182/**
    154183 * send one packet to other host
  • branches/proxy/src/lib/network/udp_socket.h

    r9291 r9334  
    3131
    3232    virtual void connectToServer( std::string host, int port );
    33 
    3433    virtual void disconnectServer();
    3534
     35    virtual void reconnectToServer( std::string host, int port);
     36    virtual void reconnectToServerSoft( std::string host, int port);
     37
    3638    virtual bool writePacket(byte * data, int length );
    37 
    3839    virtual int readPacket(byte * data, int maxLength);
    3940
  • branches/proxy/src/subprojects/network/network_unit_test.cc

    r8623 r9334  
    208208
    209209  /* esatblish a connection */
    210   IPaddress ip;
     210  IP ip;
    211211  int error = SDLNet_ResolveHost(&ip, "127.0.0.1", port);
    212212  //SDLNet_ResolveHost(&ip, "localhost", port);
     
    353353  printf("Connecting to %s, on port %i\n", name, port);
    354354
    355   IPaddress ip;
     355  IP ip;
    356356  int error = SDLNet_ResolveHost(&ip, name, port);
    357357  if(error == -1)
Note: See TracChangeset for help on using the changeset viewer.