/*
 * Brainflyer.h
 *
 *  Created on: Apr 12, 2018
 *      Author: armin
 */

#ifndef BRAINFLYER_H_
#define BRAINFLYER_H_

#include <Comm.h>
#include <Work.h>
#include <bytestr.h>
#include <stddef.h>
#include <string>

namespace bf {

class Brainflyer {
 public:
  Brainflyer(int id, std::string host, int port, util::bytestr key);

  void operator()();

 private:
  int id;
  comm::Comm comm;
  util::bytestr key;

  comm::Work getWork();
  int checkBatch(unsigned char (*pub_batch)[65], size_t batch_size);
  void dumpBatch(unsigned char (*pub_batch)[65],
                 unsigned char (*priv_batch)[32]);
  void performWork(comm::Work work);

  /*
   * Log facilities
   */
  template <typename... Args>
  void log(Args... args);

  template <typename First, typename... Rest>
  void rec_log(First f, Rest... r);

  template <typename T>
  void rec_log(T v);
};

}  // namespace bf

#endif /* BRAINFLYER_H_ */
