edits
authorbdemsky <bdemsky@uci.edu>
Sat, 20 Jan 2018 07:40:24 +0000 (23:40 -0800)
committerbdemsky <bdemsky@uci.edu>
Sat, 20 Jan 2018 07:40:24 +0000 (23:40 -0800)
version2/src/C/CloudComm.cc
version2/src/C/PendingTransaction.cc
version2/src/C/Slot.cc
version2/src/C/Slot.h
version2/src/C/common.h

index 9a15732711360236be62ab804f7a695ed88106b3..54b92da7569ffc383114c986660a4e8fd0a6cfc8 100644 (file)
@@ -4,6 +4,7 @@
 #include "IoTString.h"
 #include "Error.h"
 #include "URL.h"
 #include "IoTString.h"
 #include "Error.h"
 #include "URL.h"
+#include "Mac.h"
 
 /**
  * Empty Constructor needed for child class.
 
 /**
  * Empty Constructor needed for child class.
index 088238e93aa4d9610a2dc44beb8742aa3b1880d0..be7575f7e9aac70bf87ba2f0108408f411b1d0ee 100644 (file)
@@ -14,12 +14,16 @@ PendingTransaction::PendingTransaction(int64_t _machineId) :
        currentDataSize(0) {
 }
 
        currentDataSize(0) {
 }
 
+PendingTransaction::~PendingTransaction() {
+       delete keyValueUpdateSet;
+       delete keyValueGuardSet;
+}
+
 /**
  * Add a new key value to the updates
  *
  */
 void PendingTransaction::addKV(KeyValue *newKV) {
 /**
  * Add a new key value to the updates
  *
  */
 void PendingTransaction::addKV(KeyValue *newKV) {
-
        KeyValue *rmKV = NULL;
 
        // Make sure there are no duplicates
        KeyValue *rmKV = NULL;
 
        // Make sure there are no duplicates
@@ -27,7 +31,6 @@ void PendingTransaction::addKV(KeyValue *newKV) {
        while (kvit->hasNext()) {
                KeyValue *kv = kvit->next();
                if (kv->getKey()->equals(newKV->getKey())) {
        while (kvit->hasNext()) {
                KeyValue *kv = kvit->next();
                if (kv->getKey()->equals(newKV->getKey())) {
-
                        // Remove key if we are adding a newer version of the same key
                        rmKV = kv;
                        break;
                        // Remove key if we are adding a newer version of the same key
                        rmKV = kv;
                        break;
@@ -64,7 +67,6 @@ bool PendingTransaction::checkArbitrator(int64_t arb) {
                arbitrator = arb;
                return true;
        }
                arbitrator = arb;
                return true;
        }
-
        return arb == arbitrator;
 }
 
        return arb == arbitrator;
 }
 
@@ -72,21 +74,21 @@ bool PendingTransaction::evaluateGuard(Hashtable<IoTString *, KeyValue *> *keyVa
        SetIterator<KeyValue *> *kvit = keyValueGuardSet->iterator();
        while (kvit->hasNext()) {
                KeyValue *kvGuard = kvit->next();
        SetIterator<KeyValue *> *kvit = keyValueGuardSet->iterator();
        while (kvit->hasNext()) {
                KeyValue *kvGuard = kvit->next();
-
-               // First check if the key is in the speculative table, this is the value of the latest assumption
+               // First check if the key is in the speculative table, this is the
+               // value of the latest assumption
                KeyValue *kv = keyValTablePendingTransSpeculative->get(kvGuard->getKey());
 
 
                if (kv == NULL) {
                KeyValue *kv = keyValTablePendingTransSpeculative->get(kvGuard->getKey());
 
 
                if (kv == NULL) {
-                       // if it is not in the pending trans table then check the speculative table and use that
-                       // value as our latest assumption
+                       // if it is not in the pending trans table then check the
+                       // speculative table and use that value as our latest assumption
                        kv = keyValTableSpeculative->get(kvGuard->getKey());
                }
 
 
                if (kv == NULL) {
                        kv = keyValTableSpeculative->get(kvGuard->getKey());
                }
 
 
                if (kv == NULL) {
-                       // if it is not in the speculative table then check the committed table and use that
-                       // value as our latest assumption
+                       // if it is not in the speculative table then check the
+                       // committed table and use that value as our latest assumption
                        kv = keyValTableCommitted->get(kvGuard->getKey());
                }
 
                        kv = keyValTableCommitted->get(kvGuard->getKey());
                }
 
@@ -114,18 +116,15 @@ Transaction *PendingTransaction::createTransaction() {
        Array<char> *charData = convertDataToBytes();
 
        int currentPosition = 0;
        Array<char> *charData = convertDataToBytes();
 
        int currentPosition = 0;
-       int remaining = charData->length();
-
-       while (remaining > 0) {
-
+       for(int remaining = charData->length(); remaining > 0;) {
                bool isLastPart = false;
                // determine how much to copy
                int copySize = TransactionPart_MAX_NON_HEADER_SIZE;
                if (remaining <= TransactionPart_MAX_NON_HEADER_SIZE) {
                        copySize = remaining;
                bool isLastPart = false;
                // determine how much to copy
                int copySize = TransactionPart_MAX_NON_HEADER_SIZE;
                if (remaining <= TransactionPart_MAX_NON_HEADER_SIZE) {
                        copySize = remaining;
-                       isLastPart = true;// last bit of data so last part
+                       isLastPart = true;//last bit of data so last part
                }
                }
-
+               
                // Copy to a smaller version
                Array<char> *partData = new Array<char>(copySize);
                System_arraycopy(charData, currentPosition, partData, 0, copySize);
                // Copy to a smaller version
                Array<char> *partData = new Array<char>(copySize);
                System_arraycopy(charData, currentPosition, partData, 0, copySize);
@@ -188,4 +187,3 @@ Array<char> *PendingTransaction::convertDataToBytes() {
 
        return bbEncode->array();
 }
 
        return bbEncode->array();
 }
-
index ea698cc7e97b4de212934693f47149b76d2970d0..3f752262b46ac7db2a31ca1feb9cf770cabebb0d 100644 (file)
@@ -5,6 +5,7 @@
 #include "CloudComm.h"
 #include "Table.h"
 #include "LastMessage.h"
 #include "CloudComm.h"
 #include "Table.h"
 #include "LastMessage.h"
+#include "Mac.h"
 
 Slot::Slot(Table *_table, int64_t _seqnum, int64_t _machineid, Array<char> *_prevhmac, Array<char> *_hmac, int64_t _localSequenceNumber) :
        seqnum(_seqnum),
 
 Slot::Slot(Table *_table, int64_t _seqnum, int64_t _machineid, Array<char> *_prevhmac, Array<char> *_hmac, int64_t _localSequenceNumber) :
        seqnum(_seqnum),
@@ -78,8 +79,8 @@ Vector<Entry *> *Slot::getEntries() {
        return entries;
 }
 
        return entries;
 }
 
-Slot *Slotdecode(Table *table, Array<char> *array, Mac *mac) {
-       mac->update(array, HMAC_SIZE, array.length - HMAC_SIZE);
+Slot *Slot_decode(Table *table, Array<char> *array, Mac *mac) {
+       mac->update(array, HMAC_SIZE, array->length() - HMAC_SIZE);
        Array<char> *realmac = mac->doFinal();
 
        ByteBuffer *bb = ByteBuffer_wrap(array);
        Array<char> *realmac = mac->doFinal();
 
        ByteBuffer *bb = ByteBuffer_wrap(array);
@@ -111,11 +112,12 @@ Array<char> *Slot::encode(Mac *mac) {
        bb->putLong(seqnum);
        bb->putLong(machineid);
        bb->putInt(entries->size());
        bb->putLong(seqnum);
        bb->putLong(machineid);
        bb->putInt(entries->size());
-       for (Entry *entry : entries) {
+       for(uint ei=0; ei < entries->size(); ei++) {
+               Entry * entry = entries->get(ei);
                entry->encode(bb);
        }
        /* Compute our HMAC */
                entry->encode(bb);
        }
        /* Compute our HMAC */
-       mac->update(array, HMAC_SIZE, array.length - HMAC_SIZE);
+       mac->update(array, HMAC_SIZE, array->length() - HMAC_SIZE);
        Array<char> *realmac = mac->doFinal();
        hmac = realmac;
        bb->position(0);
        Array<char> *realmac = mac->doFinal();
        hmac = realmac;
        bb->position(0);
@@ -132,7 +134,8 @@ Array<char> *Slot::encode(Mac *mac) {
 
 Vector<Entry *> *Slot::getLiveEntries(bool resize) {
        Vector<Entry *> *liveEntries = new Vector<Entry *>();
 
 Vector<Entry *> *Slot::getLiveEntries(bool resize) {
        Vector<Entry *> *liveEntries = new Vector<Entry *>();
-       for (Entry *entry : entries) {
+       for(uint ei=0; ei < entries->size(); ei++) {
+               Entry * entry = entries->get(ei);
                if (entry->isLive()) {
                        if (!resize || entry->getType() != TypeTableStatus)
                                liveEntries->add(entry);
                if (entry->isLive()) {
                        if (!resize || entry->getType() != TypeTableStatus)
                                liveEntries->add(entry);
index b46e2ab822b298dd95bcc951f08ee4deeaa1868b..9085b3d9b96b6ad05f7a3bf52f0118adcd4244cf 100644 (file)
@@ -4,7 +4,6 @@
 #include "common.h"
 #include "Liveness.h"
 
 #include "common.h"
 #include "Liveness.h"
 
-
 #define SLOT_SIZE 2048
 #define HMAC_SIZE 32
 
 #define SLOT_SIZE 2048
 #define HMAC_SIZE 32
 
@@ -53,8 +52,8 @@ public:
        void decrementLiveCount();
        bool isLive() { return livecount > 0; }
        Array<char> *getSlotCryptIV();
        void decrementLiveCount();
        bool isLive() { return livecount > 0; }
        Array<char> *getSlotCryptIV();
-       friend Slot *Slotdecode(Table *table, Array<char> *array, Mac *mac);
+       friend Slot *Slot_decode(Table *table, Array<char> *array, Mac *mac);
 };
 
 };
 
-Slot *Slotdecode(Table *table, Array<char> *array, Mac *mac);
+Slot *Slot_decode(Table *table, Array<char> *array, Mac *mac);
 #endif
 #endif
index e7b4acd17aec6f61718fd91784f3fe1c2f43aecc..a32c1d983fa414629c5e59378ab48de093aedfc6 100644 (file)
@@ -57,4 +57,5 @@ class Thread;
 class DataInputStream;
 class URL;
 class Random;
 class DataInputStream;
 class URL;
 class Random;
+class Key;
 #endif
 #endif