//============================================================================
// Name        : bfclient.cpp
// Author      : Armin Friedl
// Version     :
// Copyright   : Public Domain
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bytestr.h>
#include <ec_pubkey_fast.h>
#include <cstdlib>
#include <iostream>
#include <thread>

#include "bf/Brainflyer.h"

using namespace std;

#define BATCH_MAX 4096
#define WIN_SIZE 16

int main() {
  util::bytestr key("b907c3a2a3b27789dfb509b730dd47703c272868");

  cout << "Initializing precomputation table" << endl;
  // init with window size 16, not reading from file
  if (secp256k1_ec_pubkey_precomp_table(WIN_SIZE, nullptr) != 0) {
    cout << "Initialization of precomputation table failed" << endl;
    return (EXIT_FAILURE);
  }

  cout << "Initializing threads" << endl;
  unsigned int numThreads = thread::hardware_concurrency();
  cout << numThreads << " hardware threads available" << endl;
  thread* threads = new thread[numThreads];
  cout << "Starting " << numThreads << " threads" << endl;

  // numThreads = 1;
  for (unsigned int i = 0; i < numThreads; i++) {
    threads[i] = thread{bf::Brainflyer(i, "127.0.0.1", 26765, key)};
  }

  for (unsigned int i = 0; i < numThreads; i++) threads[i].join();

  delete[] threads;

  return (EXIT_SUCCESS);
}
