edits
[iotcloud.git] / version2 / src / C / CloudComm.h
index 0413ca0c18c827a65cc00925d222842aa30ca5cc..2f825083214a26608087b08b656d575c59004119 100644 (file)
@@ -2,7 +2,7 @@
 #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
+
 
 class CloudComm {
 private:
        IoTString *baseurl;
-       SecretKeySpec *key;
+       AESKey *key;
        Mac *mac;
        IoTString *password;
        SecureRandom *random;
        Array<char> *salt;
        Table *table;
-       int32_t listeningPort = -1;
-       Thread *localServerThread = NULL;
-       bool doEnd = false;
-       TimingSingleton *timer = NULL;
+       int32_t listeningPort;
+       pthread_t localServerThread;
+       bool doEnd;
+       TimingSingleton *timer;
 
        /**
         * Generates Key from password.
         */
-       SecretKeySpec *initKey();
+       AESKey *initKey();
 
        /**
         * Inits the HMAC generator.
@@ -44,14 +46,14 @@ private:
        /*
         * 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(int fd);
+
 
 public:
        /**
@@ -62,7 +64,7 @@ public:
        /**
         * Constructor for actual use. Takes in the url and password.
         */
-       CloudComm(Table* _table,  IoTString* _baseurl, IoTString* _password, int _listeningPort);
+       CloudComm(Table *_table,  IoTString *_baseurl, IoTString *_password, int _listeningPort);
 
        /**
         * Inits all the security stuff
@@ -74,7 +76,7 @@ public:
         * On failure, the server will send slots with newer sequence
         * numbers.
         */
-       Array<Slot *> *putSlot(Slotslot, int max);
+       Array<Slot *> *putSlot(Slot *slot, int max);
 
        /**
         * Request the server to send all slots with the given
@@ -88,7 +90,8 @@ public:
         * server response.  Shared by both putSlot and getSlots.
         */
 
-       Array<char> *sendLocalData(Array<char> *sendData, int64_t localSequenceNumber, IoTString* host, int port);
-       public void close();
+       Array<char> *sendLocalData(Array<char> *sendData, int64_t localSequenceNumber, IoTString *host, int port);
+       void close();
+       void localServerWorkerFunction();
 };
 #endif