Skip to content

Commit 75f9971

Browse files
committed
Merge branch 'dev'
2 parents 6dc2f16 + aaa89d7 commit 75f9971

File tree

19 files changed

+239
-259
lines changed

19 files changed

+239
-259
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v6.24.0
2+
- [#3678](https://github.com/xmrig/xmrig/pull/3678) Improved IPv6 support: the new default settings use IPv6 equally with IPv4.
3+
14
# v6.23.0
25
- [#3668](https://github.com/xmrig/xmrig/issues/3668) Added support for Windows ARM64.
36
- Sync changes with XMRig v6.23.0.

src/base/kernel/config/BaseTransform.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* XMRig
2-
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
3-
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
2+
* Copyright (c) 2018-2025 SChernykh <https://github.com/SChernykh>
3+
* Copyright (c) 2016-2025 XMRig <https://github.com/xmrig>, <support@xmrig.com>
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -18,14 +18,12 @@
1818

1919
#include <cstdio>
2020

21-
2221
#ifdef _MSC_VER
2322
# include "getopt/getopt.h"
2423
#else
2524
# include <getopt.h>
2625
#endif
2726

28-
2927
#include "base/kernel/config/BaseTransform.h"
3028
#include "base/io/json/JsonChain.h"
3129
#include "base/io/log/Log.h"
@@ -37,7 +35,6 @@
3735
#include "base/net/stratum/Pools.h"
3836
#include "core/config/Config_platform.h"
3937

40-
4138
#ifdef XMRIG_FEATURE_TLS
4239
# include "base/net/tls/TlsConfig.h"
4340
#endif
@@ -47,9 +44,9 @@ void xmrig::BaseTransform::load(JsonChain &chain, Process *process, IConfigTrans
4744
{
4845
using namespace rapidjson;
4946

50-
int key = 0;
51-
int argc = process->arguments().argc();
52-
char **argv = process->arguments().argv();
47+
int key = 0;
48+
const int argc = process->arguments().argc();
49+
char **argv = process->arguments().argv();
5350

5451
Document doc(kObjectType);
5552

@@ -262,7 +259,8 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
262259
case IConfig::DaemonKey: /* --daemon */
263260
case IConfig::SubmitToOriginKey: /* --submit-to-origin */
264261
case IConfig::VerboseKey: /* --verbose */
265-
case IConfig::DnsIPv6Key: /* --dns-ipv6 */
262+
case IConfig::DnsIPv4Key: /* --ipv4 */
263+
case IConfig::DnsIPv6Key: /* --ipv6 */
266264
return transformBoolean(doc, key, true);
267265

268266
case IConfig::ColorKey: /* --no-color */
@@ -323,8 +321,11 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b
323321
case IConfig::NoTitleKey: /* --no-title */
324322
return set(doc, BaseConfig::kTitle, enable);
325323

326-
case IConfig::DnsIPv6Key: /* --dns-ipv6 */
327-
return set(doc, DnsConfig::kField, DnsConfig::kIPv6, enable);
324+
case IConfig::DnsIPv4Key: /* --ipv4 */
325+
return set(doc, DnsConfig::kField, DnsConfig::kIPv, 4);
326+
327+
case IConfig::DnsIPv6Key: /* --ipv6 */
328+
return set(doc, DnsConfig::kField, DnsConfig::kIPv, 6);
328329

329330
default:
330331
break;

src/base/kernel/interfaces/IConfig.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* XMRig
2-
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
3-
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
2+
* Copyright (c) 2018-2025 SChernykh <https://github.com/SChernykh>
3+
* Copyright (c) 2016-2025 XMRig <https://github.com/xmrig>, <support@xmrig.com>
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -16,9 +16,7 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
#ifndef XMRIG_ICONFIG_H
20-
#define XMRIG_ICONFIG_H
21-
19+
#pragma once
2220

2321
#include "3rdparty/rapidjson/fwd.h"
2422

@@ -82,7 +80,8 @@ class IConfig
8280
HugePageSizeKey = 1050,
8381
PauseOnActiveKey = 1051,
8482
SubmitToOriginKey = 1052,
85-
DnsIPv6Key = 1053,
83+
DnsIPv4Key = '4',
84+
DnsIPv6Key = '6',
8685
DnsTtlKey = 1054,
8786
SpendSecretKey = 1055,
8887
DaemonZMQPortKey = 1056,
@@ -177,7 +176,4 @@ class IConfig
177176
};
178177

179178

180-
} /* namespace xmrig */
181-
182-
183-
#endif // XMRIG_ICONFIG_H
179+
} // namespace xmrig
Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* XMRig
2-
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
3-
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
2+
* Copyright (c) 2018-2025 SChernykh <https://github.com/SChernykh>
3+
* Copyright (c) 2016-2025 XMRig <https://github.com/xmrig>, <support@xmrig.com>
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -16,21 +16,16 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
#ifndef XMRIG_IDNSBACKEND_H
20-
#define XMRIG_IDNSBACKEND_H
21-
19+
#pragma once
2220

2321
#include "base/tools/Object.h"
2422

2523

26-
#include <memory>
27-
28-
2924
namespace xmrig {
3025

3126

27+
class DnsConfig;
3228
class DnsRecords;
33-
class DnsRequest;
3429
class IDnsListener;
3530
class String;
3631

@@ -43,12 +38,8 @@ class IDnsBackend
4338
IDnsBackend() = default;
4439
virtual ~IDnsBackend() = default;
4540

46-
virtual const DnsRecords &records() const = 0;
47-
virtual std::shared_ptr<DnsRequest> resolve(const String &host, IDnsListener *listener, uint64_t ttl) = 0;
41+
virtual void resolve(const String &host, const std::weak_ptr<IDnsListener> &listener, const DnsConfig &config) = 0;
4842
};
4943

5044

51-
} /* namespace xmrig */
52-
53-
54-
#endif // XMRIG_IDNSBACKEND_H
45+
} // namespace xmrig

