#include #include // arc4random_buf #include "types.hpp" #include "preproc.hpp" // Open a file for writing with name the given prefix, and ".pX.tY" // suffix, where X is the (one-digit) player number and Y is the thread // number static std::ofstream openfile(const char *prefix, unsigned player, unsigned thread_num) { std::string filename(prefix); char suffix[20]; sprintf(suffix, ".p%d.t%u", player%10, thread_num); filename.append(suffix); std::ofstream f; f.open(filename); if (f.fail()) { std::cerr << "Failed to open " << filename << "\n"; exit(1); } return f; } // The server-to-computational-peer protocol for sending precomputed // data is: // // One byte: type // 0x80: Multiplication triple // 0x81: Multiplication half-triple // 0x01 to 0x40: DPF of that depth // 0x00: End of preprocessing // // Four bytes: number of objects of that type (not sent for type == 0x00) // // Then that number of objects // // Repeat the whole thing until type == 0x00 is received void preprocessing_comp(MPCIO &mpcio, int num_threads, char **args) { boost::asio::thread_pool pool(num_threads); for (int thread_num = 0; thread_num < num_threads; ++thread_num) { boost::asio::post(pool, [&mpcio, thread_num] { MPCTIO tio(mpcio, thread_num); while(1) { unsigned char type = 0; unsigned int num = 0; size_t res = tio.recv_server(&type, 1); if (res < 1 || type == 0) break; tio.recv_server(&num, 4); if (type == 0x80) { // Multiplication triples std::ofstream tripfile = openfile("triples", mpcio.player, thread_num); MultTriple T; for (unsigned int i=0; i