Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptozoidberg committed Mar 15, 2022
2 parents 854a2f0 + 59097d0 commit c565653
Show file tree
Hide file tree
Showing 33 changed files with 688 additions and 65 deletions.
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -196,6 +196,9 @@ if(BUILD_GUI)
find_package(Qt5PrintSupport REQUIRED)

target_link_libraries(Zano wallet rpc currency_core crypto common zlibstatic ethash Qt5::WebEngineWidgets Qt5::PrintSupport ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
if (UNIX AND NOT APPLE)
target_link_libraries(Zano rt)
endif()

if(APPLE)
target_link_libraries(Zano ${COCOA_LIBRARY})
Expand Down
3 changes: 3 additions & 0 deletions src/common/command_line.cpp
Expand Up @@ -28,6 +28,7 @@ namespace command_line
const arg_descriptor<bool> arg_show_rpc_autodoc = { "show_rpc_autodoc", "Display rpc auto-generated documentation template" };

const arg_descriptor<bool> arg_disable_upnp = { "disable-upnp", "Disable UPnP (enhances local network privacy)", false, true };
const arg_descriptor<bool> arg_disable_ntp = { "disable-ntp", "Disable NTP, could enhance to time synchronization issue but increase network privacy, consider using disable-stop-if-time-out-of-sync with it", false, true };

const arg_descriptor<bool> arg_disable_stop_if_time_out_of_sync = { "disable-stop-if-time-out-of-sync", "Do not stop the daemon if serious time synchronization problem is detected", false, true };
const arg_descriptor<bool> arg_disable_stop_on_low_free_space = { "disable-stop-on-low-free-space", "Do not stop the daemon if free space at data dir is critically low", false, true };
Expand All @@ -39,4 +40,6 @@ namespace command_line
const arg_descriptor<bool> arg_validate_predownload = { "validate-predownload", "Paranoid mode, re-validate each block from pre-downloaded database and rebuild own database", };
const arg_descriptor<std::string> arg_predownload_link = { "predownload-link", "Override url for blockchain database pre-downloading", "", true };

const arg_descriptor<std::string> arg_deeplink = { "deeplink-params", "Deeplink parameter, in that case app just forward params to running app", "", true };

}
2 changes: 2 additions & 0 deletions src/common/command_line.h
Expand Up @@ -216,6 +216,7 @@ namespace command_line
extern const arg_descriptor<bool> arg_show_details;
extern const arg_descriptor<bool> arg_show_rpc_autodoc;
extern const arg_descriptor<bool> arg_disable_upnp;
extern const arg_descriptor<bool> arg_disable_ntp;
extern const arg_descriptor<bool> arg_disable_stop_if_time_out_of_sync;
extern const arg_descriptor<bool> arg_disable_stop_on_low_free_space;
extern const arg_descriptor<bool> arg_enable_offers_service;
Expand All @@ -224,4 +225,5 @@ namespace command_line
extern const arg_descriptor<bool> arg_force_predownload;
extern const arg_descriptor<bool> arg_validate_predownload;
extern const arg_descriptor<std::string> arg_predownload_link;
extern const arg_descriptor<std::string> arg_deeplink;
}
2 changes: 2 additions & 0 deletions src/common/db_abstract_accessor.h
Expand Up @@ -600,6 +600,8 @@ namespace tools
bdb.get_backend()->enumerate(m_h, &local_enum_handler);
}

// callback format: bool cb(uint64_t index, const key_t& key, const value_t& value)
// cb should return true to continue, false -- to stop enumeration
template<class t_cb>
void enumerate_items(t_cb cb)const
{
Expand Down
4 changes: 2 additions & 2 deletions src/common/pre_download.h
Expand Up @@ -21,8 +21,8 @@ namespace tools
};

