Added TLS support for API and many other TLS related changes.
This commit is contained in:
parent
92a258f142
commit
5b610e4dfe
38 changed files with 1601 additions and 178 deletions
|
@ -27,6 +27,7 @@
|
|||
#include "base/net/http/HttpContext.h"
|
||||
#include "3rdparty/http-parser/http_parser.h"
|
||||
#include "base/kernel/interfaces/IHttpListener.h"
|
||||
#include "base/tools/Baton.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
|
||||
|
||||
|
@ -42,6 +43,37 @@ static std::map<uint64_t, HttpContext *> storage;
|
|||
static uint64_t SEQUENCE = 0;
|
||||
|
||||
|
||||
class HttpWriteBaton : public Baton<uv_write_t>
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpWriteBaton)
|
||||
|
||||
inline HttpWriteBaton(std::string &&body, HttpContext *ctx) :
|
||||
m_ctx(ctx),
|
||||
m_body(std::move(body))
|
||||
{
|
||||
m_buf = uv_buf_init(const_cast<char *>(m_body.c_str()), m_body.size());
|
||||
}
|
||||
|
||||
inline ~HttpWriteBaton()
|
||||
{
|
||||
if (m_ctx) {
|
||||
m_ctx->close();
|
||||
}
|
||||
}
|
||||
|
||||
void write(uv_stream_t *stream)
|
||||
{
|
||||
uv_write(&req, stream, &m_buf, 1, [](uv_write_t *req, int) { delete reinterpret_cast<HttpWriteBaton *>(req->data); });
|
||||
}
|
||||
|
||||
private:
|
||||
HttpContext *m_ctx;
|
||||
std::string m_body;
|
||||
uv_buf_t m_buf{};
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
|
@ -75,6 +107,17 @@ xmrig::HttpContext::~HttpContext()
|
|||
}
|
||||
|
||||
|
||||
void xmrig::HttpContext::write(std::string &&data, bool close)
|
||||
{
|
||||
if (uv_is_writable(stream()) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto baton = new HttpWriteBaton(std::move(data), close ? this : nullptr);
|
||||
baton->write(stream());
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::HttpContext::isRequest() const
|
||||
{
|
||||
return m_parser->type == HTTP_REQUEST;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue