diff --git a/Wc b/Wc index f72847e6467c730b16399f879f70fa0037ab2ac8..b6bceb0a54be988e6a693f24503be024ae36cd4f 100755 Binary files a/Wc and b/Wc differ diff --git a/Wr b/Wr index 99040bdeffdbc456762b8d3ffc2c865e8d60b972..0eefbe6fb71904f4d44313d9ee0aaf0a0cc1b668 100755 Binary files a/Wr and b/Wr differ diff --git a/src/Node.cpp b/src/Node.cpp index d474d581aed07cfcdc2b80d37a989f177a3c7b75..42e187adc2d72c3e9efe607bc944379a0b9d486e 100644 --- a/src/Node.cpp +++ b/src/Node.cpp @@ -64,19 +64,19 @@ void Node::debugOutputRep(){ set<int> members; set<string> membersIP; set<int> locations; - string debug = "[DEBUGREP] ---------------------------\n"; + string debug = "[DEBUGREP] ---------------------------\n", randSenderIp; vector<tuple<string,string,int>> toDel; bool added = false; vector<int> randSender; tuple<string,int> minKey; - int minVal; + int minVal, repTarget; for (auto pos : hashRing->nodePositions) { members.insert(pos); membersIP.insert(hashRing->getValue(pos)); } for (auto &mapping : outputReplication){ minVal = 100; randSender.clear(); locations.clear(); - string randSenderIp = ""; - int repTarget = 0; + randSenderIp = ""; + repTarget = -1; for (auto &f: fileList[mapping.first]) locations.insert(f); for (auto &reps: mapping.second){ if (reps.second < minVal){ @@ -100,13 +100,13 @@ void Node::debugOutputRep(){ int index = 0; if (!randSender.size()) randSender.push_back(get<1>(minKey)); repTarget = hashRing->getRandomNode(tuple<int,int,int>(get<1>(minKey), get<1>(minKey), randSender[0])); - while (locations.count(repTarget) && index < 20){ + while (((repTarget == -1) || locations.count(repTarget)) && index < 20){ repTarget = hashRing->getRandomNode(tuple<int,int,int>(get<1>(minKey), repTarget, randSender[0])); index++; } } - if (randSenderIp.size() || repTarget){ - if (!repTarget) repTarget = get<1>(minKey); + if (randSenderIp.size() || (repTarget != -1)){ + if (repTarget == -1) repTarget = get<1>(minKey); if (!randSenderIp.size()) randSenderIp = get<0>(minKey); outputReplication[mapping.first][make_tuple(randSenderIp,repTarget)] = minVal; Messages outMsg(REP, randSenderIp + "::" + hashRing->getValue(repTarget)+"::"+to_string(minVal)+"::"+mapping.first+"::"+to_string(get<0>(fileSizes[mapping.first]))); @@ -1484,7 +1484,7 @@ void Node::handleTcpMessage() case REP: { //Messages outMsg(REP, randSenderIp + "::" + hashRing->getValue(repTarget)+"::"+to_string(minVal)+"::"+mapping.first+"::"+to_string(get<0>(fileSizes[mapping.first]))); if (inMsg[0].compare(nodeInformation.ip)){ - this->tcpServent->sendMessage(inMsg[0], TCPPORT, inMsg[1] + "::" + inMsg[2] + "::" + inMsg[3] + "::" + inMsg[4]); + this->tcpServent->sendMessage(inMsg[0], TCPPORT, inMsg[0] + "::" + inMsg[1] + "::" + inMsg[2] + "::" + inMsg[3] + "::" + inMsg[4]); } else{ string sendMsg = inMsg[1] + "::" + to_string(REPACK) + "::" + inMsg[3] + "::" + inMsg[2] + "::" + inMsg[3] + "," + inMsg[4] + "::";