#define CLOUDCOMM_H
#include "common.h"
-
+#include <pthread.h>
/**
* This class provides a communication API to the webserver. It also
* validates the HMACs on the slots and handles encryption.
#define CloudComm_IV_SIZE 16
/** Sets the size for the HMAC. */
#define CloudComm_HMAC_SIZE 32
+#define HttpURLConnection_HTTP_OK 200
+
+typedef struct {
+ int fd;
+ int numBytes;
+} WebConnection;
+
class CloudComm {
private:
IoTString *baseurl;
- SecretKeySpec *key;
+ AESKey *key;
Mac *mac;
IoTString *password;
SecureRandom *random;
Array<char> *salt;
Table *table;
int32_t listeningPort;
- Thread *localServerThread;
+ pthread_t localServerThread;
bool doEnd;
TimingSingleton *timer;
+ Array<char> *getslot;
+ Array<char> *putslot;
/**
* Generates Key from password.
*/
- SecretKeySpec *initKey();
+ AESKey *initKey();
/**
* Inits the HMAC generator.
/*
* Builds the URL for the given request.
*/
- URL buildRequest(bool isput, int64_t sequencenumber, int64_t maxentries);
+ IoTString *buildRequest(bool isput, int64_t sequencenumber, int64_t maxentries);
void setSalt();
bool getSalt();
Array<char> *createIV(int64_t machineId, int64_t localSequenceNumber);
Array<char> *encryptSlotAndPrependIV(Array<char> *rawData, Array<char> *ivBytes);
Array<char> *stripIVAndDecryptSlot(Array<char> *rawData);
- Array<Slot *> *processSlots(DataInputStream dis);
- void localServerWorkerFunction();
+ Array<Slot *> *processSlots(WebConnection *wc);
+
public:
/**
* Constructor for actual use. Takes in the url and password.
*/
CloudComm(Table *_table, IoTString *_baseurl, IoTString *_password, int _listeningPort);
+ ~CloudComm();
/**
* Inits all the security stuff
*/
Array<char> *sendLocalData(Array<char> *sendData, int64_t localSequenceNumber, IoTString *host, int port);
- void close();
+ void closeCloud();
+ void localServerWorkerFunction();
};
#endif