diff --git a/Archive.zip b/Archive.zip new file mode 100644 index 0000000..873b10f Binary files /dev/null and b/Archive.zip differ diff --git a/Authorization b/Authorization old mode 100644 new mode 100755 diff --git a/Back-end.py b/Back-end.py old mode 100644 new mode 100755 diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index 0cf984a..a4ba469 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: rpfs.c python_caller.c python_caller.h rpfs.h +all: rpfs.c python_caller.c python_caller.h cc python_caller.c rpfs.c -o rpfs -D_FILE_OFFSET_BITS=64 -I/usr/local/include/fuse -pthread -L/usr/local/lib -lfuse -lssl -lcrypto clean: diff --git a/ReplicationNodeHandler.c b/ReplicationNodeHandler.c old mode 100644 new mode 100755 diff --git a/ReplicationNodeHandler.h b/ReplicationNodeHandler.h old mode 100644 new mode 100755 diff --git a/p205-decandia.pdf b/p205-decandia.pdf old mode 100644 new mode 100755 diff --git a/python_caller.c b/python_caller.c old mode 100644 new mode 100755 diff --git a/python_caller.h b/python_caller.h old mode 100644 new mode 100755 diff --git a/python_caller.o b/python_caller.o old mode 100644 new mode 100755 diff --git a/rpfs.c b/rpfs.c old mode 100644 new mode 100755 index 6a7ef17..90dbe29 --- a/rpfs.c +++ b/rpfs.c @@ -7,12 +7,10 @@ #include #include #include -#include +#include +#include #include "uthash.h" #include "python_caller.h" -#include "rpfs.h" - - struct photo { char md5string[MD5_DIGEST_LENGTH*2+1]; @@ -20,11 +18,169 @@ struct photo { UT_hash_handle hh; }; +struct photoBackup +{ + unsigned long long id; +}; + struct photo* photos = NULL; + static const char *master_path = "/master.node"; -char **nodeListing; -int backupNum; +int nodesAlive[10]; + +static int createBackup() +{ + int i; + char * name = "/tmp/backup/backup_"; + for(i = 0; i < 10; i++) + { + char filename[100]; + sprintf(filename, "%s%d", name, i); + FILE *f = fopen(filename, "w"); + fclose(f); + nodesAlive[i] = 1; + } + return 0; +} + +static int copy_file(char *old_filename, char *new_filename) + { + FILE *ptr_old, *ptr_new; + int err = 0, err1 = 0; + int a; + + ptr_old = fopen(old_filename, "rb"); + ptr_new = fopen(new_filename, "wb"); + + if(ptr_old == 0) + return -1; + + if(ptr_new == 0) + { + fclose(ptr_old); + return -1; + } + + while(1) + { + a = fgetc(ptr_old); + + if(!feof(ptr_old)) + fputc(a, ptr_new); + else + break; + } + + fclose(ptr_new); + fclose(ptr_old); + return 0; + } + +static int stillAlive() +{ + int i; + char * name = "/tmp/backup/backup_"; + for(i = 0; i < 10; i++) + { + char filename[100]; + sprintf(filename, "%s%d", name, i); + if(access(filename,F_OK) == 0) + { + if(nodesAlive[i] == 0) + { + printf("Erasing!\n"); + int otherIndex = 0; + int j; + for(j = 0; j < 10; j++) + { + if(nodesAlive[j] == 1) + { + otherIndex = j; + break; + } + } + char filename2[100]; + sprintf(filename2, "%s%d", name, otherIndex); + remove(filename); + copy_file(filename2,filename); + } + nodesAlive[i] = 1; + }else + { + nodesAlive[i] = 0; + } + } +} + +static int checkValue(struct photo * p) +{ + stillAlive(); + int i,j; + int agree = 0; + int disagree = 0; + char * name = "/tmp/backup/backup_"; + for(i = 0; i < 10; i++) + { + if(nodesAlive[i]) + { + char filename[100]; + sprintf(filename, "%s%d", name, i); + FILE *f = fopen(filename, "rb+"); + fseek(f, 0L, SEEK_END); + long sz = ftell(f); + fseek(f, 0L, SEEK_SET); + struct photoBackup* photosNodes = malloc(sz); + int agreed = 0; + fread(photosNodes, sizeof(photosNodes[0]), sz/sizeof(photosNodes[0]),f); + for(j = 0; j < sz/sizeof(photosNodes[0]); j++) + { + if(p->id == photosNodes[j].id) + { + agree++; + agreed = 1; + break; + } + } + if(!agreed) + { + disagree++; + } + free(photosNodes); + fclose(f); + } + } + if(agree >= disagree) + { + return 0; + } + else + { + return -1; + } + +} +static int putValue(struct photo *p) +{ + stillAlive(); + int i; + long sz = 0; + int agree = 0; + int disagree = 0; + char * name = "/tmp/backup/backup_"; + for(i = 0; i < 10; i++) + { + if(nodesAlive[i]) + { + char filename[100]; + sprintf(filename, "%s%d", name, i); + FILE *f = fopen(filename, "a"); + fwrite(&(p->id),sizeof(p->id), 1, f); + fclose(f); + } + } + return 0; +} static int rpfs_getattr(const char *path, struct stat *stbuf) { @@ -51,6 +207,7 @@ static int rpfs_setxattr(const char *path, const char *name, const char *value, return 0; } + static int rpfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { @@ -61,10 +218,6 @@ static int rpfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, filler(buf, ".", NULL, 0); filler(buf, "..", NULL, 0); filler(buf, master_path + 1, NULL, 0); - int i = 0; - for (i; i < backupNum; i++) { - filler(buf, nodeListing[i]+1, NULL, 0); - } return 0; } @@ -87,17 +240,7 @@ static int rpfs_open(const char *path, struct fuse_file_info *fi) static int rpfs_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { - - if(path != master_path && path != "/"){ - int errMsg = 0; - - errMsg = pwrite(fi->fh, buf, size, offset); - if (errMsg < 0) - return -errno; - - return errMsg; - } - + struct timeval tstartFull; struct timeval tstartFullEnd; gettimeofday(&tstartFull,NULL); @@ -120,12 +263,25 @@ static int rpfs_write(const char *path, const char *buf, size_t size, off_t offs } } - char* instr = malloc(index); - char* filename = malloc(strlen(buf)-index-1); + int index2 = 0; + for(i = index + 1; i < size; i++) + { + if(buf[i]==' ') + { + index2 = i + 1; + break; + } + index2 = i; + } + + char* instr = malloc(index + 1); + char* filename = malloc(index2 - index + 1); memcpy(instr, buf, index); - memcpy(filename, &buf[index+1], strlen(buf)-index); + memcpy(filename, &buf[index+1], index2 - index + 1); + instr[index] = '\0'; + filename[index2 - index - 1] = '\0'; printf("%s\n", instr); printf("%s\n", filename); @@ -133,12 +289,6 @@ static int rpfs_write(const char *path, const char *buf, size_t size, off_t offs if (strcmp(instr, "get")!=0 && strcmp(instr, "post")!=0) return -ENOENT; - // Check filename path validity, maybe not needed - for (i=0; iid); + }else + { + printf("Nodes did not agree!\n"); + } + } + else + { + printf("File does not exist!\n"); } - get(p->id); } // post - hash - if file exist, md5 hash, python @@ -167,113 +327,13 @@ static int rpfs_write(const char *path, const char *buf, size_t size, off_t offs memcpy(p->md5string, md5string, strlen(md5string)); //p->md5string = md5string; p->id = put(filename); + putValue(p); HASH_ADD_STR(photos, md5string, p); } gettimeofday(&tstartFullEnd, NULL); printf("Time spent performing entire operation: %4ld seconds and %d microseconds\n", tstartFullEnd.tv_sec - tstartFull.tv_sec, tstartFullEnd.tv_usec - tstartFull.tv_usec); return size; } -/* michael's shitty code*/ -/** - * Create and open a file - * - * If the file does not exist, first create it with the specified - * mode, and then open it. - * - * If this method is not implemented or under Linux kernel - * versions earlier than 2.6.15, the mknod() and open() methods - * will be called instead. - * - * Introduced in version 2.5 - * - * mode is 0777 | S_IFREG (if regular file) - */ -static int rpfs_create(const char *path, mode_t mode, struct fuse_file_info *fi){ - int fd; - fd = creat(path, mode); - if(fd < 0) - return -errno; - return fd; - -} - -/** Read data from an open file - * - * Read should return exactly the number of bytes requested except - * on EOF or error, otherwise the rest of the data will be - * substituted with zeroes. An exception to this is when the - * 'direct_io' mount option is specified, in which case the return - * value of the read system call will reflect the return value of - * this operation. - * - * Changed in version 2.2 - */ - -static int rpfs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi){ - int errMsg = 0; - errMsg = pread(fi->fh, buf, size, offset); - if (errMsg < 0) - return -errMsg; - - return errMsg; -} - -static int rpfs_writeBackup(mode_t mode, size_t size,struct fuse_file_info *fi){ - int erMsg; - erMsg = rpfs_checkCrash(fi); - if(erMsg < 0){ - return erMsg; - } - char *metaDataCopy; - rpfs_read(master_path, metaDataCopy, size, 0, fi); - int i = 0; - for (i; i < backupNum; i++) { - rpfs_write(nodeListing[i], metaDataCopy, size, 0, fi); - } - return erMsg; -} - -static int rpfs_checkCrash(struct fuse_file_info *fi){ - int errMsg; - DIR *dp = opendir("/"); - if(dp == NULL){ - return -errno; - } - int index = 0; - while(index < backupNum){ - if(fopen(nodeListing[index], 'w+')!= NULL){ - errMsg = rpfs_create(nodeListing[index], S_IFREG|0777, fi); - - } - } - /* TO DO: - Check err clauses - */ - return errMsg; - -} - -//creates nodes -static int rpfs_init(int backups){ - backupNum=backups; - int i = 0; - for(i; i> "$destdir" +done +