#ifndef TESTNET
static constexpr pre_download_entry c_pre_download_mdbx = { "http://95.217.42.247/pre-download/zano_mdbx_95_1161000.pak", "26660ffcdaf80a43a586e64a1a6da042dcb9ff3b58e14ce1ec9a775b995dc146", 1330022593, 2684313600 };
static constexpr pre_download_entry c_pre_download_lmdb = { "http://95.217.42.247/pre-download/zano_lmdb_95_1161000.pak", "9dd03f08dea396fe32e6483a8221b292be35fa41c29748f119f11c3275956cdc", 1787475468, 2600247296 };
static constexpr pre_download_entry c_pre_download_mdbx = { "http://95.217.42.247/pre-download/zano_mdbx_95_1480000.pak", "2b664de02450cc0082efb6c75824d33ffe694b9b17b21fc7966bcb9be9ac31f7", 1570460883, 3221176320 };
static constexpr pre_download_entry c_pre_download_lmdb = { "http://95.217.42.247/pre-download/zano_lmdb_95_1480000.pak", "67770faa7db22dfe97982611d7471ba5673145589e81e02ed99832644ae328f6", 2042582638, 2968252416 };
#else
static constexpr pre_download_entry c_pre_download_mdbx = { "", "", 0, 0 };
static constexpr pre_download_entry c_pre_download_lmdb = { "", "", 0, 0 };
Expand Down
153 changes: 153 additions & 0 deletions src/common/threads_pool.h
@@ -0,0 +1,153 @@
// Copyright (c) 2014-2019 Zano Project
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#pragma once

#include <thread>
#include <string>
#include <boost/thread.hpp>

namespace utils
{

struct call_executor_base
{
virtual void execute() = 0;
};

template<typename t_executor_func>
struct call_executor_t : public call_executor_base
{
call_executor_t(t_executor_func f) :m_func(f)
{}
t_executor_func m_func;
virtual void execute()
{
m_func();
}
};

template<typename t_executor_func>
std::shared_ptr<call_executor_base> build_call_executor(t_executor_func func)
{
std::shared_ptr<call_executor_base> res(static_cast<call_executor_base*>(new call_executor_t<t_executor_func>(func)));
return res;
}

class threads_pool
{
public:
typedef std::list<std::shared_ptr<call_executor_base>> jobs_container;

template<typename t_executor_func>
static void add_job_to_container(jobs_container& cntr, t_executor_func func)
{
cntr.push_back(std::shared_ptr<call_executor_base>(static_cast<call_executor_base*>(new call_executor_t<t_executor_func>(func))));
}

void init()
{
int num_threads = std::thread::hardware_concurrency();
this->init(num_threads);
}
void init(unsigned int num_threads)
{
m_is_stop = false;

for (int i = 0; i < num_threads; i++)
{
m_threads.push_back(std::thread([this]() {this->worker_func(); }));
}
}

threads_pool() : m_is_stop(false), m_threads_counter(0)
{}

template<typename t_executor_func>
bool add_job(t_executor_func func)
{
{
std::unique_lock<std::mutex> lock(m_queue_mutex);
m_jobs_que.push_back(build_call_executor(func));
}
m_condition.notify_one();
return true;
}

void add_batch_and_wait(const jobs_container& cntr)
{
std::condition_variable batch_condition;
std::mutex batch_mutex;


std::atomic<size_t> cnt = 0;
for (const auto& jb : cntr)
{
call_executor_base* pjob = jb.get();
add_job([&, pjob]() {
pjob->execute();
{
std::lock_guard<std::mutex> lock(batch_mutex);
cnt++;
}
batch_condition.notify_one();
});
}

std::unique_lock<std::mutex> lock(batch_mutex);
batch_condition.wait(lock, [&]()
{
return cnt == cntr.size();
});
LOG_PRINT_L0("All jobs finiahed");
}

~threads_pool()
{
m_is_stop = true;
m_condition.notify_all();
for (auto& th : m_threads)
{
th.join();
}
}

private:
void worker_func()
{
LOG_PRINT_L0("Worker thread is started");
while (true)
{
std::shared_ptr<call_executor_base> job;
{
std::unique_lock<std::mutex> lock(m_queue_mutex);

m_condition.wait(lock, [this]()
{
return !m_jobs_que.empty() || m_is_stop;
});
if (m_is_stop)
{
LOG_PRINT_L0("Worker thread is finished");
return;
}

job = m_jobs_que.front();
m_jobs_que.pop_front();
}

job->execute();
}
}



jobs_container m_jobs_que;
std::condition_variable m_condition;
std::mutex m_queue_mutex;
std::vector<std::thread> m_threads;
std::atomic<bool> m_is_stop;
std::atomic<int64_t> m_threads_counter;
};
}
36 changes: 36 additions & 0 deletions src/connectivity_tool/conn_tool.cpp
Expand Up @@ -12,6 +12,7 @@

