blob: 24c9b051e03dfc6c2342a7ea6bb498f4914c36c7 [file] [log] [blame]
Alexander Afanasyev026eaf32013-02-23 16:37:14 -08001/* -*- 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 Afanasyev95f9f552013-02-26 23:05:20 -080033#include "executor.h"
Alexander Afanasyev026eaf32013-02-23 16:37:14 -080034
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 Afanasyev95f9f552013-02-26 23:05:20 -080042 * For now serving only locally (using <PREFIX> = /localhost/<user's-device-name>/"chronoshare"/<FOLDER>/"info")
Alexander Afanasyev026eaf32013-02-23 16:37:14 -080043 *
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 Afanasyev95f9f552013-02-26 23:05:20 -080050 * 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 Afanasyev026eaf32013-02-23 16:37:14 -080055 *
56 * Actions are ordered in decreasing order (latest will go first).
Alexander Afanasyev026eaf32013-02-23 16:37:14 -080057 *
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080058 * 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 Afanasyev026eaf32013-02-23 16:37:14 -080062 *
63 * - file
64 *
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080065 * <PREFIX_INFO>/"filestate"/"folder"/<nonce>/<offset> (full filestate)
66 * or
67 * <PREFIX_INFO>/"filestate"/"folder"/<one-component-relative-folder-name>/<nonce>/<offset>
Alexander Afanasyev026eaf32013-02-23 16:37:14 -080068 *
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080069 * 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 Afanasyev026eaf32013-02-23 16:37:14 -080073 *
74 * Commands available:
75 *
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080076 * For now serving only locally (using <PREFIX_CMD> = /localhost/<user's-device-name>/"chronoshare"/<FOLDER>/"cmd")
Alexander Afanasyev026eaf32013-02-23 16:37:14 -080077 *
78 * - restore version of the file
79 *
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080080 * <PREFIX_CMD>/"restore"/"file"/<one-component-relative-file-name>/<version>
81 * or
Alexander Afanasyev026eaf32013-02-23 16:37:14 -080082 * <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 */
88class StateServer
89{
90public:
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
97private:
98 void
Alexander Afanasyev95f9f552013-02-26 23:05:20 -080099 info_actions_folder (const Ccnx::Name &interest);
Alexander Afanasyev026eaf32013-02-23 16:37:14 -0800100
101 void
Alexander Afanasyev95f9f552013-02-26 23:05:20 -0800102 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 Afanasyev026eaf32013-02-23 16:37:14 -0800109
110 void
111 cmd_restore_file (const Ccnx::Name &interest);
112
113 void
114 cmd_restore_file_Execute (const Ccnx::Name &interest);
115
116private:
117 void
118 registerPrefixes ();
119
120 void
121 deregisterPrefixes ();
122
123private:
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 Afanasyev95f9f552013-02-26 23:05:20 -0800134 Executor m_executor;
Alexander Afanasyev026eaf32013-02-23 16:37:14 -0800135
136 Ccnx::Name m_userName;
137 std::string m_sharedFolderName;
138 std::string m_appName;
139};
140#endif // CONTENT_SERVER_H