mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-09 20:39:27 +00:00
Implement job result submitting.
This commit is contained in:
parent
a0a8711dab
commit
6774f86fcd
8 changed files with 92 additions and 6 deletions
|
@ -9,6 +9,7 @@ set(HEADERS
|
|||
src/Console.h
|
||||
src/Cpu.h
|
||||
src/interfaces/IClientListener.h
|
||||
src/interfaces/IJobResultListener.h
|
||||
src/interfaces/IWorker.h
|
||||
src/Mem.h
|
||||
src/net/Client.h
|
||||
|
|
41
src/interfaces/IJobResultListener.h
Normal file
41
src/interfaces/IJobResultListener.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* 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 2016-2017 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 __IJOBRESULTLISTENER_H__
|
||||
#define __IJOBRESULTLISTENER_H__
|
||||
|
||||
|
||||
class Client;
|
||||
class JobResult;
|
||||
|
||||
|
||||
class IJobResultListener
|
||||
{
|
||||
public:
|
||||
virtual ~IJobResultListener() {}
|
||||
|
||||
virtual void onJobResult(const JobResult &result) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // __IJOBRESULTLISTENER_H__
|
|
@ -28,6 +28,7 @@
|
|||
#include "Console.h"
|
||||
#include "interfaces/IClientListener.h"
|
||||
#include "net/Client.h"
|
||||
#include "net/JobResult.h"
|
||||
#include "net/Url.h"
|
||||
|
||||
|
||||
|
@ -148,6 +149,25 @@ void Client::setUrl(const Url *url)
|
|||
}
|
||||
|
||||
|
||||
void Client::submit(const JobResult &result)
|
||||
{
|
||||
char *req = static_cast<char*>(malloc(345));
|
||||
char nonce[9];
|
||||
char data[65];
|
||||
|
||||
Job::toHex(reinterpret_cast<const unsigned char*>(&result.nonce), 4, nonce);
|
||||
nonce[8] = '\0';
|
||||
|
||||
Job::toHex(result.result, 32, data);
|
||||
data[64] = '\0';
|
||||
|
||||
snprintf(req, 345, "{\"id\":%llu,\"jsonrpc\":\"2.0\",\"method\":\"submit\",\"params\":{\"id\":\"%s\",\"job_id\":\"%s\",\"nonce\":\"%s\",\"result\":\"%s\"}}\n",
|
||||
m_sequence, m_rpcId, result.jobId, nonce, data);
|
||||
|
||||
send(req);
|
||||
}
|
||||
|
||||
|
||||
bool Client::parseJob(const json_t *params, int *code)
|
||||
{
|
||||
if (!json_is_object(params)) {
|
||||
|
|
|
@ -32,8 +32,9 @@
|
|||
#include "net/Job.h"
|
||||
|
||||
|
||||
class Url;
|
||||
class IClientListener;
|
||||
class JobResult;
|
||||
class Url;
|
||||
|
||||
|
||||
class Client
|
||||
|
@ -59,6 +60,7 @@ public:
|
|||
void login(const char *user, const char *pass, const char *agent);
|
||||
void send(char *data);
|
||||
void setUrl(const Url *url);
|
||||
void submit(const JobResult &result);
|
||||
|
||||
inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; }
|
||||
inline const char *host() const { return m_host; }
|
||||
|
|
|
@ -39,6 +39,8 @@ Network::Network(const Options *options) :
|
|||
m_pool(0),
|
||||
m_diff(0)
|
||||
{
|
||||
Workers::setListener(this);
|
||||
|
||||
m_pools.reserve(2);
|
||||
m_agent = userAgent();
|
||||
|
||||
|
@ -103,6 +105,13 @@ void Network::onJobReceived(Client *client, const Job &job)
|
|||
}
|
||||
|
||||
|
||||
void Network::onJobResult(const JobResult &result)
|
||||
{
|
||||
LOG_NOTICE("SHARE FOUND");
|
||||
m_pools[result.poolId]->submit(result);
|
||||
}
|
||||
|
||||
|
||||
void Network::onLoginCredentialsRequired(Client *client)
|
||||
{
|
||||
client->login(m_options->user(), m_options->pass(), m_agent);
|
||||
|
|
|
@ -30,13 +30,14 @@
|
|||
|
||||
|
||||
#include "interfaces/IClientListener.h"
|
||||
#include "interfaces/IJobResultListener.h"
|
||||
|
||||
|
||||
class Options;
|
||||
class Url;
|
||||
|
||||
|
||||
class Network : public IClientListener
|
||||
class Network : public IClientListener, public IJobResultListener
|
||||
{
|
||||
public:
|
||||
Network(const Options *options);
|
||||
|
@ -49,6 +50,7 @@ public:
|
|||
protected:
|
||||
void onClose(Client *client, int failures) override;
|
||||
void onJobReceived(Client *client, const Job &job) override;
|
||||
void onJobResult(const JobResult &result);
|
||||
void onLoginCredentialsRequired(Client *client) override;
|
||||
void onLoginSuccess(Client *client) override;
|
||||
|
||||
|
|
|
@ -21,11 +21,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "interfaces/IJobResultListener.h"
|
||||
#include "workers/Handle.h"
|
||||
#include "workers/SingleWorker.h"
|
||||
#include "workers/Workers.h"
|
||||
|
||||
|
||||
IJobResultListener *Workers::m_listener = nullptr;
|
||||
Job Workers::m_job;
|
||||
pthread_mutex_t Workers::m_mutex;
|
||||
pthread_rwlock_t Workers::m_rwlock;
|
||||
|
@ -107,4 +109,10 @@ void Workers::onResult(uv_async_t *handle)
|
|||
m_queue.pop_front();
|
||||
}
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
|
||||
for (auto result : results) {
|
||||
m_listener->onJobResult(result);
|
||||
}
|
||||
|
||||
results.clear();
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
|
||||
class Handle;
|
||||
class IJobResultListener;
|
||||
|
||||
|
||||
class Workers
|
||||
|
@ -46,15 +47,17 @@ public:
|
|||
static void start(int threads, int64_t affinity, bool nicehash);
|
||||
static void submit(const JobResult &result);
|
||||
|
||||
static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; }
|
||||
static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed) == 1; }
|
||||
static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); }
|
||||
static inline void pause() { m_paused = 1; }
|
||||
static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; }
|
||||
static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed) == 1; }
|
||||
static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); }
|
||||
static inline void pause() { m_paused = 1; }
|
||||
static inline void setListener(IJobResultListener *listener) { m_listener = listener; }
|
||||
|
||||
private:
|
||||
static void *onReady(void *arg);
|
||||
static void onResult(uv_async_t *handle);
|
||||
|
||||
static IJobResultListener *m_listener;
|
||||
static Job m_job;
|
||||
static pthread_mutex_t m_mutex;
|
||||
static pthread_rwlock_t m_rwlock;
|
||||
|
|
Loading…
Reference in a new issue