123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- #ifndef __PRSONA_NETWORK_SERVER_HPP
- #define __PRSONA_NETWORK_SERVER_HPP
- #include <string>
- #include <sstream>
- #include <cstring>
- #include <cstdio>
- #include "server.hpp"
- #include "CivetServer.h"
- #define MG_WEBSOCKET_OPCODE_DATACOMPLETE 0xb
- #define UPDATE_LOCK_URI "/lock"
- #define UPDATE_UNLOCK_URI "/unlock"
- #define GIVE_NEW_VOTE_URI "/ws?b"
- #define ACCEPT_EPOCH_UPDATES_URI "/ws?w"
- #define GIVE_NEW_USER_URI "/ws?x"
- #define PRSONA_PORT 8080
- #define USE_SSL 0
- enum RequestType {
- PRSONA_ADD_CLIENT = 'a',
- PRSONA_RECEIVE_VOTE,
- PRSONA_GET_BGN_PUBKEY,
- PRSONA_GET_NUM_CLIENTS,
- PRSONA_GET_NUM_SERVERS,
- PRSONA_GET_VOTES_BY,
- PRSONA_GET_ALL_VOTES,
- PRSONA_GET_USER_TALLY,
- PRSONA_GET_SERVER_TALLY,
- PRSONA_GET_PSEUDONYMS,
- PRSONA_GET_VOTE_ROW_COMMITMENT,
- PRSONA_GET_VOTE_MATRIX_COMMITMENT,
- PRSONA_GET_USER_TALLY_COMMITMENT,
- PRSONA_GET_SERVER_TALLY_COMMITMENT,
- PRSONA_GET_PSEUDONYMS_COMMITMENT,
- PRSONA_GET_BGN_DETAILS,
- PRSONA_ADD_CURR_SEED_TO_GENERATOR,
- PRSONA_SET_FRESH_GENERATOR,
- PRSONA_ADD_RAND_SEED_TO_GENERATOR,
- PRSONA_SET_EG_BLIND_GENERATOR,
- PRSONA_EPOCH_BUILD_UP,
- PRSONA_EPOCH_BREAK_DOWN,
- PRSONA_EPOCH_UPDATE,
- PRSONA_NEW_USER_UPDATE,
- PRSONA_GET_PARTIAL_DECRYPTION,
- PRSONA_RECEIVE_PARTIAL_DECRYPTION,
- PRSONA_GET_FRESH_GENERATOR = '-',
- PRSONA_GET_EG_BLIND_GENERATOR ='_',
- PRSONA_RECEIVE_FRESH_GENERATOR = 'a',
- PRSONA_RECEIVE_VOTE_TALLY,
- PRSONA_RECEIVE_NEW_USER_DATA,
- PRSONA_VERIFY_REPUTATION_PROOF
- };
- struct synchronization_tool {
- std::mutex mtx;
- std::condition_variable cv;
- size_t val, val2;
- };
- static int synchro_websocket_data_handler(
- struct mg_connection *conn,
- int bits,
- char *data,
- size_t data_len,
- void *user_data);
- static void synchro_websocket_close_handler(
- const struct mg_connection *conn,
- void *user_data);
- static int empty_websocket_data_handler(
- struct mg_connection *conn,
- int bits,
- char *data,
- size_t data_len,
- void *user_data)
- { return false; }
- static void empty_websocket_close_handler(
- const struct mg_connection *conn,
- void *user_data)
- { /* */ }
- void obtain_update_locks(
- std::unique_lock<std::mutex> &lck,
- const std::vector<std::string>& serverIPs,
- const std::string& selfIP,
- struct synchronization_tool *synch);
- void release_update_locks(
- std::unique_lock<std::mutex> &lck,
- const std::vector<std::string>& serverIPs,
- const std::string& selfIP,
- struct synchronization_tool *synch);
- std::string make_epoch_initiator_string(
- std::vector<Proof> generatorProof,
- Twistpoint nextGenerator);
- std::string make_epoch_update_string(
- std::vector<std::vector<Proof>> pi,
- std::vector<std::vector<Twistpoint>> permutationCommits,
- std::vector<std::vector<Twistpoint>> freshPseudonymCommits,
- std::vector<std::vector<Twistpoint>> freshPseudonymSeedCommits,
- std::vector<std::vector<CurveBipoint>> serverTallyCommits,
- std::vector<std::vector<std::vector<TwistBipoint>>> partwayVoteMatrixCommits,
- std::vector<std::vector<std::vector<TwistBipoint>>> finalVoteMatrixCommits,
- std::vector<std::vector<Twistpoint>> userTallyMaskCommits,
- std::vector<std::vector<Twistpoint>> userTallyMessageCommits,
- std::vector<std::vector<Twistpoint>> userTallySeedCommits,
- Twistpoint nextGenerator,
- bool doUserTallies);
- class PrsonaServerWebSocketHandler : public CivetWebSocketHandler {
- public:
- // CONSTRUCTORS
- PrsonaServerWebSocketHandler(
- const PrsonaServer *prsonaServer,
- const std::mutex *updateMtx,
- const std::vector<std::string> serverIPs,
- const std::string selfIP);
- virtual bool handleConnection(
- CivetServer *server,
- const struct mg_connection *conn);
- virtual void handleReadyState(
- CivetServer *server,
- struct mg_connection *conn);
- virtual bool handleData(
- CivetServer *server,
- struct mg_connection *conn,
- int bits,
- char *data,
- size_t data_len);
- virtual void handleClose(
- CivetServer *server,
- const struct mg_connection *conn);
- private:
- const PrsonaServer *prsonaServer;
- const std::mutex *updateMtx;
- const size_t *epochNum;
- const std::vector<std::string> serverIPs;
- const std::string selfIP;
- struct synchronization_tool updateSynch, distributeSynch;
- // BASIC PUBLIC SYSTEM INFO GETTERS
- void get_bgn_public_key(struct mg_connection *c) const;
- void get_num_clients(struct mg_connection *c) const;
- void get_num_servers(struct mg_connection *c) const;
- // ENCRYPTED DATA GETTERS
- void get_current_votes_by(struct mg_connection *c) const;
- void get_all_current_votes(struct mg_connection *c) const;
- void get_current_user_encrypted_tally(struct mg_connection *c) const;
- void get_current_server_encrypted_tally(struct mg_connection *c) const;
- void get_current_pseudonyms(struct mg_connection *c) const;
- // PROOF COMMITMENT GETTERS
- void get_vote_row_commitment(struct mg_connection *c) const;
- void get_vote_matrix_commitment(struct mg_connection *c) const;
- void get_user_tally_commitment(struct mg_connection *c) const;
- void get_server_tally_commitment(struct mg_connection *c) const;
- void get_pseudonyms_commitment(struct mg_connection *c) const;
- // CLIENT INTERACTIONS
- void add_new_client(struct mg_connection *c);
- void receive_vote(struct mg_connection *c);
- // CONSTRUCTOR HELPERS
- void get_bgn_details(struct mg_connection *c) const;
- void initialize_fresh_generator(struct mg_connection *c);
- void add_rand_seed_to_generator(struct mg_connection *c) const;
- void set_EG_blind_generator(struct mg_connection *c);
- // EPOCH ROUNDS
- void build_up_midway_pseudonyms(struct mg_connection *c);
- void break_down_midway_pseudonyms(struct mg_connection *c);
- void accept_epoch_updates(struct mg_connection *c);
- // DATA MAINTENANCE
- void import_new_user_update(struct mg_connection *c);
- };
- #endif
|