networkServer.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef __PRSONA_NETWORK_SERVER_HPP
  2. #define __PRSONA_NETWORK_SERVER_HPP
  3. #include <string>
  4. #include <vector>
  5. #include "server.hpp"
  6. #include "networking.hpp"
  7. void obtain_update_locks(
  8. std::unique_lock<std::mutex> &lck,
  9. const std::vector<std::string>& serverIPs,
  10. const std::string& selfIP,
  11. struct synchronization_tool *synch);
  12. void release_update_locks(
  13. std::unique_lock<std::mutex> &lck,
  14. const std::vector<std::string>& serverIPs,
  15. const std::string& selfIP,
  16. struct synchronization_tool *synch);
  17. std::string make_epoch_initiator_string(
  18. std::vector<Proof> generatorProof,
  19. Twistpoint nextGenerator);
  20. std::string make_epoch_update_string(
  21. std::vector<std::vector<Proof>> pi,
  22. std::vector<std::vector<Twistpoint>> permutationCommits,
  23. std::vector<std::vector<Twistpoint>> freshPseudonymCommits,
  24. std::vector<std::vector<Twistpoint>> freshPseudonymSeedCommits,
  25. std::vector<std::vector<CurveBipoint>> serverTallyCommits,
  26. std::vector<std::vector<std::vector<TwistBipoint>>> partwayVoteMatrixCommits,
  27. std::vector<std::vector<std::vector<TwistBipoint>>> finalVoteMatrixCommits,
  28. std::vector<std::vector<Twistpoint>> userTallyMaskCommits,
  29. std::vector<std::vector<Twistpoint>> userTallyMessageCommits,
  30. std::vector<std::vector<Twistpoint>> userTallySeedCommits,
  31. Twistpoint nextGenerator,
  32. bool doUserTallies);
  33. class PrsonaServerWebSocketHandler : public CivetWebSocketHandler {
  34. public:
  35. // CONSTRUCTORS
  36. PrsonaServerWebSocketHandler(
  37. const PrsonaServer *prsonaServer,
  38. const std::mutex *updateMtx,
  39. const std::atomic<size_t> *epochNum,
  40. const std::vector<std::string> serverIPs,
  41. const std::string selfIP);
  42. virtual bool handleConnection(
  43. CivetServer *server,
  44. const struct mg_connection *conn);
  45. virtual void handleReadyState(
  46. CivetServer *server,
  47. struct mg_connection *conn);
  48. virtual bool handleData(
  49. CivetServer *server,
  50. struct mg_connection *conn,
  51. int bits,
  52. char *data,
  53. size_t data_len);
  54. virtual void handleClose(
  55. CivetServer *server,
  56. const struct mg_connection *conn);
  57. private:
  58. const PrsonaServer *prsonaServer;
  59. const std::mutex *updateMtx;
  60. const std::atomic<size_t> *epochNum;
  61. const std::vector<std::string> serverIPs;
  62. const std::string selfIP;
  63. struct synchronization_tool updateSynch, distributeSynch;
  64. // BASIC PUBLIC SYSTEM INFO GETTERS
  65. void get_bgn_public_key(struct mg_connection *c) const;
  66. void get_num_clients(struct mg_connection *c) const;
  67. void get_num_servers(struct mg_connection *c) const;
  68. // ENCRYPTED DATA GETTERS
  69. void get_current_votes_by(struct mg_connection *c) const;
  70. void get_all_current_votes(struct mg_connection *c) const;
  71. void get_current_user_encrypted_tally(struct mg_connection *c) const;
  72. void get_current_server_encrypted_tally(struct mg_connection *c) const;
  73. void get_current_pseudonyms(struct mg_connection *c) const;
  74. // PROOF COMMITMENT GETTERS
  75. void get_vote_row_commitment(struct mg_connection *c) const;
  76. void get_vote_matrix_commitment(struct mg_connection *c) const;
  77. void get_user_tally_commitment(struct mg_connection *c) const;
  78. void get_server_tally_commitment(struct mg_connection *c) const;
  79. void get_pseudonyms_commitment(struct mg_connection *c) const;
  80. // CLIENT INTERACTIONS
  81. void add_new_client(struct mg_connection *c);
  82. void receive_vote(struct mg_connection *c);
  83. // CONSTRUCTOR HELPERS
  84. void get_bgn_details(struct mg_connection *c) const;
  85. void initialize_fresh_generator(struct mg_connection *c);
  86. void add_rand_seed_to_generator(struct mg_connection *c) const;
  87. void set_EG_blind_generator(struct mg_connection *c);
  88. // EPOCH ROUNDS
  89. void build_up_midway_pseudonyms(struct mg_connection *c);
  90. void break_down_midway_pseudonyms(struct mg_connection *c);
  91. void accept_epoch_updates(struct mg_connection *c);
  92. // DATA MAINTENANCE
  93. void import_new_user_update(struct mg_connection *c);
  94. };
  95. #endif