Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7459 for code/trunk/src


Ignore:
Timestamp:
Sep 17, 2010, 12:48:29 AM (14 years ago)
Author:
adrfried
Message:

Merged ipv6 branch

Orxonox now includes a modified version of ENet 1.3.0

Location:
code/trunk
Files:
11 edited
36 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/CMakeLists.txt

    r7451 r7459  
    3838# If no defines are specified, these libs get linked statically
    3939ADD_COMPILER_FLAGS("-DBOOST_ALL_DYN_LINK" WIN32 LINK_BOOST_DYNAMIC)
    40 ADD_COMPILER_FLAGS("-DENET_DLL"           WIN32 LINK_ENET_DYNAMIC)
     40#ADD_COMPILER_FLAGS("-DENET_DLL"           WIN32 LINK_ENET_DYNAMIC)
    4141ADD_COMPILER_FLAGS("-DLUA_BUILD_AS_DLL"   WIN32 LINK_LUA_DYNAMIC)
    4242ADD_COMPILER_FLAGS("-DZLIB_DLL"           WIN32 LINK_ZLIB_DYNAMIC)
     
    6161# If no defines are specified, these libs get linked dynamically
    6262ADD_COMPILER_FLAGS("-DCEGUILUA_STATIC"             WIN32 NOT _external_shared_link)
     63ADD_COMPILER_FLAGS("-DENET_DLL"                    WIN32     _external_shared_link)
    6364ADD_COMPILER_FLAGS("-DOGRE_GUIRENDERER_STATIC_LIB" WIN32 NOT _external_shared_link)
    6465ADD_COMPILER_FLAGS("-DOIS_STATIC_LIB"              WIN32 NOT _external_shared_link)
     
    7273  ${OGRE_INCLUDE_DIR}
    7374  ${CEGUI_INCLUDE_DIR}
    74   ${ENET_INCLUDE_DIR}
     75  #${ENET_INCLUDE_DIR}
    7576  ${Boost_INCLUDE_DIRS}
    7677  ${POCO_INCLUDE_DIR}
  • code/trunk/src/external/CMakeLists.txt

    r7266 r7459  
    3434ADD_SUBDIRECTORY(bullet)
    3535ADD_SUBDIRECTORY(cpptcl)
     36ADD_SUBDIRECTORY(enet)
    3637ADD_SUBDIRECTORY(loki)
    3738ADD_SUBDIRECTORY(ogreceguirenderer)
  • code/trunk/src/libraries/network/CMakeLists.txt

    r7163 r7459  
    7171  LINK_LIBRARIES
    7272    ${ZLIB_LIBRARY}
    73     ${ENET_LIBRARY}
     73    #${ENET_LIBRARY}
     74    enet_orxonox
    7475    ${Boost_THREAD_LIBRARY}
    7576    util
  • code/trunk/src/libraries/network/ClientConnection.cc

    r7284 r7459  
    4848    this->serverAddress_ = new ENetAddress();
    4949    //set standard address and port
    50     enet_address_set_host(this->serverAddress_, "127.0.0.1");
     50    enet_address_set_host(this->serverAddress_, "127.0.0.1"); // TODO: check for IPv6 and connect to ::1 instead
    5151    serverAddress_->port = NETWORK_PORT;
    5252  }
     
    5959
    6060  void ClientConnection::setServerAddress( const std::string& serverAddress ) {
    61     enet_address_set_host (this->serverAddress_, serverAddress.c_str());
     61    if (enet_address_set_host (this->serverAddress_, serverAddress.c_str()) < 0)
     62        COUT(1) << "Error: Could not resolve \"" << serverAddress << "\"." << std::endl;
    6263  }
    6364
     
    7071    ENetEvent event;
    7172
    72     this->host_ = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0);
     73    this->host_ = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0, 0);
    7374    if ( this->host_ == NULL )
    7475    {
    75       COUT(2) << "ClientConnection: host_ == NULL" << std::endl;
     76      COUT(1) << "ClientConnection: host_ == NULL" << std::endl;
    7677      // error handling
    7778      return false;
    7879    }
    79     this->server_ = enet_host_connect(this->host_, serverAddress_, NETWORK_CLIENT_CHANNELS);
     80    assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL );
     81    if (this->host_->socket4 == ENET_SOCKET_NULL)
     82        COUT(2) << "Warning: IPv4 Socket failed." << std::endl;
     83    else if (this->host_->socket6 == ENET_SOCKET_NULL)
     84        COUT(2) << "Warning: IPv6 Socket failed." << std::endl;
     85    else
     86        COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl;
     87
     88    this->server_ = enet_host_connect(this->host_, serverAddress_, NETWORK_CLIENT_CHANNELS, 0);
    8089    if ( this->server_==NULL )
    8190    {
    82       COUT(2) << "ClientConnection: server == NULL" << std::endl;
     91      COUT(1) << "ClientConnection: server_ == NULL" << std::endl;
    8392      // error handling
    8493      return false;
  • code/trunk/src/libraries/network/ClientInformation.cc

    r7401 r7459  
    216216    ClientInformation *temp = head_;
    217217    while(temp!=0){
    218       if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port)
     218      if(!memcmp(& temp->getPeer()->address, & peer->address, sizeof(peer->address)))
    219219        break;
    220220      temp = temp->next();
     
    252252    ClientInformation *temp = head_;
    253253    while(temp!=0){
    254       if(temp->getPeer()->address.host==address->host && temp->getPeer()->address.port == address->port)
     254      if(!memcmp(& temp->getPeer()->address, address, sizeof(*address)))
    255255        break;
    256256      temp = temp->next();
  • code/trunk/src/libraries/network/LANDiscoverable.cc

    r7163 r7459  
    6464    if( bActive )
    6565    {
    66       ENetAddress bindAddress = { ENET_HOST_ANY, LAN_DISCOVERY_PORT };
     66      ENetAddress bindAddress;
     67      memset(& bindAddress, 0, sizeof(ENetAddress));
     68      bindAddress.host = ENET_HOST_ANY;
     69      bindAddress.port = LAN_DISCOVERY_PORT;
    6770      assert( this->host_ == 0 );
    68       this->host_ = enet_host_create( &bindAddress, 10, 0, 0 );
     71      this->host_ = enet_host_create( &bindAddress, 10, 0, 0, 0 );
     72      if ( this->host_ == NULL )
     73          COUT(1) << "LANDiscoverable: host_ == NULL" << std::endl;
    6974    }
    7075    else
     
    8994      {
    9095        case ENET_EVENT_TYPE_CONNECT:
     96            COUT(4) << "Received LAN discovery connect from client " << event.peer->host->receivedAddress << std::endl;
     97            break;
    9198        case ENET_EVENT_TYPE_DISCONNECT:
    9299        case ENET_EVENT_TYPE_NONE:
     
    95102          if( strcmp( LAN_DISCOVERY_MESSAGE, (char*)event.packet->data ) == 0 )      // check for a suitable orxonox client
    96103          {
     104            COUT(3) << "Received LAN discovery message from client " << event.peer->host->receivedAddress << std::endl;
    97105            packet::ServerInformation info;
    98106            info.setServerName("Orxonox Server");
  • code/trunk/src/libraries/network/LANDiscovery.cc

    r7284 r7459  
    4242  LANDiscovery::LANDiscovery()
    4343  {
    44     this->host_ = enet_host_create(NULL, 10, 0, 0 );
     44    this->host_ = enet_host_create(NULL, 10, 0, 0, 0 );
     45    if ( this->host_ == NULL )
     46        COUT(1) << "LANDiscovery: host_ == NULL" << std::endl;
    4547  }
    4648
     
    5355  {
    5456    this->servers_.clear();
     57    ENetPeer* peer;
    5558    ENetAddress address;
    56     enet_address_set_host(&address, "255.255.255.255");
     59    memset(&address, 0, sizeof(ENetAddress));
    5760    address.port = LAN_DISCOVERY_PORT;
    5861
    59     ENetPeer* peer;
    60     peer = enet_host_connect(this->host_, &address, 0);
     62    /* TODO: check for availability of each protocol */
     63    /* IPv4 */
     64    address.host = ENET_HOST_BROADCAST;
     65    peer = enet_host_connect(this->host_, &address, 0, 0);
     66    if (peer == NULL)
     67        COUT(1) << "Error: Could not send LAN discovery to IPv4 Broadcast." << std::endl;
     68
     69    /* IPv6 */
     70    enet_address_set_host(&address, "ff02::1"); // TODO: use a multicast group
     71    peer = enet_host_connect(this->host_, &address, 0, 0);
     72    if (peer == NULL)
     73        COUT(1) << "Error: Could not send LAN discovery to IPv6 Multicast." << std::endl;
    6174
    6275    ENetEvent event;
     
    6780        case ENET_EVENT_TYPE_CONNECT:
    6881        {
    69           COUT(0) << "connect from server: " << event.peer->address.host << endl;
     82          COUT(4) << "Received LAN discovery connect from server " << event.peer->host->receivedAddress << std::endl;
    7083          ENetPacket* packet = enet_packet_create(LAN_DISCOVERY_MESSAGE, strlen(LAN_DISCOVERY_MESSAGE)+1, ENET_PACKET_FLAG_RELIABLE);
    7184          enet_peer_send(event.peer, 0, packet);
     
    7588          {
    7689            packet::ServerInformation info(&event);
    77             COUT(0) << "received server information; name: " << info.getServerName() << ", IP: " << info.getServerIP() << ", RTT: " << info.getServerRTT() << endl;
     90            COUT(3) << "Received LAN discovery server information; Name: " << info.getServerName() << ", Address: " << info.getServerIP() << ", RTT: " << info.getServerRTT() << endl;
    7891            std::vector<packet::ServerInformation>::iterator it;
    7992            for( it=this->servers_.begin(); it!=this->servers_.end(); ++it )
  • code/trunk/src/libraries/network/ServerConnection.cc

    r7163 r7459  
    4444  {
    4545    this->bindAddress_ = new ENetAddress();
     46    memset(this->bindAddress_, 0, sizeof(ENetAddress));
    4647    this->bindAddress_->host = ENET_HOST_ANY;
    4748    this->bindAddress_->port = NETWORK_PORT;
     
    5556
    5657  void ServerConnection::setBindAddress( const std::string& bindAddress ) {
    57     enet_address_set_host (this->bindAddress_, bindAddress.c_str());
     58    if (enet_address_set_host (this->bindAddress_, bindAddress.c_str()) < 0)
     59        COUT(1) << "Error: Could not resolve \"" << bindAddress << "\"." << std::endl;
    5860  }
    5961
     
    6365
    6466  bool ServerConnection::openListener() {
    65     this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, 0, 0);
     67    this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, 0, 0, 0);
    6668    if ( this->host_ == NULL )
    67       return false;
     69    {
     70        COUT(1) << "ServerConnection: host_ == NULL" << std::endl;
     71        return false;
     72    }
     73    assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL );
     74    if (this->host_->socket4 == ENET_SOCKET_NULL)
     75        COUT(2) << "Warning: IPv4 Socket failed." << std::endl;
     76    else if (this->host_->socket6 == ENET_SOCKET_NULL)
     77        COUT(2) << "Warning: IPv6 Socket failed." << std::endl;
    6878    else
    69       return true;
     79        COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl;
     80
     81    return true;
    7082  }
    7183
  • code/trunk/src/libraries/network/packet/ServerInformation.cc

    r7321 r7459  
    4747    ServerInformation::ServerInformation(ENetEvent* event)
    4848    {
     49      char serverIP[64];
     50
    4951      // Save Server Round Trip Time
    5052      this->serverRTT_ = event->peer->roundTripTime;
    51       // Save Server IP
    52       char* serverIP = new char[16];
    53       enet_address_get_host_ip(&event->peer->address, serverIP, 16);
     53      // Save Server Address, leave some space for scope ID
     54      enet_address_get_host_ip(&event->peer->address, serverIP, 64);
    5455      this->serverIP_ = std::string(serverIP);
    5556      // Save ACK
     
    8384 
    8485  } // namespace packet
     86
     87  std::ostream& operator<<(std::ostream& out, const ENetAddress& address)
     88  {
     89      char addr[64];
     90      if (!enet_address_get_host_ip(&address, addr, 64))
     91          out << addr;
     92      return out;
     93  }
    8594} // namespace orxonox
    8695
  • code/trunk/src/libraries/network/packet/ServerInformation.h

    r7163 r7459  
    5959
    6060  }
     61
     62  _NetworkExport std::ostream& operator<<(std::ostream& out, const ENetAddress& address);
    6163}
    6264
Note: See TracChangeset for help on using the changeset viewer.