mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-07-04 12:03:41 +02:00
src/key_search.cpp: add mutex lock to result output.
This commit is contained in:
parent
56fd5eecbc
commit
46df157668
1 changed files with 21 additions and 3 deletions
|
|
@ -1,10 +1,30 @@
|
||||||
|
|
||||||
|
#ifdef HAVE_THREADS
|
||||||
|
#include <mutex>
|
||||||
|
#endif /* HAVE_THREADS */
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "ec.h"
|
#include "ec.h"
|
||||||
#include "WIF.h"
|
#include "WIF.h"
|
||||||
#include "key_search.h"
|
#include "key_search.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_THREADS
|
||||||
|
// Guards result output.
|
||||||
|
std::mutex search_mutex;
|
||||||
|
#endif /* HAVE_THREADS */
|
||||||
|
|
||||||
|
static void key_result(const std::string& word, const struct ec_keypair* pair) {
|
||||||
|
|
||||||
|
#ifdef HAVE_THREADS
|
||||||
|
// Guard output with mutex, so we don't get interrupted mid write.
|
||||||
|
const std::lock_guard<std::mutex> lock(search_mutex);
|
||||||
|
#endif /* HAVE_THREADS */
|
||||||
|
|
||||||
|
std::cout << "----" << std::endl;
|
||||||
|
std::cout << "Found: " << word << std::endl;
|
||||||
|
wif_print_key(pair);
|
||||||
|
}
|
||||||
|
|
||||||
void key_search(strlist_t word_list, size_t n) {
|
void key_search(strlist_t word_list, size_t n) {
|
||||||
|
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
|
|
@ -18,9 +38,7 @@ void key_search(strlist_t word_list, size_t n) {
|
||||||
|
|
||||||
for(auto const& word: word_list) {
|
for(auto const& word: word_list) {
|
||||||
if (pubstr.find(word) != std::string::npos) {
|
if (pubstr.find(word) != std::string::npos) {
|
||||||
std::cout << "----" << std::endl;
|
key_result(word, &pair);
|
||||||
std::cout << "Found: " << word << std::endl;
|
|
||||||
wif_print_key(&pair);
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue