Skip to content
Snippets Groups Projects
Commit 4492ca33 authored by ajf5's avatar ajf5
Browse files

logging

parent 8ead31f3
No related branches found
No related tags found
No related merge requests found
Wc 0 → 100755
File added
......@@ -6,11 +6,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
#include "HashRing.h"
using namespace std;
string getMostRecentFile(string readfile);
class FileObject {
public:
string fileName;
......
#ifndef MESSAGESTYPES_H
#define MESSAGESTYPES_H
const static char *messageTypes[] =
{
"ACK",
"JOIN",
"LEADERHEARTBEAT",
"LEADERPENDING",
"HEARTBEAT",
"SWREQ",
"SWRESP",
"JOINRESPONSE",
"JOINREJECT",
"ELECTION",
"ELECTIONACK",
"PUT",
"PUTACK",
"LEADERACK",
"DNS",
"DNSANS",
"DNSGET",
"DELETE",
"GETNULL",
"REREPLICATE",
"REREPLICATEGET",
"MAPLESTART",
"JUICESTART",
"MAPLEACK",
"CHUNK",
"CHUNKACK",
};
enum MessageType {
ACK,
JOIN, //used in joinSystem to join
......@@ -47,6 +77,7 @@ enum LogType {
GOSSIPTO,
GOSSIPFROM,
BANDWIDTH,
MEMBERS};
MEMBERS
};
#endif //MESSAGESTYPES_H
......@@ -22,3 +22,18 @@ int FileObject::getPositionOnHashring(){
positionOnHashring = hash<string>{}(toBeHashed) % HASHMODULO;
return 0;
}
string getMostRecentFile(string readfile){
struct dirent *entry = nullptr;
DIR *dp = nullptr;
int matchLen = readfile.size();
vector<string> fileVersions;
if ((dp = opendir(".")) == nullptr) { cout << "tmp directory error " << endl; return ""; }
while ((entry = readdir(dp))){
if (strncmp(entry->d_name, readfile.c_str(), matchLen) == 0){
fileVersions.push_back(entry->d_name);
}
}
sort(fileVersions.begin(), fileVersions.end());
return fileVersions[fileVersions.size()-1];
}
......@@ -139,13 +139,13 @@ void TcpSocket::sendLines(string ip, string port, string execfile, string readfi
vector<string> unDirectory = splitString(readfile, "-");
string toSend = execfile + "," + readfile + "," + to_string(start) + "," + prefix+"-tmp"+to_string(start)+"-"+unDirectory[1];
Messages msg(PUT, toSend);
cout << "[CHUNK] " << msg.toString() << endl;
cout << "[CHUNK] " << messageTypes[msg.type] << " | " << msg.toString() << endl;
string payload = msg.toString();
if (send(sockfd, payload.c_str(), strlen(payload.c_str()), 0) == -1) {
perror("send");
}
sleep(1);
ifstream file(readfile.c_str());
ifstream file(getMostRecentFile(readfile));
string str;
while (getline(file, str))
{
......@@ -227,7 +227,7 @@ int TcpSocket::messageHandler(int sockfd, string payloadMessage, string returnIP
overwriteFilename = fields[4];
overwrite = fields[5];
if ((stoi(overwrite)) == 0) mode = "ab";
cout << "file is " << sdfsfilename << " with size " << filesize << " and checksum " << incomingChecksum << endl;
cout << "[PUT] file is " << sdfsfilename << " with size " << filesize << " and checksum " << incomingChecksum << endl;
time_t fileTimestamp;
time(&fileTimestamp);
localfilename = sdfsfilename+"_"+to_string(fileTimestamp);
......@@ -242,7 +242,7 @@ int TcpSocket::messageHandler(int sockfd, string payloadMessage, string returnIP
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 << "exec: " << sdfsfilename << ", actual: " << remoteLocalname << ", start: " << fields[2] << ", temp: " << fields[3] << endl;
cout << "[PUT] exec: " << sdfsfilename << ", actual: " << remoteLocalname << ", start: " << fields[2] << ", temp: " << fields[3] << endl;
}
fp = fopen(localfilename.c_str(), mode.c_str());
if (fp == NULL) {
......@@ -293,7 +293,7 @@ int TcpSocket::messageHandler(int sockfd, string payloadMessage, string returnIP
case CHUNK:
case CHUNKACK:
case DNS:{
cout << "Type: " << msg.type << " payloadMessage: " << payloadMessage << endl;
cout << "Type: " << messageTypes[msg.type] << " payloadMessage: " << payloadMessage << endl;
regMessages.push(payloadMessage); //handle from queue
break;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment