
* can build without microhttpd when WITH_HTTPD=OFF * #341 Fix wrong exit code. * +15% boost with non-AES CPU Performance boost validated on Core 2 Quad processor under Windows 10. But it's Windows/MS Visual C++ specific. * #341 Added option --dry-run. * Remove compilation warnings under MSVC * up to 20% perf increase with Cryptonight with non-AES CPU This time, the performance increase is got with MSVC and GCC. On non-AES CPU, there were an useless load/store SSE2 register. The last MSVC "hack" is replaced by a portable code and he's more complete (a load is saved). On my C2Q6600, with 3 thread, I have +16% with MSVC2015 and +20% with GCC 7.3, compared to official 2.4.4 version. * Compilation error under FreeBSD ULONG is not recognized under this OS, so replaced it with more portable definition. * Update README.md * Update README.md * Update README.md * Correct L2 cache size calculation for Intel Core 2 family This is a workaround for total L2 cache size calculation of Intel Core Solo, Core Duo, Core 2 Duo, Core 2 Quad and their Xeon homologue. These processors have L2 cache shared by 2 cores. There is maybe more CPU with L2 shared cache, but I am sure that these models are concerned and they are not so numerous. A better way would be to modify libcpuid to implement L2 cache counting. * Fix code style, replace tabs to space. * Fix code style, replace tabs to space #2. * Update README.md * Update CHANGELOG.md * Update README.md * Update README.md * v2.4.5 RC * Update CHANGELOG.md * Run internal http server in main loop to avoid requirement to thread synchronization. * Added XMRIG_DEPS cmake variable for unified dependencies. * Use adaptive timer instead of idle handler for HTTP server. * Changes for the Monero v1 PoW * #428 Fixed regression with CPU cache size detection. * Fixed regression (all versions since 2.4 affected) fragmented responses from pool/proxy parsed incorrectly. * Update copyright and move version into Job class. * PoW changes WIP * Added reference hashes. * Added full IPv6 support. * Added option to disable Monero v7 PoW, may useful in future if other coins update their network to v7 without PoW change. * Automatically enable nicehash when use with upcoming xmrig-proxy 2.5. * Added coin field support added in xmrig-proxy 2.5. * Update CHANGELOG.md * Update CHANGELOG.md * Revert changes in Api class, single threaded http server will not be included in 2.5 release. * v2.5.0-dev * Change donation address to separate old and new versions. * Some small fixes. * Better v1 PoW implementation, added variant option. * Added test hashes for AEON. * Change port for AEON donate. * Add -DBUILD_STATIC=ON for static builds See #238 * Simplify variant selection. * #438 Fixed memory release. * Fix for previous commit. * Fix FindUV.cmake and FindMHD.cmake. * Fixes for 32 bit gcc builds. * Remove align.h. * Fix. * Fix FindMHD.cmake * Fix macOS compile. * v2.5.0 * Update README.md * Update README.md
136 lines
4.5 KiB
C++
136 lines
4.5 KiB
C++
/* XMRig
|
|
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
|
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
|
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
*
|
|
* 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
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef __CLIENT_H__
|
|
#define __CLIENT_H__
|
|
|
|
|
|
#include <map>
|
|
#include <uv.h>
|
|
#include <vector>
|
|
|
|
|
|
#include "net/Id.h"
|
|
#include "net/Job.h"
|
|
#include "net/SubmitResult.h"
|
|
#include "net/Url.h"
|
|
#include "rapidjson/fwd.h"
|
|
|
|
|
|
class IClientListener;
|
|
class JobResult;
|
|
|
|
|
|
class Client
|
|
{
|
|
public:
|
|
enum SocketState {
|
|
UnconnectedState,
|
|
HostLookupState,
|
|
ConnectingState,
|
|
ConnectedState,
|
|
ClosingState
|
|
};
|
|
|
|
constexpr static int kResponseTimeout = 20 * 1000;
|
|
constexpr static int kKeepAliveTimeout = 60 * 1000;
|
|
|
|
Client(int id, const char *agent, IClientListener *listener);
|
|
~Client();
|
|
|
|
bool disconnect();
|
|
int64_t submit(const JobResult &result);
|
|
void connect();
|
|
void connect(const Url *url);
|
|
void setUrl(const Url *url);
|
|
void tick(uint64_t now);
|
|
|
|
inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; }
|
|
inline const char *host() const { return m_url.host(); }
|
|
inline const char *ip() const { return m_ip; }
|
|
inline const Job &job() const { return m_job; }
|
|
inline int id() const { return m_id; }
|
|
inline SocketState state() const { return m_state; }
|
|
inline uint16_t port() const { return m_url.port(); }
|
|
inline void setQuiet(bool quiet) { m_quiet = quiet; }
|
|
inline void setRetryPause(int ms) { m_retryPause = ms; }
|
|
|
|
private:
|
|
bool close();
|
|
bool isCriticalError(const char *message);
|
|
bool parseJob(const rapidjson::Value ¶ms, int *code);
|
|
bool parseLogin(const rapidjson::Value &result, int *code);
|
|
int resolve(const char *host);
|
|
int64_t send(size_t size);
|
|
void connect(const std::vector<addrinfo*> &ipv4, const std::vector<addrinfo*> &ipv6);
|
|
void connect(sockaddr *addr);
|
|
void login();
|
|
void parse(char *line, size_t len);
|
|
void parseExtensions(const rapidjson::Value &value);
|
|
void parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error);
|
|
void parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error);
|
|
void ping();
|
|
void reconnect();
|
|
void setState(SocketState state);
|
|
void startTimeout();
|
|
|
|
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
|
|
static void onClose(uv_handle_t *handle);
|
|
static void onConnect(uv_connect_t *req, int status);
|
|
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
|
|
static void onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res);
|
|
|
|
static inline Client *getClient(void *data) { return static_cast<Client*>(data); }
|
|
|
|
addrinfo m_hints;
|
|
bool m_ipv6;
|
|
bool m_nicehash;
|
|
bool m_quiet;
|
|
char m_buf[2048];
|
|
char m_ip[46];
|
|
char m_sendBuf[768];
|
|
const char *m_agent;
|
|
IClientListener *m_listener;
|
|
int m_id;
|
|
int m_retryPause;
|
|
int64_t m_failures;
|
|
Job m_job;
|
|
size_t m_recvBufPos;
|
|
SocketState m_state;
|
|
static int64_t m_sequence;
|
|
std::map<int64_t, SubmitResult> m_results;
|
|
uint64_t m_expire;
|
|
Url m_url;
|
|
uv_buf_t m_recvBuf;
|
|
uv_getaddrinfo_t m_resolver;
|
|
uv_stream_t *m_stream;
|
|
uv_tcp_t *m_socket;
|
|
xmrig::Id m_rpcId;
|
|
|
|
# ifndef XMRIG_PROXY_PROJECT
|
|
uv_timer_t m_keepAliveTimer;
|
|
# endif
|
|
};
|
|
|
|
|
|
#endif /* __CLIENT_H__ */
|