src/base/net/dns/Dns.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* XMRig
2-
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
3-
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
2+
* Copyright (c) 2018-2025 SChernykh <https://github.com/SChernykh>
3+
* Copyright (c) 2016-2025 XMRig <https://github.com/xmrig>, <support@xmrig.com>
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -18,24 +18,29 @@
1818

1919

2020
#include "base/net/dns/Dns.h"
21+
#include "base/net/dns/DnsRequest.h"
2122
#include "base/net/dns/DnsUvBackend.h"
2223

2324

2425
namespace xmrig {
2526

2627

2728
DnsConfig Dns::m_config;
28-
std::map<String, std::shared_ptr<IDnsBackend> > Dns::m_backends;
29+
std::map<String, std::shared_ptr<IDnsBackend>> Dns::m_backends;
2930

3031

3132
} // namespace xmrig
3233

3334

34-
std::shared_ptr<xmrig::DnsRequest> xmrig::Dns::resolve(const String &host, IDnsListener *listener, uint64_t ttl)
35+
std::shared_ptr<xmrig::DnsRequest> xmrig::Dns::resolve(const String &host, IDnsListener *listener)
3536
{
37+
auto req = std::make_shared<DnsRequest>(listener);
38+
3639
if (m_backends.find(host) == m_backends.end()) {
3740
m_backends.insert({ host, std::make_shared<DnsUvBackend>() });
3841
}
3942

40-
return m_backends.at(host)->resolve(host, listener, ttl == 0 ? m_config.ttl() : ttl);
43+
m_backends.at(host)->resolve(host, req, m_config);
44+
45+
return req;
4146
}

src/base/net/dns/Dns.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* XMRig
2-
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
3-
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
2+
* Copyright (c) 2018-2025 SChernykh <https://github.com/SChernykh>
3+
* Copyright (c) 2016-2025 XMRig <https://github.com/xmrig>, <support@xmrig.com>
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -43,7 +43,7 @@ class Dns
4343
inline static const DnsConfig &config() { return m_config; }
4444
inline static void set(const DnsConfig &config) { m_config = config; }
4545

46-
static std::shared_ptr<DnsRequest> resolve(const String &host, IDnsListener *listener, uint64_t ttl = 0);
46+
static std::shared_ptr<DnsRequest> resolve(const String &host, IDnsListener *listener);
4747

4848
private:
4949
static DnsConfig m_config;

src/base/net/dns/DnsConfig.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* XMRig
2-
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
3-
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
2+
* Copyright (c) 2018-2025 SChernykh <https://github.com/SChernykh>
3+
* Copyright (c) 2016-2025 XMRig <https://github.com/xmrig>, <support@xmrig.com>
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -20,15 +20,15 @@
2020
#include "3rdparty/rapidjson/document.h"
2121
#include "base/io/json/Json.h"
2222

23-
2423
#include <algorithm>
24+
#include <uv.h>
2525

2626

