/** Detects public IP-address and port by first sending a request to a randomly * selected STUN server and then parsing and validating the response */ void GetPublicAddress::asynchronousUpdate() { // If the user has specified an address, use it instead of the stun protocol. if (m_my_address.getIP() != 0 && m_my_address.getPort() != 0) { NetworkConfig::get()->setMyAddress(m_my_address); m_state = EXITING; requestTerminate(); } //#define LAN_TEST #ifdef LAN_TEST TransportAddress address(0x7f000001, 4); NetworkConfig::get()->setMyAddress(address); m_state = EXITING; requestTerminate(); return; #endif if (m_state == NOTHING_DONE) { createStunRequest(); } if (m_state == STUN_REQUEST_SENT) { std::string message = parseStunResponse(); delete m_transaction_host; if (message != "") { Log::warn("GetPublicAddress", "%s", message.c_str()); m_state = NOTHING_DONE; // try again } else { // The address and the port are known, so the connection can be closed m_state = EXITING; requestTerminate(); } } } // asynchronousUpdate
/** Detects public IP-address and port by first sending a request to a randomly * selected STUN server and then parsing and validating the response */ void GetPublicAddress::asynchronousUpdate() { if (m_state == NOTHING_DONE) { createStunRequest(); } if (m_state == STUN_REQUEST_SENT) { std::string message = parseStunResponse(); delete m_transaction_host; if (message != "") { Log::warn("GetPublicAddress", "%s", message.c_str()); m_state = NOTHING_DONE; // try again } else { // The address and the port are known, so the connection can be closed m_state = EXITING; requestTerminate(); } } } // asynchronousUpdate