Added new HTTP server (tiny wrapper on top of libuv + http_parser), removed libmicrohttpd support.
This commit is contained in:
parent
725796a1ab
commit
01ad6bf2d9
29 changed files with 4312 additions and 237 deletions
|
@ -1,151 +0,0 @@
|
|||
/* 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 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <microhttpd.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#include "api/Api.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/tools/Handle.h"
|
||||
#include "base/tools/Timer.h"
|
||||
#include "common/api/Httpd.h"
|
||||
#include "common/api/HttpReply.h"
|
||||
#include "common/api/HttpRequest.h"
|
||||
|
||||
|
||||
xmrig::Httpd::Httpd(int port, const char *accessToken, bool IPv6, bool restricted) :
|
||||
m_idle(true),
|
||||
m_IPv6(IPv6),
|
||||
m_restricted(restricted),
|
||||
m_accessToken(accessToken ? strdup(accessToken) : nullptr),
|
||||
m_port(port),
|
||||
m_daemon(nullptr)
|
||||
{
|
||||
m_timer = new Timer(this);
|
||||
}
|
||||
|
||||
|
||||
xmrig::Httpd::~Httpd()
|
||||
{
|
||||
stop();
|
||||
|
||||
if (m_daemon) {
|
||||
MHD_stop_daemon(m_daemon);
|
||||
}
|
||||
|
||||
delete m_accessToken;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Httpd::start()
|
||||
{
|
||||
if (!m_port) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int flags = 0;
|
||||
# if MHD_VERSION >= 0x00093500
|
||||
if (m_IPv6 && MHD_is_feature_supported(MHD_FEATURE_IPv6)) {
|
||||
flags |= MHD_USE_DUAL_STACK;
|
||||
}
|
||||
|
||||
if (MHD_is_feature_supported(MHD_FEATURE_EPOLL)) {
|
||||
flags |= MHD_USE_EPOLL_LINUX_ONLY;
|
||||
}
|
||||
# endif
|
||||
|
||||
m_daemon = MHD_start_daemon(flags, m_port, nullptr, nullptr, &Httpd::handler, this, MHD_OPTION_END);
|
||||
if (!m_daemon) {
|
||||
LOG_ERR("HTTP Daemon failed to start.");
|
||||
return false;
|
||||
}
|
||||
|
||||
# if MHD_VERSION >= 0x00093900
|
||||
m_timer->start(kIdleInterval, kIdleInterval);
|
||||
# else
|
||||
m_timer->start(kActiveInterval, kActiveInterval);
|
||||
# endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Httpd::stop()
|
||||
{
|
||||
delete m_timer;
|
||||
m_timer = nullptr;
|
||||
}
|
||||
|
||||
|
||||
int xmrig::Httpd::process(HttpRequest &req)
|
||||
{
|
||||
xmrig::HttpReply reply;
|
||||
if (!req.process(m_accessToken, m_restricted, reply)) {
|
||||
return req.end(reply);
|
||||
}
|
||||
|
||||
if (!req.isFulfilled()) {
|
||||
return MHD_YES;
|
||||
}
|
||||
|
||||
Api::exec(req, reply);
|
||||
|
||||
return req.end(reply);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Httpd::run()
|
||||
{
|
||||
MHD_run(m_daemon);
|
||||
|
||||
# if MHD_VERSION >= 0x00093900
|
||||
const MHD_DaemonInfo *info = MHD_get_daemon_info(m_daemon, MHD_DAEMON_INFO_CURRENT_CONNECTIONS);
|
||||
if (m_idle && info->num_connections) {
|
||||
m_timer->setRepeat(kActiveInterval);
|
||||
m_idle = false;
|
||||
}
|
||||
else if (!m_idle && !info->num_connections) {
|
||||
m_timer->setRepeat(kIdleInterval);
|
||||
m_idle = true;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
int xmrig::Httpd::handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *, const char *uploadData, size_t *uploadSize, void **con_cls)
|
||||
{
|
||||
HttpRequest req(connection, url, method, uploadData, uploadSize, con_cls);
|
||||
|
||||
if (req.method() == xmrig::HttpRequest::Options) {
|
||||
return req.end(MHD_HTTP_OK, nullptr);
|
||||
}
|
||||
|
||||
if (req.method() == xmrig::HttpRequest::Unsupported) {
|
||||
return req.end(MHD_HTTP_METHOD_NOT_ALLOWED, nullptr);
|
||||
}
|
||||
|
||||
return static_cast<Httpd*>(cls)->process(req);
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/* 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 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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 XMRIG_HTTPD_H
|
||||
#define XMRIG_HTTPD_H
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/ITimerListener.h"
|
||||
|
||||
|
||||
struct MHD_Connection;
|
||||
struct MHD_Daemon;
|
||||
struct MHD_Response;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class HttpRequest;
|
||||
class Timer;
|
||||
|
||||
|
||||
class Httpd : public ITimerListener
|
||||
{
|
||||
public:
|
||||
Httpd(int port, const char *accessToken, bool IPv6, bool restricted);
|
||||
~Httpd() override;
|
||||
|
||||
bool start();
|
||||
void stop();
|
||||
|
||||
protected:
|
||||
void onTimer(const Timer *) override { run(); }
|
||||
|
||||
private:
|
||||
constexpr static const int kIdleInterval = 200;
|
||||
constexpr static const int kActiveInterval = 25;
|
||||
|
||||
int process(HttpRequest &req);
|
||||
void run();
|
||||
|
||||
static int handler(void *cls, MHD_Connection *connection, const char *url, const char *method, const char *version, const char *uploadData, size_t *uploadSize, void **con_cls);
|
||||
|
||||
bool m_idle;
|
||||
bool m_IPv6;
|
||||
bool m_restricted;
|
||||
const char *m_accessToken;
|
||||
const int m_port;
|
||||
MHD_Daemon *m_daemon;
|
||||
Timer *m_timer;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_HTTPD_H */
|
|
@ -30,11 +30,6 @@
|
|||
#include <uv.h>
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_HTTP
|
||||
# include <microhttpd.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
# include <openssl/opensslv.h>
|
||||
#endif
|
||||
|
@ -123,10 +118,6 @@ void xmrig::CommonConfig::printVersions()
|
|||
}
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_HTTP
|
||||
length += snprintf(buf + length, (sizeof buf) - length, "microhttpd/%s ", MHD_get_version());
|
||||
# endif
|
||||
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", uv_version_string(), buf);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
/* 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 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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 XMRIG_ICONTROLLERLISTENER_H
|
||||
#define XMRIG_ICONTROLLERLISTENER_H
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Config;
|
||||
|
||||
|
||||
class IControllerListener
|
||||
{
|
||||
public:
|
||||
virtual ~IControllerListener() = default;
|
||||
|
||||
virtual void onConfigChanged(Config *config, Config *previousConfig) = 0;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // XMRIG_ICONTROLLERLISTENER_H
|
Loading…
Add table
Add a link
Reference in a new issue