diff --git a/CHANGELOG.md b/CHANGELOG.md index f2e477dd..116d921c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,3 @@ -# v6.24.0 -- [#3671](https://github.com/xmrig/xmrig/pull/3671) Fixed detection of L2 cache size for some complex NUMA topologies. -- [#3674](https://github.com/xmrig/xmrig/pull/3674) Fixed ARMv7 build. -- [#3677](https://github.com/xmrig/xmrig/pull/3677) Fixed auto-config for AMD CPUs with less than 2 MB L3 cache per thread. -- [#3678](https://github.com/xmrig/xmrig/pull/3678) Improved IPv6 support: the new default settings use IPv6 equally with IPv4. - # v6.23.0 - [#3668](https://github.com/xmrig/xmrig/issues/3668) Added support for Windows ARM64. - [#3665](https://github.com/xmrig/xmrig/pull/3665) Tweaked auto-config for AMD CPUs with < 2 MB L3 cache per thread. diff --git a/cmake/flags.cmake b/cmake/flags.cmake index 9abf212a..cdce9336 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -26,7 +26,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES GNU) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM8_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARM8_CXX_FLAGS} -flax-vector-conversions") elseif (ARM_TARGET EQUAL 7) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a -mfpu=neon -flax-vector-conversions") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a -mfpu=neon") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv7-a -mfpu=neon -flax-vector-conversions") else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes") diff --git a/src/backend/cpu/platform/HwlocCpuInfo.cpp b/src/backend/cpu/platform/HwlocCpuInfo.cpp index f796416b..40e05a17 100644 --- a/src/backend/cpu/platform/HwlocCpuInfo.cpp +++ b/src/backend/cpu/platform/HwlocCpuInfo.cpp @@ -311,17 +311,17 @@ void xmrig::HwlocCpuInfo::processTopLevelCache(hwloc_obj_t cache, const Algorith uint32_t intensity = algorithm.maxIntensity() == 1 ? 0 : 1; if (cache->attr->cache.depth == 3) { - auto process_L2 = [&L2, &L2_associativity, L3_exclusive, this, &extra, scratchpad](hwloc_obj_t l2) { + for (size_t i = 0; i < cache->arity; ++i) { + hwloc_obj_t l2 = cache->children[i]; if (!hwloc_obj_type_is_cache(l2->type) || l2->attr == nullptr) { - return; + continue; } L2 += l2->attr->cache.size; L2_associativity = l2->attr->cache.associativity; if (L3_exclusive) { - if ((vendor() == VENDOR_AMD) && ((arch() == ARCH_ZEN4) || (arch() == ARCH_ZEN5))) { - // Use extra L2 only on newer CPUs because older CPUs (Zen 3 and older) don't benefit from it. + if (vendor() == VENDOR_AMD) { // For some reason, AMD CPUs can use only half of the exclusive L2/L3 cache combo efficiently extra += std::min(l2->attr->cache.size / 2, scratchpad); } @@ -329,18 +329,6 @@ void xmrig::HwlocCpuInfo::processTopLevelCache(hwloc_obj_t cache, const Algorith extra += scratchpad; } } - }; - - for (size_t i = 0; i < cache->arity; ++i) { - hwloc_obj_t ch = cache->children[i]; - if (ch->type == HWLOC_OBJ_GROUP) { - for (size_t j = 0; j < ch->arity; ++j) { - process_L2(ch->children[j]); - } - } - else { - process_L2(ch); - } } } diff --git a/src/base/kernel/config/BaseTransform.cpp b/src/base/kernel/config/BaseTransform.cpp index 339e4621..a1b430da 100644 --- a/src/base/kernel/config/BaseTransform.cpp +++ b/src/base/kernel/config/BaseTransform.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,12 +18,14 @@ #include + #ifdef _MSC_VER # include "getopt/getopt.h" #else # include #endif + #include "base/kernel/config/BaseTransform.h" #include "base/io/json/JsonChain.h" #include "base/io/log/Log.h" @@ -35,6 +37,7 @@ #include "base/net/stratum/Pools.h" #include "core/config/Config_platform.h" + #ifdef XMRIG_FEATURE_TLS # include "base/net/tls/TlsConfig.h" #endif @@ -44,9 +47,9 @@ void xmrig::BaseTransform::load(JsonChain &chain, Process *process, IConfigTrans { using namespace rapidjson; - int key = 0; - const int argc = process->arguments().argc(); - char **argv = process->arguments().argv(); + int key = 0; + int argc = process->arguments().argc(); + char **argv = process->arguments().argv(); Document doc(kObjectType); @@ -259,8 +262,7 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch case IConfig::DaemonKey: /* --daemon */ case IConfig::SubmitToOriginKey: /* --submit-to-origin */ case IConfig::VerboseKey: /* --verbose */ - case IConfig::DnsIPv4Key: /* --ipv4 */ - case IConfig::DnsIPv6Key: /* --ipv6 */ + case IConfig::DnsIPv6Key: /* --dns-ipv6 */ return transformBoolean(doc, key, true); case IConfig::ColorKey: /* --no-color */ @@ -321,11 +323,8 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b case IConfig::NoTitleKey: /* --no-title */ return set(doc, BaseConfig::kTitle, enable); - case IConfig::DnsIPv4Key: /* --ipv4 */ - return set(doc, DnsConfig::kField, DnsConfig::kIPv, 4); - - case IConfig::DnsIPv6Key: /* --ipv6 */ - return set(doc, DnsConfig::kField, DnsConfig::kIPv, 6); + case IConfig::DnsIPv6Key: /* --dns-ipv6 */ + return set(doc, DnsConfig::kField, DnsConfig::kIPv6, enable); default: break; diff --git a/src/base/kernel/interfaces/IConfig.h b/src/base/kernel/interfaces/IConfig.h index 94c5760d..98957fc4 100644 --- a/src/base/kernel/interfaces/IConfig.h +++ b/src/base/kernel/interfaces/IConfig.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,9 @@ * along with this program. If not, see . */ -#pragma once +#ifndef XMRIG_ICONFIG_H +#define XMRIG_ICONFIG_H + #include "3rdparty/rapidjson/fwd.h" @@ -80,8 +82,7 @@ public: HugePageSizeKey = 1050, PauseOnActiveKey = 1051, SubmitToOriginKey = 1052, - DnsIPv4Key = '4', - DnsIPv6Key = '6', + DnsIPv6Key = 1053, DnsTtlKey = 1054, SpendSecretKey = 1055, DaemonZMQPortKey = 1056, @@ -176,4 +177,7 @@ public: }; -} // namespace xmrig +} /* namespace xmrig */ + + +#endif // XMRIG_ICONFIG_H diff --git a/src/base/kernel/interfaces/IDnsBackend.h b/src/base/kernel/interfaces/IDnsBackend.h index de069dc5..ca676f32 100644 --- a/src/base/kernel/interfaces/IDnsBackend.h +++ b/src/base/kernel/interfaces/IDnsBackend.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,16 +16,21 @@ * along with this program. If not, see . */ -#pragma once +#ifndef XMRIG_IDNSBACKEND_H +#define XMRIG_IDNSBACKEND_H + #include "base/tools/Object.h" +#include + + namespace xmrig { -class DnsConfig; class DnsRecords; +class DnsRequest; class IDnsListener; class String; @@ -38,8 +43,12 @@ public: IDnsBackend() = default; virtual ~IDnsBackend() = default; - virtual void resolve(const String &host, const std::weak_ptr &listener, const DnsConfig &config) = 0; + virtual const DnsRecords &records() const = 0; + virtual std::shared_ptr resolve(const String &host, IDnsListener *listener, uint64_t ttl) = 0; }; -} // namespace xmrig +} /* namespace xmrig */ + + +#endif // XMRIG_IDNSBACKEND_H diff --git a/src/base/net/dns/Dns.cpp b/src/base/net/dns/Dns.cpp index d5e71b49..85590bb7 100644 --- a/src/base/net/dns/Dns.cpp +++ b/src/base/net/dns/Dns.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,6 @@ #include "base/net/dns/Dns.h" -#include "base/net/dns/DnsRequest.h" #include "base/net/dns/DnsUvBackend.h" @@ -26,21 +25,17 @@ namespace xmrig { DnsConfig Dns::m_config; -std::map> Dns::m_backends; +std::map > Dns::m_backends; } // namespace xmrig -std::shared_ptr xmrig::Dns::resolve(const String &host, IDnsListener *listener) +std::shared_ptr xmrig::Dns::resolve(const String &host, IDnsListener *listener, uint64_t ttl) { - auto req = std::make_shared(listener); - if (m_backends.find(host) == m_backends.end()) { m_backends.insert({ host, std::make_shared() }); } - m_backends.at(host)->resolve(host, req, m_config); - - return req; + return m_backends.at(host)->resolve(host, listener, ttl == 0 ? m_config.ttl() : ttl); } diff --git a/src/base/net/dns/Dns.h b/src/base/net/dns/Dns.h index 2408245f..cf054390 100644 --- a/src/base/net/dns/Dns.h +++ b/src/base/net/dns/Dns.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,7 +43,7 @@ public: inline static const DnsConfig &config() { return m_config; } inline static void set(const DnsConfig &config) { m_config = config; } - static std::shared_ptr resolve(const String &host, IDnsListener *listener); + static std::shared_ptr resolve(const String &host, IDnsListener *listener, uint64_t ttl = 0); private: static DnsConfig m_config; diff --git a/src/base/net/dns/DnsConfig.cpp b/src/base/net/dns/DnsConfig.cpp index 3b2bbe73..f9ec7e28 100644 --- a/src/base/net/dns/DnsConfig.cpp +++ b/src/base/net/dns/DnsConfig.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,15 +20,15 @@ #include "3rdparty/rapidjson/document.h" #include "base/io/json/Json.h" + #include -#include namespace xmrig { const char *DnsConfig::kField = "dns"; -const char *DnsConfig::kIPv = "ip_version"; +const char *DnsConfig::kIPv6 = "ipv6"; const char *DnsConfig::kTTL = "ttl"; @@ -37,26 +37,8 @@ const char *DnsConfig::kTTL = "ttl"; xmrig::DnsConfig::DnsConfig(const rapidjson::Value &value) { - const uint32_t ipv = Json::getUint(value, kIPv, m_ipv); - if (ipv == 0 || ipv == 4 || ipv == 6) { - m_ipv = ipv; - } - - m_ttl = std::max(Json::getUint(value, kTTL, m_ttl), 1U); -} - - -int xmrig::DnsConfig::ai_family() const -{ - if (m_ipv == 4) { - return AF_INET; - } - - if (m_ipv == 6) { - return AF_INET6; - } - - return AF_UNSPEC; + m_ipv6 = Json::getBool(value, kIPv6, m_ipv6); + m_ttl = std::max(Json::getUint(value, kTTL, m_ttl), 1U); } @@ -67,8 +49,8 @@ rapidjson::Value xmrig::DnsConfig::toJSON(rapidjson::Document &doc) const auto &allocator = doc.GetAllocator(); Value obj(kObjectType); - obj.AddMember(StringRef(kIPv), m_ipv, allocator); - obj.AddMember(StringRef(kTTL), m_ttl, allocator); + obj.AddMember(StringRef(kIPv6), m_ipv6, allocator); + obj.AddMember(StringRef(kTTL), m_ttl, allocator); return obj; } diff --git a/src/base/net/dns/DnsConfig.h b/src/base/net/dns/DnsConfig.h index 7c985f90..605e837b 100644 --- a/src/base/net/dns/DnsConfig.h +++ b/src/base/net/dns/DnsConfig.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,9 @@ * along with this program. If not, see . */ -#pragma once +#ifndef XMRIG_DNSCONFIG_H +#define XMRIG_DNSCONFIG_H + #include "3rdparty/rapidjson/fwd.h" @@ -28,22 +30,25 @@ class DnsConfig { public: static const char *kField; - static const char *kIPv; + static const char *kIPv6; static const char *kTTL; DnsConfig() = default; DnsConfig(const rapidjson::Value &value); - inline uint32_t ipv() const { return m_ipv; } + inline bool isIPv6() const { return m_ipv6; } inline uint32_t ttl() const { return m_ttl * 1000U; } - int ai_family() const; rapidjson::Value toJSON(rapidjson::Document &doc) const; + private: - uint32_t m_ttl = 30U; - uint32_t m_ipv = 0U; + bool m_ipv6 = false; + uint32_t m_ttl = 30U; }; -} // namespace xmrig +} /* namespace xmrig */ + + +#endif /* XMRIG_DNSCONFIG_H */ diff --git a/src/base/net/dns/DnsRecord.cpp b/src/base/net/dns/DnsRecord.cpp index 2b5a5058..3bf8f097 100644 --- a/src/base/net/dns/DnsRecord.cpp +++ b/src/base/net/dns/DnsRecord.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2023 SChernykh + * Copyright (c) 2016-2023 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,16 +16,19 @@ * along with this program. If not, see . */ + #include + #include "base/net/dns/DnsRecord.h" -xmrig::DnsRecord::DnsRecord(const addrinfo *addr) +xmrig::DnsRecord::DnsRecord(const addrinfo *addr) : + m_type(addr->ai_family == AF_INET6 ? AAAA : (addr->ai_family == AF_INET ? A : Unknown)) { static_assert(sizeof(m_data) >= sizeof(sockaddr_in6), "Not enough storage for IPv6 address."); - memcpy(m_data, addr->ai_addr, addr->ai_family == AF_INET6 ? sizeof(sockaddr_in6) : sizeof(sockaddr_in)); + memcpy(m_data, addr->ai_addr, m_type == AAAA ? sizeof(sockaddr_in6) : sizeof(sockaddr_in)); } @@ -41,7 +44,7 @@ xmrig::String xmrig::DnsRecord::ip() const { char *buf = nullptr; - if (reinterpret_cast(m_data).sa_family == AF_INET6) { + if (m_type == AAAA) { buf = new char[45](); uv_ip6_name(reinterpret_cast(m_data), buf, 45); } diff --git a/src/base/net/dns/DnsRecord.h b/src/base/net/dns/DnsRecord.h index 548b603f..7a68ea2f 100644 --- a/src/base/net/dns/DnsRecord.h +++ b/src/base/net/dns/DnsRecord.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,11 +16,14 @@ * along with this program. If not, see . */ -#pragma once +#ifndef XMRIG_DNSRECORD_H +#define XMRIG_DNSRECORD_H + struct addrinfo; struct sockaddr; + #include "base/tools/String.h" @@ -30,15 +33,28 @@ namespace xmrig { class DnsRecord { public: + enum Type : uint32_t { + Unknown, + A, + AAAA + }; + DnsRecord() {} DnsRecord(const addrinfo *addr); const sockaddr *addr(uint16_t port = 0) const; String ip() const; + inline bool isValid() const { return m_type != Unknown; } + inline Type type() const { return m_type; } + private: mutable uint8_t m_data[28]{}; + const Type m_type = Unknown; }; -} // namespace xmrig +} /* namespace xmrig */ + + +#endif /* XMRIG_DNSRECORD_H */ diff --git a/src/base/net/dns/DnsRecords.cpp b/src/base/net/dns/DnsRecords.cpp index aff2b323..072f9672 100644 --- a/src/base/net/dns/DnsRecords.cpp +++ b/src/base/net/dns/DnsRecords.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,96 +18,90 @@ #include + #include "base/net/dns/DnsRecords.h" +#include "base/net/dns/Dns.h" -namespace { - - -static size_t dns_records_count(const addrinfo *res, int &ai_family) -{ - size_t ipv4 = 0; - size_t ipv6 = 0; - - while (res != nullptr) { - if (res->ai_family == AF_INET) { - ++ipv4; - } - - if (res->ai_family == AF_INET6) { - ++ipv6; - } - - res = res->ai_next; - } - - if (ai_family == AF_INET6 && !ipv6) { - ai_family = AF_INET; - } - - switch (ai_family) { - case AF_UNSPEC: - return ipv4 + ipv6; - - case AF_INET: - return ipv4; - - case AF_INET6: - return ipv6; - - default: - break; - } - - return 0; -} - - -} // namespace - - -xmrig::DnsRecords::DnsRecords(const addrinfo *res, int ai_family) -{ - size_t size = dns_records_count(res, ai_family); - if (!size) { - return; - } - - m_records.reserve(size); - - if (ai_family == AF_UNSPEC) { - while (res != nullptr) { - if (res->ai_family == AF_INET || res->ai_family == AF_INET6) { - m_records.emplace_back(res); - } - - res = res->ai_next; - }; - } else { - while (res != nullptr) { - if (res->ai_family == ai_family) { - m_records.emplace_back(res); - } - - res = res->ai_next; - }; - } - - size = m_records.size(); - if (size > 1) { - m_index = static_cast(rand()) % size; // NOLINT(concurrency-mt-unsafe, cert-msc30-c, cert-msc50-cpp) - } -} - - -const xmrig::DnsRecord &xmrig::DnsRecords::get() const +const xmrig::DnsRecord &xmrig::DnsRecords::get(DnsRecord::Type prefered) const { static const DnsRecord defaultRecord; - const size_t size = m_records.size(); - if (size > 0) { - return m_records[m_index++ % size]; + if (isEmpty()) { + return defaultRecord; + } + + const size_t ipv4 = m_ipv4.size(); + const size_t ipv6 = m_ipv6.size(); + + if (ipv6 && (prefered == DnsRecord::AAAA || Dns::config().isIPv6() || !ipv4)) { + return m_ipv6[ipv6 == 1 ? 0 : static_cast(rand()) % ipv6]; // NOLINT(concurrency-mt-unsafe, cert-msc30-c, cert-msc50-cpp) + } + + if (ipv4) { + return m_ipv4[ipv4 == 1 ? 0 : static_cast(rand()) % ipv4]; // NOLINT(concurrency-mt-unsafe, cert-msc30-c, cert-msc50-cpp) } return defaultRecord; } + + +size_t xmrig::DnsRecords::count(DnsRecord::Type type) const +{ + if (type == DnsRecord::A) { + return m_ipv4.size(); + } + + if (type == DnsRecord::AAAA) { + return m_ipv6.size(); + } + + return m_ipv4.size() + m_ipv6.size(); +} + + +void xmrig::DnsRecords::clear() +{ + m_ipv4.clear(); + m_ipv6.clear(); +} + + +void xmrig::DnsRecords::parse(addrinfo *res) +{ + clear(); + + addrinfo *ptr = res; + size_t ipv4 = 0; + size_t ipv6 = 0; + + while (ptr != nullptr) { + if (ptr->ai_family == AF_INET) { + ++ipv4; + } + else if (ptr->ai_family == AF_INET6) { + ++ipv6; + } + + ptr = ptr->ai_next; + } + + if (ipv4 == 0 && ipv6 == 0) { + return; + } + + m_ipv4.reserve(ipv4); + m_ipv6.reserve(ipv6); + + ptr = res; + while (ptr != nullptr) { + if (ptr->ai_family == AF_INET) { + m_ipv4.emplace_back(ptr); + } + else if (ptr->ai_family == AF_INET6) { + m_ipv6.emplace_back(ptr); + } + + ptr = ptr->ai_next; + } +} diff --git a/src/base/net/dns/DnsRecords.h b/src/base/net/dns/DnsRecords.h index 4b16d54a..cfa19217 100644 --- a/src/base/net/dns/DnsRecords.h +++ b/src/base/net/dns/DnsRecords.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,9 @@ * along with this program. If not, see . */ -#pragma once +#ifndef XMRIG_DNSRECORDS_H +#define XMRIG_DNSRECORDS_H + #include "base/net/dns/DnsRecord.h" @@ -27,19 +29,20 @@ namespace xmrig { class DnsRecords { public: - DnsRecords() = default; - DnsRecords(const addrinfo *res, int ai_family); + inline bool isEmpty() const { return m_ipv4.empty() && m_ipv6.empty(); } - inline bool isEmpty() const { return m_records.empty(); } - inline const std::vector &records() const { return m_records; } - inline size_t size() const { return m_records.size(); } - - const DnsRecord &get() const; + const DnsRecord &get(DnsRecord::Type prefered = DnsRecord::Unknown) const; + size_t count(DnsRecord::Type type = DnsRecord::Unknown) const; + void clear(); + void parse(addrinfo *res); private: - mutable size_t m_index = 0; - std::vector m_records; + std::vector m_ipv4; + std::vector m_ipv6; }; -} // namespace xmrig +} /* namespace xmrig */ + + +#endif /* XMRIG_DNSRECORDS_H */ diff --git a/src/base/net/dns/DnsRequest.h b/src/base/net/dns/DnsRequest.h index 175b9c07..036eaa34 100644 --- a/src/base/net/dns/DnsRequest.h +++ b/src/base/net/dns/DnsRequest.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,30 +16,35 @@ * along with this program. If not, see . */ -#pragma once +#ifndef XMRIG_DNSREQUEST_H +#define XMRIG_DNSREQUEST_H -#include "base/kernel/interfaces/IDnsListener.h" + +#include "base/tools/Object.h" + + +#include namespace xmrig { -class DnsRequest : public IDnsListener +class IDnsListener; + + +class DnsRequest { public: XMRIG_DISABLE_COPY_MOVE_DEFAULT(DnsRequest) - inline DnsRequest(IDnsListener *listener) : m_listener(listener) {} - ~DnsRequest() override = default; + DnsRequest(IDnsListener *listener) : listener(listener) {} + ~DnsRequest() = default; -protected: - inline void onResolved(const DnsRecords &records, int status, const char *error) override { - m_listener->onResolved(records, status, error); - } - -private: - IDnsListener *m_listener; + IDnsListener *listener; }; -} // namespace xmrig +} /* namespace xmrig */ + + +#endif /* XMRIG_DNSREQUEST_H */ diff --git a/src/base/net/dns/DnsUvBackend.cpp b/src/base/net/dns/DnsUvBackend.cpp index 850f493e..33f27f95 100644 --- a/src/base/net/dns/DnsUvBackend.cpp +++ b/src/base/net/dns/DnsUvBackend.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2023 SChernykh + * Copyright (c) 2016-2023 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,11 +16,13 @@ * along with this program. If not, see . */ + #include + #include "base/net/dns/DnsUvBackend.h" #include "base/kernel/interfaces/IDnsListener.h" -#include "base/net/dns/DnsConfig.h" +#include "base/net/dns/DnsRequest.h" #include "base/tools/Chrono.h" @@ -71,23 +73,21 @@ xmrig::DnsUvBackend::~DnsUvBackend() } -void xmrig::DnsUvBackend::resolve(const String &host, const std::weak_ptr &listener, const DnsConfig &config) +std::shared_ptr xmrig::DnsUvBackend::resolve(const String &host, IDnsListener *listener, uint64_t ttl) { - m_queue.emplace_back(listener); + auto req = std::make_shared(listener); - if (Chrono::currentMSecsSinceEpoch() - m_ts <= config.ttl()) { - return notify(); + if (Chrono::currentMSecsSinceEpoch() - m_ts <= ttl && !m_records.isEmpty()) { + req->listener->onResolved(m_records, 0, nullptr); + } else { + m_queue.emplace(req); } - if (m_req) { - return; + if (m_queue.size() == 1 && !resolve(host)) { + done(); } - m_ai_family = config.ai_family(); - - if (!resolve(host)) { - notify(); - } + return req; } @@ -102,46 +102,44 @@ bool xmrig::DnsUvBackend::resolve(const String &host) } -void xmrig::DnsUvBackend::notify() +void xmrig::DnsUvBackend::done() { const char *error = m_status < 0 ? uv_strerror(m_status) : nullptr; - for (const auto &l : m_queue) { - auto listener = l.lock(); - if (listener) { - listener->onResolved(m_records, m_status, error); + while (!m_queue.empty()) { + auto req = std::move(m_queue.front()).lock(); + if (req) { + req->listener->onResolved(m_records, m_status, error); } + + m_queue.pop(); } - m_queue.clear(); m_req.reset(); } void xmrig::DnsUvBackend::onResolved(int status, addrinfo *res) { - m_status = status; - m_ts = Chrono::currentMSecsSinceEpoch(); + m_ts = Chrono::currentMSecsSinceEpoch(); - if (m_status < 0) { - m_records = {}; - - return notify(); + if ((m_status = status) < 0) { + return done(); } - m_records = { res, m_ai_family }; + m_records.parse(res); if (m_records.isEmpty()) { m_status = UV_EAI_NONAME; } - notify(); + done(); } void xmrig::DnsUvBackend::onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res) { - auto *backend = getStorage().get(req->data); + auto backend = getStorage().get(req->data); if (backend) { backend->onResolved(status, res); } diff --git a/src/base/net/dns/DnsUvBackend.h b/src/base/net/dns/DnsUvBackend.h index 24a6e1aa..3c2436c7 100644 --- a/src/base/net/dns/DnsUvBackend.h +++ b/src/base/net/dns/DnsUvBackend.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,13 +16,16 @@ * along with this program. If not, see . */ -#pragma once +#ifndef XMRIG_DNSUVBACKEND_H +#define XMRIG_DNSUVBACKEND_H + #include "base/kernel/interfaces/IDnsBackend.h" #include "base/net/dns/DnsRecords.h" #include "base/net/tools/Storage.h" -#include + +#include using uv_getaddrinfo_t = struct uv_getaddrinfo_s; @@ -40,19 +43,20 @@ public: ~DnsUvBackend() override; protected: - void resolve(const String &host, const std::weak_ptr &listener, const DnsConfig &config) override; + inline const DnsRecords &records() const override { return m_records; } + + std::shared_ptr resolve(const String &host, IDnsListener *listener, uint64_t ttl) override; private: bool resolve(const String &host); - void notify(); + void done(); void onResolved(int status, addrinfo *res); static void onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res); DnsRecords m_records; - int m_ai_family = 0; int m_status = 0; - std::deque> m_queue; + std::queue > m_queue; std::shared_ptr m_req; uint64_t m_ts = 0; uintptr_t m_key; @@ -62,4 +66,7 @@ private: }; -} // namespace xmrig +} /* namespace xmrig */ + + +#endif /* XMRIG_DNSUVBACKEND_H */ diff --git a/src/config.json b/src/config.json index 48adef17..1cdedac2 100644 --- a/src/config.json +++ b/src/config.json @@ -93,7 +93,7 @@ "dhparam": null }, "dns": { - "ip_version": 0, + "ipv6": false, "ttl": 30 }, "user-agent": null, diff --git a/src/core/config/Config_platform.h b/src/core/config/Config_platform.h index c689ed8a..52f66f30 100644 --- a/src/core/config/Config_platform.h +++ b/src/core/config/Config_platform.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,9 @@ * along with this program. If not, see . */ -#pragma once +#ifndef XMRIG_CONFIG_PLATFORM_H +#define XMRIG_CONFIG_PLATFORM_H + #ifdef _MSC_VER # include "getopt/getopt.h" @@ -26,12 +28,13 @@ #include "base/kernel/interfaces/IConfig.h" +#include "version.h" namespace xmrig { -static const char short_options[] = "a:c:kBp:Px:r:R:s:t:T:o:u:O:v:l:Sx:46"; +static const char short_options[] = "a:c:kBp:Px:r:R:s:t:T:o:u:O:v:l:Sx:"; static const option options[] = { @@ -96,8 +99,7 @@ static const option options[] = { { "no-title", 0, nullptr, IConfig::NoTitleKey }, { "pause-on-battery", 0, nullptr, IConfig::PauseOnBatteryKey }, { "pause-on-active", 1, nullptr, IConfig::PauseOnActiveKey }, - { "ipv4", 0, nullptr, IConfig::DnsIPv4Key }, - { "ipv6", 0, nullptr, IConfig::DnsIPv6Key }, + { "dns-ipv6", 0, nullptr, IConfig::DnsIPv6Key }, { "dns-ttl", 1, nullptr, IConfig::DnsTtlKey }, { "spend-secret-key", 1, nullptr, IConfig::SpendSecretKey }, # ifdef XMRIG_FEATURE_BENCHMARK @@ -167,3 +169,6 @@ static const option options[] = { } // namespace xmrig + + +#endif /* XMRIG_CONFIG_PLATFORM_H */ diff --git a/src/core/config/usage.h b/src/core/config/usage.h index cbec1b41..53a8e58c 100644 --- a/src/core/config/usage.h +++ b/src/core/config/usage.h @@ -4,8 +4,8 @@ * Copyright (c) 2014 Lucas Jones * Copyright (c) 2014-2016 Wolf9466 * Copyright (c) 2016 Jay D Dee - * Copyright (c) 2018-2025 SChernykh - * Copyright (c) 2016-2025 XMRig , + * Copyright (c) 2018-2024 SChernykh + * Copyright (c) 2016-2024 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,10 +21,13 @@ * along with this program. If not, see . */ -#pragma once +#ifndef XMRIG_USAGE_H +#define XMRIG_USAGE_H + #include "version.h" + #include @@ -56,8 +59,7 @@ static inline const std::string &usage() u += " --tls-fingerprint=HEX pool TLS certificate fingerprint for strict certificate pinning\n"; # endif - u += " -4, --ipv4 resolve names to IPv4 addresses\n"; - u += " -6, --ipv6 resolve names to IPv6 addresses\n"; + u += " --dns-ipv6 prefer IPv6 records from DNS responses\n"; u += " --dns-ttl=N N seconds (default: 30) TTL for internal DNS cache\n"; # ifdef XMRIG_FEATURE_HTTP @@ -203,4 +205,6 @@ static inline const std::string &usage() } -} // namespace xmrig +} /* namespace xmrig */ + +#endif /* XMRIG_USAGE_H */ diff --git a/src/version.h b/src/version.h index 9176a3d9..9f8d8333 100644 --- a/src/version.h +++ b/src/version.h @@ -22,14 +22,14 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig miner" -#define APP_VERSION "6.24.0" +#define APP_VERSION "6.23.0" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2025 xmrig.com" #define APP_KIND "miner" #define APP_VER_MAJOR 6 -#define APP_VER_MINOR 24 +#define APP_VER_MINOR 23 #define APP_VER_PATCH 0 #ifdef _MSC_VER diff --git a/src/xmrig.cpp b/src/xmrig.cpp index b7ad0ef8..635e071e 100644 --- a/src/xmrig.cpp +++ b/src/xmrig.cpp @@ -25,8 +25,6 @@ int main(int argc, char **argv) { using namespace xmrig; - std::cout << "goobus\n"; - Process process(argc, argv); const Entry::Id entry = Entry::get(process); if (entry) {