From 06841026603ce8c6bee3e03cd465a461e295a4d0 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 29 Mar 2018 07:27:31 -0700 Subject: [PATCH] checkpoint --- version2/src/C/CloudComm.cpp | 247 ++++++++++++-------------------- version2/src/C/CloudComm.h | 8 +- version2/src/C/KeyValue.cpp | 2 +- version2/src/C/LocalComm.cpp | 3 +- version2/src/C/SecureRandom.cpp | 2 +- version2/src/C/Slot.cpp | 3 +- version2/src/C/SlotBuffer.cpp | 4 +- version2/src/C/SlotIndexer.cpp | 3 +- version2/src/C/Table.cpp | 96 ++++++++----- version2/src/C/aes.cpp | 2 +- version2/src/C/array.h | 2 - version2/src/C/common.h | 10 +- 12 files changed, 177 insertions(+), 205 deletions(-) diff --git a/version2/src/C/CloudComm.cpp b/version2/src/C/CloudComm.cpp index 8fe0cee..4f97029 100644 --- a/version2/src/C/CloudComm.cpp +++ b/version2/src/C/CloudComm.cpp @@ -11,11 +11,11 @@ #include "ByteBuffer.h" #include "aes.h" #include -#include -#include -#include +//#include +//#include +//#include #include -#include +//#include /** * Empty Constructor needed for child class. @@ -58,9 +58,9 @@ CloudComm::CloudComm(Table *_table, IoTString *_baseurl, IoTString *_password, timer(TimingSingleton_getInstance()), getslot(new Array("getslot", 7)), putslot(new Array("putslot", 7)) { - if (listeningPort > 0) { + /* if (listeningPort > 0) { pthread_create(&localServerThread, NULL, threadWrapper, this); - } + }*/ } CloudComm::~CloudComm() { @@ -84,15 +84,11 @@ CloudComm::~CloudComm() { * Generates Key from password. */ AESKey *CloudComm::initKey() { - try { - AESKey *key = new AESKey(password->internalBytes(), - salt, - 65536, - 128); - return key; - } catch (Exception *e) { - throw new Error("Failed generating key."); - } + AESKey *key = new AESKey(password->internalBytes(), + salt, + 65536, + 128); + return key; } /** @@ -116,15 +112,11 @@ void CloudComm::initCrypt() { if (password == NULL) { return; } - try { - key = initKey(); - delete password; - password = NULL;// drop password - mac = new Mac(); - mac->init(key); - } catch (Exception *e) { - throw new Error("Failed To Initialize Ciphers"); - } + key = initKey(); + delete password; + password = NULL;// drop password + mac = new Mac(); + mac->init(key); } /* @@ -143,10 +135,10 @@ IoTString *CloudComm::buildRequest(bool isput, int64_t sequencenumber, int64_t m return urlstr; } -void loopWrite(int fd, char *array, int bytestowrite) { +void loopWrite(TCPClient client, char *array, int bytestowrite) { int byteswritten = 0; while (bytestowrite) { - int bytes = write(fd, &array[byteswritten], bytestowrite); + int bytes = client.write(&array[byteswritten], bytestowrite); if (bytes >= 0) { byteswritten += bytes; bytestowrite -= bytes; @@ -157,10 +149,10 @@ void loopWrite(int fd, char *array, int bytestowrite) { } } -void loopRead(int fd, char *array, int bytestoread) { +void loopRead(TCPClient client, char *array, int bytestoread) { int bytesread = 0; while (bytestoread) { - int bytes = read(fd, &array[bytesread], bytestoread); + int bytes = client.read(&array[bytesread], bytestoread); if (bytes >= 0) { bytesread += bytes; bytestoread -= bytes; @@ -203,38 +195,23 @@ WebConnection openURL(IoTString *url) { memcpy(&message[endpost + post + url->length() + hostlen - i], host, i - 7); sprintf(&message[endpost + post + url->length() + hostlen - 7], "\r\n"); - /* create the socket */ - int sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (sockfd < 0) {printf("ERROR opening socket\n"); exit(-1);} - - /* lookup the ip address */ - struct hostent *server = gethostbyname(host); - free(host); - - if (server == NULL) {printf("ERROR, no such host"); exit(-1);} - /* fill in the structure */ - struct sockaddr_in serv_addr; + WebConnection wc; + wc.numBytes = -1; - memset(&serv_addr,0,sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - serv_addr.sin_port = htons(80); - memcpy(&serv_addr.sin_addr.s_addr,server->h_addr,server->h_length); - - /* connect the socket */ - if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0) { - printf("ERROR connecting"); - exit(-1); + if (!wc.client.connect(host, 80)) { + myerror("ERROR connecting\n"); } - + free(host); + /* send the request */ int total = strlen(message); loopWrite(sockfd, message, total); free(message); - return (WebConnection) {sockfd, -1}; + return wc; } -int createSocket(IoTString *name, int port) { +TCPClient createSocket(IoTString *name, int port) { char *host = (char *) malloc(name->length() + 1); memcpy(host, name->internalBytes()->internalArray(), name->length()); host[name->length()] = 0; @@ -246,66 +223,24 @@ int createSocket(IoTString *name, int port) { if (sockfd < 0) {printf("ERROR opening socket\n"); exit(-1);} /* lookup the ip address */ - struct hostent *server = gethostbyname(host); - free(host); - - if (server == NULL) {printf("ERROR, no such host"); exit(-1);} - - /* fill in the structure */ - struct sockaddr_in serv_addr; - - memset(&serv_addr,0,sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - serv_addr.sin_port = htons(port); - memcpy(&serv_addr.sin_addr.s_addr,server->h_addr,server->h_length); - - /* connect the socket */ - if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0) { - printf("ERROR connecting"); - exit(-1); + TCPClient client; + if (!client.connect(host, port)) { + myerror("ERROR connecting\n"); } - return sockfd; + free(host); + return client; } -int createSocket(int port) { +TCPServer createSocket(int port) { int fd; struct sockaddr_in sin; + TCPServer server = TCPServer(port); + server.begin(); - bzero(&sin, sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - sin.sin_addr.s_addr = htonl(INADDR_ANY); - fd = socket(AF_INET, SOCK_STREAM, 0); - int n = 1; - if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&n, sizeof (n)) < 0) { - close(fd); - printf("Create Socket Error\n"); - exit(-1); - } - if (bind(fd, (struct sockaddr *) &sin, sizeof(sin)) < 0) { - close(fd); - exit(-1); - } - if (listen(fd, 5) < 0) { - close(fd); - exit(-1); - } - return fd; + return server; } -int acceptSocket(int socket) { - struct sockaddr_in sin; - unsigned int sinlen = sizeof(sin); - int newfd = accept(socket, (struct sockaddr *)&sin, &sinlen); - int flag = 1; - setsockopt(newfd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(flag)); - if (newfd < 0) { - printf("Accept Error\n"); - exit(-1); - } - return newfd; -} void writeSocketData(int fd, Array *data) { loopWrite(fd, data->internalArray(), data->length()); @@ -404,7 +339,7 @@ void CloudComm::setSalt() { } WebConnection wc = {-1, -1}; - try { + // try { Array *saltTmp = new Array(CloudComm_SALT_SIZE); random->nextBytes(saltTmp); @@ -422,40 +357,41 @@ void CloudComm::setSalt() { int responsecode = getResponseCode(&wc); if (responsecode != HttpURLConnection_HTTP_OK) { - throw new Error("Invalid response"); + //throw new Error("Invalid response"); + myerror("Invalid response\n"); } close(wc.fd); timer->endTime(); salt = saltTmp; - } catch (Exception *e) { + /* } catch (Exception *e) { timer->endTime(); throw new ServerException("Failed setting salt", ServerException_TypeConnectTimeout); - } + }*/ } bool CloudComm::getSalt() { WebConnection wc = {-1, -1}; IoTString *urlstr = NULL; - try { + // try { char *buffer = (char *) malloc(baseurl->length() + 100); memcpy(buffer, baseurl->internalBytes()->internalArray(), baseurl->length()); int offset = baseurl->length(); offset += sprintf(&buffer[offset], "?req=getsalt"); urlstr = new IoTString(buffer); free(buffer); - } catch (Exception *e) { + /* } catch (Exception *e) { throw new Error("getSlot failed"); - } - try { + }*/ + // try { timer->startTime(); wc = openURL(urlstr); delete urlstr; urlstr = NULL; closeURLReq(&wc); timer->endTime(); - } catch (SocketTimeoutException *e) { + /* } catch (SocketTimeoutException *e) { if (urlstr) delete urlstr; timer->endTime(); @@ -464,14 +400,15 @@ bool CloudComm::getSalt() { if (urlstr) delete urlstr; throw new Error("getSlot failed"); - } + }*/ - try { + // try { timer->startTime(); int responsecode = getResponseCode(&wc); readHeaders(&wc); if (responsecode != HttpURLConnection_HTTP_OK) { - throw new Error("Invalid response"); + //throw new Error("Invalid response"); + myerror("Invalid response\n"); } if (wc.numBytes == 0) { timer->endTime(); @@ -488,12 +425,12 @@ bool CloudComm::getSalt() { salt = tmp; timer->endTime(); return true; - } catch (SocketTimeoutException *e) { + /* } catch (SocketTimeoutException *e) { timer->endTime(); throw new ServerException("getSalt failed", ServerException_TypeInputTimeout); } catch (Exception *e) { throw new Error("getSlot failed"); - } + }*/ } Array *CloudComm::createIV(int64_t machineId, int64_t localSequenceNumber) { @@ -517,20 +454,20 @@ Array *AESDecrypt(Array *ivBytes, AESKey *key, Array *data) { } Array *CloudComm::encryptSlotAndPrependIV(Array *rawData, Array *ivBytes) { - try { + // try { Array *encryptedBytes = AESEncrypt(ivBytes, key, rawData); Array *chars = new Array(encryptedBytes->length() + CloudComm_IV_SIZE); System_arraycopy(ivBytes, 0, chars, 0, ivBytes->length()); System_arraycopy(encryptedBytes, 0, chars, CloudComm_IV_SIZE, encryptedBytes->length()); delete encryptedBytes; return chars; - } catch (Exception *e) { + /* } catch (Exception *e) { throw new Error("Failed To Encrypt"); - } + }*/ } Array *CloudComm::stripIVAndDecryptSlot(Array *rawData) { - try { + // try { Array *ivBytes = new Array(CloudComm_IV_SIZE); Array *encryptedBytes = new Array(rawData->length() - CloudComm_IV_SIZE); System_arraycopy(rawData, 0, ivBytes, 0, CloudComm_IV_SIZE); @@ -539,9 +476,9 @@ Array *CloudComm::stripIVAndDecryptSlot(Array *rawData) { delete encryptedBytes; delete ivBytes; return data; - } catch (Exception *e) { + /* } catch (Exception *e) { throw new Error("Failed To Decrypt"); - } + }*/ } /* @@ -551,10 +488,11 @@ Array *CloudComm::stripIVAndDecryptSlot(Array *rawData) { */ Array *CloudComm::putSlot(Slot *slot, int max) { WebConnection wc = {-1, -1}; - try { + // try { if (salt == NULL) { if (!getSalt()) { - throw new ServerException("putSlot failed", ServerException_TypeSalt); + // throw new ServerException("putSlot failed", ServerException_TypeSalt); + myerror("putSlot failed\n"); } initCrypt(); } @@ -572,7 +510,7 @@ Array *CloudComm::putSlot(Slot *slot, int max) { writeURLDataAndClose(&wc, chars); delete chars; timer->endTime(); - } catch (ServerException *e) { + /* } catch (ServerException *e) { timer->endTime(); throw e; } catch (SocketTimeoutException *e) { @@ -580,10 +518,10 @@ Array *CloudComm::putSlot(Slot *slot, int max) { throw new ServerException("putSlot failed", ServerException_TypeConnectTimeout); } catch (Exception *e) { throw new Error("putSlot failed"); - } + }*/ Array *resptype = NULL; - try { + // try { int respcode = getResponseCode(&wc); readHeaders(&wc); timer->startTime(); @@ -603,9 +541,10 @@ Array *CloudComm::putSlot(Slot *slot, int max) { } else { delete resptype; close(wc.fd); - throw new Error("Bad response to putslot"); + //throw new Error("Bad response to putslot"); + myerror("Bad response to putslot\n"); } - } catch (SocketTimeoutException *e) { + /* } catch (SocketTimeoutException *e) { if (resptype != NULL) delete resptype; timer->endTime(); @@ -615,7 +554,7 @@ Array *CloudComm::putSlot(Slot *slot, int max) { if (resptype != NULL) delete resptype; throw new Error("putSlot failed"); - } + }*/ } /** @@ -624,10 +563,11 @@ Array *CloudComm::putSlot(Slot *slot, int max) { */ Array *CloudComm::getSlots(int64_t sequencenumber) { WebConnection wc = {-1, -1}; - try { + // try { if (salt == NULL) { if (!getSalt()) { - throw new ServerException("getSlots failed", ServerException_TypeSalt); + //throw new ServerException("getSlots failed", ServerException_TypeSalt); + myerror("getSlots failed\n"); } initCrypt(); } @@ -638,7 +578,7 @@ Array *CloudComm::getSlots(int64_t sequencenumber) { delete url; closeURLReq(&wc); timer->endTime(); - } catch (SocketTimeoutException *e) { + /* } catch (SocketTimeoutException *e) { timer->endTime(); throw new ServerException("getSlots failed", ServerException_TypeConnectTimeout); } catch (ServerException *e) { @@ -647,9 +587,9 @@ Array *CloudComm::getSlots(int64_t sequencenumber) { throw e; } catch (Exception *e) { throw new Error("getSlots failed"); - } + }*/ - try { + // try { timer->startTime(); int responsecode = getResponseCode(&wc); readHeaders(&wc); @@ -657,19 +597,20 @@ Array *CloudComm::getSlots(int64_t sequencenumber) { readURLData(&wc, resptype); timer->endTime(); if (!resptype->equals(getslot)) - throw new Error("Bad Response: "); + // throw new Error("Bad Response: "); + myerror("Bad Response: \n"); delete resptype; Array *tmp = processSlots(&wc); close(wc.fd); return tmp; - } catch (SocketTimeoutException *e) { + /* } catch (SocketTimeoutException *e) { timer->endTime(); close(wc.fd); throw new ServerException("getSlots failed", ServerException_TypeInputTimeout); } catch (Exception *e) { throw new Error("getSlots failed"); - } + }*/ } /** @@ -698,7 +639,7 @@ Array *CloudComm::processSlots(WebConnection *wc) { Array *CloudComm::sendLocalData(Array *sendData, int64_t localSequenceNumber, IoTString *host, int port) { if (salt == NULL) return NULL; - try { + // try { printf("Passing Locally\n"); mac->update(sendData, 0, sendData->length()); Array *genmac = mac->doFinal(); @@ -732,40 +673,41 @@ Array *CloudComm::sendLocalData(Array *sendData, int64_t localSequen System_arraycopy(returnData, returnData->length() - realmac->length(), recmac, 0, realmac->length()); if (!recmac->equals(realmac)) - throw new Error("Local Error: Invalid HMAC! Potential Attack!"); + // throw new Error("Local Error: Invalid HMAC! Potential Attack!"); + myerror("Local Error: Invalid HMAC! Potential Attack!\n"); Array *returnData2 = new Array(lengthOfReturnData - recmac->length()); System_arraycopy(returnData, 0, returnData2, 0, returnData2->length()); return returnData2; - } catch (Exception *e) { + /* } catch (Exception *e) { printf("Exception\n"); - } + }*/ return NULL; } void CloudComm::localServerWorkerFunction() { - int inputSocket = -1; - + /* int inputSocket = -1; + try { // Local server socket inputSocket = createSocket(listeningPort); } catch (Exception *e) { throw new Error("Local server setup failure..."); } - + while (!doEnd) { try { // Accept incoming socket int socket = acceptSocket(inputSocket); - + // Get the encrypted data from the server int dataSize = readSocketInt(socket); Array *readData = new Array(dataSize); readSocketData(socket, readData); timer->endTime(); - + // Decrypt the data readData = stripIVAndDecryptSlot(readData); mac->update(readData, 0, readData->length() - CloudComm_HMAC_SIZE); @@ -774,7 +716,8 @@ void CloudComm::localServerWorkerFunction() { System_arraycopy(readData, readData->length() - recmac->length(), recmac, 0, recmac->length()); if (!recmac->equals(genmac)) - throw new Error("Local Error: Invalid HMAC! Potential Attack!"); + // throw new Error("Local Error: Invalid HMAC! Potential Attack!"); + error("Local Error: Invalid HMAC! Potential Attack!\n"); Array *returnData = new Array(readData->length() - recmac->length()); System_arraycopy(readData, 0, returnData, 0, returnData->length()); @@ -799,21 +742,21 @@ void CloudComm::localServerWorkerFunction() { } catch (Exception *e) { } } - + if (inputSocket != -1) { try { close(inputSocket); } catch (Exception *e) { throw new Error("Local server close failure..."); } - } + }*/ } void CloudComm::closeCloud() { doEnd = true; - if (listeningPort > 0) { + /* if (listeningPort > 0) { if (pthread_join(localServerThread, NULL) != 0) throw new Error("Local Server thread join issue..."); - } + }*/ } diff --git a/version2/src/C/CloudComm.h b/version2/src/C/CloudComm.h index ce7cfa0..35d5fcc 100644 --- a/version2/src/C/CloudComm.h +++ b/version2/src/C/CloudComm.h @@ -2,7 +2,9 @@ #define CLOUDCOMM_H #include "common.h" -#include +#include "application.h" + +//#include /** * This class provides a communication API to the webserver. It also * validates the HMACs on the slots and handles encryption. @@ -19,7 +21,7 @@ #define HttpURLConnection_HTTP_OK 200 typedef struct { - int fd; + TCPClient client; int numBytes; } WebConnection; @@ -34,7 +36,7 @@ private: Array *salt; Table *table; int32_t listeningPort; - pthread_t localServerThread; + // pthread_t localServerThread; bool doEnd; TimingSingleton *timer; Array *getslot; diff --git a/version2/src/C/KeyValue.cpp b/version2/src/C/KeyValue.cpp index 8aea6f2..13ecc34 100644 --- a/version2/src/C/KeyValue.cpp +++ b/version2/src/C/KeyValue.cpp @@ -40,7 +40,7 @@ void KeyValue::encode(ByteBuffer *bb) { } } -int KeyValue::getSize() { +int32_t KeyValue::getSize() { if (value != NULL) return 2 * sizeof(int32_t) + key->length() + value->length(); return 2 * sizeof(int32_t) + key->length(); diff --git a/version2/src/C/LocalComm.cpp b/version2/src/C/LocalComm.cpp index ac4c343..a019bc2 100644 --- a/version2/src/C/LocalComm.cpp +++ b/version2/src/C/LocalComm.cpp @@ -10,7 +10,8 @@ Array *LocalComm::sendDataToLocalDevice(int64_t deviceId, Array *dat } else if (deviceId == t2->getMachineId()) { // return t2.localCommInput(data); } else { - throw new Error("Cannot send to deviceId using this local comm"); + //throw new Error("Cannot send to deviceId using this local comm"); + error("Cannot send to deviceId using this local comm"); } return new Array((uint32_t)0); diff --git a/version2/src/C/SecureRandom.cpp b/version2/src/C/SecureRandom.cpp index 84f40c3..9336b33 100644 --- a/version2/src/C/SecureRandom.cpp +++ b/version2/src/C/SecureRandom.cpp @@ -1,6 +1,6 @@ #include "SecureRandom.h" #include -#include +//#include SecureRandom::SecureRandom() { } diff --git a/version2/src/C/Slot.cpp b/version2/src/C/Slot.cpp index 31cce57..2233b0e 100644 --- a/version2/src/C/Slot.cpp +++ b/version2/src/C/Slot.cpp @@ -97,7 +97,8 @@ Slot *Slot_decode(Table *table, Array *array, Mac *mac) { bb->get(hmac); bb->get(prevhmac); if (!realmac->equals(hmac)) - throw new Error("Server Error: Invalid HMAC! Potential Attack!"); + //throw new Error("Server Error: Invalid HMAC! Potential Attack!"); + error("Server Error: Invalid HMAC! Potential Attack!\n"); delete realmac; int64_t seqnum = bb->getLong(); diff --git a/version2/src/C/SlotBuffer.cpp b/version2/src/C/SlotBuffer.cpp index 06c46e9..de2a0b2 100644 --- a/version2/src/C/SlotBuffer.cpp +++ b/version2/src/C/SlotBuffer.cpp @@ -24,13 +24,13 @@ SlotBuffer::~SlotBuffer() { delete array; } -int SlotBuffer::size() { +int32_t SlotBuffer::size() { if (head >= tail) return head - tail; return (array->length() + head) - tail; } -int SlotBuffer::capacity() { +int32_t SlotBuffer::capacity() { return array->length() - 1; } diff --git a/version2/src/C/SlotIndexer.cpp b/version2/src/C/SlotIndexer.cpp index b49ca45..e46f83e 100644 --- a/version2/src/C/SlotIndexer.cpp +++ b/version2/src/C/SlotIndexer.cpp @@ -19,7 +19,8 @@ Slot *SlotIndexer::getSlot(int64_t seqnum) { if (seqnum >= firstslotseqnum) { int32_t offset = (int32_t) (seqnum - firstslotseqnum); if (((uint32_t)offset) >= updates->length()) - throw new Error("Invalid Slot Sequence Number Reference"); + //throw new Error("Invalid Slot Sequence Number Reference"); + myerror("Invalid Slot Sequence Number Reference"); else return updates->get(offset); } else diff --git a/version2/src/C/Table.cpp b/version2/src/C/Table.cpp index 255ba3c..896af0a 100644 --- a/version2/src/C/Table.cpp +++ b/version2/src/C/Table.cpp @@ -263,7 +263,7 @@ Table::~Table() { } delete pendingSendArbitrationEntriesToDelete; { - SetIterator *> *trit = getKeyIterator(transactionPartsSent); + SetIterator *> *trit = (SetIterator *> *) getKeyIterator(transactionPartsSent); while (trit->hasNext()) { Transaction *transaction = trit->next(); delete trit->currVal(); @@ -359,7 +359,8 @@ void Table::initTable() { } else { delete s; delete array; - throw new Error("Error on initialization"); + //throw new Error("Error on initialization"); + myerror("Error on initialization\n"); } } @@ -420,13 +421,15 @@ IoTString *Table::getCommittedAtomic(IoTString *key) { KeyValue *kv = committedKeyValueTable->get(key); if (!arbitratorTable->contains(key)) { - throw new Error("Key not Found."); + // throw new Error("Key not Found."); + myerror("Key not found!\n"); } // Make sure new key value pair matches the current arbitrator if (!pendingTransactionBuilder->checkArbitrator(arbitratorTable->get(key))) { // TODO: Maybe not throw en error - throw new Error("Not all Key Values Match Arbitrator."); + //throw new Error("Not all Key Values Match Arbitrator."); + myerror("Not all key values match arbitrator\n"); } if (kv != NULL) { @@ -440,13 +443,15 @@ IoTString *Table::getCommittedAtomic(IoTString *key) { IoTString *Table::getSpeculativeAtomic(IoTString *key) { if (!arbitratorTable->contains(key)) { - throw new Error("Key not Found."); + //throw new Error("Key not Found."); + myerror("Key not found\n"); } // Make sure new key value pair matches the current arbitrator if (!pendingTransactionBuilder->checkArbitrator(arbitratorTable->get(key))) { // TODO: Maybe not throw en error - throw new Error("Not all Key Values Match Arbitrator."); + //throw new Error("Not all Key Values Match Arbitrator."); + myerror("Not all Key Values Match Arbitrator.\n"); } KeyValue *kv = pendingTransactionSpeculatedKeyValueTable->get(key); @@ -469,21 +474,21 @@ IoTString *Table::getSpeculativeAtomic(IoTString *key) { } bool Table::update() { - try { + //try { Array *newSlots = cloud->getSlots(sequenceNumber + 1); validateAndUpdate(newSlots, false); delete newSlots; sendToServer(NULL); updateLiveTransactionsAndStatus(); return true; - } catch (Exception *e) { + /* } catch (Exception *e) { SetIterator *> *kit = getKeyIterator(localCommunicationTable); while (kit->hasNext()) { int64_t m = kit->next(); updateFromLocal(m); } delete kit; - } + }*/ return false; } @@ -513,13 +518,15 @@ void Table::startTransaction() { void Table::put(IoTString *key, IoTString *value) { // Make sure it is a valid key if (!arbitratorTable->contains(key)) { - throw new Error("Key not Found."); + //throw new Error("Key not Found."); + myerror("Key not Found.\n"); } // Make sure new key value pair matches the current arbitrator if (!pendingTransactionBuilder->checkArbitrator(arbitratorTable->get(key))) { // TODO: Maybe not throw en error - throw new Error("Not all Key Values Match Arbitrator."); + //throw new Error("Not all Key Values Match Arbitrator."); + myerror("Not all Key Values Match Arbitrator.\n"); } // Add the key value to this transaction @@ -557,9 +564,9 @@ TransactionStatus *Table::commitTransaction() { pendingTransactionBuilder = new PendingTransaction(localMachineId); - try { + // try { sendToServer(NULL); - } catch (ServerException *e) { + /* } catch (ServerException *e) { Hashset *arbitratorTriedAndFailed = new Hashset(); uint size = pendingTransactionQueue->size(); @@ -590,7 +597,7 @@ TransactionStatus *Table::commitTransaction() { } } pendingTransactionQueue->setSize(oldindex); - } + }*/ updateLiveStateFromLocal(); @@ -610,7 +617,7 @@ int64_t Table::getLocalSequenceNumber() { } void Table::processTransactionList(bool handlePartial) { - SetIterator *> *trit = getKeyIterator(lastTransactionPartsSent); + SetIterator *> *trit = (SetIterator *> *)getKeyIterator(lastTransactionPartsSent); while (trit->hasNext()) { Transaction *transaction = trit->next(); transaction->resetServerFailure(); @@ -670,7 +677,7 @@ NewKey * Table::handlePartialSend(NewKey * newKey) { } } - SetIterator *> *trit = getKeyIterator(lastTransactionPartsSent); + SetIterator *> *trit = (SetIterator *> *)getKeyIterator(lastTransactionPartsSent); while (trit->hasNext()) { Transaction *transaction = trit->next(); transaction->resetServerFailure(); @@ -696,7 +703,7 @@ NewKey * Table::handlePartialSend(NewKey * newKey) { processTransactionList(true); } else { - SetIterator *> *trit = getKeyIterator(lastTransactionPartsSent); + SetIterator *> *trit = (SetIterator *> *) getKeyIterator(lastTransactionPartsSent); while (trit->hasNext()) { Transaction *transaction = trit->next(); transaction->resetServerFailure(); @@ -718,7 +725,7 @@ NewKey * Table::handlePartialSend(NewKey * newKey) { void Table::clearSentParts() { // Clear the sent data since we are trying again pendingSendArbitrationEntriesToDelete->clear(); - SetIterator *> *trit = getKeyIterator(transactionPartsSent); + SetIterator *> *trit = (SetIterator *> *) getKeyIterator(transactionPartsSent); while (trit->hasNext()) { Transaction *transaction = trit->next(); delete trit->currVal(); @@ -732,11 +739,12 @@ bool Table::sendToServer(NewKey *newKey) { newKey = handlePartialSend(newKey); } - try { + // try { // While we have stuff that needs inserting into the block chain while ((pendingTransactionQueue->size() > 0) || (pendingSendArbitrationRounds->size() > 0) || (newKey != NULL)) { if (hadPartialSendToServer) { - throw new Error("Should Be error free"); + // throw new Error("Should Be error free"); + myerror("Should Be error free\n"); } // If there is a new key with same name then end @@ -756,7 +764,7 @@ bool Table::sendToServer(NewKey *newKey) { if (needsResize) { // Reset which transaction to send - SetIterator *> *trit = getKeyIterator(transactionPartsSent); + SetIterator *> *trit = (SetIterator *> *) getKeyIterator(transactionPartsSent); while (trit->hasNext()) { Transaction *transaction = trit->next(); transaction->resetNextPartToSend(); @@ -819,7 +827,7 @@ bool Table::sendToServer(NewKey *newKey) { processTransactionList(false); } else { // Reset which transaction to send - SetIterator *> *trit = getKeyIterator(transactionPartsSent); + SetIterator *> *trit = (SetIterator *> *) getKeyIterator(transactionPartsSent); while (trit->hasNext()) { Transaction *transaction = trit->next(); transaction->resetNextPartToSend(); @@ -841,10 +849,10 @@ bool Table::sendToServer(NewKey *newKey) { } delete newSlots; } - } catch (ServerException *e) { + /* } catch (ServerException *e) { if (e->getType() != ServerException_TypeInputTimeout) { // Nothing was able to be sent to the server so just clear these data structures - SetIterator *> *trit = getKeyIterator(transactionPartsSent); + SetIterator *> *trit = (SetIterator *> *) getKeyIterator(transactionPartsSent); while (trit->hasNext()) { Transaction *transaction = trit->next(); transaction->resetNextPartToSend(); @@ -860,7 +868,7 @@ bool Table::sendToServer(NewKey *newKey) { hadPartialSendToServer = true; // Nothing was able to be sent to the server so just clear these data structures - SetIterator *> *trit = getKeyIterator(transactionPartsSent); + SetIterator *> *trit = (SetIterator *> *) getKeyIterator(transactionPartsSent); while (trit->hasNext()) { Transaction *transaction = trit->next(); transaction->resetNextPartToSend(); @@ -872,7 +880,7 @@ bool Table::sendToServer(NewKey *newKey) { clearSentParts(); throw e; - } + }*/ return newKey == NULL; } @@ -1201,7 +1209,8 @@ bool Table::sendSlotsToServer(Slot *slot, int newSize, bool isNewKey, bool *isIn return true; } else { if ((*array)->length() == 0) { - throw new Error("Server Error: Did not send any slots"); + // throw new Error("Server Error: Did not send any slots"); + myerror("Server Error: Did not send any slots\n"); } if (hadPartialSendToServer) { @@ -1467,7 +1476,8 @@ void Table::validateAndUpdate(Array *newSlots, bool acceptUpdatesToLocal // client has seen int64_t firstSeqNum = newSlots->get(0)->getSequenceNumber(); if (firstSeqNum <= sequenceNumber) { - throw new Error("Server Error: Sent older slots!"); + // throw new Error("Server Error: Sent older slots!"); + myerror("Server Error: Sent older slots!\n"); } // Create an object that can access both new slots and slots in our @@ -1510,7 +1520,8 @@ void Table::validateAndUpdate(Array *newSlots, bool acceptUpdatesToLocal // hiding slots if (!machineSet->isEmpty()) { delete machineSet; - throw new Error("Missing record for machines: "); + //throw new Error("Missing record for machines: "); + myerror("Missing record for machines: \n"); } } delete machineSet; @@ -1602,7 +1613,8 @@ void Table::updateExpectedSize() { */ void Table::checkNumSlots(int numberOfSlots) { if (numberOfSlots != expectedsize) { - throw new Error("Server Error: Server did not send all slots-> Expected: "); + //throw new Error("Server Error: Server did not send all slots-> Expected: "); + myerror("Server Error: Server did not send all slots-> Expected: \n"); } } @@ -2489,7 +2501,8 @@ void Table::processSlot(SlotIndexer *indexer, Slot *slot, bool acceptUpdatesToLo processEntry((TableStatus *)entry, slot->getSequenceNumber()); break; default: - throw new Error("Unrecognized type: "); + //throw new Error("Unrecognized type: "); + myerror("Unrecognized type: \n"); } } } @@ -2561,7 +2574,8 @@ void Table::processEntry(RejectedMessage *entry, SlotIndexer *indexer) { // a rejected slot int64_t slotMachineId = slot->getMachineID(); if (isequal != (slotMachineId == machineId)) { - throw new Error("Server Error: Trying to insert rejected message for slot "); + //throw new Error("Server Error: Trying to insert rejected message for slot "); + myerror("Server Error: Trying to insert rejected message for slot\n"); } } } @@ -2788,7 +2802,8 @@ void Table::updateLastMessage(int64_t machineId, int64_t seqNum, Liveness *liven } else if (livenessType == TypeSlot) { ((Slot *)liveness)->setDead(); } else { - throw new Error("Unrecognized type"); + //throw new Error("Unrecognized type"); + myerror("Unrecognized type\n"); } } // Get the old last message for this device @@ -2811,7 +2826,8 @@ void Table::updateLastMessage(int64_t machineId, int64_t seqNum, Liveness *liven } else if (lastEntryType == TypeSlot) { ((Slot *)lastEntry)->setDead(); } else { - throw new Error("Unrecognized type"); + //throw new Error("Unrecognized type"); + myerror("Unrecognized type\n"); } } // Make sure the server is not playing any games @@ -2819,17 +2835,20 @@ void Table::updateLastMessage(int64_t machineId, int64_t seqNum, Liveness *liven if (hadPartialSendToServer) { // We were not making any updates and we had a machine mismatch if (lastMessageSeqNum > seqNum && !acceptUpdatesToLocal) { - throw new Error("Server Error: Mismatch on local machine sequence number, needed at least: "); + //throw new Error("Server Error: Mismatch on local machine sequence number, needed at least: "); + myerror("Server Error: Mismatch on local machine sequence number, needed at least: \n"); } } else { // We were not making any updates and we had a machine mismatch if (lastMessageSeqNum != seqNum && !acceptUpdatesToLocal) { - throw new Error("Server Error: Mismatch on local machine sequence number, needed: "); + //throw new Error("Server Error: Mismatch on local machine sequence number, needed: "); + myerror("Server Error: Mismatch on local machine sequence number, needed: \n"); } } } else { if (lastMessageSeqNum > seqNum) { - throw new Error("Server Error: Rollback on remote machine sequence number"); + //throw new Error("Server Error: Rollback on remote machine sequence number"); + myerror("Server Error: Rollback on remote machine sequence number\n"); } } } @@ -2858,6 +2877,7 @@ void Table::checkHMACChain(SlotIndexer *indexer, Array *newSlots) { Slot *prevSlot = indexer->getSlot(currSlot->getSequenceNumber() - 1); if (prevSlot != NULL && !prevSlot->getHMAC()->equals(currSlot->getPrevHMAC())) - throw new Error("Server Error: Invalid HMAC Chain"); + // throw new Error("Server Error: Invalid HMAC Chain"); + myerror("Server Error: Invalid HMAC Chain\n"); } } diff --git a/version2/src/C/aes.cpp b/version2/src/C/aes.cpp index a917c7f..871100e 100644 --- a/version2/src/C/aes.cpp +++ b/version2/src/C/aes.cpp @@ -17,7 +17,7 @@ /*************************** HEADER FILES ***************************/ #include -#include +#include #include "aes.h" #include diff --git a/version2/src/C/array.h b/version2/src/C/array.h index 5e7acdb..1527911 100644 --- a/version2/src/C/array.h +++ b/version2/src/C/array.h @@ -3,8 +3,6 @@ #include #include "common.h" -typedef uint32_t uint; - template class Array { public: diff --git a/version2/src/C/common.h b/version2/src/C/common.h index 7966477..134c13b 100644 --- a/version2/src/C/common.h +++ b/version2/src/C/common.h @@ -1,7 +1,8 @@ #ifndef COMMON_H #define COMMON_H #include -typedef uint32_t uint; + +//typedef uint32_t uint; #define CMEMALLOC ; #define model_print printf #define ASSERT(expr) \ @@ -17,7 +18,12 @@ typedef uint32_t uint; #include "vector.h" #include "array.h" - +#define myerror(msg) \ + do { \ + printf(msg); \ + exit(-1); \ + } while(0) + class TimingSingleton; class Abort; class Entry; -- 2.34.1