7 * This class provides a communication API to the webserver. It also
8 * validates the HMACs on the slots and handles encryption.
9 * @author Brian Demsky <bdemsky@uci.edu>
13 #define CloudComm_SALT_SIZE 8
14 #define CloudComm_TIMEOUT_MILLIS 5000
16 #define CloudComm_IV_SIZE 16
17 /** Sets the size for the HMAC. */
18 #define CloudComm_HMAC_SIZE 32
19 #define HttpURLConnection_HTTP_OK 200
31 int32_t listeningPort;
32 pthread_t localServerThread;
34 TimingSingleton *timer;
39 * Generates Key from password.
44 * Inits the HMAC generator.
49 * Builds the URL for the given request.
51 IoTString *buildRequest(bool isput, int64_t sequencenumber, int64_t maxentries);
54 Array<char> *createIV(int64_t machineId, int64_t localSequenceNumber);
55 Array<char> *encryptSlotAndPrependIV(Array<char> *rawData, Array<char> *ivBytes);
56 Array<char> *stripIVAndDecryptSlot(Array<char> *rawData);
57 Array<Slot *> *processSlots(int fd);
62 * Empty Constructor needed for child class.
67 * Constructor for actual use. Takes in the url and password.
69 CloudComm(Table *_table, IoTString *_baseurl, IoTString *_password, int _listeningPort);
72 * Inits all the security stuff
77 * API for putting a slot into the queue. Returns NULL on success.
78 * On failure, the server will send slots with newer sequence
81 Array<Slot *> *putSlot(Slot *slot, int max);
84 * Request the server to send all slots with the given
85 * sequencenumber or newer.
87 Array<Slot *> *getSlots(int64_t sequencenumber);
91 * Method that actually handles building Slot objects from the
92 * server response. Shared by both putSlot and getSlots.
95 Array<char> *sendLocalData(Array<char> *sendData, int64_t localSequenceNumber, IoTString *host, int port);
97 void localServerWorkerFunction();