blob: da6c8123d03672133f6bd35ac1c2be06be7142fe [file] [log] [blame]
Yingdi Yud04ed1a2013-10-14 14:07:03 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
9 */
10
Yingdi Yufa4ce792014-02-06 18:09:22 -080011#ifndef CHRONOS_CONTACT_STORAGE_H
12#define CHRONOS_CONTACT_STORAGE_H
Yingdi Yud04ed1a2013-10-14 14:07:03 -070013
Yingdi Yud04ed1a2013-10-14 14:07:03 -070014#include "contact-item.h"
Yingdi Yufa4ce792014-02-06 18:09:22 -080015#include <sqlite3.h>
Yingdi Yud04ed1a2013-10-14 14:07:03 -070016
Yingdi Yu4685b1b2013-10-18 17:05:02 -070017
Yingdi Yufa4ce792014-02-06 18:09:22 -080018namespace chronos{
19
Yingdi Yud04ed1a2013-10-14 14:07:03 -070020class ContactStorage
21{
Yingdi Yu4685b1b2013-10-18 17:05:02 -070022
Yingdi Yud04ed1a2013-10-14 14:07:03 -070023public:
Yingdi Yuf8f572d2014-01-13 11:19:47 -080024 struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
25
Yingdi Yu4685b1b2013-10-18 17:05:02 -070026 ContactStorage();
Yingdi Yud04ed1a2013-10-14 14:07:03 -070027
Yingdi Yu4685b1b2013-10-18 17:05:02 -070028 ~ContactStorage()
Yingdi Yufa4ce792014-02-06 18:09:22 -080029 { sqlite3_close(m_db); }
30
31 ndn::shared_ptr<Profile>
32 getSelfProfile(const ndn::Name& identity) const;
33
34 // ndn::Block
35 // getSelfEndorseCertificate(const ndn::Name& identity);
36
37 void
38 addSelfEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity);
39
40 // ndn::Block
41 // getEndorseCertificate(const ndn::Name& identity);
Yingdi Yud04ed1a2013-10-14 14:07:03 -070042
43 void
Yingdi Yufa4ce792014-02-06 18:09:22 -080044 addEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity);
Yingdi Yu3b318c12013-10-15 17:54:00 -070045
Yingdi Yufa4ce792014-02-06 18:09:22 -080046 void
47 updateCollectEndorse(const EndorseCertificate& endorseCertificate);
48
49 void
50 getCollectEndorseList(const ndn::Name& name, std::vector<ndn::Buffer>& endorseList);
51
52 void
53 getEndorseList(const ndn::Name& identity, std::vector<std::string>& endorseList);
54
55
Yingdi Yu3b318c12013-10-15 17:54:00 -070056
57 void
Yingdi Yuae8217c2013-11-09 00:03:26 -080058 removeContact(const ndn::Name& identity);
59
60 void
Yingdi Yu71c01872013-11-03 16:22:05 -080061 addContact(const ContactItem& contactItem);
Yingdi Yud04ed1a2013-10-14 14:07:03 -070062
Yingdi Yufa4ce792014-02-06 18:09:22 -080063 ndn::shared_ptr<ContactItem>
64 getContact(const ndn::Name& name);
65
Yingdi Yub2e747d2013-11-05 23:06:43 -080066 void
67 updateIsIntroducer(const ndn::Name& identity, bool isIntroducer);
68
Yingdi Yu2ac40fb2013-10-21 13:38:38 -070069 void
70 updateAlias(const ndn::Name& identity, std::string alias);
71
Yingdi Yu76dd8002013-12-24 11:16:32 +080072 void
Yingdi Yufa4ce792014-02-06 18:09:22 -080073 getAllContacts(std::vector<ndn::shared_ptr<ContactItem> >& contacts) const;
Yingdi Yu4ef8cf62013-10-23 14:05:12 -070074
Yingdi Yufa4ce792014-02-06 18:09:22 -080075
Yingdi Yub2e747d2013-11-05 23:06:43 -080076
77
Yingdi Yud04ed1a2013-10-14 14:07:03 -070078private:
Yingdi Yufa4ce792014-02-06 18:09:22 -080079 void
80 initializeTable(const std::string& tableName, const std::string& sqlCreateStmt);
Yingdi Yu3b318c12013-10-15 17:54:00 -070081
Yingdi Yud04ed1a2013-10-14 14:07:03 -070082 bool
Yingdi Yu71c01872013-11-03 16:22:05 -080083 doesContactExist(const ndn::Name& name);
Yingdi Yu3b318c12013-10-15 17:54:00 -070084
Yingdi Yud04ed1a2013-10-14 14:07:03 -070085private:
Yingdi Yud04ed1a2013-10-14 14:07:03 -070086 sqlite3 *m_db;
87};
88
Yingdi Yufa4ce792014-02-06 18:09:22 -080089}//chronos
Yingdi Yud04ed1a2013-10-14 14:07:03 -070090#endif