Changeset 9334 in orxonox.OLD
- Timestamp:
- Jul 19, 2006, 10:29:14 PM (18 years ago)
- Location:
- branches/proxy/src
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/network/handshake.cc
r9327 r9334 63 63 localState.canDel = 0; 64 64 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); 69 67 70 68 … … 81 79 remoteState.canDel = 0; 82 80 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); 87 83 88 84 // activate the synchronization process -
branches/proxy/src/lib/network/handshake.h
r9300 r9334 9 9 10 10 #include "base_object.h" 11 #include "ip.h" 11 12 #include "synchronizeable.h" 12 13 … … 33 34 34 35 int redirectProxy; //!< true if the client should reconnect to a proxy server (either 1 or 2 ) 35 IP addressproxy1; //!< ip address of the first proxy (0.0.0.0 of not available)36 IP addressproxy2; //!< 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) 37 38 }; 38 39 … … 82 83 83 84 /** @param address: the address of the proxy server 1 if any */ 84 inline void setProxy1Address(IP addressaddress) { this->localState.proxy1 = address; }85 inline void setProxy1Address(IP address) { this->localState.proxy1 = address; } 85 86 /** @returns the address of the proxy server 1 if any */ 86 inline IP addressgetProxy1Address() { return this->localState.proxy1; }87 inline IP getProxy1Address() { return this->localState.proxy1; } 87 88 /** @param address: the address of the proxy server 2 if any */ 88 inline void setProxy2Address(IP addressaddress) { this->localState.proxy2 = address; }89 inline void setProxy2Address(IP address) { this->localState.proxy2 = address; } 89 90 /** @returns the address of the proxy server 2 if any */ 90 inline IP addressgetProxy2Address() { return this->localState.proxy2; }91 inline IP getProxy2Address() { return this->localState.proxy2; } 91 92 92 93 -
branches/proxy/src/lib/network/ip.cc
r9321 r9334 4 4 * 5 5 * 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 6 20 */ 7 21 … … 97 111 } 98 112 113 114 /** 115 * @brief copy operator 116 * @param ip the IP to copy. 117 * @return self. 118 */ 119 const IP& IP::operator=(const IPaddress& ip) 120 { 121 this->_ip = ip.host; 122 this->_port = ip.port; 123 return *this; 124 } 125 126 99 127 /** 100 128 * @brief comparison operator … … 106 134 return (this->_ip == ip.ip() && 107 135 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 */ 144 bool IP::operator!=(const IP& ip) 145 { 146 return (this->_ip != ip.ip() || 147 this->_port != ip.port()); 108 148 } 109 149 -
branches/proxy/src/lib/network/ip.h
r9323 r9334 29 29 /// OPERATORS 30 30 const IP& operator=(const IP& ip); 31 const IP& operator=(const IPaddress& ip); 31 32 bool operator==(const IP& ip); 33 bool operator!=(const IP& up); 32 34 33 35 /// RETRIVEAL … … 36 38 /** @returns the Port */ 37 39 short port() const { return this->_port; }; 40 inline IPaddress getSDLNotation() { IPaddress sdlIP; sdlIP.host = this->_ip; sdlIP.port = this->_port; return sdlIP; } 38 41 39 42 int ipPart(unsigned int part) const; -
branches/proxy/src/lib/network/monitor/network_monitor.cc
r9308 r9334 117 117 * @param ip ip of the new node 118 118 */ 119 void NetworkMonitor::addNode(IP addressip, int nodeType)119 void NetworkMonitor::addNode(IP ip, int nodeType) 120 120 { 121 121 PeerInfo* pInfo = new PeerInfo(); -
branches/proxy/src/lib/network/monitor/network_monitor.h
r9327 r9334 10 10 #include "synchronizeable.h" 11 11 #include "shared_network_data.h" 12 #include "ip.h" 12 13 13 14 #include "network_node.h" … … 36 37 37 38 void addNode(PeerInfo* pInfo); 38 void addNode(IP addressip, int nodeType);39 void addNode(IP ip, int nodeType); 39 40 void addNode(NetworkNode* node) { this->nodeList.push_back(node); } 40 41 void addNode(NetworkNode* node, PeerInfo* pInfo); … … 65 66 PeerInfo* getSecondChoiceProxy(); 66 67 /** @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; } 68 69 69 70 -
branches/proxy/src/lib/network/monitor/network_node.cc
r9308 r9334 239 239 for(; it != this->masterServerList.end(); it++) 240 240 { 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()); 243 243 } 244 244 … … 247 247 for(; it != this->activeProxyServerList.end(); it++) 248 248 { 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()); 251 251 } 252 252 … … 255 255 for(; it != this->passiveProxyServerList.end(); it++) 256 256 { 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()); 259 259 } 260 260 … … 263 263 for(; it != this->clientList.end(); it++) 264 264 { 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 24 24 #ifndef _NETDEFS 25 25 #define _NETDEFS 26 26 27 27 28 #ifdef HAVE_SDL_NET_H -
branches/proxy/src/lib/network/network_socket.h
r9308 r9334 32 32 */ 33 33 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; 34 44 35 45 /** -
branches/proxy/src/lib/network/network_stream.cc
r9327 r9334 28 28 #include "monitor/network_monitor.h" 29 29 #include "synchronizeable.h" 30 #include "ip.h" 30 31 #include "network_game_manager.h" 31 32 #include "shared_network_data.h" … … 85 86 this->pInfo->nodeType = NET_CLIENT; 86 87 // 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; 88 91 } 89 92 … … 99 102 this->pInfo->nodeType = NET_MASTER_SERVER; 100 103 // 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; 102 107 } 103 108 … … 356 361 357 362 // 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()); 359 364 360 365 … … 364 369 365 370 // 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 379 385 } 380 386 … … 493 499 it->second.nodeType = it->second.handshake->getRemoteNodeType(); 494 500 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) 495 502 this->networkMonitor->addNode(&it->second); 496 497 503 // get proxy 1 address and add it 498 504 this->networkMonitor->addNode(it->second.handshake->getProxy1Address(), NET_PROXY_SERVER_ACTIVE); … … 500 506 this->networkMonitor->addNode(it->second.handshake->getProxy2Address(), NET_PROXY_SERVER_ACTIVE); 501 507 502 503 // now check if there server accepted the connection 508 // now check if the server accepted the connection 504 509 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); 514 511 515 512 // create the new network game manager and init it … … 537 534 this->networkMonitor->addNode(&it->second); 538 535 539 handleNewClient( it->second.userId );536 this->handleNewClient( it->second.userId ); 540 537 541 538 if ( PlayerStats::getStats( it->second.userId ) && it->second.handshake->getPreferedNickName() != "" ) … … 560 557 } 561 558 } 559 } 560 561 562 /** 563 * this functions handles a reconnect event received from the a NET_MASTER_SERVER or NET_PROXY_SERVER 564 */ 565 void 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(); 562 588 } 563 589 -
branches/proxy/src/lib/network/network_stream.h
r9327 r9334 82 82 83 83 void updateConnectionList(); 84 84 /* handle processes */ 85 85 void handleHandshakes(); 86 86 void handleUpstream( int tick ); 87 87 void handleDownstream(int tick ); 88 89 /* handle events*/ 88 90 void handleNewClient( int userId ); 89 91 void handleReconnect( int userId ); 90 92 91 93 void writeToNewDict( byte * data, int length, bool upstream ); -
branches/proxy/src/lib/network/peer_info.cc
r9308 r9334 50 50 this->connectionMonitor = NULL; 51 51 52 this->ip.host = 0; 53 this->ip.port = 0; 52 this->ip = IP(0,0); 54 53 } 55 54 -
branches/proxy/src/lib/network/peer_info.h
r9303 r9334 32 32 int userId; 33 33 int nodeType; 34 IP addressip;34 IP ip; 35 35 36 36 NetworkSocket * socket; -
branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_ip.cc
r9308 r9334 16 16 #include "synchronizeable_ip.h" 17 17 #include "converter.h" 18 18 // #include "ip.h" 19 19 20 20 /** … … 22 22 * @todo this constructor is not jet implemented - do it 23 23 */ 24 SynchronizeableIP::SynchronizeableIP( IP address * ptrIn, IPaddress* ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 2*INTSIZE, permission, priority )24 SynchronizeableIP::SynchronizeableIP( IP * ptrIn, IP * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 2*INTSIZE, permission, priority ) 25 25 { 26 26 this->vPtrIn = ptrIn; … … 47 47 int res; 48 48 49 res = Converter::intToByteArray( (int)vPtrIn-> host, buf, maxLength );49 res = Converter::intToByteArray( (int)vPtrIn->ip(), buf, maxLength ); 50 50 assert(res > 0); 51 51 n += res; 52 52 53 res = Converter::intToByteArray( (int)vPtrIn->port , buf, maxLength);53 res = Converter::intToByteArray( (int)vPtrIn->port(), buf, maxLength); 54 54 assert(res > 0); 55 55 n += res; … … 75 75 int n = 0; 76 76 77 IPaddress oldIP = *vPtrOut; 78 IPaddress newIP; 77 IP oldIP = *vPtrOut; 79 78 80 79 res = Converter::byteArrayToInt( buf + n, &host); … … 87 86 n += res; 88 87 89 newIP.host = host; 90 newIP.port = port; 88 *this->vPtrOut = IP(host, port); 91 89 92 setHasChanged( (newIP.host != oldIP.host || newIP.port != oldIP.port));90 setHasChanged( *this->vPtrOut != oldIP); 93 91 94 92 assert( n == 2 * INTSIZE); … … 103 101 void SynchronizeableIP::SynchronizeableIP::debug( ) 104 102 { 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()); 106 104 } 107 105 -
branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_ip.h
r9293 r9334 12 12 13 13 #include "netdefs.h" 14 #include "ip.h" 14 15 15 16 class SynchronizeableIP : public SynchronizeableVar { 16 17 17 18 public: 18 SynchronizeableIP( IP address *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 ); 19 20 virtual ~SynchronizeableIP(); 20 21 … … 32 33 33 34 private: 34 IP address* vPtrIn; //!< pointer to data (read)35 IP address* vPtrOut; //!< pointer to data (write)35 IP * vPtrIn; //!< pointer to data (read) 36 IP * vPtrOut; //!< pointer to data (write) 36 37 37 38 }; -
branches/proxy/src/lib/network/tcp_server_socket.cc
r7954 r9334 136 136 _isListening = false; 137 137 } 138 -
branches/proxy/src/lib/network/tcp_server_socket.h
r7954 r9334 28 28 virtual void close(); 29 29 virtual void update() {}; 30 30 31 31 private: 32 32 TCPsocket listenSocket; … … 36 36 37 37 void init(); 38 38 39 39 }; 40 40 -
branches/proxy/src/lib/network/tcp_socket.h
r7954 r9334 1 1 /*! 2 * @file network_socket.h3 * Main interface for the network module. Manages all the modules2 * @file tcp_socket.h 3 * tcp socket network interface 4 4 5 5 */ … … 47 47 48 48 virtual void connectToServer( std::string host, int port ); 49 49 50 50 virtual void disconnectServer(); 51 virtual void reconnectToServer( std::string host, int port); 52 virtual void reconnectToServerSoft( std::string host, int port); 51 53 52 54 virtual bool writePacket(byte * data, int length); -
branches/proxy/src/lib/network/udp_socket.cc
r9319 r9334 151 151 } 152 152 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 */ 161 void 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 */ 178 void UdpSocket::reconnectToServerSoft( std::string host, int port) 179 {} 180 181 153 182 /** 154 183 * send one packet to other host -
branches/proxy/src/lib/network/udp_socket.h
r9291 r9334 31 31 32 32 virtual void connectToServer( std::string host, int port ); 33 34 33 virtual void disconnectServer(); 35 34 35 virtual void reconnectToServer( std::string host, int port); 36 virtual void reconnectToServerSoft( std::string host, int port); 37 36 38 virtual bool writePacket(byte * data, int length ); 37 38 39 virtual int readPacket(byte * data, int maxLength); 39 40 -
branches/proxy/src/subprojects/network/network_unit_test.cc
r8623 r9334 208 208 209 209 /* esatblish a connection */ 210 IP addressip;210 IP ip; 211 211 int error = SDLNet_ResolveHost(&ip, "127.0.0.1", port); 212 212 //SDLNet_ResolveHost(&ip, "localhost", port); … … 353 353 printf("Connecting to %s, on port %i\n", name, port); 354 354 355 IP addressip;355 IP ip; 356 356 int error = SDLNet_ResolveHost(&ip, name, port); 357 357 if(error == -1)
Note: See TracChangeset
for help on using the changeset viewer.