Merge branch 'dev' into feature-opencl
This commit is contained in:
commit
71329718e4
23 changed files with 536 additions and 339 deletions
|
@ -91,6 +91,10 @@ public:
|
|||
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
if (Log::background && m_backends.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
timestamp(level, size, offset);
|
||||
color(level, size);
|
||||
|
||||
|
@ -111,7 +115,7 @@ public:
|
|||
if (!m_backends.empty()) {
|
||||
for (ILogBackend *backend : m_backends) {
|
||||
backend->print(level, m_buf, offset, size, true);
|
||||
backend->print(level, txt.c_str(), offset, txt.size(), false);
|
||||
backend->print(level, txt.c_str(), offset ? (offset - 11) : 0, txt.size(), false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -190,8 +194,9 @@ private:
|
|||
};
|
||||
|
||||
|
||||
bool Log::colors = true;
|
||||
LogPrivate *Log::d = new LogPrivate();
|
||||
bool Log::background = false;
|
||||
bool Log::colors = true;
|
||||
LogPrivate *Log::d = new LogPrivate();
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
static void print(const char *fmt, ...);
|
||||
static void print(Level level, const char *fmt, ...);
|
||||
|
||||
static bool background;
|
||||
static bool colors;
|
||||
|
||||
private:
|
||||
|
|
|
@ -37,7 +37,7 @@ class SysLog : public ILogBackend
|
|||
{
|
||||
public:
|
||||
SysLog();
|
||||
~SysLog();
|
||||
~SysLog() override;
|
||||
|
||||
protected:
|
||||
void print(int level, const char *line, size_t offset, size_t size, bool colors) override;
|
||||
|
|
|
@ -184,7 +184,10 @@ int xmrig::Base::init()
|
|||
Platform::setProcessPriority(config()->cpu().priority());
|
||||
# endif
|
||||
|
||||
if (!config()->isBackground()) {
|
||||
if (config()->isBackground()) {
|
||||
Log::background = true;
|
||||
}
|
||||
else {
|
||||
Log::add(new ConsoleLog());
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,8 @@ xmrig::BaseClient::BaseClient(int id, IClientListener *listener) :
|
|||
m_retries(5),
|
||||
m_failures(0),
|
||||
m_state(UnconnectedState),
|
||||
m_retryPause(5000)
|
||||
m_retryPause(5000),
|
||||
m_enabled(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,8 @@ protected:
|
|||
HostLookupState,
|
||||
ConnectingState,
|
||||
ConnectedState,
|
||||
ClosingState
|
||||
ClosingState,
|
||||
ReconnectingState
|
||||
};
|
||||
|
||||
inline bool isQuiet() const { return m_quiet || m_failures >= m_retries; }
|
||||
|
|
|
@ -70,21 +70,15 @@ static const char *states[] = {
|
|||
"host-lookup",
|
||||
"connecting",
|
||||
"connected",
|
||||
"closing"
|
||||
"closing",
|
||||
"reconnecting"
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
xmrig::Client::Client(int id, const char *agent, IClientListener *listener) :
|
||||
BaseClient(id, listener),
|
||||
m_agent(agent),
|
||||
m_tls(nullptr),
|
||||
m_expire(0),
|
||||
m_jobs(0),
|
||||
m_keepAlive(0),
|
||||
m_key(0),
|
||||
m_stream(nullptr),
|
||||
m_socket(nullptr)
|
||||
m_agent(agent)
|
||||
{
|
||||
m_key = m_storage.add(this);
|
||||
m_dns = new Dns(this);
|
||||
|
@ -234,10 +228,16 @@ void xmrig::Client::tick(uint64_t now)
|
|||
else if (m_keepAlive && now > m_keepAlive) {
|
||||
ping();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_expire && now > m_expire && m_state == ConnectingState) {
|
||||
connect();
|
||||
if (m_state == ReconnectingState && m_expire && now > m_expire) {
|
||||
return connect();
|
||||
}
|
||||
|
||||
if (m_state == ConnectingState && m_expire && now > m_expire) {
|
||||
return reconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -447,7 +447,6 @@ int xmrig::Client::resolve(const String &host)
|
|||
{
|
||||
setState(HostLookupState);
|
||||
|
||||
m_expire = 0;
|
||||
m_recvBuf.reset();
|
||||
|
||||
if (m_failures == -1) {
|
||||
|
@ -754,6 +753,8 @@ void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, co
|
|||
void xmrig::Client::ping()
|
||||
{
|
||||
send(snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data()));
|
||||
|
||||
m_keepAlive = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -810,12 +811,10 @@ void xmrig::Client::reconnect()
|
|||
return m_listener->onClose(this, -1);
|
||||
}
|
||||
|
||||
setState(ConnectingState);
|
||||
setState(ReconnectingState);
|
||||
|
||||
m_failures++;
|
||||
m_listener->onClose(this, static_cast<int>(m_failures));
|
||||
|
||||
m_expire = Chrono::steadyMSecs() + m_retryPause;
|
||||
}
|
||||
|
||||
|
||||
|
@ -827,6 +826,23 @@ void xmrig::Client::setState(SocketState state)
|
|||
return;
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case HostLookupState:
|
||||
m_expire = 0;
|
||||
break;
|
||||
|
||||
case ConnectingState:
|
||||
m_expire = Chrono::steadyMSecs() + kConnectTimeout;
|
||||
break;
|
||||
|
||||
case ReconnectingState:
|
||||
m_expire = Chrono::steadyMSecs() + m_retryPause;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
m_state = state;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,12 +56,13 @@ class JobResult;
|
|||
class Client : public BaseClient, public IDnsListener, public ILineListener
|
||||
{
|
||||
public:
|
||||
constexpr static int kResponseTimeout = 20 * 1000;
|
||||
constexpr static uint64_t kConnectTimeout = 20 * 1000;
|
||||
constexpr static uint64_t kResponseTimeout = 20 * 1000;
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
constexpr static int kInputBufferSize = 1024 * 16;
|
||||
constexpr static size_t kInputBufferSize = 1024 * 16;
|
||||
# else
|
||||
constexpr static int kInputBufferSize = 1024 * 2;
|
||||
constexpr static size_t kInputBufferSize = 1024 * 2;
|
||||
# endif
|
||||
|
||||
Client(int id, const char *agent, IClientListener *listener);
|
||||
|
@ -122,19 +123,19 @@ private:
|
|||
|
||||
static inline Client *getClient(void *data) { return m_storage.get(data); }
|
||||
|
||||
char m_sendBuf[2048];
|
||||
char m_sendBuf[2048] = { 0 };
|
||||
const char *m_agent;
|
||||
Dns *m_dns;
|
||||
RecvBuf<kInputBufferSize> m_recvBuf;
|
||||
std::bitset<EXT_MAX> m_extensions;
|
||||
String m_rpcId;
|
||||
Tls *m_tls;
|
||||
uint64_t m_expire;
|
||||
uint64_t m_jobs;
|
||||
uint64_t m_keepAlive;
|
||||
uintptr_t m_key;
|
||||
uv_stream_t *m_stream;
|
||||
uv_tcp_t *m_socket;
|
||||
Tls *m_tls = nullptr;
|
||||
uint64_t m_expire = 0;
|
||||
uint64_t m_jobs = 0;
|
||||
uint64_t m_keepAlive = 0;
|
||||
uintptr_t m_key = 0;
|
||||
uv_stream_t *m_stream = nullptr;
|
||||
uv_tcp_t *m_socket = nullptr;
|
||||
|
||||
static Storage<Client> m_storage;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue