blob: dfc06ef7e23d798cc51f0f31191edbc3a6533d24 [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
11#ifndef LINKNDN_CONTACT_STORAGE_H
12#define LINKNDN_CONTACT_STORAGE_H
13
14#include <sqlite3.h>
Yingdi Yud04ed1a2013-10-14 14:07:03 -070015#include "contact-item.h"
Yingdi Yu92e8e482013-10-17 21:13:03 -070016#include "endorse-certificate.h"
Yingdi Yud04ed1a2013-10-14 14:07:03 -070017
Yingdi Yu4685b1b2013-10-18 17:05:02 -070018
Yingdi Yud04ed1a2013-10-14 14:07:03 -070019class ContactStorage
20{
Yingdi Yu4685b1b2013-10-18 17:05:02 -070021
Yingdi Yud04ed1a2013-10-14 14:07:03 -070022public:
Yingdi Yuf8f572d2014-01-13 11:19:47 -080023 struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
24
Yingdi Yu4685b1b2013-10-18 17:05:02 -070025 ContactStorage();
Yingdi Yud04ed1a2013-10-14 14:07:03 -070026
Yingdi Yu4685b1b2013-10-18 17:05:02 -070027 ~ContactStorage()
28 {sqlite3_close(m_db);}
Yingdi Yud04ed1a2013-10-14 14:07:03 -070029
30 void
Yingdi Yuf8f572d2014-01-13 11:19:47 -080031 setSelfProfileEntry(const ndn::Name& identity, const std::string& profileType, const ndn::Buffer& profileValue);
Yingdi Yu3b318c12013-10-15 17:54:00 -070032
Yingdi Yu76dd8002013-12-24 11:16:32 +080033 ndn::ptr_lib::shared_ptr<Profile>
Yingdi Yu54dcecc2013-10-17 15:07:17 -070034 getSelfProfile(const ndn::Name& identity);
Yingdi Yu3b318c12013-10-15 17:54:00 -070035
36 void
Yingdi Yuae8217c2013-11-09 00:03:26 -080037 removeContact(const ndn::Name& identity);
38
39 void
Yingdi Yu71c01872013-11-03 16:22:05 -080040 addContact(const ContactItem& contactItem);
Yingdi Yud04ed1a2013-10-14 14:07:03 -070041
Yingdi Yub2e747d2013-11-05 23:06:43 -080042 void
43 updateIsIntroducer(const ndn::Name& identity, bool isIntroducer);
44
Yingdi Yu2ac40fb2013-10-21 13:38:38 -070045 void
46 updateAlias(const ndn::Name& identity, std::string alias);
47
Yingdi Yu76dd8002013-12-24 11:16:32 +080048 void
49 getAllContacts(std::vector<ndn::ptr_lib::shared_ptr<ContactItem> >& contacts) const;
Yingdi Yu4ef8cf62013-10-23 14:05:12 -070050
Yingdi Yu76dd8002013-12-24 11:16:32 +080051 ndn::ptr_lib::shared_ptr<ContactItem>
Yingdi Yu71c01872013-11-03 16:22:05 -080052 getContact(const ndn::Name& name);
Yingdi Yu4685b1b2013-10-18 17:05:02 -070053
Yingdi Yu76dd8002013-12-24 11:16:32 +080054 ndn::ptr_lib::shared_ptr<Profile>
Yingdi Yu4685b1b2013-10-18 17:05:02 -070055 getSelfProfile(const ndn::Name& identity) const;
56
Yingdi Yub2e747d2013-11-05 23:06:43 -080057
58 //SelfEndorse
Yingdi Yuf8f572d2014-01-13 11:19:47 -080059 ndn::Block
Yingdi Yu4685b1b2013-10-18 17:05:02 -070060 getSelfEndorseCertificate(const ndn::Name& identity);
Yingdi Yud04ed1a2013-10-14 14:07:03 -070061
Yingdi Yu3b318c12013-10-15 17:54:00 -070062 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080063 updateSelfEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity);
Yingdi Yu4685b1b2013-10-18 17:05:02 -070064
65 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080066 addSelfEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity);
Yingdi Yub2e747d2013-11-05 23:06:43 -080067
68
69 //ProfileEndorse
Yingdi Yuf8f572d2014-01-13 11:19:47 -080070 ndn::Block
Yingdi Yub2e747d2013-11-05 23:06:43 -080071 getEndorseCertificate(const ndn::Name& identity);
72
73 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080074 updateEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity);
Yingdi Yub2e747d2013-11-05 23:06:43 -080075
76 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080077 addEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity);
Yingdi Yub2e747d2013-11-05 23:06:43 -080078
Yingdi Yu76dd8002013-12-24 11:16:32 +080079 void
80 getEndorseList(const ndn::Name& identity, std::vector<std::string>& endorseList);
Yingdi Yub2e747d2013-11-05 23:06:43 -080081
Yingdi Yu8f7325a2013-10-17 17:03:46 -070082
Yingdi Yub2e747d2013-11-05 23:06:43 -080083 //CollectEndorse
84 void
85 updateCollectEndorse(const EndorseCertificate& endorseCertificate);
86
Yingdi Yu76dd8002013-12-24 11:16:32 +080087 void
Yingdi Yuf8f572d2014-01-13 11:19:47 -080088 getCollectEndorseList(const ndn::Name& name, std::vector<ndn::Buffer>& endorseList);
Yingdi Yub2e747d2013-11-05 23:06:43 -080089
90
Yingdi Yud04ed1a2013-10-14 14:07:03 -070091private:
Yingdi Yu3b318c12013-10-15 17:54:00 -070092 bool
Yingdi Yu54dcecc2013-10-17 15:07:17 -070093 doesSelfEntryExist(const ndn::Name& identity, const std::string& profileType);
Yingdi Yu3b318c12013-10-15 17:54:00 -070094
Yingdi Yud04ed1a2013-10-14 14:07:03 -070095 bool
Yingdi Yu71c01872013-11-03 16:22:05 -080096 doesContactExist(const ndn::Name& name);
Yingdi Yu3b318c12013-10-15 17:54:00 -070097
Yingdi Yud04ed1a2013-10-14 14:07:03 -070098private:
Yingdi Yud04ed1a2013-10-14 14:07:03 -070099 sqlite3 *m_db;
100};
101
102#endif