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
|
@ -6,8 +6,8 @@
|
|||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 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
|
||||
|
@ -28,8 +28,6 @@
|
|||
#include "3rdparty/http-parser/http_parser.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/http/HttpContext.h"
|
||||
#include "base/tools/Baton.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
#include <cinttypes>
|
||||
|
@ -45,52 +43,6 @@ static const char *kCRLF = "\r\n";
|
|||
static const char *kUserAgent = "user-agent";
|
||||
|
||||
|
||||
class WriteBaton : public Baton<uv_write_t>
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(WriteBaton)
|
||||
|
||||
inline WriteBaton(const std::stringstream &ss, const char *data, size_t size, HttpContext *ctx) :
|
||||
m_ctx(ctx),
|
||||
m_header(ss.str())
|
||||
{
|
||||
bufs[0].len = m_header.size();
|
||||
bufs[0].base = const_cast<char *>(m_header.c_str());
|
||||
|
||||
if (data) {
|
||||
bufs[1].len = size;
|
||||
bufs[1].base = new char[size];
|
||||
memcpy(bufs[1].base, data, size);
|
||||
}
|
||||
else {
|
||||
bufs[1].base = nullptr;
|
||||
bufs[1].len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline ~WriteBaton()
|
||||
{
|
||||
if (count() == 2) {
|
||||
delete [] bufs[1].base;
|
||||
}
|
||||
|
||||
m_ctx->close();
|
||||
}
|
||||
|
||||
|
||||
inline size_t count() const { return bufs[1].base == nullptr ? 1 : 2; }
|
||||
inline size_t size() const { return bufs[0].len + bufs[1].len; }
|
||||
inline static void onWrite(uv_write_t *req, int) { delete reinterpret_cast<WriteBaton *>(req->data); }
|
||||
|
||||
|
||||
uv_buf_t bufs[2]{};
|
||||
|
||||
private:
|
||||
HttpContext *m_ctx;
|
||||
std::string m_header;
|
||||
};
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
|
@ -134,8 +86,8 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
|
|||
|
||||
ss << kCRLF;
|
||||
|
||||
auto ctx = HttpContext::get(m_id);
|
||||
auto baton = new WriteBaton(ss, data, size, ctx);
|
||||
auto ctx = HttpContext::get(m_id);
|
||||
std::string body = data ? (ss.str() + std::string(data, size)) : ss.str();
|
||||
|
||||
# ifndef APP_DEBUG
|
||||
if (statusCode() >= 400)
|
||||
|
@ -149,11 +101,11 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
|
|||
ctx->url.c_str(),
|
||||
err ? 31 : 32,
|
||||
statusCode(),
|
||||
baton->size(),
|
||||
body.size(),
|
||||
ctx->elapsed(),
|
||||
ctx->headers.count(kUserAgent) ? ctx->headers.at(kUserAgent).c_str() : nullptr
|
||||
);
|
||||
}
|
||||
|
||||
uv_write(&baton->req, ctx->stream(), baton->bufs, baton->count(), WriteBaton::onWrite);
|
||||
ctx->write(std::move(body), true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue