mirror of https://github.com/SChernykh/p2pool
Added memory hooks for CURL
parent
75b9a0228b
commit
8b681d6efb
|
@ -333,6 +333,7 @@ void* malloc_hook(size_t n) noexcept;
|
||||||
void* realloc_hook(void* ptr, size_t size) noexcept;
|
void* realloc_hook(void* ptr, size_t size) noexcept;
|
||||||
void* calloc_hook(size_t count, size_t size) noexcept;
|
void* calloc_hook(size_t count, size_t size) noexcept;
|
||||||
void free_hook(void* p) noexcept;
|
void free_hook(void* p) noexcept;
|
||||||
|
char* strdup_hook(const char* s) noexcept;
|
||||||
|
|
||||||
extern const char* BLOCK_FOUND;
|
extern const char* BLOCK_FOUND;
|
||||||
|
|
||||||
|
|
10
src/main.cpp
10
src/main.cpp
|
@ -20,6 +20,7 @@
|
||||||
#include "p2pool.h"
|
#include "p2pool.h"
|
||||||
#include "stratum_server.h"
|
#include "stratum_server.h"
|
||||||
#include "p2p_server.h"
|
#include "p2p_server.h"
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
void p2pool_usage()
|
void p2pool_usage()
|
||||||
{
|
{
|
||||||
|
@ -81,12 +82,15 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int result;
|
|
||||||
|
|
||||||
memory_tracking_start();
|
memory_tracking_start();
|
||||||
|
|
||||||
p2pool::init_crypto_cache();
|
p2pool::init_crypto_cache();
|
||||||
|
|
||||||
|
int result = static_cast<int>(curl_global_init_mem(CURL_GLOBAL_ALL, p2pool::malloc_hook, p2pool::free_hook, p2pool::realloc_hook, p2pool::strdup_hook, p2pool::calloc_hook));
|
||||||
|
if (result != CURLE_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
p2pool::p2pool pool(argc, argv);
|
p2pool::p2pool pool(argc, argv);
|
||||||
result = pool.run();
|
result = pool.run();
|
||||||
|
@ -95,6 +99,8 @@ int main(int argc, char* argv[])
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
curl_global_cleanup();
|
||||||
|
|
||||||
p2pool::destroy_crypto_cache();
|
p2pool::destroy_crypto_cache();
|
||||||
|
|
||||||
memory_tracking_stop();
|
memory_tracking_stop();
|
||||||
|
|
|
@ -144,6 +144,19 @@ void free_hook(void* p) noexcept
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* strdup_hook(const char* s) noexcept
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
char* s1 = _strdup(s);
|
||||||
|
#else
|
||||||
|
char* s1 = strdup(s);
|
||||||
|
#endif
|
||||||
|
if (s1) {
|
||||||
|
add_alocation(s1, strlen(s) + 1);
|
||||||
|
}
|
||||||
|
return s1;
|
||||||
|
}
|
||||||
|
|
||||||
void* realloc_hook(void* ptr, size_t size) noexcept
|
void* realloc_hook(void* ptr, size_t size) noexcept
|
||||||
{
|
{
|
||||||
remove_allocation(ptr);
|
remove_allocation(ptr);
|
||||||
|
@ -248,5 +261,14 @@ void* realloc_hook(void* ptr, size_t size) noexcept { return realloc(ptr, size);
|
||||||
void* calloc_hook(size_t count, size_t size) noexcept { return calloc(count, size); }
|
void* calloc_hook(size_t count, size_t size) noexcept { return calloc(count, size); }
|
||||||
void free_hook(void* p) noexcept { free(p); }
|
void free_hook(void* p) noexcept { free(p); }
|
||||||
|
|
||||||
|
char* strdup_hook(const char* s) noexcept
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
return _strdup(s);
|
||||||
|
#else
|
||||||
|
return strdup(s);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
#include "keccak.h"
|
#include "keccak.h"
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <curl/curl.h>
|
|
||||||
|
|
||||||
constexpr char log_category_prefix[] = "P2Pool ";
|
constexpr char log_category_prefix[] = "P2Pool ";
|
||||||
constexpr int BLOCK_HEADERS_REQUIRED = 720;
|
constexpr int BLOCK_HEADERS_REQUIRED = 720;
|
||||||
|
@ -89,13 +88,7 @@ p2pool::p2pool(int argc, char* argv[])
|
||||||
LOGWARN(1, "Mining to a stagenet wallet address");
|
LOGWARN(1, "Mining to a stagenet wallet address");
|
||||||
}
|
}
|
||||||
|
|
||||||
int err = static_cast<int>(curl_global_init(CURL_GLOBAL_ALL));
|
int err = uv_async_init(uv_default_loop_checked(), &m_submitBlockAsync, on_submit_block);
|
||||||
if (err != CURLE_OK) {
|
|
||||||
LOGERR(1, "Failed to initialize curl, error " << err);
|
|
||||||
throw std::exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
err = uv_async_init(uv_default_loop_checked(), &m_submitBlockAsync, on_submit_block);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
LOGERR(1, "uv_async_init failed, error " << uv_err_name(err));
|
LOGERR(1, "uv_async_init failed, error " << uv_err_name(err));
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
|
@ -183,8 +176,6 @@ p2pool::~p2pool()
|
||||||
delete m_mempool;
|
delete m_mempool;
|
||||||
delete m_params;
|
delete m_params;
|
||||||
delete m_consoleCommands;
|
delete m_consoleCommands;
|
||||||
|
|
||||||
curl_global_cleanup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p2pool::calculate_hash(const void* data, size_t size, uint64_t height, const hash& seed, hash& result)
|
bool p2pool::calculate_hash(const void* data, size_t size, uint64_t height, const hash& seed, hash& result)
|
||||||
|
|
|
@ -31,7 +31,7 @@ static constexpr uint64_t MIN_DIFF = 1000;
|
||||||
static constexpr uint64_t AUTO_DIFF_TARGET_TIME = 30;
|
static constexpr uint64_t AUTO_DIFF_TARGET_TIME = 30;
|
||||||
|
|
||||||
// Use short target format (4 bytes) for diff <= 4 million
|
// Use short target format (4 bytes) for diff <= 4 million
|
||||||
static constexpr uint64_t TARGET_4_BYTES_LIMIT = std::numeric_limits<uint64_t>::max() / 4000000 + 1;
|
static constexpr uint64_t TARGET_4_BYTES_LIMIT = std::numeric_limits<uint64_t>::max() / 4000001;
|
||||||
|
|
||||||
#include "tcp_server.inl"
|
#include "tcp_server.inl"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue