config.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include "Enclave_t.h"
  2. #include "comms.hpp"
  3. #include "config.hpp"
  4. #include "utils.hpp"
  5. #include "route.hpp"
  6. Config g_teems_config;
  7. bool ecall_config_load(threadid_t nthreads, bool private_routing,
  8. EnclaveAPIParams *apiparams,
  9. EnclaveAPINodeConfig *apinodeconfigs,
  10. nodenum_t num_nodes, nodenum_t my_node_num)
  11. {
  12. g_teems_config.nthreads = nthreads;
  13. g_teems_config.num_nodes = num_nodes;
  14. g_teems_config.num_ingestion_nodes = 0;
  15. g_teems_config.num_routing_nodes = 0;
  16. g_teems_config.num_storage_nodes = 0;
  17. g_teems_config.my_node_num = my_node_num;
  18. g_teems_config.user_count = apiparams->user_count;
  19. g_teems_config.msg_size = apiparams->msg_size;
  20. g_teems_config.m_priv_out = apiparams->m_priv_out;
  21. g_teems_config.m_priv_in = apiparams->m_priv_in;
  22. g_teems_config.m_pub_out = apiparams->m_pub_out;
  23. g_teems_config.m_pub_in = apiparams->m_pub_in;
  24. g_teems_config.private_routing = private_routing;
  25. memcpy(g_teems_config.clients_aes_key, apiparams->client_aes_key, SGX_AESGCM_KEY_SIZE);
  26. // Temporary vectors to store node numbers for nodes of different
  27. // types, where the node numbers are smaller than our own node
  28. // number
  29. std::vector<nodenum_t> ing_smaller, rte_smaller, str_smaller;
  30. uint16_t cumul_weight = 0;
  31. g_teems_config.weights.clear();
  32. g_teems_config.ingestion_nodes.clear();
  33. g_teems_config.routing_nodes.clear();
  34. g_teems_config.storage_nodes.clear();
  35. for (nodenum_t i=0; i<num_nodes; ++i) {
  36. NodeWeight nw;
  37. nw.startweight = cumul_weight;
  38. nw.weight = apinodeconfigs[i].weight;
  39. if (apinodeconfigs[i].roles & ROLE_INGESTION) {
  40. g_teems_config.num_ingestion_nodes += 1;
  41. if (i < my_node_num) {
  42. ing_smaller.push_back(i);
  43. } else {
  44. g_teems_config.ingestion_nodes.push_back(i);
  45. }
  46. }
  47. if (apinodeconfigs[i].roles & ROLE_ROUTING) {
  48. g_teems_config.num_routing_nodes += 1;
  49. if (i < my_node_num) {
  50. rte_smaller.push_back(i);
  51. } else {
  52. g_teems_config.routing_nodes.push_back(i);
  53. }
  54. }
  55. if (apinodeconfigs[i].roles & ROLE_STORAGE) {
  56. g_teems_config.num_storage_nodes += 1;
  57. if (i < my_node_num) {
  58. str_smaller.push_back(i);
  59. } else {
  60. g_teems_config.storage_nodes.push_back(i);
  61. }
  62. }
  63. cumul_weight += nw.weight;
  64. g_teems_config.weights.push_back(nw);
  65. if (i == my_node_num) {
  66. g_teems_config.my_weight = nw.weight;
  67. }
  68. }
  69. g_teems_config.tot_weight = cumul_weight;
  70. // Concatenate the *_smaller vectors to the ends of the
  71. // g_teems_config.*_nodes vectors. This way, each node has a list
  72. // of nodes of each role starting with itself and "looping around".
  73. // This should make the communication pattern have less of a
  74. // bottleneck.
  75. g_teems_config.ingestion_nodes.insert(
  76. g_teems_config.ingestion_nodes.end(),
  77. ing_smaller.begin(),
  78. ing_smaller.end());
  79. g_teems_config.routing_nodes.insert(
  80. g_teems_config.routing_nodes.end(),
  81. rte_smaller.begin(),
  82. rte_smaller.end());
  83. g_teems_config.storage_nodes.insert(
  84. g_teems_config.storage_nodes.end(),
  85. str_smaller.begin(),
  86. str_smaller.end());
  87. // Initialize the threadpool and the pseudorandom bytes pools
  88. threadpool_init(nthreads);
  89. PRB_pool_init(nthreads);
  90. if (!route_init()) {
  91. return false;
  92. }
  93. return comms_init_nodestate(apinodeconfigs, num_nodes, my_node_num);
  94. }
  95. void ecall_close()
  96. {
  97. PRB_pool_shutdown();
  98. threadpool_shutdown();
  99. }