123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- #ifndef __PRSONA_NETWORK_CLIENT_HPP
- #define __PRSONA_NETWORK_CLIENT_HPP
- #include <string>
- #include <vector>
- #include <random>
- #include "client.hpp"
- #include "networking.hpp"
- enum EventType {
- CLIENT_MAKE_VOTE = 1,
- CLIENT_MAKE_REP_PROOF
- };
- /* "PUBLIC" FUNCTIONS */
- // CREATOR FOR A NEW CLIENT
- PrsonaClient *create_client(
- std::default_random_engine& rng,
- const std::vector<std::string>& serverIPs,
- const std::vector<int>& serverPorts,
- size_t numServers);
- // FUNCTIONS TO PERFORM OPERATIONS FOR EXPERIMENT
- void make_vote(
- std::default_random_engine& rng,
- PrsonaClient* prsonaClient,
- const std::vector<std::string>& serverIPs,
- const std::vector<int>& serverPorts,
- const std::string& target,
- int targetPort,
- size_t numClients,
- const CivetServer& civetServer,
- std::mutex& outputMtx,
- const std::string& outputFilename,
- std::mutex& usageMtx,
- const std::string& usageFilename);
- bool make_reputation_proof(
- std::default_random_engine& rng,
- PrsonaClient* prsonaClient,
- const std::vector<std::string>& serverIPs,
- const std::vector<int>& serverPorts,
- const std::string& target,
- int targetPort,
- size_t numClients,
- const CivetServer& civetServer,
- std::mutex& outputMtx,
- const std::string& outputFilename,
- std::mutex& usageMtx,
- const std::string& usageFilename);
- /* "PRIVATE" FUNCTIONS */
- // HELPERS TO ADD THIS CLIENT TO SERVERS
- void register_new_client(
- std::default_random_engine& rng,
- PrsonaClient *newUser,
- const std::vector<std::string>& serverIPs,
- const std::vector<int>& serverPorts,
- const Proof& proofOfValidSTPK,
- const Twistpoint& shortTermPublicKey);
- void verify_valid_addition(
- std::default_random_engine& rng,
- PrsonaClient *newUser,
- const std::vector<std::string>& serverIPs,
- const std::vector<int>& serverPorts,
- const std::vector<Proof>& proofOfValidAddition,
- const Twistpoint& shortTermPublicKey);
- // GETTERS FOR VARIOUS SERVER VALUES
- Twistpoint get_generator(
- std::default_random_engine& rng,
- const std::vector<std::string>& serverIPs,
- const std::vector<int>& serverPorts,
- bool fresh,
- std::vector<Proof>& pi,
- std::vector<size_t>& bandwidthData);
- BGNPublicKey get_bgn_public_key(
- std::default_random_engine& rng,
- const std::vector<std::string>& serverIPs,
- const std::vector<int>& serverPorts);
- template <typename T>
- T get_server_committed_val(
- std::default_random_engine& rng,
- const std::vector<std::string>& serverIPs,
- const std::vector<int>& serverPorts,
- const char *firstUri,
- const char *commitUri,
- std::vector<Proof>& pi,
- const Twistpoint& shortTermPublicKey,
- std::vector<size_t>& bandwidthData);
- // HELPERS FOR GENERALIZED GETTER FUNCTION
- template <typename T>
- T get_first_committed_val(
- std::default_random_engine& rng,
- const std::string& serverIP,
- int serverPort,
- const char *firstUri,
- Proof& pi,
- const Twistpoint& shortTermPublicKey,
- std::vector<size_t>& bandwidthData);
- void get_additional_commitment(
- std::default_random_engine& rng,
- const std::vector<std::string>& serverIPs,
- const std::vector<int>& serverPorts,
- const std::string& skipIP,
- int skipPort,
- const char *commitUri,
- std::vector<Proof>& pi,
- const Twistpoint& shortTermPublicKey,
- std::vector<size_t>& bandwidthData);
- // FILE I/O HELPERS FOR ALL GETTERS
- std::vector<Proof> get_valid_addition_proof_from_file(
- const char *filename);
- Twistpoint get_generator_from_file(
- const char *filename,
- std::vector<Proof>& pi);
- BGNPublicKey get_bgn_public_key_from_file(
- const char *filename);
- template <typename T>
- T get_committed_val_from_file(
- const char *filename,
- Proof& pi);
- Proof get_commitment_from_file(
- struct synchronization_tool *sync,
- const char *filename);
- // GENERALIZED SENDER FOR ORCHESTRATOR-SIGNALED OPERATIONS
- char *send_item(
- std::default_random_engine& rng,
- const std::string& target,
- int targetPort,
- const char* whichUri,
- const std::string& data,
- bool responseExpected,
- std::vector<size_t>& bandwidthData);
- // DATA SERIALIZERS
- std::string make_vote_string(
- const std::vector<Proof>& pi,
- const std::vector<TwistBipoint>& newVotes,
- const Twistpoint& shortTermPublicKey);
- std::string make_rep_proof_string(
- const std::vector<Proof>& pi,
- const Twistpoint& shortTermPublicKey,
- const Scalar& threshold);
- /* OTHER CLIENT-RELEVANT HANDLERS */
- // Used to tell orchestrator when the client is no longer doing a triggered task
- class ClientReadyHandler : public CivetHandler
- {
- public:
- ClientReadyHandler(
- struct synchronization_tool *exitSync);
- bool handleGet(
- CivetServer *server,
- struct mg_connection *conn);
- private:
- struct synchronization_tool *exitSync;
- };
- /* CLIENT-SPECIFIC HANDLER */
- class PrsonaClientWebSocketHandler : public CivetWebSocketHandler {
- public:
- // CONSTRUCTOR
- PrsonaClientWebSocketHandler(
- std::default_random_engine& rng,
- PrsonaClient *prsonaClient,
- const std::vector<std::string>& serverIPs,
- const std::vector<int>& serverPorts,
- std::mutex& outputMtx,
- const std::string& outputFilename,
- std::mutex& usageMtx,
- const std::string& usageFilename);
- // REQUIRED BY INHERITED CLASS
- 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:
- std::default_random_engine &rng;
-
- PrsonaClient *prsonaClient;
- const std::vector<std::string> serverIPs;
- const std::vector<int> serverPorts;
- std::mutex& outputMtx;
- const std::string outputFilename;
- std::mutex& usageMtx;
- const std::string usageFilename;
- // RESPONSE ROUTER FUNCTION
- void generate_response(
- CivetServer *server,
- struct mg_connection *conn,
- const char *filename);
- // REPUTATION PROOF RESPONSE
- void verify_reputation_proof(
- CivetServer *civetServer,
- struct mg_connection *conn,
- const char *filename);
- };
- #endif
|