Move the STUN request creating and sending from GetPublicAddress::asynchronousUpdate() into its own function
This commit is contained in:
parent
5ec9fa38ab
commit
1ce3be98ee
@ -73,7 +73,7 @@ void GetPublicAddress::setup()
|
||||
/**
|
||||
* Gets the response from the STUN server, checks it for its validity and
|
||||
* then parses the answer into address and port
|
||||
* \return "" if the adress could be parsed or an error message
|
||||
* \return "" if the address could be parsed or an error message
|
||||
*/
|
||||
std::string GetPublicAddress::parseResponse()
|
||||
{
|
||||
@ -158,16 +158,13 @@ std::string GetPublicAddress::parseResponse()
|
||||
}
|
||||
|
||||
|
||||
/** 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()
|
||||
/** Creates a request and sends it to a random STUN server randomly slected
|
||||
* from the list saved in the config file
|
||||
* The request is send through m_transaction_host, from which the answer
|
||||
* will be retrieved by parseResponse()
|
||||
*/
|
||||
void GetPublicAddress::createStunRequest()
|
||||
{
|
||||
// Creates a request and sends it to a random STUN server randomly slected
|
||||
// from the list saved in the config file
|
||||
// The request is send through m_transaction_host, from which the answer
|
||||
// can be retrieved
|
||||
if (m_state == NOTHING_DONE)
|
||||
{
|
||||
// format : 00MMMMMCMMMCMMMM (cf rfc 5389)
|
||||
uint16_t message_type = 0x0001; // binding request
|
||||
m_stun_tansaction_id[0] = stunRand();
|
||||
@ -239,9 +236,15 @@ void GetPublicAddress::asynchronousUpdate()
|
||||
return;
|
||||
}
|
||||
freeaddrinfo(res); // free the linked list
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** 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 == TEST_SENT)
|
||||
{
|
||||
std::string message = parseResponse();
|
||||
|
@ -51,6 +51,7 @@ class GetPublicAddress : public Protocol
|
||||
|
||||
private:
|
||||
std::string parseResponse();
|
||||
void createStunRequest();
|
||||
};
|
||||
|
||||
#endif // GET_PUBLIC_ADDRESS_HPP
|
||||
|
Loading…
Reference in New Issue
Block a user