start.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <stdlib.h>
  2. #include "start.hpp"
  3. // Once all the networking is set up, start doing whatever we were asked
  4. // to do on the command line
  5. void start(NetIO &netio, int argc, char **argv)
  6. {
  7. srand48(netio.me);
  8. // Send a bunch of data to all peers
  9. for(int j=0;j<3;++j)
  10. for (size_t node_num = 0; node_num < netio.num_nodes; ++node_num) {
  11. if (node_num == netio.me) continue;
  12. NodeIO &node = netio.node(node_num);
  13. uint32_t msgsize = lrand48() % 10000000;
  14. printf("Msgsize to %lu: %u\n", node_num, msgsize);
  15. node.send_message_header(msgsize);
  16. uint8_t c = 0;
  17. uint32_t cl = 0;
  18. while (msgsize > 0) {
  19. uint8_t* frame = node.request_frame();
  20. uint32_t chunk_size = (lrand48() % (MAXCHUNKSIZE-1)) + 1;
  21. if (chunk_size > msgsize) {
  22. chunk_size = msgsize;
  23. }
  24. memset(frame, ++c, chunk_size);
  25. ++cl;
  26. memmove(frame, &cl, sizeof(cl));
  27. node.send_chunk(frame, chunk_size);
  28. msgsize -= chunk_size;
  29. }
  30. }
  31. printf("Sleeping\n");
  32. sleep(3);
  33. printf("Reading\n");
  34. for (size_t node_num = 0; node_num < netio.num_nodes; ++node_num) {
  35. if (node_num == netio.me) continue;
  36. NodeIO &node = netio.node(node_num);
  37. node.recv_commands(
  38. // error_cb
  39. [](boost::system::error_code) {
  40. printf("Error\n");
  41. },
  42. // epoch_cb
  43. [](uint32_t epoch) {
  44. printf("Epoch %u\n", epoch);
  45. },
  46. // message_cb
  47. [](uint32_t msg_len) {
  48. printf("Message len %u\n", msg_len);
  49. },
  50. // chunk_cb
  51. [](uint8_t *data, uint32_t chunk_len) {
  52. printf("Chunk len %u: ", chunk_len);
  53. for (size_t i=0;i<chunk_len && i<10; ++i) {
  54. printf("%02x", data[i]);
  55. }
  56. printf("\n");
  57. });
  58. }
  59. }