mirror of
https://github.com/xmrig/xmrig.git
synced 2025-03-12 09:37:35 +00:00
Better support for Round Robin DNS, related https://github.com/fireice-uk/xmr-stak-cpu/pull/220
This commit is contained in:
parent
66d3e96a1a
commit
986aee4297
2 changed files with 24 additions and 3 deletions
|
@ -277,7 +277,7 @@ void Client::connect(struct sockaddr *addr)
|
|||
uv_tcp_keepalive(m_socket, 1, 60);
|
||||
# endif
|
||||
|
||||
uv_tcp_connect(req, m_socket, (const sockaddr*) addr, Client::onConnect);
|
||||
uv_tcp_connect(req, m_socket, reinterpret_cast<const sockaddr*>(addr), Client::onConnect);
|
||||
}
|
||||
|
||||
|
||||
|
@ -545,8 +545,26 @@ void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res)
|
|||
return client->reconnect();;
|
||||
}
|
||||
|
||||
uv_ip4_name(reinterpret_cast<sockaddr_in*>(res->ai_addr), client->m_ip, 16);
|
||||
addrinfo *ptr = res;
|
||||
std::vector<addrinfo*> ipv4;
|
||||
|
||||
client->connect(res->ai_addr);
|
||||
while (ptr != nullptr) {
|
||||
if (ptr->ai_family == AF_INET) {
|
||||
ipv4.push_back(ptr);
|
||||
}
|
||||
|
||||
ptr = ptr->ai_next;
|
||||
}
|
||||
|
||||
if (ipv4.empty()) {
|
||||
LOG_ERR("[%s:%u] DNS error: \"No IPv4 records found\"", client->m_url.host(), client->m_url.port());
|
||||
return client->reconnect();
|
||||
}
|
||||
|
||||
ptr = ipv4[rand() % ipv4.size()];
|
||||
|
||||
uv_ip4_name(reinterpret_cast<sockaddr_in*>(ptr->ai_addr), client->m_ip, 16);
|
||||
|
||||
client->connect(ptr->ai_addr);
|
||||
uv_freeaddrinfo(res);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <ctime>
|
||||
#include <memory>
|
||||
|
||||
|
||||
|
@ -43,6 +44,8 @@ Network::Network(const Options *options) :
|
|||
m_accepted(0),
|
||||
m_rejected(0)
|
||||
{
|
||||
std::srand(std::time(0) ^ (uintptr_t) this);
|
||||
|
||||
Workers::setListener(this);
|
||||
m_agent = userAgent();
|
||||
|
||||
|
|
Loading…
Reference in a new issue