blob: da6c8123d03672133f6bd35ac1c2be06be7142fe [file] [log] [blame]
Yingdi Yuede8eaf2013-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 Yua1a688f2014-02-06 18:09:22 -080011#ifndef CHRONOS_CONTACT_STORAGE_H
12#define CHRONOS_CONTACT_STORAGE_H
Yingdi Yuede8eaf2013-10-14 14:07:03 -070013
Yingdi Yuede8eaf2013-10-14 14:07:03 -070014#include "contact-item.h"
Yingdi Yua1a688f2014-02-06 18:09:22 -080015#include <sqlite3.h>
Yingdi Yuede8eaf2013-10-14 14:07:03 -070016
Yingdi Yuaa8d7692013-10-18 17:05:02 -070017
Yingdi Yua1a688f2014-02-06 18:09:22 -080018namespace chronos{
19
Yingdi Yuede8eaf2013-10-14 14:07:03 -070020class ContactStorage
21{
Yingdi Yuaa8d7692013-10-18 17:05:02 -070022
Yingdi Yuede8eaf2013-10-14 14:07:03 -070023public:
Yingdi Yuc9ffa9f2014-01-13 11:19:47 -080024 struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
25
Yingdi Yuaa8d7692013-10-18 17:05:02 -070026 ContactStorage();
Yingdi Yuede8eaf2013-10-14 14:07:03 -070027
Yingdi Yuaa8d7692013-10-18 17:05:02 -070028 ~ContactStorage()
Yingdi Yua1a688f2014-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 Yuede8eaf2013-10-14 14:07:03 -070042
43 void
Yingdi Yua1a688f2014-02-06 18:09:22 -080044 addEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity);
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070045
Yingdi Yua1a688f2014-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 Yu0a6b6c52013-10-15 17:54:00 -070056
57 void
Yingdi Yu908f8412013-11-09 00:03:26 -080058 removeContact(const ndn::Name& identity);
59
60 void
Yingdi Yu813d4e92013-11-03 16:22:05 -080061 addContact(const ContactItem& contactItem);
Yingdi Yuede8eaf2013-10-14 14:07:03 -070062
Yingdi Yua1a688f2014-02-06 18:09:22 -080063 ndn::shared_ptr<ContactItem>
64 getContact(const ndn::Name& name);
65
Yingdi Yu8dacdf22013-11-05 23:06:43 -080066 void
67 updateIsIntroducer(const ndn::Name& identity, bool isIntroducer);
68
Yingdi Yu79c25a22013-10-21 13:38:38 -070069 void
70 updateAlias(const ndn::Name& identity, std::string alias);
71
Yingdi Yu64206112013-12-24 11:16:32 +080072 void
Yingdi Yua1a688f2014-02-06 18:09:22 -080073 getAllContacts(std::vector<ndn::shared_ptr<ContactItem> >& contacts) const;
Yingdi Yud40226b2013-10-23 14:05:12 -070074
Yingdi Yua1a688f2014-02-06 18:09:22 -080075
Yingdi Yu8dacdf22013-11-05 23:06:43 -080076
77
Yingdi Yuede8eaf2013-10-14 14:07:03 -070078private:
Yingdi Yua1a688f2014-02-06 18:09:22 -080079 void
80 initializeTable(const std::string& tableName, const std::string& sqlCreateStmt);
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070081
Yingdi Yuede8eaf2013-10-14 14:07:03 -070082 bool
Yingdi Yu813d4e92013-11-03 16:22:05 -080083 doesContactExist(const ndn::Name& name);
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070084
Yingdi Yuede8eaf2013-10-14 14:07:03 -070085private:
Yingdi Yuede8eaf2013-10-14 14:07:03 -070086 sqlite3 *m_db;
87};
88
Yingdi Yua1a688f2014-02-06 18:09:22 -080089}//chronos
Yingdi Yuede8eaf2013-10-14 14:07:03 -070090#endif