mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-22 10:45:06 +00:00
Job flow.
This commit is contained in:
parent
f9c244f0aa
commit
bcef4b12ec
7 changed files with 45 additions and 8 deletions
|
@ -22,6 +22,9 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
||||
#include "Console.h"
|
||||
#include "interfaces/IClientListener.h"
|
||||
#include "net/Client.h"
|
||||
|
@ -168,7 +171,8 @@ bool Client::parseJob(const json_t *params, int *code)
|
|||
return false;
|
||||
}
|
||||
|
||||
m_job = job;
|
||||
job.setPoolId(m_id);
|
||||
m_job = std::move(job);
|
||||
|
||||
LOG_DEBUG("[%s:%u] job: \"%s\", diff: %lld", m_host, m_port, job.id(), job.diff());
|
||||
return true;
|
||||
|
|
|
@ -60,7 +60,9 @@ public:
|
|||
void send(char *data);
|
||||
void setUrl(const Url *url);
|
||||
|
||||
inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; }
|
||||
inline const char *host() const { return m_host; }
|
||||
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_port; }
|
||||
|
|
|
@ -57,7 +57,8 @@ static inline char hf_bin2hex(unsigned char c)
|
|||
}
|
||||
|
||||
|
||||
Job::Job() :
|
||||
Job::Job(int poolId) :
|
||||
m_poolId(poolId),
|
||||
m_size(0),
|
||||
m_diff(0),
|
||||
m_target(0)
|
||||
|
|
|
@ -31,22 +31,26 @@
|
|||
class Job
|
||||
{
|
||||
public:
|
||||
Job();
|
||||
Job(int poolId = -2);
|
||||
bool setBlob(const char *blob);
|
||||
bool setId(const char *id);
|
||||
bool setTarget(const char *target);
|
||||
|
||||
inline const uint8_t *blob() const { return m_blob; }
|
||||
inline bool isValid() const { return m_size > 0 && m_diff > 0; }
|
||||
inline const char *id() const { return m_id; }
|
||||
inline uint32_t size() const { return m_size; }
|
||||
inline const uint8_t *blob() const { return m_blob; }
|
||||
inline int poolId() const { return m_poolId; }
|
||||
inline uint32_t diff() const { return m_diff; }
|
||||
inline uint32_t size() const { return m_size; }
|
||||
inline uint64_t target() const { return m_target; }
|
||||
inline void setPoolId(int poolId) { m_poolId = poolId; }
|
||||
|
||||
static bool fromHex(const char* in, unsigned int len, unsigned char* out);
|
||||
static void toHex(const unsigned char* in, unsigned int len, char* out);
|
||||
inline static uint64_t toDiff(uint64_t target) { return 0xFFFFFFFFFFFFFFFFULL / target; }
|
||||
static inline uint64_t toDiff(uint64_t target) { return 0xFFFFFFFFFFFFFFFFULL / target; }
|
||||
|
||||
private:
|
||||
int m_poolId;
|
||||
char m_id[64] __attribute__((aligned(16)));
|
||||
uint8_t m_blob[84] __attribute__((aligned(16))); // Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk.
|
||||
uint32_t m_size;
|
||||
|
|
|
@ -35,7 +35,8 @@
|
|||
Network::Network(const Options *options) :
|
||||
m_donate(false),
|
||||
m_options(options),
|
||||
m_pool(0)
|
||||
m_pool(0),
|
||||
m_diff(0)
|
||||
{
|
||||
m_pools.reserve(2);
|
||||
m_agent = userAgent();
|
||||
|
@ -92,7 +93,11 @@ void Network::onClose(Client *client, int failures)
|
|||
|
||||
void Network::onJobReceived(Client *client, const Job &job)
|
||||
{
|
||||
if (m_donate && client->id() != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
setJob(client, job);
|
||||
}
|
||||
|
||||
|
||||
|
@ -138,6 +143,18 @@ void Network::addPool(const Url *url)
|
|||
}
|
||||
|
||||
|
||||
void Network::setJob(Client *client, const Job &job)
|
||||
{
|
||||
if (m_options->colors()){
|
||||
LOG_INFO("\x1B[01;33mnew job\x1B[0m from \"%s:%d\", diff: %d", client->host(), client->port(), job.diff());
|
||||
|
||||
}
|
||||
else {
|
||||
LOG_INFO("new job from \"%s:%d\", diff: %d", client->host(), client->port(), job.diff());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Network::startDonate()
|
||||
{
|
||||
if (m_donate) {
|
||||
|
@ -159,6 +176,14 @@ void Network::stopDonate()
|
|||
LOG_NOTICE("dev donate finished");
|
||||
|
||||
m_donate = false;
|
||||
if (!m_pool) {
|
||||
return;
|
||||
}
|
||||
|
||||
Client *client = m_pools[m_pool];
|
||||
if (client->isReady()) {
|
||||
setJob(client, client->job());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ protected:
|
|||
|
||||
private:
|
||||
void addPool(const Url *url);
|
||||
void setJob(Client *client, const Job &job);
|
||||
void startDonate();
|
||||
void stopDonate();
|
||||
|
||||
|
@ -64,6 +65,7 @@ private:
|
|||
const Options *m_options;
|
||||
int m_pool;
|
||||
std::vector<Client*> m_pools;
|
||||
uint64_t m_diff;
|
||||
uv_timer_t m_timer;
|
||||
};
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include "workers/SingleWorker.h"
|
||||
#include "workers/Workers.h"
|
||||
|
||||
|
||||
std::vector<Handle*> Workers::m_workers;
|
||||
uv_async_t Workers::m_async;
|
||||
|
||||
|
|
Loading…
Reference in a new issue