typedef uint8_t token[TOKEN_SIZE]; typedef uint8_t aes_key[SGX_AESGCM_KEY_SIZE]; // #define VERBOSE_CLIENT #define RANDOMIZE_CLIENT_RETRY_SLEEP_TIME // #define CLIENT_UNIQUE_IP // #define SHOW_RECEIVED_MESSAGES // VERBOSE_CLIENT implies SHOW_RECEIVED_MESSAGES #ifdef VERBOSE_CLIENT #define SHOW_RECEIVED_MESSAGES #endif #define PORT_START 32769 #define PORT_END 60000 /* Client -> Ingestion Server (C->I) communication protocols: 1) Authentication Format: Client sim_id, Epoch number, Authentication token 2) Messages Format: IV, AESGCM([CM_1], [CM_2], ..., [CM_k]), TAG - each CM = Client Message for token channel has the format : 4-byte Sender ID, 4-byte Recipient ID, 16-byte Token, - bytes of message data where the Sender ID and Recipient ID are the TEEMS client id (and not sim_id) */ struct ip_addr { uint8_t ip1; uint8_t ip2; uint8_t ip3; uint8_t ip4; void increment(int nthreads) { ip4++; if(ip4==0) { ip3++; if(ip3==0) { ip2+=nthreads; } } } std::string ip_str() { return(std::to_string(ip1) + "." + std::to_string(ip2) + "." + std::to_string(ip3) + "." + std::to_string(ip4)); } }; /* Structure for capture each individual simulated client's state */ class Client { private: // Clients' have a simulator ID sim_id used for: // (i) the simulator to divvy up clients across threads // (ii) the simulator and ingestion servers to align simulated clients // and their pre-established shared-secrets clientid_t sim_id; // The actual client id used by TEEMS is id. // Format: the first DEST_STORAGE_NODE_BITS bits store the storage node // number and the userid at that storage node in the last DEST_UID_BITS clientid_t id; aes_key ing_key; aes_key stg_key; // Clients send encrypted messages to ingestion // so they set and increment the IV unsigned char ing_iv[SGX_AESGCM_IV_SIZE] = {0}; token *token_list; boost::asio::ip::tcp::socket *ingestion_sock = NULL; boost::asio::ip::tcp::socket *storage_sock = NULL; void generateAuthenticationMessage(); int sendIngAuthMessage(unsigned long epoch_no); int sendStgAuthMessage(unsigned long epoch_no); void generateMessageBundle(uint8_t token_out, uint32_t msg_size, unsigned char *pt_msgbundle); bool encryptMessageBundle(uint32_t bundle_size, unsigned char *pt_msgbundle, unsigned char* enc_msgbundle); void sendMessageBundle(); void initializeIngSocket(boost::asio::io_context &ioc, NodeConfig &ing_server, ip_addr *curr_ip, uint16_t &port_no); void initializeStgSocket(boost::asio::io_context &ioc, NodeConfig &ing_server, ip_addr *curr_ip, uint16_t &port_no); void initClient(clientid_t cid, uint16_t stg_id, aes_key ikey, aes_key skey); public: Client() {} ~Client() { free(token_list); delete(ingestion_sock); delete(storage_sock); } void setup_client(boost::asio::io_context &ioc, uint32_t sim_id, uint16_t ing_node_id, uint16_t stg_node_id, ip_addr *curr_ip, uint16_t &pno); void epoch_process(); };