Reduced memory consumption on network level.

This commit is contained in:
XMRig 2020-03-20 20:53:27 +07:00
parent bb96684daf
commit 1b875fdabb
No known key found for this signature in database
GPG key ID: 446A53638BE94409
17 changed files with 462 additions and 205 deletions

View file

@ -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 2018 Lee Clagett <https://github.com/vtnerd>
* 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
@ -24,12 +24,9 @@
*/
#include <assert.h>
#include "base/net/stratum/Tls.h"
#include "base/io/log/Log.h"
#include "base/net/stratum/Client.h"
#include "base/net/stratum/Tls.h"
#include "base/tools/Buffer.h"
@ -38,12 +35,12 @@
#endif
#include <cassert>
#include <openssl/ssl.h>
xmrig::Client::Tls::Tls(Client *client) :
m_ready(false),
m_buf(),
m_fingerprint(),
m_client(client),
m_ssl(nullptr)
m_client(client)
{
m_ctx = SSL_CTX_new(SSLv23_method());
assert(m_ctx != nullptr);
@ -52,8 +49,8 @@ xmrig::Client::Tls::Tls(Client *client) :
return;
}
m_writeBio = BIO_new(BIO_s_mem());
m_readBio = BIO_new(BIO_s_mem());
m_write = BIO_new(BIO_s_mem());
m_read = BIO_new(BIO_s_mem());
SSL_CTX_set_options(m_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
}
@ -80,7 +77,7 @@ bool xmrig::Client::Tls::handshake()
}
SSL_set_connect_state(m_ssl);
SSL_set_bio(m_ssl, m_readBio, m_writeBio);
SSL_set_bio(m_ssl, m_read, m_write);
SSL_do_handshake(m_ssl);
return send();
@ -109,7 +106,7 @@ const char *xmrig::Client::Tls::version() const
void xmrig::Client::Tls::read(const char *data, size_t size)
{
BIO_write(m_readBio, data, size);
BIO_write(m_read, data, size);
if (!SSL_is_init_finished(m_ssl)) {
const int rc = SSL_connect(m_ssl);
@ -133,17 +130,18 @@ void xmrig::Client::Tls::read(const char *data, size_t size)
return;
}
static char buf[16384]{};
int bytes_read = 0;
while ((bytes_read = SSL_read(m_ssl, m_buf, sizeof(m_buf))) > 0) {
m_buf[bytes_read - 1] = '\0';
m_client->parse(m_buf, static_cast<size_t>(bytes_read));
while ((bytes_read = SSL_read(m_ssl, buf, sizeof(buf))) > 0) {
m_client->m_reader.parse(buf, static_cast<size_t>(bytes_read));
}
}
bool xmrig::Client::Tls::send()
{
return m_client->send(m_writeBio);
return m_client->send(m_write);
}