Commit 2699f348 authored by Nikola Hardi's avatar Nikola Hardi
Browse files

Force IPv4 when needed

parent f17f8d99
......@@ -36,6 +36,7 @@ class TJAlienDNSResolver : public TObject {
vector<string> addr_ipv4;
vector<string> addr_ipv6;
vector<string> addr_combined;
string addr2string(const struct addrinfo *ai);
vector<string> get_addr(const char *host, const char *port, int ipv = 6);
......
......@@ -139,6 +139,7 @@ void TJAlienConnectionManager::MakeWebsocketConnection(TJAlienCredentialsObject
{
// Create the connection to JBox using the parameters read from the token
// returns true if the connection was established
bool is_ipv4 = host.find(".") != -1;
if (gDebug > 0) {
Info("TJAlienConnectionManager", "Connecting to Server %s:%d", host.c_str(), WSPort);
......@@ -147,7 +148,7 @@ void TJAlienConnectionManager::MakeWebsocketConnection(TJAlienCredentialsObject
// Use this for debugging
//lws_set_log_level(LLL_EXT | LLL_USER | LLL_PARSER | LLL_INFO | LLL_ERR | LLL_NOTICE, nullptr);
lws_set_log_level(gDebug, nullptr);
lws_set_log_level(2047, nullptr);
// Reset context variables
context = nullptr;
......@@ -186,6 +187,7 @@ void TJAlienConnectionManager::MakeWebsocketConnection(TJAlienCredentialsObject
creation_info.options = 0;
creation_info.vhost_name = "tjalien-root";
creation_info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
if(is_ipv4) creation_info.options |= LWS_SERVER_OPTION_DISABLE_IPV6;
creation_info.ws_ping_pong_interval = 60*15;
creation_info.timeout_secs = 5;
......
......@@ -60,33 +60,27 @@ vector<string> TJAlienDNSResolver::get_addr(const char *host, const char *port,
}
void TJAlienDNSResolver::reset() {
addr_ipv4 = get_addr(host.c_str(), port.c_str(), 4);
addr_ipv6 = get_addr(host.c_str(), port.c_str(), 6);
use_ipv6 = false;
use_ipv6 = true;
current_position = 0;
}
string TJAlienDNSResolver::get_next_host() {
string result;
int ipv6_len = addr_ipv6.size();
int ipv4_len = addr_ipv4.size();
addr_ipv4 = get_addr(host.c_str(), port.c_str(), 4);
addr_combined = addr_ipv4;
if(use_ipv6 && current_position < ipv6_len) {
result = addr_ipv6[current_position];
} else if(!use_ipv6 && current_position < ipv4_len) {
result = addr_ipv4[current_position];
if(use_ipv6) {
addr_ipv6 = get_addr(host.c_str(), port.c_str(), 6);
addr_combined.append(addr_combined.end(), addr_ipv6.begin(), addr_ipv6.end());
}
current_position++;
}
string TJAlienDNSResolver::get_next_host() {
string result;
if(use_ipv6 && current_position >= ipv6_len) {
use_ipv6 = false;
current_position = 0;
} else if(!use_ipv6 && current_position >= ipv4_len) {
reset();
if(current_position >= addr_combined.size()) {
current_position = 0;
}
return result;
return addr_combined[current_position++];
}
int TJAlienDNSResolver::lenght() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment