networkClient.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. // #define BGN_TMP_FILE (TMP_DIR "bgn")
  9. // #define GEN_TMP_FILE (TMP_DIR "generator")
  10. // #define EPOCH_GEN_TMP_FILE (TMP_DIR "epoch")
  11. class PrsonaClientWebSocketHandler : public CivetWebSocketHandler {
  12. public:
  13. // CONSTRUCTORS
  14. PrsonaClientWebSocketHandler(
  15. PrsonaClient *prsonaClient,
  16. const std::vector<std::string>& serverIPs,
  17. const std::vector<int>& serverPorts,
  18. std::default_random_engine *generator);
  19. virtual bool handleConnection(
  20. CivetServer *server,
  21. const struct mg_connection *conn);
  22. virtual void handleReadyState(
  23. CivetServer *server,
  24. struct mg_connection *conn);
  25. virtual bool handleData(
  26. CivetServer *server,
  27. struct mg_connection *conn,
  28. int bits,
  29. char *data,
  30. size_t data_len);
  31. virtual void handleClose(
  32. CivetServer *server,
  33. const struct mg_connection *conn);
  34. private:
  35. PrsonaClient *prsonaClient;
  36. const std::vector<std::string> serverIPs;
  37. const std::vector<int> serverPorts;
  38. std::default_random_engine *generator;
  39. void generate_response(
  40. struct mg_connection *conn,
  41. const char *filename) const;
  42. void verify_reputation_proof(
  43. struct mg_connection *conn,
  44. const char *filename) const;
  45. };
  46. template <typename T>
  47. T get_committed_val_from_file(
  48. struct synchronization_tool *sync,
  49. const char *filename,
  50. Proof& pi);
  51. template <typename T>
  52. T get_first_committed_val(
  53. std::default_random_engine *rng,
  54. const std::string& server,
  55. int serverPort,
  56. Proof& pi,
  57. const Twistpoint& shortTermPublicKey,
  58. const char *firstUri);
  59. Proof get_commitment_from_file(
  60. struct synchronization_tool *sync,
  61. char *filename);
  62. void get_additional_commitment(
  63. std::default_random_engine *rng,
  64. const std::vector<std::string>& serverIPs,
  65. const std::vector<int>& serverPorts,
  66. const std::string& skipIP,
  67. int skipPort,
  68. std::vector<Proof>& pi,
  69. const Twistpoint& shortTermPublicKey,
  70. char *which);
  71. template <typename T>
  72. T get_server_committed_val(
  73. std::default_random_engine *generator,
  74. const std::vector<std::string>& serverIPs,
  75. const std::vector<int>& serverPorts,
  76. std::vector<Proof>& pi,
  77. const Twistpoint& shortTermPublicKey,
  78. const char *firstUri,
  79. const char *commitUri);
  80. Twistpoint get_generator_from_file(
  81. struct synchronization_tool *sync,
  82. const char *filename,
  83. std::vector<Proof>& pi);
  84. Twistpoint get_generator(
  85. std::default_random_engine *randomGenerator,
  86. const std::vector<std::string>& serverIPs,
  87. const std::vector<int>& serverPorts,
  88. std::vector<Proof>& pi,
  89. bool fresh);
  90. #endif