diff --git a/inc/Node.h b/inc/Node.h index 22537e2593451f0978275143177fb4c3fb3ed3b7..6a3f50e5ea9e0d341ba0f88787cb4ec2a09415c2 100644 --- a/inc/Node.h +++ b/inc/Node.h @@ -40,13 +40,13 @@ using namespace std; #define EXEC_CMD "./" //python for python script, ./ for an executable // --- parameters (stay tuned) --- -#define T_period 250000 // in microseconds -#define T_timeout 80 // in T_period -#define T_cleanup 20 // in T_period +#define T_period 150000 // in microseconds +#define T_timeout 175 // in T_period +#define T_cleanup 50 // in T_period #define N_b 5 // how many nodes GOSSIP want to use -#define T_election 40 // in T_period +#define T_election 50 // in T_period #define T_switch 5 // in seconds -#define T_maples 100 // lines to process, 2 for testing, probably 100 for real +#define T_maples 50 // lines to process, 2 for testing, probably 100 for real // void *runUdpServer(void *udpSocket); diff --git a/src/Messages.cpp b/src/Messages.cpp index e9bfa7cd6e692d3325aa10e1918093bcc490fd81..e0c15a0e78f9640f3df5f4802118264e54b7a518 100644 --- a/src/Messages.cpp +++ b/src/Messages.cpp @@ -11,7 +11,7 @@ Messages::Messages(string payloadMessage) switch (line) { case 0: { try{ type = static_cast<MessageType>(stoi(token)); } - catch(...) { cout << "[ERROR] stoi: bad message " << payloadMessage << endl; exit(1); } + catch(...) { cout << "[ERROR] stoi: bad message " << payloadMessage << endl; fflush(stdout);exit(1); } break; } default: diff --git a/src/Node.cpp b/src/Node.cpp index 8887ca1097624951532a65bc823fd7111ed0df4b..3b5b3488e90b502f2f08a1f1a0dd412b582f1d28 100644 --- a/src/Node.cpp +++ b/src/Node.cpp @@ -30,7 +30,7 @@ Node::Node(){ sa.sa_flags = SA_RESTART; if (sigaction(SIGCHLD, &sa, NULL) == -1) { perror("sigaction"); - exit(1); + fflush(stdout);exit(1); } } @@ -1130,7 +1130,7 @@ void Node::handleTcpMessage() //processor, exec, sdfs, start int end, start; try {end = stoi(inMsg[3]) + T_maples, start = stoi(inMsg[3]); } - catch(...) { cout << "[ERROR] stoi: bad CHUNK start and end. Last arg is start " << msg.toString() << endl; exit(1);} + catch(...) { cout << "[ERROR] stoi: bad CHUNK start and end. Last arg is start " << msg.toString() << endl; fflush(stdout);exit(1);} string starts = inMsg[3] + "," + to_string(end); string localfile = "", sdfsFile = inMsg[2]; @@ -1243,7 +1243,7 @@ void Node::handleTcpMessage() } else{ try{ filesAtWorker[inMsg[0]] = stoi(inMsg[1]); } - catch(...) { cout << "[ERROR] stoi: " << msg.toString() << " should have arg1 as filesAtWorker" << endl; exit(1);} + catch(...) { cout << "[ERROR] stoi: " << msg.toString() << " should have arg1 as filesAtWorker" << endl; fflush(stdout);exit(1);} Messages alreadyDone(MERGECOMPLETE, inMsg[0] + "::"); if (filesAtWorker[inMsg[0]] == 0) tcpServent->regMessages.push(alreadyDone.toString()); } diff --git a/src/TcpSocket.cpp b/src/TcpSocket.cpp index 99e4a564ffffd4b73510526449705a1d8eaeb045..c933d9b1e659b2faf1199331b3298346faff3de1 100644 --- a/src/TcpSocket.cpp +++ b/src/TcpSocket.cpp @@ -39,7 +39,7 @@ void TcpSocket::bindServer(string port) if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) { perror("setsockopt"); - exit(1); + fflush(stdout);exit(1); } if (::bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) { close(sockfd); @@ -58,7 +58,7 @@ void TcpSocket::bindServer(string port) if (listen(sockfd, BACKLOG) == -1) { perror("listen"); - exit(1); + fflush(stdout);exit(1); } sa.sa_handler = sigchld_handler; // reap all dead processes @@ -66,7 +66,7 @@ void TcpSocket::bindServer(string port) sa.sa_flags = SA_RESTART; if (sigaction(SIGCHLD, &sa, NULL) == -1) { perror("sigaction"); - exit(1); + fflush(stdout);exit(1); } while(1) { // main accept() loop sin_size = sizeof their_addr; @@ -128,7 +128,7 @@ void TcpSocket::mergeFiles(string ip, string port, string handler, string filede int dirSize = toProcess.size(); int mode; try { mode = stoi(handler); } - catch (...) { cout << "[ERROR] stoi: " << handler << endl; exit(1);} + catch (...) { cout << "[ERROR] stoi: " << handler << endl; fflush(stdout);exit(1);} string payload = handler + "," + filedest + "," + header + "," + toSend; //73,11,dir-w100_1606725536,dir-w100,dataset/100.txt,dataset/100.txt,10502025 payload = to_string(payload.size()) + "," + payload; @@ -145,7 +145,7 @@ void TcpSocket::mergeFiles(string ip, string port, string handler, string filede int sj = stoi(toStart[index+1]); sendLines(sockfd, toProcess[index], si, sj); } - catch (...) { cout << "[ERROR] stoi: " << "send lines " << toStart[index] << "," << toStart[index+1] << endl; exit(1);} + catch (...) { cout << "[ERROR] stoi: " << "send lines " << toStart[index] << "," << toStart[index+1] << endl; fflush(stdout);exit(1);} } else{ fp = fopen(toProcess[index].c_str(), "rb"); @@ -153,7 +153,7 @@ void TcpSocket::mergeFiles(string ip, string port, string handler, string filede else { int sj; try { sj = stoi(toProcess[index+1]); } - catch (...) { cout << "[ERROR] stoi: " << "send file size (" << toProcess[index] << toProcess[index+1] << ") from " << payload << endl; exit(1);} + catch (...) { cout << "[ERROR] stoi: " << "send file size (" << toProcess[index] << toProcess[index+1] << ") from " << payload << endl; fflush(stdout);exit(1);} sendFile(sockfd, fp, sj); fclose(fp); } @@ -256,14 +256,14 @@ int TcpSocket::messageHandler(int sockfd, string payloadMessage, string returnIP int skipSize; try { skipSize = stoi(metainfo[0]); - } catch(...) { cout << "[ERROR] stoi: bad payload size: " << metainfo[0] << " from " << msg.payload << endl; exit(1);} + } catch(...) { cout << "[ERROR] stoi: bad payload size: " << metainfo[0] << " from " << msg.payload << endl; fflush(stdout);exit(1);} string payload = msg.payload.substr(metainfo[0].size() + 1, skipSize), extra = ""; try { extra = msg.payload.substr(metainfo[0].size() + 1 + skipSize); } catch (const out_of_range&) { extra = ""; } //good try catch here, not just error stuff actually functional vector<string> filesAndSizes = splitString(payload, ","); int returnType = 0, processedCounter = 0; try { returnType = stoi(filesAndSizes[0]); } - catch(...) { cout << "[ERROR] stoi: bad return type: " << filesAndSizes[0] << endl; exit(1); } + catch(...) { cout << "[ERROR] stoi: bad return type: " << filesAndSizes[0] << endl; fflush(stdout);exit(1); } string returnTypeString = "", remoteLocalname = "", execfilename = "", mode = "wb"; int dirSize = (int)filesAndSizes.size() - 1, fail = 0; int index = 3; @@ -308,7 +308,7 @@ int TcpSocket::messageHandler(int sockfd, string payloadMessage, string returnIP //cout << "[MERGE] index:" << to_string(index) << " , dest:" << filename << " , size:" << filesAndSizes[index+1] << endl; numbytes = 0; try{ filesize = stoi(filesAndSizes[index+1]); } - catch(...) { cout << "[ERROR] stoi: bad file size: " << filesAndSizes[index] << "," << filesAndSizes[index+1] << endl; exit(1); } + catch(...) { cout << "[ERROR] stoi: bad file size: " << filesAndSizes[index] << "," << filesAndSizes[index+1] << endl; fflush(stdout);exit(1); } bytesLeft = filesize; buffersize = DEFAULT_TCP_BLKSIZE; buffersize = (bytesLeft < buffersize) ? bytesLeft : DEFAULT_TCP_BLKSIZE; diff --git a/src/UdpSocket.cpp b/src/UdpSocket.cpp index c7997ab7064778ca0f9ba79fe3bc1d6815244f97..49756115924119c26565139524a374954fb7b7cc 100644 --- a/src/UdpSocket.cpp +++ b/src/UdpSocket.cpp @@ -111,7 +111,7 @@ void UdpSocket::sendMessage(string ip, string port, string message) if (numbytes == -1) { perror("sendMessage: sendto"); - exit(1); + fflush(stdout);exit(1); } freeaddrinfo(servinfo); diff --git a/src/Utils.cpp b/src/Utils.cpp index 74fd92294914991232904d4162c009dc97cc65e4..266a22d2ed08d467951c6cfa83601d8dc1df2c9d 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -27,7 +27,7 @@ string getIP(const char * host){ struct hostent *hp; if (!(hp = gethostbyname(host)) || (hp->h_addr_list[0] == NULL)) { perror("error: no ip"); - exit(1); + fflush(stdout);exit(1); } return inet_ntoa(*(struct in_addr*)hp->h_addr_list[0]); }