Skip to content

Commit 36ef254

Browse files
committed
Rename class Url to Pool.
1 parent ad7545d commit 36ef254

18 files changed

+136
-126
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ set(HEADERS
4545
src/net/Job.h
4646
src/net/JobResult.h
4747
src/net/Network.h
48+
src/net/Pool.h
4849
src/net/Storage.h
4950
src/net/strategies/DonateStrategy.h
5051
src/net/strategies/FailoverStrategy.h
5152
src/net/strategies/SinglePoolStrategy.h
5253
src/net/SubmitResult.h
53-
src/net/Url.h
5454
src/Platform.h
5555
src/Summary.h
5656
src/version.h
@@ -102,11 +102,11 @@ set(SOURCES
102102
src/net/Client.cpp
103103
src/net/Job.cpp
104104
src/net/Network.cpp
105+
src/net/Pool.cpp
105106
src/net/strategies/DonateStrategy.cpp
106107
src/net/strategies/FailoverStrategy.cpp
107108
src/net/strategies/SinglePoolStrategy.cpp
108109
src/net/SubmitResult.cpp
109-
src/net/Url.cpp
110110
src/Platform.cpp
111111
src/Summary.cpp
112112
src/workers/CpuThread.cpp

src/Summary.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "Cpu.h"
3333
#include "log/Log.h"
3434
#include "Mem.h"
35-
#include "net/Url.h"
35+
#include "net/Pool.h"
3636
#include "Summary.h"
3737
#include "version.h"
3838

@@ -112,13 +112,13 @@ static void print_threads(xmrig::Config *config)
112112

113113
static void print_pools(xmrig::Config *config)
114114
{
115-
const std::vector<Url*> &pools = config->pools();
115+
const std::vector<Pool> &pools = config->pools();
116116

117117
for (size_t i = 0; i < pools.size(); ++i) {
118-
Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mPOOL #%d: \x1B[01;36m%s:%d" : " * POOL #%d: %s:%d",
118+
Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mPOOL #%d: \x1B[01;36m%s" : " * POOL #%d: %s",
119119
i + 1,
120-
pools[i]->host(),
121-
pools[i]->port());
120+
pools[i].url()
121+
);
122122
}
123123

124124
# ifdef APP_DEBUG

src/core/CommonConfig.cpp

+19-26
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "core/CommonConfig.h"
3333
#include "donate.h"
3434
#include "log/Log.h"
35-
#include "net/Url.h"
35+
#include "net/Pool.h"
3636
#include "rapidjson/document.h"
3737
#include "rapidjson/filewritestream.h"
3838
#include "rapidjson/prettywriter.h"
@@ -79,7 +79,7 @@ xmrig::CommonConfig::CommonConfig() :
7979
m_retries(5),
8080
m_retryPause(5)
8181
{
82-
m_pools.push_back(new Url());
82+
m_pools.push_back(Pool());
8383

8484
# ifdef XMRIG_PROXY_PROJECT
8585
m_retries = 2;
@@ -90,11 +90,6 @@ xmrig::CommonConfig::CommonConfig() :
9090

9191
xmrig::CommonConfig::~CommonConfig()
9292
{
93-
for (Url *url : m_pools) {
94-
delete url;
95-
}
96-
97-
m_pools.clear();
9893
}
9994

10095

@@ -112,8 +107,8 @@ bool xmrig::CommonConfig::adjust()
112107

113108
m_adjusted = true;
114109

115-
for (Url *url : m_pools) {
116-
url->adjust(algorithm());
110+
for (Pool &pool : m_pools) {
111+
pool.adjust(algorithm());
117112
}
118113

119114
return true;
@@ -122,7 +117,7 @@ bool xmrig::CommonConfig::adjust()
122117

123118
bool xmrig::CommonConfig::isValid() const
124119
{
125-
return m_pools[0]->isValid();
120+
return m_pools[0].isValid();
126121
}
127122

128123

@@ -138,12 +133,12 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable)
138133
break;
139134

140135
case KeepAliveKey: /* --keepalive */
141-
m_pools.back()->setKeepAlive(enable ? Url::kKeepAliveTimeout : 0);
136+
m_pools.back().setKeepAlive(enable ? Pool::kKeepAliveTimeout : 0);
142137
break;
143138

144139
# ifndef XMRIG_PROXY_PROJECT
145140
case NicehashKey: /* --nicehash */
146-
m_pools.back()->setNicehash(enable);
141+
m_pools.back().setNicehash(enable);
147142
break;
148143
# endif
149144

@@ -177,38 +172,36 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg)
177172
break;
178173

179174
case UserpassKey: /* --userpass */
180-
if (!m_pools.back()->setUserpass(arg)) {
175+
if (!m_pools.back().setUserpass(arg)) {
181176
return false;
182177
}
183178

184179
break;
185180

186181
case UrlKey: /* --url */
187-
if (m_pools.size() > 1 || m_pools[0]->isValid()) {
188-
Url *url = new Url(arg);
189-
if (url->isValid()) {
190-
m_pools.push_back(url);
191-
}
192-
else {
193-
delete url;
182+
if (m_pools.size() > 1 || m_pools[0].isValid()) {
183+
Pool pool(arg);
184+
185+
if (pool.isValid()) {
186+
m_pools.push_back(std::move(pool));
194187
}
195188
}
196189
else {
197-
m_pools[0]->parse(arg);
190+
m_pools[0].parse(arg);
198191
}
199192

200-
if (!m_pools.back()->isValid()) {
193+
if (!m_pools.back().isValid()) {
201194
return false;
202195
}
203196

204197
break;
205198

206199
case UserKey: /* --user */
207-
m_pools.back()->setUser(arg);
200+
m_pools.back().setUser(arg);
208201
break;
209202

210203
case PasswordKey: /* --pass */
211-
m_pools.back()->setPassword(arg);
204+
m_pools.back().setPassword(arg);
212205
break;
213206

214207
case LogFileKey: /* --log-file */
@@ -325,11 +318,11 @@ bool xmrig::CommonConfig::parseInt(int key, int arg)
325318
break;
326319

327320
case KeepAliveKey: /* --keepalive */
328-
m_pools.back()->setKeepAlive(arg);
321+
m_pools.back().setKeepAlive(arg);
329322
break;
330323

331324
case VariantKey: /* --variant */
332-
m_pools.back()->setVariant(arg);
325+
m_pools.back().setVariant(arg);
333326
break;
334327

335328
case DonateLevelKey: /* --donate-level */

src/core/CommonConfig.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
#include "core/utils/c_str.h"
3232
#include "interfaces/IConfig.h"
3333
#include "xmrig.h"
34-
35-
36-
class Url;
34+
#include "net/Pool.h"
3735

3836

3937
namespace xmrig {
@@ -58,7 +56,7 @@ class CommonConfig : public IConfig
5856
inline const char *apiWorkerId() const { return m_apiWorkerId.data(); }
5957
inline const char *logFile() const { return m_logFile.data(); }
6058
inline const char *userAgent() const { return m_userAgent.data(); }
61-
inline const std::vector<Url*> &pools() const { return m_pools; }
59+
inline const std::vector<Pool> &pools() const { return m_pools; }
6260
inline int apiPort() const { return m_apiPort; }
6361
inline int donateLevel() const { return m_donateLevel; }
6462
inline int printTime() const { return m_printTime; }
@@ -91,7 +89,7 @@ class CommonConfig : public IConfig
9189
int m_printTime;
9290
int m_retries;
9391
int m_retryPause;
94-
std::vector<Url*> m_pools;
92+
std::vector<Pool> m_pools;
9593
xmrig::c_str m_apiToken;
9694
xmrig::c_str m_apiWorkerId;
9795
xmrig::c_str m_fileName;

src/core/Config.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "core/ConfigCreator.h"
3131
#include "core/ConfigLoader.h"
3232
#include "Cpu.h"
33-
#include "net/Url.h"
33+
#include "net/Pool.h"
3434
#include "rapidjson/document.h"
3535
#include "rapidjson/filewritestream.h"
3636
#include "rapidjson/prettywriter.h"
@@ -110,22 +110,22 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
110110

111111
rapidjson::Value pools(rapidjson::kArrayType);
112112

113-
for (const Url *url : m_pools) {
113+
for (const Pool &pool : m_pools) {
114114
rapidjson::Value obj(rapidjson::kObjectType);
115115

116-
obj.AddMember("url", rapidjson::StringRef(url->url()), allocator);
117-
obj.AddMember("user", rapidjson::StringRef(url->user()), allocator);
118-
obj.AddMember("pass", rapidjson::StringRef(url->password()), allocator);
116+
obj.AddMember("url", rapidjson::StringRef(pool.url()), allocator);
117+
obj.AddMember("user", rapidjson::StringRef(pool.user()), allocator);
118+
obj.AddMember("pass", rapidjson::StringRef(pool.password()), allocator);
119119

120-
if (url->keepAlive() == 0 || url->keepAlive() == Url::kKeepAliveTimeout) {
121-
obj.AddMember("keepalive", url->keepAlive() > 0, allocator);
120+
if (pool.keepAlive() == 0 || pool.keepAlive() == Pool::kKeepAliveTimeout) {
121+
obj.AddMember("keepalive", pool.keepAlive() > 0, allocator);
122122
}
123123
else {
124-
obj.AddMember("keepalive", url->keepAlive(), allocator);
124+
obj.AddMember("keepalive", pool.keepAlive(), allocator);
125125
}
126126

127-
obj.AddMember("nicehash", url->isNicehash(), allocator);
128-
obj.AddMember("variant", url->variant(), allocator);
127+
obj.AddMember("nicehash", pool.isNicehash(), allocator);
128+
obj.AddMember("variant", pool.variant(), allocator);
129129

130130
pools.PushBack(obj, allocator);
131131
}

src/core/ConfigLoader.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include "core/ConfigWatcher.h"
3939
#include "interfaces/IConfig.h"
4040
#include "interfaces/IWatcherListener.h"
41-
#include "net/Url.h"
41+
#include "net/Pool.h"
4242
#include "Platform.h"
4343
#include "rapidjson/document.h"
4444
#include "rapidjson/error/en.h"

src/core/utils/c_str.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ namespace xmrig {
4343
class c_str
4444
{
4545
public:
46-
inline c_str() : m_data(nullptr) {}
47-
inline c_str(const char *str) : m_data(nullptr) { set(str); }
48-
inline ~c_str() { free(m_data); }
46+
inline c_str() : m_data(nullptr) {}
47+
inline c_str(c_str &&other) { m_data = other.m_data; other.m_data = nullptr; }
48+
inline c_str(const c_str &other) : m_data(nullptr) { set(other.data()); }
49+
inline c_str(const char *str) : m_data(nullptr) { set(str); }
50+
inline ~c_str() { free(m_data); }
4951

5052

5153
inline void set(const char *str)

0 commit comments

Comments
 (0)