5 #include "application.h"
9 * This class provides a communication API to the webserver. It also
10 * validates the HMACs on the slots and handles encryption.
11 * @author Brian Demsky <bdemsky@uci.edu>
15 #define CloudComm_SALT_SIZE 8
16 #define CloudComm_TIMEOUT_MILLIS 5000
18 #define CloudComm_IV_SIZE 16
19 /** Sets the size for the HMAC. */
20 #define CloudComm_HMAC_SIZE 32
21 #define HttpURLConnection_HTTP_OK 200
38 int32_t listeningPort;
39 // pthread_t localServerThread;
41 TimingSingleton *timer;
46 * Generates Key from password.
51 * Inits the HMAC generator.
56 * Builds the URL for the given request.
58 IoTString *buildRequest(bool isput, int64_t sequencenumber, int64_t maxentries);
61 Array<char> *createIV(int64_t machineId, int64_t localSequenceNumber);
62 Array<char> *encryptSlotAndPrependIV(Array<char> *rawData, Array<char> *ivBytes);
63 Array<char> *stripIVAndDecryptSlot(Array<char> *rawData);
64 Array<Slot *> *processSlots(WebConnection *wc);
69 * Empty Constructor needed for child class.
74 * Constructor for actual use. Takes in the url and password.
76 CloudComm(Table *_table, IoTString *_baseurl, IoTString *_password, int _listeningPort);
80 * Inits all the security stuff
85 * API for putting a slot into the queue. Returns NULL on success.
86 * On failure, the server will send slots with newer sequence
89 Array<Slot *> *putSlot(Slot *slot, int max);
92 * Request the server to send all slots with the given
93 * sequencenumber or newer.
95 Array<Slot *> *getSlots(int64_t sequencenumber);
99 * Method that actually handles building Slot objects from the
100 * server response. Shared by both putSlot and getSlots.
103 Array<char> *sendLocalData(Array<char> *sendData, int64_t localSequenceNumber, IoTString *host, int port);
105 void localServerWorkerFunction();