123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- #ifndef __PRSONA_NETWORK_SERVER_HPP
- #define __PRSONA_NETWORK_SERVER_HPP
- #include <random>
- #include <string>
- #include <vector>
- #include <atomic>
- #include "server.hpp"
- #include "networking.hpp"
- void obtain_update_locks(
- std::unique_lock<std::mutex> &lck,
- const std::vector<std::string>& serverIPs,
- const std::vector<int>& serverPorts,
- const std::string& selfIP,
- int selfPort,
- struct synchronization_tool *synch);
- void release_update_locks(
- std::unique_lock<std::mutex> &lck,
- const std::vector<std::string>& serverIPs,
- const std::vector<int>& serverPorts,
- const std::string& selfIP,
- int selfPort,
- struct synchronization_tool *synch);
- std::string make_epoch_initiator_string(
- const std::vector<Proof>& generatorProof,
- const Twistpoint& nextGenerator);
- std::string make_epoch_update_string(
- const std::vector<std::vector<Proof>>& pi,
- const std::vector<std::vector<Twistpoint>>& permutationCommits,
- const std::vector<std::vector<Twistpoint>>& freshPseudonymCommits,
- const std::vector<std::vector<Twistpoint>>& freshPseudonymSeedCommits,
- const std::vector<std::vector<CurveBipoint>>& serverTallyCommits,
- const std::vector<std::vector<std::vector<TwistBipoint>>>& partwayVoteMatrixCommits,
- const std::vector<std::vector<std::vector<TwistBipoint>>>& finalVoteMatrixCommits,
- const std::vector<std::vector<Twistpoint>>& userTallyMaskCommits,
- const std::vector<std::vector<Twistpoint>>& userTallyMessageCommits,
- const std::vector<std::vector<Twistpoint>>& userTallySeedCommits,
- const Twistpoint& nextGenerator,
- bool doUserTallies);
- void distribute_epoch_updates(
- const std::string& recipient,
- int recipientPort,
- const std::string& data,
- const struct synchronization_tool* sync);
- class PrsonaServerWebSocketHandler : public CivetWebSocketHandler {
- public:
- // CONSTRUCTORS
- PrsonaServerWebSocketHandler(
- PrsonaServer *prsonaServer,
- std::default_random_engine *rng,
- std::mutex *updateMtx,
- std::atomic<size_t> *epochNum,
- const std::vector<std::string>& serverIPs,
- const std::vector<int>& serverPorts,
- const std::string& selfIP,
- int selfPort);
- 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:
- PrsonaServer *prsonaServer;
- std::default_random_engine *rng;
- std::mutex *updateMtx;
- std::atomic<size_t> *epochNum;
- const std::vector<std::string> serverIPs;
- const std::vector<int> serverPorts;
- const std::string selfIP;
- const int selfPort;
- struct synchronization_tool updateSynch, distributeSynch;
- void generate_response(
- struct mg_connection *conn,
- const char *filename);
- // 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 char *filename
- ) const;
- void get_all_current_votes(
- struct mg_connection *c
- ) const;
- void get_current_user_encrypted_tally(
- struct mg_connection *c,
- const char *filename
- ) const;
- void get_current_server_encrypted_tally(
- struct mg_connection *c,
- const char *filename
- ) const;
- void get_current_pseudonyms(
- struct mg_connection *c
- ) const;
- // PROOF COMMITMENT GETTERS
- void get_vote_row_commitment(
- struct mg_connection *c,
- const char *filename
- ) const;
- void get_vote_matrix_commitment(
- struct mg_connection *c
- ) const;
- void get_user_tally_commitment(
- struct mg_connection *c,
- const char *filename
- ) const;
- void get_server_tally_commitment(
- struct mg_connection *c,
- const char *filename
- ) const;
- void get_pseudonyms_commitment(
- struct mg_connection *c
- ) const;
- // CLIENT INTERACTIONS
- void add_new_client(
- struct mg_connection *c,
- const char *filename
- );
- void receive_vote(
- struct mg_connection *c,
- const char *filename
- );
- // CONSTRUCTOR HELPERS
- void get_bgn_details(struct mg_connection *c) const;
- void add_seed_to_generator(
- struct mg_connection *conn,
- const char *filename,
- bool fresh
- ) const;
- void set_generator(
- const char *filename,
- bool fresh
- );
- // EPOCH ROUNDS
- void build_up_midway_pseudonyms(
- struct mg_connection *c,
- const char *filename
- );
- void break_down_midway_pseudonyms(
- struct mg_connection *c,
- const char *filename
- );
- void accept_epoch_updates(
- struct mg_connection *c,
- const char *filename
- );
- // DATA MAINTENANCE
- void import_new_user_update(
- const char *filename
- );
- void distribute_new_user_updates(
- std::vector<Proof> proofOfValidAddition,
- std::vector<CurveBipoint> previousVoteTallies,
- std::vector<Twistpoint> currentPseudonyms,
- std::vector<EGCiphertext> currentUserEncryptedTallies,
- std::vector<std::vector<TwistBipoint>> voteMatrix
- ) const;
- void distribute_new_vote(
- std::vector<Proof> pi,
- std::vector<TwistBipoint> newVotes,
- Twistpoint shortTermPublicKey
- ) const;
- void get_partial_decryption(
- struct mg_connection *conn
- ) const;
- void receive_tallied_scores(
- struct mg_connection *conn,
- const char *filename
- );
- void get_generator(
- struct mg_connection *conn,
- bool fresh
- );
- };
- #endif
|