blob: cb78224f89b72e928e4de3a7d007d230d4d8a2cb [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev1cf5c432017-01-13 23:22:15 -08003 * Copyright (c) 2013-2017, Regents of the University of California.
Alexander Afanasyeveb575e02013-01-26 17:14:51 -08004 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08005 * This file is part of ChronoShare, a decentralized file sharing application over NDN.
Alexander Afanasyeveb575e02013-01-26 17:14:51 -08006 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08007 * ChronoShare is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
Alexander Afanasyeveb575e02013-01-26 17:14:51 -080010 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080011 * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyeveb575e02013-01-26 17:14:51 -080014 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080015 * You should have received copies of the GNU General Public License along with
16 * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ChronoShare authors and contributors.
Alexander Afanasyeveb575e02013-01-26 17:14:51 -080019 */
20
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080021#include "dispatcher.hpp"
Alexander Afanasyev61ced272015-05-31 16:25:16 -070022#include "sync-core.hpp"
23
24#include "core/logging.hpp"
25
26#include <ndn-cxx/util/string-helper.hpp>
Alexander Afanasyeveb575e02013-01-26 17:14:51 -080027
Alexander Afanasyeveb575e02013-01-26 17:14:51 -080028#include <boost/lexical_cast.hpp>
29
Alexander Afanasyev61ced272015-05-31 16:25:16 -070030namespace ndn {
31namespace chronoshare {
Alexander Afanasyeveb575e02013-01-26 17:14:51 -080032
Alexander Afanasyev1cf5c432017-01-13 23:22:15 -080033_LOG_INIT(DumpDb);
Alexander Afanasyev24b449f2013-02-06 13:27:59 -080034
Alexander Afanasyev61ced272015-05-31 16:25:16 -070035using std::cout;
36using std::cerr;
37using std::endl;
38using std::setw;
39
40namespace fs = boost::filesystem;
41
Alexander Afanasyev24b449f2013-02-06 13:27:59 -080042class StateLogDumper : public DbHelper
43{
44public:
Alexander Afanasyev61ced272015-05-31 16:25:16 -070045 StateLogDumper(const fs::path& path)
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080046 : DbHelper(path / ".chronoshare", "sync-log.db")
Alexander Afanasyev24b449f2013-02-06 13:27:59 -080047 {
48 }
49
50 void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080051 DumpState()
Alexander Afanasyev24b449f2013-02-06 13:27:59 -080052 {
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080053 sqlite3_stmt* stmt;
54 sqlite3_prepare_v2(m_db,
Alexander Afanasyev61ced272015-05-31 16:25:16 -070055 "SELECT hash(device_name, seq_no) FROM(SELECT * FROM SyncNodes ORDER BY device_name)",
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080056 -1, &stmt, 0);
57 sqlite3_step(stmt);
Alexander Afanasyev61ced272015-05-31 16:25:16 -070058 ndn::Buffer hash(sqlite3_column_blob(stmt, 0), sqlite3_column_bytes(stmt, 0));
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080059 sqlite3_finalize(stmt);
Alexander Afanasyev24b449f2013-02-06 13:27:59 -080060
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080061 sqlite3_prepare_v2(m_db, "SELECT device_name, seq_no, last_known_locator, last_update "
62 " FROM SyncNodes "
63 " ORDER BY device_name",
64 -1, &stmt, 0);
Alexander Afanasyev24b449f2013-02-06 13:27:59 -080065
66 cout.setf(std::ios::left, std::ios::adjustfield);
Alexander Afanasyev61ced272015-05-31 16:25:16 -070067 cout << ">> SYNC NODES(" << toHex(hash).substr(0, 8) << ") <<" << endl;
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080068 cout << "===================================================================================="
69 << endl;
70 cout << setw(30) << "device_name"
71 << " | seq_no | " << setw(20) << "locator"
72 << " | last_update " << endl;
73 cout << "===================================================================================="
74 << endl;
Alexander Afanasyev24b449f2013-02-06 13:27:59 -080075
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080076 while (sqlite3_step(stmt) == SQLITE_ROW) {
77 cout << setw(30)
Alexander Afanasyev61ced272015-05-31 16:25:16 -070078 << (Name(Block(sqlite3_column_blob(stmt, 0), (sqlite3_column_bytes(stmt, 0))))).toUri()
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080079 << " | "; // device_name
80 cout << setw(6) << sqlite3_column_int64(stmt, 1) << " | "; // seq_no
Alexander Afanasyev61ced272015-05-31 16:25:16 -070081 cout << setw(20);
82 if (sqlite3_column_bytes(stmt, 2) > 0) {
83 cout << (Name(Block(sqlite3_column_blob(stmt, 2), (sqlite3_column_bytes(stmt, 2))))).toUri();
84 }
85 else {
86 cout << "NULL";
87 }
88 cout << " | "; // locator
89
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080090 if (sqlite3_column_bytes(stmt, 3) > 0) {
91 cout << setw(10) << sqlite3_column_text(stmt, 3) << endl;
Alexander Afanasyev24b449f2013-02-06 13:27:59 -080092 }
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080093 else {
94 cout << "unknown" << endl;
95 }
96 }
97 sqlite3_finalize(stmt);
Alexander Afanasyev24b449f2013-02-06 13:27:59 -080098 }
99
100 void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800101 DumpLog()
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800102 {
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800103 sqlite3_stmt* stmt;
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700104 sqlite3_prepare_v2(m_db, "SELECT state_hash, last_update, state_id, last_update "
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800105 " FROM SyncLog "
106 " ORDER BY last_update",
107 -1, &stmt, 0);
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800108
109 cout.setf(std::ios::left, std::ios::adjustfield);
110 cout << ">> SYNC LOG <<" << endl;
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800111 cout << "===================================================================================="
112 << endl;
113 cout << setw(10) << "state_hash"
114 << " | state details " << endl;
115 cout << "===================================================================================="
116 << endl;
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800117
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800118 while (sqlite3_step(stmt) == SQLITE_ROW) {
119 cout << setw(10)
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700120 << toHex(reinterpret_cast<const uint8_t*>(sqlite3_column_blob(stmt, 0)),
121 sqlite3_column_bytes(stmt, 0))
122 .substr(0, 8)
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800123 << " | "; // state hash
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800124
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800125 sqlite3_stmt* stmt2;
126 sqlite3_prepare_v2(m_db,
127 "SELECT device_name, ss.seq_no "
128 " FROM SyncStateNodes ss JOIN SyncNodes sn ON ss.device_id = sn.device_id "
129 " WHERE state_id=? "
130 " ORDER BY device_name",
131 -1, &stmt2, 0);
132 _LOG_DEBUG_COND(sqlite3_errcode(m_db) != SQLITE_OK, sqlite3_errmsg(m_db));
133 sqlite3_bind_int64(stmt2, 1, sqlite3_column_int64(stmt, 2));
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800134
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800135 while (sqlite3_step(stmt2) == SQLITE_ROW) {
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700136 cout << (Name(Block(sqlite3_column_blob(stmt2, 0), (sqlite3_column_bytes(stmt2, 0))))).toUri()
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800137 << "(" << sqlite3_column_int64(stmt2, 1) << "); ";
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800138 }
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800139
140 sqlite3_finalize(stmt2);
141
142 cout << endl;
143 }
144 sqlite3_finalize(stmt);
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800145 }
146};
147
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800148class ActionLogDumper : public DbHelper
149{
150public:
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700151 ActionLogDumper(const fs::path& path)
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800152 : DbHelper(path / ".chronoshare", "action-log.db")
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800153 {
154 }
155
156 void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800157 Dump()
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800158 {
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800159 sqlite3_stmt* stmt;
160 sqlite3_prepare_v2(m_db,
161 "SELECT device_name, seq_no, action, filename, version, file_hash, file_seg_num, parent_device_name, parent_seq_no "
162 " FROM ActionLog "
163 " ORDER BY action_timestamp",
164 -1, &stmt, 0);
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800165
166 cout.setf(std::ios::left, std::ios::adjustfield);
167 cout << ">> ACTION LOG <<" << endl;
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800168 cout << "============================================================================================================================================================================="
169 << endl;
170 cout << setw(30) << "device_name"
171 << " | seq_no | action |" << setw(40) << " filename "
172 << " | version | file_hash | seg_num | parent_device_name | parent_seq_no"
173 << endl;
174 cout << "============================================================================================================================================================================="
175 << endl;
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800176
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800177 while (sqlite3_step(stmt) == SQLITE_ROW) {
178 cout << setw(30)
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700179 << (Name(Block(sqlite3_column_blob(stmt, 0), (sqlite3_column_bytes(stmt, 0))))).toUri()
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800180 << " | "; // device_name
181 cout << setw(6) << sqlite3_column_int64(stmt, 1) << " | "; // seq_no
182 cout << setw(6) << (sqlite3_column_int(stmt, 2) == 0 ? "UPDATE" : "DELETE") << " | "; // action
183 cout << setw(40) << sqlite3_column_text(stmt, 3) << " | "; // filename
184 cout << setw(7) << sqlite3_column_int64(stmt, 4) << " | "; // version
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800185
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800186 if (sqlite3_column_int(stmt, 2) == 0) {
187 cout << setw(10)
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700188 << toHex(reinterpret_cast<const uint8_t*>(sqlite3_column_blob(stmt, 5)),
189 sqlite3_column_bytes(stmt, 5))
190 .substr(0, 8)
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800191 << " | ";
192 cout << setw(7) << sqlite3_column_int64(stmt, 6) << " | "; // seg_num
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800193 }
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800194 else
195 cout << " | | ";
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800196
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800197 if (sqlite3_column_bytes(stmt, 7) > 0) {
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700198 cout << setw(30)
199 << (Name(Block(sqlite3_column_blob(stmt, 7), (sqlite3_column_bytes(stmt, 7))))).toUri()
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800200 << " | "; // parent_device_name
201 cout << setw(5) << sqlite3_column_int64(stmt, 8); // seq_no
202 }
203 else
204 cout << setw(30) << " "
205 << " | ";
206 cout << endl;
207 }
208
209 sqlite3_finalize(stmt);
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800210 }
Zhenkai Zhued457c32013-02-13 15:51:48 -0800211
212 void
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700213 DumpActionData(const ndn::Name& deviceName, int64_t seqno)
Zhenkai Zhued457c32013-02-13 15:51:48 -0800214 {
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800215 sqlite3_stmt* stmt;
216 sqlite3_prepare_v2(m_db,
217 "SELECT action_content_object, action_name FROM ActionLog WHERE device_name = ? and seq_no = ?",
218 -1, &stmt, 0);
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700219 const ndn::Block nameBlock = deviceName.wireEncode();
220 sqlite3_bind_blob(stmt, 1, nameBlock.wire(), nameBlock.size(), SQLITE_STATIC);
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800221 sqlite3_bind_int64(stmt, 2, seqno);
222 cout << "Dumping action data for: [" << deviceName << ", " << seqno << "]" << endl;
223 if (sqlite3_step(stmt) == SQLITE_ROW) {
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700224 ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>(
225 ndn::Block(reinterpret_cast<const uint8_t*>(sqlite3_column_blob(stmt, 0)),
226 sqlite3_column_bytes(stmt, 0)));
227 ndn::Name actionName =
228 Name(Block(sqlite3_column_blob(stmt, 1), (sqlite3_column_bytes(stmt, 1))));
229 if (data) {
230 ActionItemPtr action = deserializeMsg<ActionItem>(
231 ndn::Buffer(data->getContent().value(), data->getContent().value_size()));
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800232 if (action) {
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700233 cout << "Action data size : " << data->getContent().size() << endl;
Zhenkai Zhu555c4f12013-02-13 16:57:36 -0800234 cout << "Action data name : " << actionName << endl;
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700235 std::string type = action->action() == ActionItem::UPDATE ? "UPDATE" : "DELETE";
Zhenkai Zhued457c32013-02-13 15:51:48 -0800236 cout << "Action Type = " << type << endl;
237 cout << "Timestamp = " << action->timestamp() << endl;
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700238 std::string filename = action->filename();
Zhenkai Zhued457c32013-02-13 15:51:48 -0800239 cout << "Filename = " << filename << endl;
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800240 if (action->has_seg_num()) {
Zhenkai Zhued457c32013-02-13 15:51:48 -0800241 cout << "Segment number = " << action->seg_num() << endl;
242 }
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800243 if (action->has_file_hash()) {
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700244 cout << "File hash = "
245 << toHex(reinterpret_cast<const uint8_t*>(action->file_hash().data()),
246 action->file_hash().size())
247 .substr(0, 8)
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800248 << endl;
Zhenkai Zhued457c32013-02-13 15:51:48 -0800249 }
250 }
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800251 else {
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700252 cerr << "Error! Failed to parse action from data! " << endl;
Zhenkai Zhued457c32013-02-13 15:51:48 -0800253 }
254 }
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800255 else {
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700256 cerr << "Error! Invalid data! " << endl;
Zhenkai Zhued457c32013-02-13 15:51:48 -0800257 }
258 }
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800259 else {
Zhenkai Zhued457c32013-02-13 15:51:48 -0800260 cerr << "Error! Can not find the requested action" << endl;
261 }
262 sqlite3_finalize(stmt);
263 }
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800264};
265
266class FileStateDumper : public DbHelper
267{
268public:
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700269 FileStateDumper(const fs::path& path)
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800270 : DbHelper(path / ".chronoshare", "file-state.db")
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800271 {
272 }
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800273
274 void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800275 Dump()
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800276 {
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800277 sqlite3_stmt* stmt;
278 sqlite3_prepare_v2(m_db,
279 "SELECT filename,device_name,seq_no,file_hash,strftime('%s', file_mtime),file_chmod,file_seg_num,directory,is_complete "
280 " FROM FileState "
281 " WHERE type = 0 ORDER BY filename",
282 -1, &stmt, 0);
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800283
284 cout.setf(std::ios::left, std::ios::adjustfield);
285 cout << ">> FILE STATE <<" << endl;
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800286 cout << "==================================================================================================================================="
287 << endl;
288 cout << "filename | device_name | seq_no | file_hash | seg_num | directory | is_complete"
289 << endl;
290 cout << "==================================================================================================================================="
291 << endl;
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800292
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800293 while (sqlite3_step(stmt) == SQLITE_ROW) {
294 cout << setw(40) << sqlite3_column_text(stmt, 0) << " | ";
295 cout << setw(30)
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700296 << Name(Block(sqlite3_column_blob(stmt, 1), (sqlite3_column_bytes(stmt, 1)))).toUri()
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800297 << " | ";
298 cout << setw(6) << sqlite3_column_int64(stmt, 2) << " | ";
299 cout << setw(10)
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700300 << toHex(reinterpret_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
301 sqlite3_column_bytes(stmt, 3))
302 .substr(0, 8)
303 << " | ";
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800304 cout << setw(6) << sqlite3_column_int64(stmt, 6) << " | ";
305 if (sqlite3_column_bytes(stmt, 7) == 0)
306 cout << setw(20) << "<NULL>"
307 << " | ";
308 else
309 cout << setw(20) << sqlite3_column_text(stmt, 7) << " | ";
Alexander Afanasyev38826ce2013-01-31 16:31:42 -0800310
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800311 if (sqlite3_column_int(stmt, 8) == 0)
312 cout << setw(20) << "no" << endl;
313 else
314 cout << setw(20) << "yes" << endl;
315 }
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800316
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800317 sqlite3_finalize(stmt);
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800318 }
319};
320
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800321int
322main(int argc, char* argv[])
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800323{
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700324 if (argc != 3 && !(argc == 5 && std::string(argv[1]) == "action")) {
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800325 cerr << "Usage: ./dump-db state|action|file|all <path-to-shared-folder>" << endl;
326 cerr << " or: ./dump-db action <path-to-shared-folder> <device-name> <seq-no>" << endl;
327 return 1;
328 }
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800329
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700330 std::string type = argv[1];
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800331 if (type == "state") {
332 StateLogDumper dumper(argv[2]);
333 dumper.DumpState();
334 dumper.DumpLog();
335 }
336 else if (type == "action") {
337 ActionLogDumper dumper(argv[2]);
338 if (argc == 5) {
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700339 dumper.DumpActionData(std::string(argv[3]), boost::lexical_cast<int64_t>(argv[4]));
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800340 }
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800341 else {
342 dumper.Dump();
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800343 }
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800344 }
345 else if (type == "file") {
346 FileStateDumper dumper(argv[2]);
347 dumper.Dump();
348 }
349 else if (type == "all") {
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800350 {
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800351 StateLogDumper dumper(argv[2]);
352 dumper.DumpState();
353 dumper.DumpLog();
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800354 }
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800355
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800356 {
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800357 ActionLogDumper dumper(argv[2]);
358 dumper.Dump();
Alexander Afanasyev24b449f2013-02-06 13:27:59 -0800359 }
360
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800361 {
362 FileStateDumper dumper(argv[2]);
363 dumper.Dump();
364 }
365 }
366 else {
367 cerr << "ERROR: Wrong database type" << endl;
368 cerr << "\nUsage: ./dump-db state|action|file|all <path-to-shared-folder>" << endl;
369 return 1;
370 }
371
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800372 return 0;
373}
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700374
375} // namespace chronoshare
376} // namespace ndn
377
378int
379main(int argc, char* argv[])
380{
381 return ndn::chronoshare::main(argc, argv);
382}