diff --git a/program/Build/RaspberryCloud.sdf b/program/Build/RaspberryCloud.sdf index fc689ef9c000ed498bd0eccd96149902c6b599d0..e97bf8390bff699ce4eaec9c5ea6c8c7ee5e686c 100644 Binary files a/program/Build/RaspberryCloud.sdf and b/program/Build/RaspberryCloud.sdf differ diff --git a/program/Build/RaspberryCloud.v12.suo b/program/Build/RaspberryCloud.v12.suo index 96f8b4f1153a378a17093a8ad958187a533169a2..44482ad31c43cff93d6fe360d3d16c0ef38d42bb 100644 Binary files a/program/Build/RaspberryCloud.v12.suo and b/program/Build/RaspberryCloud.v12.suo differ diff --git a/program/Source/app/Application.cpp b/program/Source/app/Application.cpp index 874c0a9dc1ad2b746ecb094eeeb8da41c2e4c4b2..4988a89bbc9adb418aa762e7eaf2293b9cf5c380 100644 --- a/program/Source/app/Application.cpp +++ b/program/Source/app/Application.cpp @@ -1,4 +1,6 @@ #include <string.h> +#include <ctime> +#include <random> #include "../logger/Logger.h" #include "Application.h" #include "../cloud/LocalCloudAdapter.h" @@ -13,6 +15,8 @@ #define WITH_MEASURE +#include <boost/lexical_cast.hpp> + using namespace std; /** @@ -36,7 +40,7 @@ const string Application::SERVER = "server"; * Requests commands from the user and sends them to the UI */ -int main(int argc, char **argv) { +int main2(int argc, char **argv){ LOG_ENTER_EXIT; Application application; @@ -71,8 +75,12 @@ int main(int argc, char **argv) { } } - application.cfs.getEncoder()->setFolders(dataFolder,fragFolder); - application.cfs.getDecoder()->setFolders(dataFolder,fragFolder); + application.cfs.getEncoder()->setFolders(dataFolder, fragFolder); + application.cfs.getDecoder()->setFolders(dataFolder, fragFolder); + + application.cfs.getEncoder()->setSymbols(4, 128, 1.0); + application.cfs.getDecoder()->setSymbols(4, 128, 1.0); + application.cfs.setFolders(fragFolder); Cache *cacheToSetup = nullptr; @@ -140,7 +148,7 @@ int main(int argc, char **argv) { cout << "Welcome to the amazing RaspberryCloud application" << endl; cout << "=================================================" << endl << endl; cout << "Setting up system" << endl; - + while (true){ cout << "Please set home network behaviour (pi/client)" << endl; string answer = ""; @@ -153,7 +161,7 @@ int main(int argc, char **argv) { application.ui.setComputeOnPi(false); break; } - } + } cout << "To list avaliable orders enter \"help\"." << endl; @@ -204,14 +212,15 @@ int main(int argc, char **argv) { ReturnableFile returned = application.ui.getFile(fileDesc); if (returned.isValid()) { cout << "Successfully downloaded: " << returned.getLocalFileId() << endl; - } else { + } + else { cout << "ERROR with getting: " << returned.getLocalFileId() << endl << returned.getErrorMessage() << endl; - } + } } else if (command == "getFileList"){ list<FileDescriptor*>* fileTree = application.ui.getFileTree(); cout << "fileTree has " << fileTree->size() << " file(s)." << endl; - for(FileDescriptor* fileD : *fileTree) + for (FileDescriptor* fileD : *fileTree) { cout << fileD->getFileID() << endl; for (Fragment f : fileD->getFragments()){ @@ -259,6 +268,380 @@ int main(int argc, char **argv) { cout << "Completed in: " << double(stop - start) / CLOCKS_PER_SEC * 1000 << "ms" << endl; #endif } + + return 0; +} + +void addFile(Application& application, string localid, string destid) { + //cout << + application.ui.addFile(localid, destid); + //<< endl; +} + +void getFile(Application& application, string fileid) { + FileDescriptor fileDesc = FileDescriptor(fileid); + ReturnableFile returned = application.ui.getFile(fileDesc); + //if (returned.isValid()) { + // cout << "Successfully downloaded: " << returned.getLocalFileId() << endl; + //} + //else { + // cout << "ERROR with getting: " << returned.getLocalFileId() << endl << returned.getErrorMessage() << endl; + //} +} + +void getFileList(Application& application) { + list<FileDescriptor*>* fileTree = application.ui.getFileTree(); + cout << "fileTree has " << fileTree->size() << " file(s)." << endl; + for (FileDescriptor* fileD : *fileTree) + { + cout << fileD->getFileID() << endl; + for (Fragment f : fileD->getFragments()){ + cout << f.getCloudFileID() << endl; + cout << f.getCloudId() << endl; + } + } +} + +void deleteFile(Application& application, string fileid) { + FileDescriptor fileDesc = FileDescriptor(fileid); + cout << application.ui.deleteFile(fileDesc) << endl; +} + +int test1(){ + Application application; + + application.cm.addCloud(make_shared<LocalCloudAdapter>()); + application.cm.addCloud(make_shared<DropboxAdapter>()); + //application.cm.addCloud(make_shared<FTPAdapter>()); + + string dataFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\data\\"; + string fragFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\temp\\"; + string cloudFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\cloud\\"; + string cacheFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\cache\\"; + + application.cfs.getEncoder()->setFolders(dataFolder, fragFolder); + application.cfs.getDecoder()->setFolders(dataFolder, fragFolder); + application.cfs.setFolders(fragFolder); + + Cache *cacheToSetup; + + int cacheSize = 16; + //cacheToSetup = new NoCache(); + cacheToSetup = new FIFOCache(cacheSize); + //cacheToSetup = new LRUCache(cacheSize); + //cacheToSetup = new LFUCache(cacheSize); + + application.cfs.setCache(cacheToSetup); + application.cfs.getCache()->setFolders(cacheFolder, dataFolder); + application.cfs.getCache()->readCache(); + + application.hnc.setDataFolder(dataFolder); + + for (auto ca : application.cm.getCloudList()){ + ca->setFolders(cloudFolder, fragFolder); + } + + application.ui.setComputeOnPi(false); + + clock_t begin = clock(); + + + addFile(application, "1.html", "1.html"); + addFile(application, "2.html", "2.html"); + addFile(application, "3.html", "3.html"); + addFile(application, "4.html", "4.html"); + addFile(application, "5.html", "5.html"); + addFile(application, "6.html", "6.html"); + addFile(application, "7.html", "7.html"); + addFile(application, "8.html", "8.html"); + addFile(application, "9.html", "9.html"); + addFile(application, "10.html", "10.html"); + addFile(application, "11.html", "11.html"); + addFile(application, "12.html", "12.html"); + addFile(application, "13.html", "13.html"); + addFile(application, "14.html", "14.html"); + addFile(application, "15.html", "15.html"); + addFile(application, "16.html", "16.html"); + addFile(application, "17.html", "17.html"); + addFile(application, "18.html", "18.html"); + addFile(application, "19.html", "19.html"); + addFile(application, "20.html", "20.html"); + + std::default_random_engine generator; + std::normal_distribution<double> distribution(10.0, 4.0); + const int nrolls = 300; // number of experiments + const double nfiles = 20.0; // number of files + int out = 0; + double elapsed_secs = 0; + + for (int i = 0; i<nrolls; ++i) { + if (i % 10 == 0) { + cout << i * 100 / nrolls << "%" << endl; + } + int random1 = -1.0; + int random2 = -1.0; + + double number1 = distribution(generator); + if ((number1 >= 0.0) && (number1 < nfiles)) { + random1 = int(number1); + } + else { + out++; + } + + double number2 = distribution(generator); + if ((number2 >= 0.0) && (number2 < nfiles)) { + random2 = int(number2); + } + else { + out++; + } + + if (random1 > 0 && random2 > 0 && random1 < 20 && random2 < 20) { + string file1 = boost::lexical_cast<string>(random1)+".html"; + string file2 = boost::lexical_cast<string>(random2)+".html"; + + addFile(application, file1, file1); + getFile(application, file2); + } + } + + clock_t end = clock(); + elapsed_secs += double(end - begin); + + deleteFile(application, "1.html"); + deleteFile(application, "2.html"); + deleteFile(application, "3.html"); + deleteFile(application, "4.html"); + deleteFile(application, "5.html"); + deleteFile(application, "6.html"); + deleteFile(application, "7.html"); + deleteFile(application, "8.html"); + deleteFile(application, "9.html"); + deleteFile(application, "10.html"); + deleteFile(application, "11.html"); + deleteFile(application, "12.html"); + deleteFile(application, "13.html"); + deleteFile(application, "14.html"); + deleteFile(application, "15.html"); + deleteFile(application, "16.html"); + deleteFile(application, "17.html"); + deleteFile(application, "18.html"); + deleteFile(application, "19.html"); + deleteFile(application, "20.html"); + + application.cfs.getCache()->clearCache(); + + cout << "Out: " << out << endl; + cout.precision(15); + cout << "Spent time:" << elapsed_secs << endl; + + + int i; + cin >> i; + return 0; +} + +int test2(){ + Application application; + + application.cm.addCloud(make_shared<LocalCloudAdapter>()); + //application.cm.addCloud(make_shared<DropboxAdapter>()); + //application.cm.addCloud(make_shared<FTPAdapter>()); + + string dataFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\data\\"; + string fragFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\temp\\"; + string cloudFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\cloud\\"; + string cacheFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\cache\\"; + + application.cfs.getEncoder()->setFolders(dataFolder, fragFolder); + application.cfs.getDecoder()->setFolders(dataFolder, fragFolder); + + application.cfs.setFolders(fragFolder); + + Cache *cacheToSetup; + + cacheToSetup = new NoCache(); + + application.cfs.setCache(cacheToSetup); + application.cfs.getCache()->setFolders(cacheFolder, dataFolder); + application.cfs.getCache()->readCache(); + + application.hnc.setDataFolder(dataFolder); + + for (auto ca : application.cm.getCloudList()){ + ca->setFolders(cloudFolder, fragFolder); + } + + application.ui.setComputeOnPi(false); + + int redundancy = 1.5; + for (int max_symbols = 1; max_symbols <= 64; max_symbols *= 2){ + for (int max_symbol_size = 128; max_symbol_size <= 4096; max_symbol_size *= 2) { + application.cfs.getEncoder()->setSymbols(max_symbols, max_symbol_size, redundancy); + application.cfs.getDecoder()->setSymbols(max_symbols, max_symbol_size, redundancy); + + for (int i = 0; i < 9; i++) { + + double elapsed_secs = 0; + clock_t begin = clock(); + + string file1 = boost::lexical_cast<string>(i + 1) + ".html"; + addFile(application, file1, file1); + deleteFile(application, file1); + + + clock_t end = clock(); + elapsed_secs += double(end - begin); + + cout.precision(15); + cout << "File size: " << pow(2, i) << "KB Spent time:" << elapsed_secs << "Max sym: " << max_symbols << " MSS: " << max_symbol_size << endl; + } + } + } + + int i; + cin >> i; + return 0; +} + +int redTest() { + Application application; + + application.cm.addCloud(make_shared<LocalCloudAdapter>()); + //application.cm.addCloud(make_shared<DropboxAdapter>()); + //application.cm.addCloud(make_shared<FTPAdapter>()); + + string dataFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\data\\"; + string fragFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\temp\\"; + string cloudFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\cloud\\"; + string cacheFolder = "C:\\Users\\krisz\\raspberrycloud\\skeleton\\Program\\cache\\"; + double redundancy = 1.5; + + + application.cfs.getEncoder()->setFolders(dataFolder, fragFolder); + application.cfs.getDecoder()->setFolders(dataFolder, fragFolder); + application.cfs.getEncoder()->setSymbols(4, 128, redundancy); + application.cfs.getDecoder()->setSymbols(4, 128, redundancy); + + application.cfs.setFolders(fragFolder); + + bool waitAnswer = true; + Cache *cacheToSetup; + cacheToSetup = new FIFOCache(12); + application.cfs.setCache(cacheToSetup); + application.cfs.getCache()->setFolders(cacheFolder, dataFolder); + application.cfs.getCache()->readCache(); + + application.hnc.setDataFolder(dataFolder); + + for (auto ca : application.cm.getCloudList()){ + ca->setFolders(cloudFolder, fragFolder); + } + + string command = ""; + cout << "=================================================" << endl; + cout << "Welcome to the amazing RaspberryCloud application" << endl; + cout << "=================================================" << endl << endl; + cout << "Setting up system" << endl; + + application.ui.setComputeOnPi(false); + + cout << "To list avaliable orders enter \"help\"." << endl; + + while (true){ + cout << "Please give a new order!" << endl; + cin >> command; + + if (command == "help"){ + cout << "To stop the application enter \"exit\"." << endl; + cout << "To add a new file enter \"addFile\"." << endl; + cout << "To create a new directory enter \"createDirectory\"." << endl; + cout << "To get a file enter \"getFile\"." << endl; + cout << "To get the avaliable files enter \"getFileList\"." << endl; + cout << "To delete a file enter \"deleteFile\"." << endl; + cout << "To authorize a cloud adapter enter \"authCA\"." << endl; + cout << "To start or stop the server enter \"serverCfg\"." << endl; + } + else if (command == "addFile"){ + cout << "Adding file. Please enter local file id" << endl; + string localid; + string destid; + cin >> localid; + cout << "Adding file. Please enter destination file id" << endl; + cin >> destid; + cout << application.ui.addFile(localid, destid, redundancy) << endl; + } + else if (command == "createDirectory"){ + cout << "Creating directory. Please enter directory id" << endl; + string dirid; + cin >> dirid; + cout << application.ui.createDirectory(dirid) << endl; + } + else if (command == "getFile"){ + cout << "Getting file. Please enter file id" << endl; + string fileid; + cin >> fileid; + FileDescriptor fileDesc = FileDescriptor(fileid); + ReturnableFile returned = application.ui.getFile(fileDesc); + if (returned.isValid()) { + cout << "Successfully downloaded: " << returned.getLocalFileId() << endl; + } + else { + cout << "ERROR with getting: " << returned.getLocalFileId() << endl << returned.getErrorMessage() << endl; + } + } + else if (command == "getFileList"){ + list<FileDescriptor*>* fileTree = application.ui.getFileTree(); + cout << "fileTree has " << fileTree->size() << " file(s)." << endl; + for (FileDescriptor* fileD : *fileTree) + { + cout << fileD->getFileID() << endl; + for (Fragment f : fileD->getFragments()){ + cout << f.getCloudFileID() << endl; + cout << f.getCloudId() << endl; + } + } + } + else if (command == "deleteFile"){ + cout << "Deleting file. Please enter file id" << endl; + string fileid; + cin >> fileid; + FileDescriptor fileDesc = FileDescriptor(fileid); + cout << application.ui.deleteFile(fileDesc) << endl; + } + else if (command == "authCA") + { + cout << "Enter cloud adapter ID (eg. \"dropboxAdapter\")" << endl; + string cloudAdapterId; + cin >> cloudAdapterId; + application.ui.authCloudAdapter(cloudAdapterId); + } + else if (command == "serverCfg") + { + string startOrStop; + cout << "Start or stop server?" << endl; + cin >> startOrStop; + + if (startOrStop == "start") + application.ui.startServer(true); + else + application.ui.startServer(false); + } + else if (command == "exit"){ + cout << "Bye! Thanks for choosing us." << endl; + return 0; + } + else { + cout << "Invalid command." << endl; + } + } + return 0; } + +int main(int argc, char **argv) { + cout << CLOCKS_PER_SEC << endl; + return redTest(); +} \ No newline at end of file diff --git a/program/Source/app/UI.cpp b/program/Source/app/UI.cpp index 91164e912bb1d56b6b810102e5346fe5d1701c26..871da06929657bd2893f773d8f6812f8cb2ca841 100644 --- a/program/Source/app/UI.cpp +++ b/program/Source/app/UI.cpp @@ -18,9 +18,9 @@ UI::UI(Application& app) : LOG_ENTER_EXIT; } -bool UI::addFile(string localFileID, string destinationFileID) { +bool UI::addFile(string localFileID, string destinationFileID, double redundancy) { LOG_ENTER_EXIT; - return app.cfs.addFile(localFileID, destinationFileID); + return app.cfs.addFile(localFileID, destinationFileID, redundancy); } bool UI::createDirectory(string directoryID) { @@ -39,7 +39,6 @@ bool UI::deleteFile(FileDescriptor fileDescriptor) { LOG_ENTER_EXIT; return app.cfs.deleteFile(fileDescriptor); } - void UI::setComputeOnPi(bool b) { LOG_ENTER_EXIT; if (b){ diff --git a/program/Source/app/UI.h b/program/Source/app/UI.h index 68e63faadf9cb7584cf2a2148c1c2422fc4440b6..0cbbfbf8c604532b4d35df8e989ed90ce2d6f71c 100644 --- a/program/Source/app/UI.h +++ b/program/Source/app/UI.h @@ -34,7 +34,7 @@ public: * @param destinationFileID remote path to the file to add * @return successful */ - bool addFile(std::string localFileID, std::string destinationFileID); + bool addFile(std::string localFileID, std::string destinationFileID, double redundancy = 1.0); /** * It starts the process of creating a new directory diff --git a/program/Source/cache/Cache.h b/program/Source/cache/Cache.h index a02c9c9a4d27e4653978ebf24ec3b6cdfd0a7983..d71a818505c6389a2eb50971ffc4f8f35d616165 100644 --- a/program/Source/cache/Cache.h +++ b/program/Source/cache/Cache.h @@ -40,6 +40,16 @@ public: virtual bool addFile(std::string localFileID) = 0; virtual void readCache() = 0; + + void clearCache() { + for (int i = 0; i < maxSize; i++) { + if (files[i].getFileId() != "") { + string spath = cacheFolder + files[i].getFileId(); + const char* path = spath.c_str(); + int res = remove(path); + } + } + } }; #endif //_CACHE_H \ No newline at end of file diff --git a/program/Source/cache/LFUCache.cpp b/program/Source/cache/LFUCache.cpp index ef223028adc6fb266269614165cbdac5b5c79b80..55f20f70dbb94e14b7c8c7c9b676e0025af128f9 100644 --- a/program/Source/cache/LFUCache.cpp +++ b/program/Source/cache/LFUCache.cpp @@ -77,7 +77,7 @@ bool LFUCache::addFile(std::string localFileID) { ofstream dst(cacheFolder + localFileID, ios::binary); if (dst) { int minAge = 2147483647; - for (int i = 0; i < minAge; i++) + for (int i = 0; i < maxSize; i++) { if (files[i].used < minAge) { minAge = files[i].used; diff --git a/program/Source/dataAccess/CloudFileSystem.cpp b/program/Source/dataAccess/CloudFileSystem.cpp index 039bd58b98b43bdfc91d959dbbf1ace45f8064e4..1bc6c7dce04132ccf7bf121a7cee8a67b90b1386 100644 --- a/program/Source/dataAccess/CloudFileSystem.cpp +++ b/program/Source/dataAccess/CloudFileSystem.cpp @@ -71,7 +71,7 @@ bool CloudFileSystem::getComputeOnPi(){ return computeOnPi; } -bool CloudFileSystem::addFile(string localFileID, string destinationFileID) { +bool CloudFileSystem::addFile(string localFileID, string destinationFileID, double redundancy = 1.0) { LOG_ENTER_EXIT; if (homeNetworkBehaviour == nullptr) { @@ -79,7 +79,7 @@ bool CloudFileSystem::addFile(string localFileID, string destinationFileID) { return false; } - return homeNetworkBehaviour->addFile(localFileID, destinationFileID); + return homeNetworkBehaviour->addFile(localFileID, destinationFileID, redundancy); } diff --git a/program/Source/dataAccess/CloudFileSystem.h b/program/Source/dataAccess/CloudFileSystem.h index a1fbfc99d66852b48ae5998eb04b29b6d11dadad..31b70e945490e0856b98176814b92e9b6a964da4 100644 --- a/program/Source/dataAccess/CloudFileSystem.h +++ b/program/Source/dataAccess/CloudFileSystem.h @@ -99,7 +99,7 @@ public: * @param localFileID full path of the local file to upload * @param destinationFileID full path of the file on the cloud */ - bool addFile(std::string localFileID, std::string destinationFileID); + bool addFile(std::string localFileID, std::string destinationFileID, double redundancy); /** * Downloads a file from the cloud diff --git a/program/Source/dataAccess/ComputeOnClient.cpp b/program/Source/dataAccess/ComputeOnClient.cpp index 00c130a091eacdc2185f2ecbfc6ce14e21c0c2ab..8a85a96cea2187f86e66db92d53b4be67e29538a 100644 --- a/program/Source/dataAccess/ComputeOnClient.cpp +++ b/program/Source/dataAccess/ComputeOnClient.cpp @@ -13,7 +13,7 @@ using namespace std; * ComputeOnClient implementation */ -bool ComputeOnClient::addFile(string localFileID, string destinationFileID) { +bool ComputeOnClient::addFile(string localFileID, string destinationFileID, double redundancy) { LOG_ENTER_EXIT; bool success; @@ -24,7 +24,7 @@ bool ComputeOnClient::addFile(string localFileID, string destinationFileID) { auto fileDescriptor = Encoder::encode(localFileID, destinationFileID); if (cloudFileSystem.addToFileTreeByID(fileDescriptor)){ - if (cloudFileSystem.getDistributor()->distribute(fileDescriptor)) { + if (cloudFileSystem.getDistributor()->distribute(fileDescriptor, redundancy)) { cloudFileSystem.getCloudFileList()->save(); success = cloudFileSystem.getCloudAccessLayer()->upload(*fileDescriptor); } diff --git a/program/Source/dataAccess/ComputeOnClient.h b/program/Source/dataAccess/ComputeOnClient.h index 03c363658870d16d33f910e306ce17af41636460..0b3c84004f2cedc97b07caaaf76c9f82e2680e08 100644 --- a/program/Source/dataAccess/ComputeOnClient.h +++ b/program/Source/dataAccess/ComputeOnClient.h @@ -26,8 +26,9 @@ public: * Adds a file to the cloud * @param localFileID path of file to be added * @param destinationFileID path of file on cloud + * @param redundancy rate of redundancy: 100% -> 1.0, 150% -> 1.5 */ - bool addFile(std::string localFileID, std::string destinationFileID) override; + bool addFile(std::string localFileID, std::string destinationFileID, double redundancy) override; /** * Gets a file from the cloud diff --git a/program/Source/dataAccess/ComputeOnPi.cpp b/program/Source/dataAccess/ComputeOnPi.cpp index d6faea6c98b9e38d0603c6c754b4aa6b33c5c9dd..c9caaa5ddb6e02624d497239639c4e20a190b5f4 100644 --- a/program/Source/dataAccess/ComputeOnPi.cpp +++ b/program/Source/dataAccess/ComputeOnPi.cpp @@ -6,7 +6,7 @@ using namespace std; * ComputeOnPi implementation */ -bool ComputeOnPi::addFile(string localFileID, string destinationFileID) { +bool ComputeOnPi::addFile(string localFileID, string destinationFileID, double redundancy) { return cloudFileSystem.getHomeNetworkCommunications()->addFileRemote(localFileID); } diff --git a/program/Source/dataAccess/ComputeOnPi.h b/program/Source/dataAccess/ComputeOnPi.h index 06c25a060961f7966a7b01545c27706bedd44ada..384c98442abb452eb05abd4f2b93505c7e7186e2 100644 --- a/program/Source/dataAccess/ComputeOnPi.h +++ b/program/Source/dataAccess/ComputeOnPi.h @@ -23,8 +23,9 @@ public: * Adds a file to the cloud * @param localFileID path of file to be added * @param destinationFileID path of file on cloud + * @param redundancy rate of redundancy: 100% -> 1.0, 150% -> 1.5 */ - bool addFile(std::string localFileID, std::string destinationFileID); + bool addFile(std::string localFileID, std::string destinationFileID, double redundancy); /** * Gets a file from the cloud diff --git a/program/Source/dataAccess/Decoder.cpp b/program/Source/dataAccess/Decoder.cpp index 5fde2b48ce6b91ea742c5faf39b7043a6b5d67e3..22c902370094bbb6ce7017fdb60064522bba44b4 100644 --- a/program/Source/dataAccess/Decoder.cpp +++ b/program/Source/dataAccess/Decoder.cpp @@ -19,8 +19,17 @@ void Decoder::setFolders(string _dataFolder, string _fragFolder){ fragFolder = _fragFolder; } +void Decoder::setSymbols(int _max_symbols, int _max_symbol_size, double _redundancy){ + max_symbols = _max_symbols; + max_symbol_size = _max_symbol_size; + redundancy = _redundancy; +} + string Decoder::dataFolder = ""; string Decoder::fragFolder = ""; +int Decoder::max_symbols = 10; +int Decoder::max_symbol_size = 256; +double Decoder::redundancy = 1.0; ReturnableFile Decoder::decode(FileDescriptor* fileDescriptor) { @@ -35,8 +44,8 @@ ReturnableFile Decoder::decode(FileDescriptor* fileDescriptor) auto fragments = fileDescriptor->getFragments(); if (fragments.size() > 0) { - uint32_t max_symbols = 10; - uint32_t max_symbol_size = fileDescriptor->getSize() / 10 + 1; + //uint32_t max_symbols = 10; + //uint32_t max_symbol_size = 256; using file_decoder = kodo::object::file_decoder< kodo::shallow_full_rlnc_decoder<fifi::binary>>; diff --git a/program/Source/dataAccess/Decoder.h b/program/Source/dataAccess/Decoder.h index d4ec1107773f9847ddd3bddf8a09302f24bdbd3f..82673ffa0c584df6dd88df149223b560751ac241 100644 --- a/program/Source/dataAccess/Decoder.h +++ b/program/Source/dataAccess/Decoder.h @@ -12,8 +12,12 @@ class Decoder { static std::string dataFolder; static std::string fragFolder; + static int max_symbols; + static int max_symbol_size; + static double redundancy; public: void setFolders(std::string _dataFolder, std::string _fragFolder); + void setSymbols(int max_symbols, int max_symbol_size, double redundancy); /** * decodes the fragments to a file diff --git a/program/Source/dataAccess/Distributor.cpp b/program/Source/dataAccess/Distributor.cpp index f726fd8e30786c1fb2539c20e85c20e5f54e30f6..53f7a65808493a7623c7b506e7641d08e985410d 100644 --- a/program/Source/dataAccess/Distributor.cpp +++ b/program/Source/dataAccess/Distributor.cpp @@ -19,7 +19,7 @@ Distributor::Distributor(CloudManager &cloudManager) : cloudManager(cloudManager }*/ } -bool Distributor::distribute(FileDescriptor* fileDescriptor) { +bool Distributor::distribute(FileDescriptor* fileDescriptor, double redundancy) { LOG_ENTER_EXIT; auto cloudIDs = cloudManager.getCloudList(); diff --git a/program/Source/dataAccess/Distributor.h b/program/Source/dataAccess/Distributor.h index 9ee707841f2dd1678041465b1efcc96b2ffdd611..0df797647e5a79126b27cf4079dd4ae3c93c0de2 100644 --- a/program/Source/dataAccess/Distributor.h +++ b/program/Source/dataAccess/Distributor.h @@ -27,7 +27,7 @@ public: * It sets the files' fragments' cloudIDs to a valid cloudAdapter ID * @param fileDescriptor */ - bool distribute(FileDescriptor* fileDescriptor); + bool distribute(FileDescriptor* fileDescriptor, double redundancy); }; #endif //_DISTRIBUTOR_H \ No newline at end of file diff --git a/program/Source/dataAccess/Encoder.cpp b/program/Source/dataAccess/Encoder.cpp index f9186758f5c738be53ab2d8cae6aa9a14c2d7c7b..57012d87bf690df0f8350eacb68950e9bb3ef49c 100644 --- a/program/Source/dataAccess/Encoder.cpp +++ b/program/Source/dataAccess/Encoder.cpp @@ -22,8 +22,17 @@ void Encoder::setFolders(string _dataFolder, string _fragFolder){ fragFolder = _fragFolder; } +void Encoder::setSymbols(int _max_symbols, int _max_symbol_size, double _redundancy){ + max_symbols = _max_symbols; + max_symbol_size = _max_symbol_size; + redundancy = _redundancy; +} + string Encoder::dataFolder = ""; string Encoder::fragFolder = ""; +int Encoder::max_symbols = 10; +int Encoder::max_symbol_size = 256; +double Encoder::redundancy = 1.0; FileDescriptor* Encoder::encode(string localFileID, string destinationFileID) { LOG_ENTER_EXIT; @@ -45,8 +54,8 @@ FileDescriptor* Encoder::encode(string localFileID, string destinationFileID) { long file_size = filesystem::file_size(encode_filename); encoded->setSize(file_size); - uint32_t max_symbols = 10; - uint32_t max_symbol_size = file_size / 10 + 1; + //uint32_t max_symbols = 10; //db + //uint32_t max_symbol_size = 256; // file_size / 10 + 1; //byte <- mindig 1 k�dol� using file_encoder = kodo::object::file_encoder< kodo::shallow_full_rlnc_encoder<fifi::binary >> ; @@ -62,7 +71,7 @@ FileDescriptor* Encoder::encode(string localFileID, string destinationFileID) { vector<uint8_t> payload(e->payload_size()); - for (uint32_t j = 0; j < max_symbols; j++) + for (uint32_t j = 0; j < (e->symbols()*redundancy); j++) { e->encode(payload.data()); diff --git a/program/Source/dataAccess/Encoder.h b/program/Source/dataAccess/Encoder.h index d86253091300505cec6152c9964fd67f2a35aca5..f79c503b41b14907af795f08cd78f7c3f8ccee80 100644 --- a/program/Source/dataAccess/Encoder.h +++ b/program/Source/dataAccess/Encoder.h @@ -12,8 +12,12 @@ class Encoder { static std::string dataFolder; static std::string fragFolder; + static int max_symbols; + static int max_symbol_size; + static double redundancy; public: void setFolders(std::string _dataFolder, std::string _fragFolder); + void setSymbols(int max_symbols, int max_symbol_size, double redundancy); /** * encodes the file to fragments diff --git a/program/Source/dataAccess/HomeNetworkBehaviour.h b/program/Source/dataAccess/HomeNetworkBehaviour.h index 60b8cf69e0cb571393d03154222a5bab7a906377..77ffb7096e33983c89479d17bfc2b85b6d74b6f7 100644 --- a/program/Source/dataAccess/HomeNetworkBehaviour.h +++ b/program/Source/dataAccess/HomeNetworkBehaviour.h @@ -19,8 +19,9 @@ public: * Adds a file to the cloud * @param localFileID path of file to be added * @param destinationFileID path of file on cloud + * @param redundancy rate of redundancy: 100% -> 1.0, 150% -> 1.5 */ - virtual bool addFile(std::string localFileID, std::string destinationFileID) = 0; + virtual bool addFile(std::string localFileID, std::string destinationFileID, double redundancy) = 0; /** * Gets a file from the cloud diff --git a/program/Source/networking/FileServerConnection.cpp b/program/Source/networking/FileServerConnection.cpp index 82a38329694db7e2067d53d807ceee48c695a3f3..cada50de3a1caeef276a9a3d5f0a34efe7b7aab0 100644 --- a/program/Source/networking/FileServerConnection.cpp +++ b/program/Source/networking/FileServerConnection.cpp @@ -82,7 +82,8 @@ void FileServerConnection::run() file.close(); cout << "received: " << fileName << endl; - auto result = app.cfs.addFile(fileName, fileName); + // TODO: implement sending of redundancy + auto result = app.cfs.addFile(fileName, fileName, 1.0); if (!result) cout << "error uploading file: " << fileName << endl; else