diff --git a/mappers/wc.cpp b/mappers/wc.cpp index dd2307ba0bdec8f2a21ca4038978a7df05e5bd7e..e94bc4e07f66b8e478aecff1bdda2d552660f54e 100644 --- a/mappers/wc.cpp +++ b/mappers/wc.cpp @@ -1,4 +1,6 @@ #include "../inc/Utils.h" +#include <algorithm> + int main(int argc, char **argv) { const char *filename = argv[1]; std::ifstream file(filename); @@ -8,8 +10,8 @@ int main(int argc, char **argv) { { for (int i = 0; i < str.size(); i++) { if (str[i] == '.' || str[i] == ',' || str[i] == '?' || str[i] == ';' || str[i] == '!') str[i] = ' '; - str[i] = tolower(str[i]); } + std::transform(str.begin(), str.end(), str.begin(), ::tolower); std::vector<std::string> temp = splitString(str, delim); for (auto &e : temp) std::cout << e << "," << "1" << std::endl; } diff --git a/src/Node.cpp b/src/Node.cpp index 71e98e01b99e62ba79a039f751d27c71ce952f4b..971d0ec0d0d18400d05ac9e22046af2f071a86f8 100644 --- a/src/Node.cpp +++ b/src/Node.cpp @@ -227,7 +227,7 @@ int Node::failureDetection(){ { // it sent out, but replicates are failed // restart again - cout << "[PUT/REREPLICATE] The sender " << get<0>(keyTuple) << " failed, try again" << endl; + //cout << "[PUT/REREPLICATE] The sender " << get<0>(keyTuple) << " failed, try again" << endl; pendingRequests.erase(sdfsfilename); } } diff --git a/src/TcpSocket.cpp b/src/TcpSocket.cpp index fa9c6c26ed6456ff70c05e0cd41fbd75bf7e40a7..1890cd87af3f3e6d84011c73f7f0eb00a73c82bb 100644 --- a/src/TcpSocket.cpp +++ b/src/TcpSocket.cpp @@ -133,11 +133,22 @@ void TcpSocket::sendFile(string ip, string port, void TcpSocket::sendLines(string ip, string port, string execfile, string readfile, string prefix, int start, int end) { - int sockfd = 0, lineCounter = -1; + int sockfd = 0, lineCounter = -1; numbytes = 0; if ((sockfd = createConnection(ip, port)) == -1) return; //exec, read, start, tmp, prefix vector<string> unDirectory = splitString(readfile, "-"); - string toSend = execfile + "," + readfile + "," + to_string(start) + "," + prefix+"-tmp"+to_string(start)+"-"+unDirectory[1]; + ifstream file(getMostRecentFile(readfile).c_str()); + string str; + while (getline(file, str)) + { + lineCounter++; + if (lineCounter < start) continue; + if (lineCounter >= end) break; + numbytes += str.size(); + } + file.clear(); // clear fail and eof bits + file.seekg(0, std::ios::beg); // back to the start! + string toSend = to_string(numbytes) + "," + execfile + "," + readfile + "," + to_string(start) + "," + prefix+"-tmp"+to_string(start)+"-"+unDirectory[1]; Messages msg(PUT, toSend); cout << "[CHUNK] " << messageTypes[msg.type] << " | " << msg.toString() << endl; string payload = msg.toString(); @@ -237,12 +248,13 @@ int TcpSocket::messageHandler(int sockfd, string payloadMessage, string returnIP } //cout << "backup filename " << localfilename << endl; } else { - //exec, read, start, tmp, prefix - localfilename = fields[3]; //tempfile to read from - sdfsfilename = fields[0]; //exec file name - start = stoi(fields[2]); //start line (used just for signalling what work finished to master) - remoteLocalname = fields[1]; //actual file (used for signalling) - cout << "[PUT] exec: " << sdfsfilename << ", actual: " << remoteLocalname << ", start: " << fields[2] << ", temp: " << fields[3] << endl; + //size, exec, read, start, tmp, prefix + filesize = stoi(fields[0]); + localfilename = fields[4]; //tempfile to read from + sdfsfilename = fields[1]; //exec file name + start = stoi(fields[3]); //start line (used just for signalling what work finished to master) + remoteLocalname = fields[2]; //actual file (used for signalling) + cout << "[PUT] bytes: " << fields[0] << " exec: " << sdfsfilename << ", actual: " << remoteLocalname << ", start: " << fields[2] << ", temp: " << fields[3] << endl; } fp = fopen(localfilename.c_str(), mode.c_str()); if (fp == NULL) {