Browse Source

affinity

pull/21/head
Warlock-Dalbaeb 7 years ago
parent
commit
ba48d4482e
  1. 48
      vanity.hpp
  2. 73
      vanitygen.cpp

48
vanity.hpp

@ -0,0 +1,48 @@
#pragma once
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <openssl/rand.h>
#include "Crypto.h"
#include "Identity.h"
#include "common/key.hpp"
#include <thread>
#include <unistd.h>
#include <vector>
#include <mutex>
// MARCO
#define INIT_CPUS(count_cpu){\
cpu = CPU_ALLOC(count_cpu-1);\
if (cpu == NULL) {\
return 1;\
}\
std::cout << "Succefully CPU_ALLOC" << std::endl;\
}
static std::mutex thread_mutex;
static i2p::data::SigningKeyType type;
static i2p::data::PrivateKeys keys;
static bool finded=false;
static size_t padding_size;
static uint8_t * KeyBuf;
static uint8_t * PaddingBuf;
static unsigned long long hash;
static cpu_set_t * cpu;
//Functions visible and don't need.
/*
it does not need, but maybe in future we are can create.
namespace i2p{
namespace tools{
namespace vain{
}
}
}
*/

73
vanitygen.cpp

@ -1,24 +1,9 @@
#include <iostream> #include "vanity.hpp"
#include <fstream>
#include <stdlib.h>
#include <openssl/rand.h>
#include "Crypto.h"
#include "Identity.h"
#include "common/key.hpp"
#include <thread>
#include <unistd.h>
#include <vector>
#include <mutex>
static std::mutex thread_mutex;
static i2p::data::SigningKeyType type;
static i2p::data::PrivateKeys keys;
static bool finded=false;
static size_t padding_size;
static uint8_t * KeyBuf;
static uint8_t * PaddingBuf;
static unsigned long long hash;
#define CPU_ONLY #define CPU_ONLY
static bool check_prefix(const char * buf){ static bool check_prefix(const char * buf){
unsigned short size_str=0; unsigned short size_str=0;
while(*buf) while(*buf)
@ -35,10 +20,10 @@ while(*buf)
size_str++; size_str++;
*buf++; *buf++;
} }
return true; return true;
} }
#ifdef CPU_ONLY #ifdef CPU_ONLY
static inline bool NotThat(const char * a, const char *b){ static inline bool NotThat(const char * a, const char *b){
while(*b) while(*b)
@ -46,7 +31,7 @@ while(*b)
return false; return false;
} }
inline void twist_cpu(uint8_t * buf,size_t * l0){ inline void twist_cpu(uint8_t * buf){
//TODO: NORMAL IMPLEMENTATION,\ //TODO: NORMAL IMPLEMENTATION,\
As in miner... As in miner...
@ -57,26 +42,35 @@ As in miner...
// XXX: make this faster // XXX: make this faster
static inline void mutate_keys_cpu( static inline void mutate_keys_cpu(
uint8_t * buf, uint8_t * buf,
uint8_t * padding, uint8_t * padding)
size_t * l0)
{ {
twist_cpu(padding,l0); twist_cpu(padding);
thread_mutex.lock(); thread_mutex.lock();
keys.RecalculateIdentHash(buf); keys.RecalculateIdentHash(buf);
thread_mutex.unlock(); thread_mutex.unlock();
} }
void thread_find(const char * prefix){ static void thread_find(const char * prefix,int id_thread){
sched_setaffinity(0, sizeof(cpu), cpu);
cpu++;
std::cout << "Thread " << id_thread << " binded" << std::endl;
while(NotThat(keys.GetPublic()->GetIdentHash().ToBase32().c_str(),prefix) and !finded) while(NotThat(keys.GetPublic()->GetIdentHash().ToBase32().c_str(),prefix) and !finded)
{ {
size_t l0 = 0; //size_t l0 = 0; \
in future.
mutate_keys_cpu(KeyBuf,PaddingBuf, (size_t*)&l0); mutate_keys_cpu(KeyBuf,PaddingBuf);
hash++; hash++;
} }
} }
#endif #endif
int main (int argc, char * argv[]) int main (int argc, char * argv[])
{ {
if ( argc < 3 ) if ( argc < 3 )
@ -141,25 +135,24 @@ TODO:
<orignal> без всех это pthread <orignal> без всех это pthread
* orignal has quit (Quit: Leaving) * orignal has quit (Quit: Leaving)
*/ */
//
KeyBuf = new uint8_t[keys.GetFullLen()]; KeyBuf = new uint8_t[keys.GetFullLen()];
PaddingBuf = keys.GetPadding(); PaddingBuf = keys.GetPadding();
//
unsigned int count_cpu = sysconf(_SC_NPROCESSORS_ONLN); unsigned int count_cpu = sysconf(_SC_NPROCESSORS_ONLN);
std::vector<std::thread> threads(count_cpu); std::vector<std::thread> threads(count_cpu);
INIT_CPUS(count_cpu);
//
std::cout << "Start vanity generator in " << count_cpu << " threads" << std::endl; std::cout << "Start vanity generator in " << count_cpu << " threads" << std::endl;
for ( unsigned int j = count_cpu;j--;){ ///
threads[j] = std::thread(thread_find,argv[2]); for ( unsigned int j = count_cpu;j--;)
sched_param sch; threads[j] = std::thread(thread_find,argv[2],j);
int policy;
pthread_getschedparam(threads[j].native_handle(), &policy, &sch); // SET AFFINITY NOW IN FUNCTION
sch.sched_priority = 10;
if (pthread_setschedparam(threads[j].native_handle(), SCHED_FIFO, &sch)) {
std::cout << "Failed to setschedparam" << std::endl;
return 1;
}
}
for(unsigned int j = 0; j < count_cpu;j++) for(unsigned int j = 0; j < count_cpu;j++)
threads[j].join(); threads[j].join();
///
std::cout << "Hashes: " << hash << std::endl; std::cout << "Hashes: " << hash << std::endl;
std::ofstream f (argv[1], std::ofstream::binary | std::ofstream::out); std::ofstream f (argv[1], std::ofstream::binary | std::ofstream::out);

Loading…
Cancel
Save