networkServer.hpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #ifndef __PRSONA_NETWORK_SERVER_HPP
  2. #define __PRSONA_NETWORK_SERVER_HPP
  3. #include <string>
  4. #include <vector>
  5. #include <atomic>
  6. #include "server.hpp"
  7. #include "networking.hpp"
  8. void obtain_update_locks(
  9. std::unique_lock<std::mutex> &lck,
  10. const std::vector<std::string>& serverIPs,
  11. const std::string& selfIP,
  12. struct synchronization_tool *synch);
  13. void release_update_locks(
  14. std::unique_lock<std::mutex> &lck,
  15. const std::vector<std::string>& serverIPs,
  16. const std::string& selfIP,
  17. struct synchronization_tool *synch);
  18. std::string make_epoch_initiator_string(
  19. const std::vector<Proof>& generatorProof,
  20. const Twistpoint& nextGenerator);
  21. std::string make_epoch_update_string(
  22. const std::vector<std::vector<Proof>>& pi,
  23. const std::vector<std::vector<Twistpoint>>& permutationCommits,
  24. const std::vector<std::vector<Twistpoint>>& freshPseudonymCommits,
  25. const std::vector<std::vector<Twistpoint>>& freshPseudonymSeedCommits,
  26. const std::vector<std::vector<CurveBipoint>>& serverTallyCommits,
  27. const std::vector<std::vector<std::vector<TwistBipoint>>>& partwayVoteMatrixCommits,
  28. const std::vector<std::vector<std::vector<TwistBipoint>>>& finalVoteMatrixCommits,
  29. const std::vector<std::vector<Twistpoint>>& userTallyMaskCommits,
  30. const std::vector<std::vector<Twistpoint>>& userTallyMessageCommits,
  31. const std::vector<std::vector<Twistpoint>>& userTallySeedCommits,
  32. const Twistpoint& nextGenerator,
  33. bool doUserTallies);
  34. void distribute_epoch_updates(
  35. const std::string& recipient,
  36. const std::string& data,
  37. const struct synchronization_tool* sync);
  38. class PrsonaServerWebSocketHandler : public CivetWebSocketHandler {
  39. public:
  40. // CONSTRUCTORS
  41. PrsonaServerWebSocketHandler(
  42. PrsonaServer *prsonaServer,
  43. std::mutex *updateMtx,
  44. std::atomic<size_t> *epochNum,
  45. const std::vector<std::string>& serverIPs,
  46. const std::string& selfIP);
  47. virtual bool handleConnection(
  48. CivetServer *server,
  49. const struct mg_connection *conn);
  50. virtual void handleReadyState(
  51. CivetServer *server,
  52. struct mg_connection *conn);
  53. virtual bool handleData(
  54. CivetServer *server,
  55. struct mg_connection *conn,
  56. int bits,
  57. char *data,
  58. size_t data_len);
  59. virtual void handleClose(
  60. CivetServer *server,
  61. const struct mg_connection *conn);
  62. private:
  63. PrsonaServer *prsonaServer;
  64. std::mutex *updateMtx;
  65. std::atomic<size_t> *epochNum;
  66. const std::vector<std::string> serverIPs;
  67. const std::string selfIP;
  68. struct synchronization_tool updateSynch, distributeSynch;
  69. void generate_response(
  70. struct mg_connection *conn,
  71. const char *filename);
  72. // BASIC PUBLIC SYSTEM INFO GETTERS
  73. void get_bgn_public_key(struct mg_connection *c) const;
  74. void get_num_clients(struct mg_connection *c) const;
  75. void get_num_servers(struct mg_connection *c) const;
  76. // ENCRYPTED DATA GETTERS
  77. void get_current_votes_by(
  78. struct mg_connection *c,
  79. const char *filename
  80. ) const;
  81. void get_all_current_votes(
  82. struct mg_connection *c
  83. ) const;
  84. void get_current_user_encrypted_tally(
  85. struct mg_connection *c,
  86. const char *filename
  87. ) const;
  88. void get_current_server_encrypted_tally(
  89. struct mg_connection *c,
  90. const char *filename
  91. ) const;
  92. void get_current_pseudonyms(
  93. struct mg_connection *c
  94. ) const;
  95. // PROOF COMMITMENT GETTERS
  96. void get_vote_row_commitment(
  97. struct mg_connection *c,
  98. const char *filename
  99. ) const;
  100. void get_vote_matrix_commitment(
  101. struct mg_connection *c
  102. ) const;
  103. void get_user_tally_commitment(
  104. struct mg_connection *c,
  105. const char *filename
  106. ) const;
  107. void get_server_tally_commitment(
  108. struct mg_connection *c,
  109. const char *filename
  110. ) const;
  111. void get_pseudonyms_commitment(
  112. struct mg_connection *c
  113. ) const;
  114. // CLIENT INTERACTIONS
  115. void add_new_client(
  116. struct mg_connection *c,
  117. const char *filename
  118. );
  119. void receive_vote(
  120. struct mg_connection *c,
  121. const char *filename
  122. );
  123. // CONSTRUCTOR HELPERS
  124. void get_bgn_details(struct mg_connection *c) const;
  125. void add_seed_to_generator(
  126. struct mg_connection *conn,
  127. const char *filename,
  128. bool fresh
  129. ) const;
  130. void set_generator(
  131. const char *filename,
  132. bool fresh
  133. );
  134. // EPOCH ROUNDS
  135. void build_up_midway_pseudonyms(
  136. struct mg_connection *c,
  137. const char *filename
  138. );
  139. void break_down_midway_pseudonyms(
  140. struct mg_connection *c,
  141. const char *filename
  142. );
  143. void accept_epoch_updates(
  144. struct mg_connection *c,
  145. const char *filename
  146. );
  147. // DATA MAINTENANCE
  148. void import_new_user_update(
  149. const char *filename
  150. );
  151. void distribute_new_user_updates(
  152. std::vector<Proof> proofOfValidAddition,
  153. std::vector<CurveBipoint> previousVoteTallies,
  154. std::vector<Twistpoint> currentPseudonyms,
  155. std::vector<EGCiphertext> currentUserEncryptedTallies,
  156. std::vector<std::vector<TwistBipoint>> voteMatrix
  157. ) const;
  158. void distribute_new_vote(
  159. std::vector<Proof> pi,
  160. std::vector<TwistBipoint> newVotes,
  161. Twistpoint shortTermPublicKey
  162. ) const;
  163. void get_partial_decryption(
  164. struct mg_connection *conn
  165. ) const;
  166. void receive_tallied_scores(
  167. struct mg_connection *conn,
  168. const char *filename
  169. );
  170. void get_generator(
  171. struct mg_connection *conn,
  172. bool fresh
  173. );
  174. };
  175. #endif