Implement job result submitting.
This commit is contained in:
parent
a0a8711dab
commit
6774f86fcd
8 changed files with 92 additions and 6 deletions
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue