networkClient.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef __PRSONA_NETWORK_CLIENT_HPP
  2. #define __PRSONA_NETWORK_CLIENT_HPP
  3. #include <string>
  4. #include <sstream>
  5. #include <cstring>
  6. #include <cstdio>
  7. #include "client.hpp"
  8. #include "CivetServer.h"
  9. #define MG_WEBSOCKET_OPCODE_DATACOMPLETE 0xb
  10. #define PRSONA_PORT 8080
  11. #define USE_SSL 0
  12. #define USER_TALLY_URI "/ws?h"
  13. #define USER_TALLY_COMMIT_URI "/ws?m"
  14. enum RequestType {
  15. PRSONA_ADD_CLIENT = 'a',
  16. PRSONA_RECEIVE_VOTE,
  17. PRSONA_GET_BGN_PUBKEY,
  18. PRSONA_GET_NUM_CLIENTS,
  19. PRSONA_GET_NUM_SERVERS,
  20. PRSONA_GET_VOTES_BY,
  21. PRSONA_GET_ALL_VOTES,
  22. PRSONA_GET_USER_TALLY,
  23. PRSONA_GET_SERVER_TALLY,
  24. PRSONA_GET_PSEUDONYMS,
  25. PRSONA_GET_VOTE_ROW_COMMITMENT,
  26. PRSONA_GET_VOTE_MATRIX_COMMITMENT,
  27. PRSONA_GET_USER_TALLY_COMMITMENT,
  28. PRSONA_GET_SERVER_TALLY_COMMITMENT,
  29. PRSONA_GET_PSEUDONYMS_COMMITMENT,
  30. PRSONA_GET_BGN_DETAILS,
  31. PRSONA_ADD_CURR_SEED_TO_GENERATOR,
  32. PRSONA_SET_FRESH_GENERATOR,
  33. PRSONA_ADD_RAND_SEED_TO_GENERATOR,
  34. PRSONA_SET_EG_BLIND_GENERATOR,
  35. PRSONA_EPOCH_BUILD_UP,
  36. PRSONA_EPOCH_BREAK_DOWN,
  37. PRSONA_EPOCH_UPDATE,
  38. PRSONA_NEW_USER_UPDATE,
  39. PRSONA_GET_PARTIAL_DECRYPTION,
  40. PRSONA_RECEIVE_PARTIAL_DECRYPTION,
  41. PRSONA_GET_FRESH_GENERATOR = '-',
  42. PRSONA_GET_EG_BLIND_GENERATOR ='_',
  43. PRSONA_RECEIVE_FRESH_GENERATOR = 'a',
  44. PRSONA_RECEIVE_VOTE_TALLY,
  45. PRSONA_RECEIVE_NEW_USER_DATA,
  46. PRSONA_VERIFY_REPUTATION_PROOF
  47. };
  48. struct synchronization_tool {
  49. std::mutex mtx;
  50. std::condition_variable cv;
  51. size_t val, val2;
  52. };
  53. class PrsonaClientWebSocketHandler : public CivetWebSocketHandler {
  54. public:
  55. // CONSTRUCTORS
  56. PrsonaClientWebSocketHandler(
  57. const PrsonaClient *prsonaClient,
  58. const std::vector<std::string> serverIPs,
  59. const std::string selfIP);
  60. virtual bool handleConnection(
  61. CivetServer *server,
  62. const struct mg_connection *conn);
  63. virtual void handleReadyState(
  64. CivetServer *server,
  65. struct mg_connection *conn);
  66. virtual bool handleData(
  67. CivetServer *server,
  68. struct mg_connection *conn,
  69. int bits,
  70. char *data,
  71. size_t data_len);
  72. virtual void handleClose(
  73. CivetServer *server,
  74. const struct mg_connection *conn);
  75. private:
  76. const PrsonaClient *prsonaClient;
  77. const std::vector<std::string> serverIPs;
  78. const std::string selfIP;
  79. void verify_reputation_proof(struct mg_connection *c) const;
  80. }
  81. #endif