MCPcopy Create free account
hub / github.com/data61/MP-SPDZ / write_socket

Method write_socket

Processor/Processor.hpp:271–329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269// determine the data structure being sent in a message.
270template<class sint, class sgf2n>
271void Processor<sint, sgf2n>::write_socket(const RegType reg_type,
272 bool send_macs, int socket_id, int message_type,
273 const ArgVector& registers, int size)
274{
275 int m = registers.size();
276 socket_stream.reset_write_head();
277
278 //First 4 bytes is message_type (unless indicate not needed)
279 if (message_type != 0) {
280 socket_stream.store(message_type);
281 }
282
283 auto rec_factor = sint::get_rec_factor(P.my_num(), P.num_players());
284
285 for (int j = 0; j < size; j++)
286 {
287 for (int i = 0; i < m; i++)
288 {
289 if (reg_type == SINT)
290 {
291 // Send vector of secret shares and optionally macs
292 if (send_macs)
293 get_Sp_ref(registers[i] + j).pack(socket_stream);
294 else
295 get_Sp_ref(registers[i] + j).pack(socket_stream, rec_factor);
296 }
297 else if (reg_type == CINT)
298 {
299 // Send vector of clear public field elements
300 get_Cp_ref(registers[i] + j).pack(socket_stream);
301 }
302 else if (reg_type == INT)
303 {
304 // Send vector of 64-bit clear ints
305 socket_stream.store(get_Ci_ref(registers[i] + j));
306 }
307 else
308 {
309 stringstream ss;
310 ss << "Write socket instruction with unknown reg type "
311 << reg_type << "." << endl;
312 throw Processor_Error(ss.str());
313 }
314 }
315 }
316
317 if (OnlineOptions::singleton.has_option("verbose_comm"))
318 fprintf(stderr, "Send %zu bytes to client %d\n", socket_stream.get_length(),
319 socket_id);
320
321 try {
322 TimeScope _(client_stats.add(socket_stream.get_length()));
323 socket_stream.Send(external_clients.get_socket(socket_id));
324 }
325 catch (bad_value& e) {
326 cerr << "Send error thrown when writing " << m << " values of type " << reg_type << " to socket id "
327 << socket_id << "." << endl;
328 }

Callers 1

executeMethod · 0.80

Calls 13

Processor_ErrorClass · 0.85
has_optionMethod · 0.80
sizeMethod · 0.45
reset_write_headMethod · 0.45
storeMethod · 0.45
my_numMethod · 0.45
num_playersMethod · 0.45
packMethod · 0.45
strMethod · 0.45
get_lengthMethod · 0.45
addMethod · 0.45
SendMethod · 0.45

Tested by

no test coverage detected