blob: b577be08328afbfec1e66d1e888ce11bf6f03650 [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"
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070016#include "../ndn-handle/tcp-bulk-insert-handle.hpp"
Shuo Chen09f09bb2014-03-18 15:37:11 -070017#include "../ndn-handle/delete-handle.hpp"
Shuo Chen9c2477f2014-03-13 15:01:06 -070018
19using namespace repo;
20
21static const string ndnRepoUsageMessage =
22 "ndn-repo - NDNx Repository Daemon\n"
23 "-d: set database path\n"
24 "-h: show help message\n"
25 "-c: set config file path\n"
26 ;
27
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070028int
Shuo Chen9c2477f2014-03-13 15:01:06 -070029main(int argc, char** argv) {
30 int opt;
31 string dbPath;
32 string confPath;
33 while ((opt = getopt(argc, argv, "d:hc:")) != -1) {
34 switch (opt) {
35 case 'd':
36 dbPath = string(optarg);
37 break;
38 case 'h':
39 std::cout << ndnRepoUsageMessage << std::endl;
40 return 1;
41 case 'c':
42 confPath = string(optarg);
43 break;
44 default:
45 break;
46 }
47 }
Shuo Chen9c2477f2014-03-13 15:01:06 -070048
Shuo Chen9c2477f2014-03-13 15:01:06 -070049 if (confPath.empty()) {
50 confPath = "./repo.conf";
51 }
Shuo Chen29c77fe2014-03-18 11:29:41 -070052
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070053 Name dataPrefix("ndn:/");
Shuo Chen29c77fe2014-03-18 11:29:41 -070054 Name repoPrefix("ndn:/example/repo");
55 /// @todo read from configuration
56
57 SqliteHandle sqliteHandle(dbPath);
58
59 shared_ptr<boost::asio::io_service> io =
60 ndn::make_shared<boost::asio::io_service>();
61
62 Face face(io);
63 Scheduler scheduler(*io);
64
65 /// @todo specify trust model
66 CommandInterestValidator validator;
67 KeyChain keyChain;
68
69 ReadHandle readHandle(face, sqliteHandle, keyChain, scheduler);
70 readHandle.listen(dataPrefix);
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070071
Shuo Chen29c77fe2014-03-18 11:29:41 -070072 WriteHandle writeHandle(face, sqliteHandle, keyChain, scheduler, validator);
73 writeHandle.listen(repoPrefix);
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070074
Shuo Chen09f09bb2014-03-18 15:37:11 -070075 DeleteHandle deleteHandle(face, sqliteHandle, keyChain, scheduler, validator);
76 deleteHandle.listen(repoPrefix);
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070077
78 TcpBulkInsertHandle tcpBulkInsertHandle(*io, sqliteHandle);
79 tcpBulkInsertHandle.listen("localhost", "7376");
80
Shuo Chen9c2477f2014-03-13 15:01:06 -070081 face.processEvents();
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070082 return 0;
83}