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
|
@ -29,7 +29,6 @@
|
|||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "base/net/dns/Dns.h"
|
||||
#include "base/tools/Baton.h"
|
||||
|
||||
|
||||
#include <sstream>
|
||||
|
@ -41,31 +40,6 @@ namespace xmrig {
|
|||
static const char *kCRLF = "\r\n";
|
||||
|
||||
|
||||
class HttpClientWriteBaton : public Baton<uv_write_t>
|
||||
{
|
||||
public:
|
||||
inline HttpClientWriteBaton(const std::string &header, std::string &&body) :
|
||||
m_body(std::move(body)),
|
||||
m_header(header)
|
||||
{
|
||||
m_bufs[0] = uv_buf_init(const_cast<char *>(m_header.c_str()), m_header.size());
|
||||
m_bufs[1] = m_body.empty() ? uv_buf_init(nullptr, 0) : uv_buf_init(const_cast<char *>(m_body.c_str()), m_body.size());
|
||||
}
|
||||
|
||||
void write(uv_stream_t *stream)
|
||||
{
|
||||
uv_write(&req, stream, m_bufs, nbufs(), [](uv_write_t *req, int) { delete reinterpret_cast<HttpClientWriteBaton *>(req->data); });
|
||||
}
|
||||
|
||||
private:
|
||||
inline size_t nbufs() const { return m_bufs[1].len > 0 ? 2 : 1; }
|
||||
|
||||
std::string m_body;
|
||||
std::string m_header;
|
||||
uv_buf_t m_bufs[2]{};
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
|
@ -137,7 +111,8 @@ void xmrig::HttpClient::handshake()
|
|||
|
||||
headers.clear();
|
||||
|
||||
write(ss.str());
|
||||
body.insert(0, ss.str());
|
||||
write(std::move(body), false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -149,13 +124,6 @@ void xmrig::HttpClient::read(const char *data, size_t size)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::HttpClient::write(const std::string &header)
|
||||
{
|
||||
auto baton = new HttpClientWriteBaton(header, std::move(body));
|
||||
baton->write(stream());
|
||||
}
|
||||
|
||||
|
||||
void xmrig::HttpClient::onConnect(uv_connect_t *req, int status)
|
||||
{
|
||||
auto client = static_cast<HttpClient *>(req->data);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue