Alexander Afanasyev | 026eaf3 | 2013-02-23 16:37:14 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 20 | */ |
| 21 | |
| 22 | #ifndef STATE_SERVER_H |
| 23 | #define STATE_SERVER_H |
| 24 | |
| 25 | #include "ccnx-wrapper.h" |
| 26 | #include "object-manager.h" |
| 27 | #include "object-db.h" |
| 28 | #include "action-log.h" |
| 29 | #include <set> |
| 30 | #include <map> |
| 31 | #include <boost/thread/shared_mutex.hpp> |
| 32 | #include <boost/thread/locks.hpp> |
Alexander Afanasyev | 95f9f55 | 2013-02-26 23:05:20 -0800 | [diff] [blame] | 33 | #include "executor.h" |
Alexander Afanasyev | 026eaf3 | 2013-02-23 16:37:14 -0800 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * @brief Class serving state information from ChronoShare |
| 37 | * |
| 38 | * Eventually, the same info/actions can be made available via a global scope prefix |
| 39 | * |
| 40 | * Information available: |
| 41 | * |
Alexander Afanasyev | 95f9f55 | 2013-02-26 23:05:20 -0800 | [diff] [blame] | 42 | * For now serving only locally (using <PREFIX> = /localhost/<user's-device-name>/"chronoshare"/<FOLDER>/"info") |
Alexander Afanasyev | 026eaf3 | 2013-02-23 16:37:14 -0800 | [diff] [blame] | 43 | * |
| 44 | * - state: get list of SyncNodes, their sequence numbers, and forwarding hint (almost the same as RECOVERY interest) |
| 45 | * |
| 46 | * <PREFIX_INFO>/"state"/<nonce> (nonce should probably be the authentification code or authentication code should in addition somewhere) |
| 47 | * |
| 48 | * - action |
| 49 | * |
Alexander Afanasyev | 95f9f55 | 2013-02-26 23:05:20 -0800 | [diff] [blame] | 50 | * Get list of actions for a folder (for all files under this folder) |
| 51 | * |
| 52 | * <PREFIX_INFO>/"actions"/"folder"/<nonce>/<offset> (all actions) |
| 53 | * or |
| 54 | * <PREFIX_INFO>/"actions"/"folder"/<one-component-relative-file-name>/<nonce>/<offset> |
Alexander Afanasyev | 026eaf3 | 2013-02-23 16:37:14 -0800 | [diff] [blame] | 55 | * |
| 56 | * Actions are ordered in decreasing order (latest will go first). |
Alexander Afanasyev | 026eaf3 | 2013-02-23 16:37:14 -0800 | [diff] [blame] | 57 | * |
Alexander Afanasyev | 95f9f55 | 2013-02-26 23:05:20 -0800 | [diff] [blame] | 58 | * Each data packet contains up to 100 actions. |
| 59 | * If more items are available, application data will specify URL for the next packet |
| 60 | * |
| 61 | * @todo SPECIFY FORMAT OF THIS FIELD |
Alexander Afanasyev | 026eaf3 | 2013-02-23 16:37:14 -0800 | [diff] [blame] | 62 | * |
| 63 | * - file |
| 64 | * |
Alexander Afanasyev | 95f9f55 | 2013-02-26 23:05:20 -0800 | [diff] [blame] | 65 | * <PREFIX_INFO>/"filestate"/"folder"/<nonce>/<offset> (full filestate) |
| 66 | * or |
| 67 | * <PREFIX_INFO>/"filestate"/"folder"/<one-component-relative-folder-name>/<nonce>/<offset> |
Alexander Afanasyev | 026eaf3 | 2013-02-23 16:37:14 -0800 | [diff] [blame] | 68 | * |
Alexander Afanasyev | 95f9f55 | 2013-02-26 23:05:20 -0800 | [diff] [blame] | 69 | * Each Data packets contains a list of up to 100 files. |
| 70 | * If more items are available, application data will specify URL for the next packet |
| 71 | * |
| 72 | * @todo SPECIFY FORMAT OF THIS FIELD |
Alexander Afanasyev | 026eaf3 | 2013-02-23 16:37:14 -0800 | [diff] [blame] | 73 | * |
| 74 | * Commands available: |
| 75 | * |
Alexander Afanasyev | 95f9f55 | 2013-02-26 23:05:20 -0800 | [diff] [blame] | 76 | * For now serving only locally (using <PREFIX_CMD> = /localhost/<user's-device-name>/"chronoshare"/<FOLDER>/"cmd") |
Alexander Afanasyev | 026eaf3 | 2013-02-23 16:37:14 -0800 | [diff] [blame] | 77 | * |
| 78 | * - restore version of the file |
| 79 | * |
Alexander Afanasyev | 95f9f55 | 2013-02-26 23:05:20 -0800 | [diff] [blame] | 80 | * <PREFIX_CMD>/"restore"/"file"/<one-component-relative-file-name>/<version> |
| 81 | * or |
Alexander Afanasyev | 026eaf3 | 2013-02-23 16:37:14 -0800 | [diff] [blame] | 82 | * <PREFIX_CMD>/"restore"/"file"/<one-component-relative-file-name>/<version>/<file-hash> |
| 83 | * |
| 84 | * - clean state log |
| 85 | * (this may not need to be here, if we implement periodic cleaning) |
| 86 | * - ? flatten action log (should be supported eventually, but not supported now) |
| 87 | */ |
| 88 | class StateServer |
| 89 | { |
| 90 | public: |
| 91 | StateServer(Ccnx::CcnxWrapperPtr ccnx, ActionLogPtr actionLog, const boost::filesystem::path &rootDir, |
| 92 | const Ccnx::Name &userName, const std::string &sharedFolderName, const std::string &appName, |
| 93 | ObjectManager &objectManager, |
| 94 | int freshness = -1); |
| 95 | ~StateServer(); |
| 96 | |
| 97 | private: |
| 98 | void |
Alexander Afanasyev | 95f9f55 | 2013-02-26 23:05:20 -0800 | [diff] [blame] | 99 | info_actions_folder (const Ccnx::Name &interest); |
Alexander Afanasyev | 026eaf3 | 2013-02-23 16:37:14 -0800 | [diff] [blame] | 100 | |
| 101 | void |
Alexander Afanasyev | 95f9f55 | 2013-02-26 23:05:20 -0800 | [diff] [blame] | 102 | info_actions_folder_Execute (const Ccnx::Name &interest); |
| 103 | |
| 104 | void |
| 105 | info_filestate_folder (const Ccnx::Name &interest); |
| 106 | |
| 107 | void |
| 108 | info_filestate_folder_Execute (const Ccnx::Name &interest); |
Alexander Afanasyev | 026eaf3 | 2013-02-23 16:37:14 -0800 | [diff] [blame] | 109 | |
| 110 | void |
| 111 | cmd_restore_file (const Ccnx::Name &interest); |
| 112 | |
| 113 | void |
| 114 | cmd_restore_file_Execute (const Ccnx::Name &interest); |
| 115 | |
| 116 | private: |
| 117 | void |
| 118 | registerPrefixes (); |
| 119 | |
| 120 | void |
| 121 | deregisterPrefixes (); |
| 122 | |
| 123 | private: |
| 124 | Ccnx::CcnxWrapperPtr m_ccnx; |
| 125 | ActionLogPtr m_actionLog; |
| 126 | ObjectManager &m_objectManager; |
| 127 | |
| 128 | Ccnx::Name m_PREFIX_INFO; |
| 129 | Ccnx::Name m_PREFIX_CMD; |
| 130 | |
| 131 | boost::filesystem::path m_rootDir; |
| 132 | int m_freshness; |
| 133 | |
Alexander Afanasyev | 95f9f55 | 2013-02-26 23:05:20 -0800 | [diff] [blame] | 134 | Executor m_executor; |
Alexander Afanasyev | 026eaf3 | 2013-02-23 16:37:14 -0800 | [diff] [blame] | 135 | |
| 136 | Ccnx::Name m_userName; |
| 137 | std::string m_sharedFolderName; |
| 138 | std::string m_appName; |
| 139 | }; |
| 140 | #endif // CONTENT_SERVER_H |