diff --git a/program/Build/RaspberryCloud.sdf b/program/Build/RaspberryCloud.sdf index b20cf7c7d5366d51979ea664a9367942cdfa0072..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 0e216ea257a0b66722d14df7ba57eba18b9c9069..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 d14c277b90112c241785f96f55c710e8d2489721..a7100c2e502d5887ff70e5d8cc7e27d97b1694d8 100644 --- a/program/Source/app/Application.cpp +++ b/program/Source/app/Application.cpp @@ -481,7 +481,143 @@ int test2(){ 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 main2(argc, argv); + 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/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/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 8533c232149afc7bb5b9ed581a2bdeaf586b32b2..57012d87bf690df0f8350eacb68950e9bb3ef49c 100644 --- a/program/Source/dataAccess/Encoder.cpp +++ b/program/Source/dataAccess/Encoder.cpp @@ -71,7 +71,7 @@ FileDescriptor* Encoder::encode(string localFileID, string destinationFileID) { vector<uint8_t> payload(e->payload_size()); - for (uint32_t j = 0; j < e->symbols(); j++) + for (uint32_t j = 0; j < (e->symbols()*redundancy); j++) { e->encode(payload.data()); 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 08233bff94655b31ef919c12a4269c15d30ec406..6c7bccbdab371db65fa94c31283db6108b2383f4 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