networkClient.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #ifndef __PRSONA_NETWORK_CLIENT_HPP
  2. #define __PRSONA_NETWORK_CLIENT_HPP
  3. #include <string>
  4. #include <vector>
  5. #include <random>
  6. #include "client.hpp"
  7. #include "networking.hpp"
  8. enum EventType {
  9. CLIENT_MAKE_VOTE = 1,
  10. CLIENT_MAKE_REP_PROOF
  11. };
  12. /* "PUBLIC" FUNCTIONS */
  13. // CREATOR FOR A NEW CLIENT
  14. PrsonaClient *create_client(
  15. std::default_random_engine& rng,
  16. const std::vector<std::string>& serverIPs,
  17. const std::vector<int>& serverPorts,
  18. size_t numServers);
  19. // FUNCTIONS TO PERFORM OPERATIONS FOR EXPERIMENT
  20. void make_vote(
  21. std::default_random_engine& rng,
  22. PrsonaClient* prsonaClient,
  23. const std::vector<std::string>& serverIPs,
  24. const std::vector<int>& serverPorts,
  25. const std::string& target,
  26. int targetPort,
  27. size_t numClients);
  28. bool make_reputation_proof(
  29. std::default_random_engine& rng,
  30. PrsonaClient* prsonaClient,
  31. const std::vector<std::string>& serverIPs,
  32. const std::vector<int>& serverPorts,
  33. const std::string& target,
  34. int targetPort,
  35. size_t numClients);
  36. /* "PRIVATE" FUNCTIONS */
  37. // HELPERS TO ADD THIS CLIENT TO SERVERS
  38. void register_new_client(
  39. std::default_random_engine& rng,
  40. PrsonaClient *newUser,
  41. const std::vector<std::string>& serverIPs,
  42. const std::vector<int>& serverPorts,
  43. const Proof& proofOfValidSTPK,
  44. const Twistpoint& shortTermPublicKey);
  45. void verify_valid_addition(
  46. std::default_random_engine& rng,
  47. PrsonaClient *newUser,
  48. const std::vector<std::string>& serverIPs,
  49. const std::vector<int>& serverPorts,
  50. const std::vector<Proof>& proofOfValidAddition,
  51. const Twistpoint& shortTermPublicKey);
  52. // GETTERS FOR VARIOUS SERVER VALUES
  53. Twistpoint get_generator(
  54. std::default_random_engine& rng,
  55. const std::vector<std::string>& serverIPs,
  56. const std::vector<int>& serverPorts,
  57. bool fresh,
  58. std::vector<Proof>& pi);
  59. BGNPublicKey get_bgn_public_key(
  60. std::default_random_engine& rng,
  61. const std::vector<std::string>& serverIPs,
  62. const std::vector<int>& serverPorts);
  63. template <typename T>
  64. T get_server_committed_val(
  65. std::default_random_engine& rng,
  66. const std::vector<std::string>& serverIPs,
  67. const std::vector<int>& serverPorts,
  68. const char *firstUri,
  69. const char *commitUri,
  70. std::vector<Proof>& pi,
  71. const Twistpoint& shortTermPublicKey);
  72. // HELPERS FOR GENERALIZED GETTER FUNCTION
  73. template <typename T>
  74. T get_first_committed_val(
  75. std::default_random_engine& rng,
  76. const std::string& server,
  77. int serverPort,
  78. const char *firstUri,
  79. Proof& pi,
  80. const Twistpoint& shortTermPublicKey);
  81. void get_additional_commitment(
  82. std::default_random_engine& rng,
  83. const std::vector<std::string>& serverIPs,
  84. const std::vector<int>& serverPorts,
  85. const std::string& skipIP,
  86. int skipPort,
  87. const char *commitUri,
  88. std::vector<Proof>& pi,
  89. const Twistpoint& shortTermPublicKey);
  90. // FILE I/O HELPERS FOR ALL GETTERS
  91. std::vector<Proof> get_valid_addition_proof_from_file(
  92. const char *filename);
  93. Twistpoint get_generator_from_file(
  94. const char *filename,
  95. std::vector<Proof>& pi);
  96. BGNPublicKey get_bgn_public_key_from_file(
  97. const char *filename);
  98. template <typename T>
  99. T get_committed_val_from_file(
  100. const char *filename,
  101. Proof& pi);
  102. Proof get_commitment_from_file(
  103. struct synchronization_tool *sync,
  104. const char *filename);
  105. // GENERALIZED SENDER FOR ORCHESTRATOR-SIGNALED OPERATIONS
  106. char *send_item(
  107. std::default_random_engine& rng,
  108. const std::string& target,
  109. int targetPort,
  110. const char* whichUri,
  111. const std::string& data,
  112. bool responseExpected);
  113. // DATA SERIALIZERS
  114. std::string make_vote_string(
  115. const std::vector<Proof>& pi,
  116. const std::vector<TwistBipoint>& newVotes,
  117. const Twistpoint& shortTermPublicKey);
  118. std::string make_rep_proof_string(
  119. const std::vector<Proof>& pi,
  120. const Twistpoint& shortTermPublicKey,
  121. const Scalar& threshold);
  122. /* CLIENT-SPECIFIC HANDLER */
  123. class PrsonaClientWebSocketHandler : public CivetWebSocketHandler {
  124. public:
  125. // CONSTRUCTOR
  126. PrsonaClientWebSocketHandler(
  127. std::default_random_engine& rng,
  128. PrsonaClient *prsonaClient,
  129. const std::vector<std::string>& serverIPs,
  130. const std::vector<int>& serverPorts);
  131. // REQUIRED BY INHERITED CLASS
  132. virtual bool handleConnection(
  133. CivetServer *server,
  134. const struct mg_connection *conn);
  135. virtual void handleReadyState(
  136. CivetServer *server,
  137. struct mg_connection *conn);
  138. virtual bool handleData(
  139. CivetServer *server,
  140. struct mg_connection *conn,
  141. int bits,
  142. char *data,
  143. size_t data_len);
  144. virtual void handleClose(
  145. CivetServer *server,
  146. const struct mg_connection *conn);
  147. private:
  148. std::default_random_engine &rng;
  149. PrsonaClient *prsonaClient;
  150. const std::vector<std::string> serverIPs;
  151. const std::vector<int> serverPorts;
  152. // RESPONSE ROUTER FUNCTION
  153. void generate_response(
  154. struct mg_connection *conn,
  155. const char *filename);
  156. // REPUTATION PROOF RESPONSE
  157. void verify_reputation_proof(
  158. struct mg_connection *conn,
  159. const char *filename);
  160. };
  161. #endif