2727
namespace xmrig {
2828

2929

3030
const char *DnsConfig::kField = "dns";
31-
const char *DnsConfig::kIPv6 = "ipv6";
31+
const char *DnsConfig::kIPv = "ip_version";
3232
const char *DnsConfig::kTTL = "ttl";
3333

3434

@@ -37,8 +37,26 @@ const char *DnsConfig::kTTL = "ttl";
3737

3838
xmrig::DnsConfig::DnsConfig(const rapidjson::Value &value)
3939
{
40-
m_ipv6 = Json::getBool(value, kIPv6, m_ipv6);
41-
m_ttl = std::max(Json::getUint(value, kTTL, m_ttl), 1U);
40+
const uint32_t ipv = Json::getUint(value, kIPv, m_ipv);
41+
if (ipv == 0 || ipv == 4 || ipv == 6) {
42+
m_ipv = ipv;
43+
}
44+
45+
m_ttl = std::max(Json::getUint(value, kTTL, m_ttl), 1U);
46+
}
47+
48+
49+
int xmrig::DnsConfig::ai_family() const
50+
{
51+
if (m_ipv == 4) {
52+
return AF_INET;
53+
}
54+
55+
if (m_ipv == 6) {
56+
return AF_INET6;
57+
}
58+
59+
return AF_UNSPEC;
4260
}
4361

4462

@@ -49,8 +67,8 @@ rapidjson::Value xmrig::DnsConfig::toJSON(rapidjson::Document &doc) const
4967
auto &allocator = doc.GetAllocator();
5068
Value obj(kObjectType);
5169

52-
obj.AddMember(StringRef(kIPv6), m_ipv6, allocator);
53-
obj.AddMember(StringRef(kTTL), m_ttl, allocator);
70+
obj.AddMember(StringRef(kIPv), m_ipv, allocator);
71+
obj.AddMember(StringRef(kTTL), m_ttl, allocator);
5472

5573
return obj;
5674
}

src/base/net/dns/DnsConfig.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* XMRig
2-
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
3-
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
2+
* Copyright (c) 2018-2025 SChernykh <https://github.com/SChernykh>
3+
* Copyright (c) 2016-2025 XMRig <https://github.com/xmrig>, <support@xmrig.com>
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -16,9 +16,7 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
#ifndef XMRIG_DNSCONFIG_H
20-
#define XMRIG_DNSCONFIG_H
21-
19+
#pragma once
2220

2321
#include "3rdparty/rapidjson/fwd.h"
2422

@@ -30,25 +28,22 @@ class DnsConfig
3028
{
3129
public:
3230
static const char *kField;
33-
static const char *kIPv6;
31+
static const char *kIPv;
3432
static const char *kTTL;
3533

3634
DnsConfig() = default;
3735
DnsConfig(const rapidjson::Value &value);
3836

39-
inline bool isIPv6() const { return m_ipv6; }
37+
inline uint32_t ipv() const { return m_ipv; }
4038
inline uint32_t ttl() const { return m_ttl * 1000U; }
4139

40+
int ai_family() const;
4241
rapidjson::Value toJSON(rapidjson::Document &doc) const;
4342

44-
4543
private:
46-
bool m_ipv6 = false;
47-
uint32_t m_ttl = 30U;
44+
uint32_t m_ttl = 30U;
45+
uint32_t m_ipv = 0U;
4846
};
4947

5048

51-
} /* namespace xmrig */
52-
53-
54-
#endif /* XMRIG_DNSCONFIG_H */
49+
} // namespace xmrig

src/base/net/dns/DnsRecord.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* XMRig
2-
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
3-
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
2+
* Copyright (c) 2018-2025 SChernykh <https://github.com/SChernykh>
3+
* Copyright (c) 2016-2025 XMRig <https://github.com/xmrig>, <support@xmrig.com>
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -16,19 +16,16 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
2019
#include <uv.h>
2120

22-
2321
#include "base/net/dns/DnsRecord.h"
2422

2523

26-
xmrig::DnsRecord::DnsRecord(const addrinfo *addr) :
27-
m_type(addr->ai_family == AF_INET6 ? AAAA : (addr->ai_family == AF_INET ? A : Unknown))
24+
xmrig::DnsRecord::DnsRecord(const addrinfo *addr)
2825
{
2926
static_assert(sizeof(m_data) >= sizeof(sockaddr_in6), "Not enough storage for IPv6 address.");
3027

31-
memcpy(m_data, addr->ai_addr, m_type == AAAA ? sizeof(sockaddr_in6) : sizeof(sockaddr_in));
28+
memcpy(m_data, addr->ai_addr, addr->ai_family == AF_INET6 ? sizeof(sockaddr_in6) : sizeof(sockaddr_in));
3229
}
3330

3431

@@ -44,7 +41,7 @@ xmrig::String xmrig::DnsRecord::ip() const
4441
{
4542
char *buf = nullptr;
4643

47-
if (m_type == AAAA) {
44+
if (reinterpret_cast<const sockaddr &>(m_data).sa_family == AF_INET6) {
4845
buf = new char[45]();
4946
uv_ip6_name(reinterpret_cast<const sockaddr_in6*>(m_data), buf, 45);
5047
}

0 commit comments

Comments
 (0)