blob: 3eec803319765202b58b0f7c4aa98c50117797cc [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>
33#include "scheduler.h"
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 *
42 * For now serving only locally (using <PREFIX> = /localhost/<user's-device-name>/"chronoshare"/"info")
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 *
50 * <PREFIX_INFO>/"actions"/"all"/<nonce>/<segment> get list of all actions
51 * <PREFIX_INFO>/"actions"/"file"/<nonce>/<segment> get list of actions for a file
52 *
53 * Actions are ordered in decreasing order (latest will go first).
54 * Each data packet contains up to 100 actions. If there are more, they will be segmented. Data packet always
55 * contains a segment number (even if there are less than 100 actions available).
56 *
57 * Number of segments is indicated in FinalBlockID of the first data packet (in <PREFIX>/"action"/"all"/<nonce>/%00)
58 *
59 * - file
60 *
61 * <PREFIX_INFO>/"filestate"/"all"/<nonce>/<segment>
62 *
63 * Each Data packets contains a list of up to 100 files, the rest is published in other segments.
64 * Number of segments is indicated in FinalBlockID of the first data packet (in <PREFIX>/"file"/"all"/<nonce>/%00).
65 *
66 * Commands available:
67 *
68 * For now serving only locally (using <PREFIX_CMD> = /localhost/<user's-device-name>/"chronoshare"/"cmd")
69 *
70 * - restore version of the file
71 *
72 * <PREFIX_CMD>/"restore"/"file"/<one-component-relative-file-name>/<version>/<file-hash>
73 *
74 * - clean state log
75 * (this may not need to be here, if we implement periodic cleaning)
76 * - ? flatten action log (should be supported eventually, but not supported now)
77 */
78class StateServer
79{
80public:
81 StateServer(Ccnx::CcnxWrapperPtr ccnx, ActionLogPtr actionLog, const boost::filesystem::path &rootDir,
82 const Ccnx::Name &userName, const std::string &sharedFolderName, const std::string &appName,
83 ObjectManager &objectManager,
84 int freshness = -1);
85 ~StateServer();
86
87private:
88 void
89 info_actions_all (const Ccnx::Name &interest);
90
91 void
92 info_actions_all_Execute (const Ccnx::Name &interest);
93
94 void
95 cmd_restore_file (const Ccnx::Name &interest);
96
97 void
98 cmd_restore_file_Execute (const Ccnx::Name &interest);
99
100private:
101 void
102 registerPrefixes ();
103
104 void
105 deregisterPrefixes ();
106
107private:
108 Ccnx::CcnxWrapperPtr m_ccnx;
109 ActionLogPtr m_actionLog;
110 ObjectManager &m_objectManager;
111
112 Ccnx::Name m_PREFIX_INFO;
113 Ccnx::Name m_PREFIX_CMD;
114
115 boost::filesystem::path m_rootDir;
116 int m_freshness;
117
118 SchedulerPtr m_scheduler;
119
120 Ccnx::Name m_userName;
121 std::string m_sharedFolderName;
122 std::string m_appName;
123};
124#endif // CONTENT_SERVER_H