edits
[iotcloud.git] / version2 / src / C / CloudComm.cc
index 97a96c25520f51376ef67edbfea1e977ba231737..452317f42335854743b9e95cb3d1f81bc62e8858 100644 (file)
@@ -124,7 +124,7 @@ void CloudComm::setSalt() {
                }
 
 
-               URLurl = new URL(baseurl + "?req=setsalt");
+               URL *url = new URL(baseurl + "?req=setsalt");
 
                timer->startTime();
                URLConnection con = url->openConnection();
@@ -138,7 +138,7 @@ void CloudComm::setSalt() {
 
                http->connect();
 
-               OutputStreamos = http->getOutputStream();
+               OutputStream *os = http->getOutputStream();
                os->write(saltTmp);
                os->flush();
 
@@ -200,9 +200,9 @@ bool CloudComm::getSalt() {
 
                InputStream is = http->getInputStream();
                if (is->available() > 0) {
-                       DataInputStreamdis = new DataInputStream(is);
+                       DataInputStream *dis = new DataInputStream(is);
                        int salt_length = dis->readInt();
-                       Array<char> * tmp = new Array<char>(salt_length);
+                       Array<char> *tmp = new Array<char>(salt_length);
                        dis->readFully(tmp);
                        salt = tmp;
                        timer->endTime();
@@ -257,9 +257,9 @@ Array<char> *CloudComm::stripIVAndDecryptSlot(Array<char> *rawData) {
                System_arraycopy(rawData, 0, ivBytes, 0, CloudComm_IV_SIZE);
                System_arraycopy(rawData, CloudComm_IV_SIZE, encryptedBytes, 0, encryptedBytes->length);
 
-               IvParameterSpecivSpec = new IvParameterSpec(ivBytes);
+               IvParameterSpec *ivSpec = new IvParameterSpec(ivBytes);
 
-               Ciphercipher = Cipher_getInstance("AES/CTR/NoPadding");
+               Cipher *cipher = Cipher_getInstance("AES/CTR/NoPadding");
                cipher->init(Cipher_DECRYPT_MODE, key, ivSpec);
                return cipher->doFinal(encryptedBytes);
 
@@ -291,8 +291,8 @@ Array<Slot *> *CloudComm::putSlot(Slot *slot, int max) {
                URL *url = buildRequest(true, sequencenumber, max);
 
                timer->startTime();
-               URLConnection * con = url->openConnection();
-               HttpURLConnection * http = (HttpURLConnection *) con;
+               URLConnection *con = url->openConnection();
+               HttpURLConnection *http = (HttpURLConnection *) con;
 
                http->setRequestMethod("POST");
                http->setFixedLengthStreamingMode(chars->length);
@@ -301,7 +301,7 @@ Array<Slot *> *CloudComm::putSlot(Slot *slot, int max) {
                http->setReadTimeout(CloudComm_TIMEOUT_MILLIS);
                http->connect();
 
-               OutputStream * os = http->getOutputStream();
+               OutputStream *os = http->getOutputStream();
                os->write(chars);
                os->flush();
 
@@ -325,8 +325,8 @@ Array<Slot *> *CloudComm::putSlot(Slot *slot, int max) {
        try {
                timer->startTime();
                InputStream is = http->getInputStream();
-               DataInputStream * dis = new DataInputStream(is);
-               Array<char> *resptype = new char[7];
+               DataInputStream *dis = new DataInputStream(is);
+               Array<char> *resptype = new Array<char>(7);
                dis->readFully(resptype);
                timer->endTime();
 
@@ -412,26 +412,17 @@ Array<Slot *> *CloudComm::getSlots(int64_t sequencenumber) {
  */
 Array<Slot *> *CloudComm::processSlots(DataInputStream *dis) {
        int numberofslots = dis->readInt();
-       Array<int> * sizesofslots = new Array<int>(numberofslots);
+       Array<int> *sizesofslots = new Array<int>(numberofslots);
 
-       Array<Slot*> * slots = new Array<Slot*>(numberofslots);
+       Array<Slot *> *slots = new Array<Slot *>(numberofslots);
        for (int i = 0; i < numberofslots; i++)
-               sizesofslots->set(i], dis->readInt());
+               sizesofslots->set(i, dis->readInt());
 
        for (int i = 0; i < numberofslots; i++) {
-
                Array<char> *rawData = new Array<char>(sizesofslots->get(i));
                dis->readFully(rawData);
 
-
-               // Array<char> * data = new char[rawData.length - IV_SIZE];
-               // System.arraycopy(rawData, IV_SIZE, data, 0, data.length);
-
-
                Array<char> *data = stripIVAndDecryptSlot(rawData);
-
-               // data = decryptCipher.doFinal(data);
-               
                slots->set(i, Slot_decode(table, data, mac));
        }
        dis->close();
@@ -443,23 +434,23 @@ Array<char> *sendLocalData(Array<char> *sendData, int64_t localSequenceNumber, S
                return NULL;
        }
        try {
-               printf("Passing Locally"\m);
+               printf("Passing Locally\n");
 
                mac->update(sendData);
                Array<char> *genmac = mac->doFinal();
                Array<char> *totalData = new Array<char>(sendData->length() + genmac->length());
                System_arraycopy(sendData, 0, totalData, 0, sendData.length());
-               System-arraycopy(genmac, 0, totalData, sendData.length, genmac->length());
+               System - arraycopy(genmac, 0, totalData, sendData.length, genmac->length());
 
                // Encrypt the data for sending
                Array<char> *iv = createIV(table->getMachineId(), table->getLocalSequenceNumber());
                Array<char> *encryptedData = encryptSlotAndPrependIV(totalData, iv);
 
                // Open a TCP socket connection to a local device
-               Socketsocket = new Socket(host, port);
+               Socket *socket = new Socket(host, port);
                socket->setReuseAddress(true);
-               DataOutputStreamoutput = new DataOutputStream(socket->getOutputStream());
-               DataInputStreaminput = new DataInputStream(socket->getInputStream());
+               DataOutputStream *output = new DataOutputStream(socket->getOutputStream());
+               DataInputStream *input = new DataInputStream(socket->getInputStream());
 
                timer->startTime();
                // Send data to output (length of data, the data)