123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- #ifndef __PRSONA_NETWORKING_HPP
- #define __PRSONA_NETWORKING_HPP
- #include <mutex>
- #include <condition_variable>
- #include <string>
- #include "CivetServer.h"
- #define MG_WEBSOCKET_OPCODE_DATACOMPLETE 0xb
- #define PRSONA_PORT_STR "8080"
- #define USE_SSL 0
- #define EXIT_URI "/exit"
- #define SERVER_READY_URI "/init"
- #define EPOCH_READY_URI "/ready"
- #define TRIGGER_EPOCH_URI "/epoch"
- #define TRIGGER_VOTE_URI "/vote"
- #define TRIGGER_REP_URI "/rep"
- #define WHICH_EPOCH_URI "/which"
- #define UPDATE_LOCK_URI "/lock"
- #define UPDATE_UNLOCK_URI "/unlock"
- #define ADD_USER_URI "/ws?a"
- #define GIVE_NEW_VOTE_URI "/ws?b"
- #define PUBLIC_BGN_URI "/ws?c"
- #define NUM_CLIENTS_URI "/ws?d"
- #define VOTES_BY_URI "/ws?f"
- #define VOTE_MATRIX_URI "/ws?g"
- #define USER_TALLY_URI "/ws?h"
- #define SERVER_TALLY_URI "/ws?i"
- #define PSEUDONYMS_URI "/ws?j"
- #define VOTES_BY_COMMIT_URI "/ws?k"
- #define VOTE_MATRIX_COMMIT_URI "/ws?l"
- #define USER_TALLY_COMMIT_URI "/ws?m"
- #define SERVER_TALLY_COMMIT_URI "/ws?n"
- #define PSEUDONYMS_COMMIT_URI "/ws?o"
- #define PRIVATE_BGN_URI "/ws?p"
- #define GET_FRESH_GEN_URI "/ws?q"
- #define GIVE_FRESH_GEN_URI "/ws?r"
- #define GET_BLIND_GEN_URI "/ws?s"
- #define GIVE_BLIND_GEN_URI "/ws?t"
- #define EPOCH_BUILD_UP_URI "/ws?u"
- #define EPOCH_BREAK_DOWN_URI "/ws?v"
- #define ACCEPT_EPOCH_UPDATES_URI "/ws?w"
- #define GIVE_NEW_USER_URI "/ws?x"
- #define GET_DECRYPTION_URI "/ws?y"
- #define GIVE_DECRYPTION_URI "/ws?z"
- #define FRESH_GEN_URI "/ws?-"
- #define BLIND_GEN_URI "/ws?_"
- #define REP_PROOF_URI "/ws?d"
- #define TMP_FILE_SIZE 12
- #define TMP_DIR "./tmp/"
- #define TMP_DIR_SIZE 6
- 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;
- };
- std::string random_string(std::default_random_engine& generator, size_t length);
- char *set_temp_filename(std::default_random_engine& generator, struct mg_connection *conn);
- class RemoteControlHandler : public CivetHandler
- {
- public:
- RemoteControlHandler(struct synchronization_tool *sync)
- : sync(sync)
- { /* */ }
- RemoteControlHandler(struct synchronization_tool *sync,
- const std::string& message)
- : sync(sync), message(message)
- { /* */ }
- bool handleGet(CivetServer *server, struct mg_connection *conn);
- private:
- struct synchronization_tool *sync;
- const std::string message;
- };
- class AltRemoteControlHandler : public CivetHandler
- {
- public:
- AltRemoteControlHandler(size_t value, struct synchronization_tool *sync)
- : value(value), sync(sync)
- { /* */ }
- AltRemoteControlHandler(size_t value,
- struct synchronization_tool *sync,
- const std::string& message)
- : value(value), sync(sync), message(message)
- { /* */ }
- bool handleGet(CivetServer *server, struct mg_connection *conn);
- std::string getQuery() const;
- private:
- const size_t value;
- struct synchronization_tool *sync;
- const std::string message;
- std::string query;
- };
- int empty_websocket_data_handler(
- struct mg_connection *conn,
- int bits,
- char *data,
- size_t data_len,
- void *user_data);
- void empty_websocket_close_handler(
- const struct mg_connection *conn,
- void *user_data);
- int synchro_websocket_data_handler(
- struct mg_connection *conn,
- int bits,
- char *data,
- size_t data_len,
- void *user_data);
- void synchro_websocket_close_handler(
- const struct mg_connection *conn,
- void *user_data);
- int file_websocket_data_handler(
- struct mg_connection *conn,
- int bits,
- char *data,
- size_t data_len,
- void *user_data);
- void file_websocket_close_handler(
- const struct mg_connection *conn,
- void *user_data);
- #endif
|