#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 // // The incoming objects are written into num_threads files in a // round-robin manner void preprocessing_comp(MPCIO &mpcio, int num_threads, char **args) { while(1) { unsigned char type = 0; unsigned int num = 0; size_t res = mpcio.serverio.recv(&type, 1); if (res < 1 || type == 0) break; mpcio.serverio.recv(&num, 4); if (type == 0x80) { // Multiplication triples std::vector tripfiles; for (int i=0; i halffiles; for (int i=0; i