using namespace epee;
#include <boost/program_options.hpp>
//#include <boost/interprocess/ipc/message_queue.hpp>
#include "p2p/p2p_protocol_defs.h"
#include "common/command_line.h"
#include "currency_core/currency_core.h"
Expand Down Expand Up @@ -62,6 +63,7 @@ namespace
const command_line::arg_descriptor<std::string> arg_pack_file = {"pack-file", "perform gzip-packing and calculate hash for a given file", "", true };
const command_line::arg_descriptor<std::string> arg_unpack_file = {"unpack-file", "Perform gzip-unpacking and calculate hash for a given file", "", true };
const command_line::arg_descriptor<std::string> arg_target_file = {"target-file", "Specify target file for pack-file and unpack-file commands", "", true };
//const command_line::arg_descriptor<std::string> arg_send_ipc = {"send-ipc", "Send IPC request to UI", "", true };
}

typedef COMMAND_REQUEST_STAT_INFO_T<t_currency_protocol_handler<core>::stat_info> COMMAND_REQUEST_STAT_INFO;
Expand Down Expand Up @@ -1165,6 +1167,34 @@ bool process_archive(archive_processor_t& arch_processor, bool is_packing, std::
return true;
}

/*
bool handle_send_ipc(const std::string& parms)
{
try{
boost::interprocess::message_queue mq
(boost::interprocess::open_only //only open
, GUI_IPC_MESSAGE_CHANNEL_NAME //name
);
mq.send(parms.data(), parms.size(), 0);
return true;
}
catch (const std::exception& ex)
{
boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME);
LOG_ERROR("Failed to receive IPC que: " << ex.what());
}
catch (...)
{
boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME);
LOG_ERROR("Failed to receive IPC que: unknown exception");
}
return false;
}
*/

bool handle_pack_file(po::variables_map& vm)
{
bool do_pack = false;
Expand Down Expand Up @@ -1263,6 +1293,8 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_params, arg_pack_file);
command_line::add_arg(desc_params, arg_unpack_file);
command_line::add_arg(desc_params, arg_target_file);
//command_line::add_arg(desc_params, arg_send_ipc);


po::options_description desc_all;
desc_all.add(desc_general).add(desc_params);
Expand Down Expand Up @@ -1339,6 +1371,10 @@ int main(int argc, char* argv[])
{
return handle_pack_file(vm) ? EXIT_SUCCESS : EXIT_FAILURE;
}
/*else if (command_line::has_arg(vm, arg_send_ipc))
{
handle_send_ipc(command_line::get_arg(vm, arg_send_ipc)) ? EXIT_SUCCESS : EXIT_FAILURE;
}*/
else
{
std::cerr << "Not enough arguments." << ENDL;
Expand Down
28 changes: 16 additions & 12 deletions src/crypto/crypto-ops.c
Expand Up @@ -325,7 +325,7 @@ return 0 if f is in {0,2,4,...,q-1}
|f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
*/

static int fe_isnegative(const fe f) {
int fe_isnegative(const fe f) {
unsigned char s[32];
fe_tobytes(s, f);
return s[0] & 1;
Expand All @@ -342,16 +342,6 @@ int fe_isnonzero(const fe f) {
s[27] | s[28] | s[29] | s[30] | s[31]) - 1) >> 8) + 1;
}

