123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- #ifndef __PRSONA_NETWORKING_HPP
- #define __PRSONA_NETWORKING_HPP
- #include <mutex>
- #include <condition_variable>
- #include "CivetServer.h"
- #define MG_WEBSOCKET_OPCODE_DATACOMPLETE 0xb
- #define PRSONA_PORT 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 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 USER_TALLY_URI "/ws?h"
- #define VOTES_BY_COMMIT_URI "/ws?k"
- #define USER_TALLY_COMMIT_URI "/ws?m"
- #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(size_t length);
- void set_temp_filename(struct mg_connection *conn) const;
- class RemoteControlHandler : public CivetHandler
- {
- public:
- ExitHandler(struct synchronization_tool *sync)
- : sync(sync)
- { /* */ }
- ExitHandler(struct synchronization_tool *sync,
- const std::string& message)
- : sync(sync), message(message)
- { /* */ }
- bool handleGet(CivetServer *server, struct mg_connection *conn);
- private:
- const struct synchronization_tool *sync;
- const std::string message;
- };
- class AltRemoteControlHandler : public CivetHandler
- {
- public:
- ExitHandler(size_t value, struct synchronization_tool *sync)
- : value(value), sync(sync)
- { /* */ }
- ExitHandler(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 query() const;
- private:
- const size_t value;
- const struct synchronization_tool *sync;
- const std::string message;
- std::string query;
- };
- 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)
- { /* */ }
- 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 file_websocket_data_handler(
- struct mg_connection *conn,
- int bits,
- char *data,
- size_t data_len,
- void *user_data);
- static void file_websocket_close_handler(
- const struct mg_connection *conn,
- void *user_data);
- #endif
|