orchestratorMain.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /**
  2. * orchestratorMain.cpp
  3. * - compiles to bin/orchestrator
  4. * - initiates a set of servers and clients, then commands them, for PRSONA experiments
  5. *
  6. * Stan Gurtler
  7. */
  8. #include <iostream>
  9. #include <fstream>
  10. #include <thread>
  11. #include "networkOrchestrator.hpp"
  12. using namespace std;
  13. /**
  14. * This program (bin/orchestrator) expects to be called as follows:
  15. * `bin/orchestrator <output> <servers_are_malicious>`
  16. *
  17. * <output> - a string that will name the files in which outputs for this run of
  18. * the experiment will be written (that is, timings and traffic data)
  19. * <lambda> - a positive integer that determines the absolute soundness parameter
  20. * for batched proofs
  21. * <servers_are_malicious> - a bool (given as T/t or F/f)
  22. * which is true when servers are in malicious security
  23. * and false when they are in HBC security
  24. */
  25. int main(int argc, char* argv[])
  26. {
  27. /*
  28. * PRELIMINARY SETUP CODE
  29. */
  30. #if USE_SSL
  31. mg_init_library(MG_FEATURES_SSL);
  32. #else
  33. mg_init_library(0);
  34. #endif
  35. string output = "default";
  36. if (argc > 1)
  37. output = argv[1];
  38. // Default to not proof batching if not specified
  39. size_t lambda = 0;
  40. if (argc > 2)
  41. lambda = atoi(argv[2]);
  42. // Default to malicious security if not specified
  43. bool maliciousServers = true;
  44. if (argc > 3)
  45. maliciousServers = argv[3][0] == 't' || argv[3][0] == 'T';
  46. // This seed is used to pick which users vote during which epochs
  47. // and which users make reputation proofs to which other users
  48. string seedStr = output;
  49. seedStr += "-orchestrator";
  50. seed_seq seed(seedStr.begin(), seedStr.end());
  51. default_random_engine rng(seed);
  52. vector<string> serverIPs, clientIPs;
  53. vector<int> serverPorts, clientPorts;
  54. string dealerIP, dealerPortStr;
  55. int dealerPort = 0;
  56. std::map<std::string,std::string> targeter;
  57. targeter["129.97.119.208"] = "tick0";
  58. targeter["129.97.119.209"] = "tick1";
  59. targeter["129.97.119.215"] = "tock";
  60. string configDir = "cfg/" + output;
  61. // Read in from config files the server locations
  62. load_multiple_instances_config(serverIPs, serverPorts, (configDir + "/serverIPs.cfg").c_str());
  63. // And now the client locations
  64. load_multiple_instances_config(clientIPs, clientPorts, (configDir + "/clientIPs.cfg").c_str());
  65. // And finally the dealer location
  66. load_single_instance_config(dealerIP, dealerPortStr, dealerPort, (configDir + "/dealerIP.cfg").c_str());
  67. size_t numServers = serverIPs.size();
  68. size_t numClients = clientIPs.size();
  69. /*
  70. * ORCHESTRATOR SETUP CODE
  71. */
  72. cout << "[ORC] This experiment is running with output code: " << output << endl;
  73. cout << "[ORC] This experiment is running with " << (maliciousServers ? "MALICIOUS" : "HBC") << " servers." << endl;
  74. cout << endl;
  75. cout << "[ORC] Starting BGN dealer server." << endl;
  76. vector<thread> serverStartup, clientStartup, clientReady;
  77. serverStartup.push_back(thread(start_remote_actor, targeter[dealerIP], true, "d", output, lambda, maliciousServers));
  78. this_thread::sleep_for(HALF_SECOND);
  79. cout << "[ORC] Starting other servers." << endl;
  80. for (size_t i = 0; i < numServers; i++)
  81. {
  82. if (serverIPs[i] == dealerIP && serverPorts[i] == dealerPort)
  83. continue;
  84. serverStartup.push_back(thread(start_remote_actor, targeter[serverIPs[i]], true, "s" + to_string(i), output, lambda, maliciousServers));
  85. }
  86. cout << "[ORC] Waiting for confirmation that servers are ready to continue." << endl;
  87. for (size_t i = 0; i < numServers; i++)
  88. serverStartup[i].join();
  89. wait_for_servers_ready(dealerIP, dealerPort);
  90. cout << "[ORC] Starting clients." << endl;
  91. for (size_t i = 0; i < numClients; i++)
  92. {
  93. clientStartup.push_back(thread(start_remote_actor, targeter[clientIPs[i]], false, "c" + to_string(i), output, lambda, maliciousServers));
  94. this_thread::sleep_for(HALF_SECOND);
  95. }
  96. cout << "[ORC] Waiting for confirmation that servers have all clients logged." << endl;
  97. for (size_t i = 0; i < numClients; i++)
  98. clientStartup[i].join();
  99. wait_for_clients_created(dealerIP, dealerPort, numClients);
  100. cout << "[ORC] Waiting for confirmation that clients are ready to continue." << endl;
  101. for (size_t i = 0; i < numClients; i++)
  102. clientReady.push_back(thread(wait_for_client_ready, clientIPs[i], clientPorts[i]));
  103. for (size_t i = 0; i < numClients; i++)
  104. clientReady[i].join();
  105. /*
  106. * MAIN ORCHESTRATOR LOOP CODE
  107. */
  108. cout << "[ORC] Beginning experiment." << endl;
  109. execute_experiment(rng, dealerIP, dealerPort, serverIPs, serverPorts, clientIPs, clientPorts, (configDir + "/commands.cfg").c_str());
  110. /*
  111. * SHUTDOWN CODE
  112. */
  113. cout << "[ORC] Finishing experiment." << endl;
  114. cout << "[ORC] Sending shutdown commands to clients." << endl;
  115. shut_down_remote_actors(clientIPs, clientPorts);
  116. cout << "[ORC] Sending shutdown commands to servers." << endl;
  117. shut_down_remote_actors(serverIPs, serverPorts);
  118. return 0;
  119. }