blob: 7e43180184ac6f9c38c722d0ae159e2d8a7d0b44 [file] [log] [blame]
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Regents of the University of California.
4 * See COPYING for copyright and distribution information.
5 */
6
Shuo Chen9c2477f2014-03-13 15:01:06 -07007#include <string>
8#include <iostream>
9#include <ndn-cpp-dev/face.hpp>
Shuo Chen29c77fe2014-03-18 11:29:41 -070010#include <ndn-cpp-dev/util/command-interest-validator.hpp>
Shuo Chen9c2477f2014-03-13 15:01:06 -070011
12#include "../storage/storage-handle.hpp"
13#include "../storage/sqlite/sqlite-handle.hpp"
14#include "../ndn-handle/read-handle.hpp"
Shuo Chen29c77fe2014-03-18 11:29:41 -070015#include "../ndn-handle/write-handle.hpp"
Shuo Chen9c2477f2014-03-13 15:01:06 -070016
17using namespace repo;
18
19static const string ndnRepoUsageMessage =
20 "ndn-repo - NDNx Repository Daemon\n"
21 "-d: set database path\n"
22 "-h: show help message\n"
23 "-c: set config file path\n"
24 ;
25
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070026int
Shuo Chen9c2477f2014-03-13 15:01:06 -070027main(int argc, char** argv) {
28 int opt;
29 string dbPath;
30 string confPath;
31 while ((opt = getopt(argc, argv, "d:hc:")) != -1) {
32 switch (opt) {
33 case 'd':
34 dbPath = string(optarg);
35 break;
36 case 'h':
37 std::cout << ndnRepoUsageMessage << std::endl;
38 return 1;
39 case 'c':
40 confPath = string(optarg);
41 break;
42 default:
43 break;
44 }
45 }
Shuo Chen9c2477f2014-03-13 15:01:06 -070046
Shuo Chen9c2477f2014-03-13 15:01:06 -070047 if (confPath.empty()) {
48 confPath = "./repo.conf";
49 }
Shuo Chen29c77fe2014-03-18 11:29:41 -070050
51 Name dataPrefix("ndn:/example/data");
52 Name repoPrefix("ndn:/example/repo");
53 /// @todo read from configuration
54
55 SqliteHandle sqliteHandle(dbPath);
56
57 shared_ptr<boost::asio::io_service> io =
58 ndn::make_shared<boost::asio::io_service>();
59
60 Face face(io);
61 Scheduler scheduler(*io);
62
63 /// @todo specify trust model
64 CommandInterestValidator validator;
65 KeyChain keyChain;
66
67 ReadHandle readHandle(face, sqliteHandle, keyChain, scheduler);
68 readHandle.listen(dataPrefix);
69 WriteHandle writeHandle(face, sqliteHandle, keyChain, scheduler, validator);
70 writeHandle.listen(repoPrefix);
71
Shuo Chen9c2477f2014-03-13 15:01:06 -070072 face.processEvents();
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070073 return 0;
74}