int fe_cmp(const fe a, const fe b)
{
for (size_t i = 9; i != SIZE_MAX; --i)
{
if ((const uint32_t)a[i] < (const uint32_t)b[i]) return -1;
if ((const uint32_t)a[i] > (const uint32_t)b[i]) return 1;
}
return 0;
}

/* From fe_mul.c */

/*
Expand Down Expand Up @@ -970,7 +960,7 @@ Can overlap h with f or g.
|h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
*/

static void fe_sub(fe h, const fe f, const fe g) {
void fe_sub(fe h, const fe f, const fe g) {
int32_t f0 = f[0];
int32_t f1 = f[1];
int32_t f2 = f[2];
Expand Down Expand Up @@ -4310,3 +4300,17 @@ void ge_scalarmult_vartime_p3_v2(ge_p3 *r, const unsigned char *a, const ge_p3 *
ge_p1p1_to_p3(r, &t);
}
}


void ge_cached_to_p2(ge_p2 *r, const ge_cached *c)
{
static const fe inv2 = { 10, 0, 0, 0, 0, 0, 0, 0, 0, -16777216 };

fe_sub(r->X, c->YplusX, c->YminusX);
fe_mul(r->X, r->X, inv2);

fe_add(r->Y, c->YplusX, c->YminusX);
fe_mul(r->Y, r->Y, inv2);

fe_copy(r->Z, c->Z);
}
4 changes: 3 additions & 1 deletion src/crypto/crypto-ops.h
Expand Up @@ -111,6 +111,7 @@ void ge_fromfe_frombytes_vartime(ge_p2 *, const unsigned char *);
void ge_p2_to_p3(ge_p3 *r, const ge_p2 *t);
void ge_bytes_hash_to_ec(ge_p3 *, const void *, size_t);
void ge_bytes_hash_to_ec_32(ge_p3 *, const unsigned char *);
void ge_cached_to_p2(ge_p2 *r, const ge_cached *c);

void ge_p3_0(ge_p3 *h);
void ge_sub(ge_p1p1 *, const ge_p3 *, const ge_cached *);
Expand Down Expand Up @@ -138,8 +139,9 @@ void sc_invert(unsigned char*, const unsigned char*);

void fe_sq(fe h, const fe f);
int fe_isnonzero(const fe f);
int fe_cmp(const fe a, const fe b);
void fe_sub(fe h, const fe f, const fe g);
void fe_mul(fe, const fe, const fe);
void fe_frombytes(fe h, const unsigned char *s);
void fe_invert(fe out, const fe z);
void fe_tobytes(unsigned char *s, const fe h);
int fe_isnegative(const fe f);
15 changes: 12 additions & 3 deletions src/crypto/crypto-sugar.h
Expand Up @@ -246,7 +246,7 @@ namespace crypto
return result;
}

// genrate 0 <= x < L
// generate 0 <= x < L
void make_random()
{
unsigned char tmp[64];
Expand Down Expand Up @@ -497,7 +497,7 @@ namespace crypto
zero();
}

// as we're using additive notation, zero means identity group element here and after
// as we're using additive notation, zero means identity group element (EC point (0, 1)) here and after
void zero()
{
ge_p3_0(&m_p3);
Expand All @@ -506,7 +506,11 @@ namespace crypto
bool is_zero() const
{
// (0, 1) ~ (0, z, z, 0)
return fe_isnonzero(m_p3.X) * fe_cmp(m_p3.Y, m_p3.Z) == 0;
if (fe_isnonzero(m_p3.X) != 0)
return false;
fe y_minus_z;
fe_sub(y_minus_z, m_p3.Y, m_p3.Z);
return fe_isnonzero(y_minus_z) == 0;
}

bool is_in_main_subgroup() const
Expand Down Expand Up @@ -669,6 +673,11 @@ namespace crypto
return true;
};

friend bool operator!=(const point_t& lhs, const point_t& rhs)
{
return !(lhs == rhs);
};

friend std::ostream& operator<<(std::ostream& ss, const point_t &v)
{
crypto::public_key pk = v.to_public_key();
Expand Down

0 comments on commit c565653

Please sign in to comment.