Background http changes from proxy.

This commit is contained in:
XMRig 2018-03-27 14:01:38 +07:00
parent f1bc06473f
commit 9fe863b5d7
17 changed files with 929 additions and 125 deletions

View file

@ -4,8 +4,8 @@
* 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>
*
* 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
@ -25,17 +25,17 @@
#include "api/Api.h"
#include "api/ApiState.h"
#include "api/ApiRouter.h"
#include "api/HttpReply.h"
#include "api/HttpRequest.h"
ApiState *Api::m_state = nullptr;
uv_mutex_t Api::m_mutex;
ApiRouter *Api::m_router = nullptr;
bool Api::start()
bool Api::start(xmrig::Controller *controller)
{
uv_mutex_init(&m_mutex);
m_state = new ApiState();
m_router = new ApiRouter(controller);
return true;
}
@ -43,43 +43,40 @@ bool Api::start()
void Api::release()
{
delete m_state;
delete m_router;
}
char *Api::get(const char *url, int *status)
void Api::exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply)
{
if (!m_state) {
return nullptr;
if (!m_router) {
reply.status = 500;
return;
}
uv_mutex_lock(&m_mutex);
char *buf = m_state->get(url, status);
uv_mutex_unlock(&m_mutex);
if (req.method() == xmrig::HttpRequest::Get) {
return m_router->get(req, reply);
}
return buf;
m_router->exec(req, reply);
}
void Api::tick(const Hashrate *hashrate)
{
if (!m_state) {
if (!m_router) {
return;
}
uv_mutex_lock(&m_mutex);
m_state->tick(hashrate);
uv_mutex_unlock(&m_mutex);
m_router->tick(hashrate);
}
void Api::tick(const NetworkState &network)
{
if (!m_state) {
if (!m_router) {
return;
}
uv_mutex_lock(&m_mutex);
m_state->tick(network);
uv_mutex_unlock(&m_mutex);
m_router->tick(network);
}