blob: 8b7bc6ec29d6e4e0367b92463ed24e8e213babdb [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
11#ifndef LINKNDN_CONTACT_STORAGE_H
12#define LINKNDN_CONTACT_STORAGE_H
13
14#include <sqlite3.h>
Yingdi Yuede8eaf2013-10-14 14:07:03 -070015#include "contact-item.h"
Yingdi Yu68aced92013-10-17 21:13:03 -070016#include "endorse-certificate.h"
Yingdi Yu64206112013-12-24 11:16:32 +080017#include <ndn-cpp/security/identity/identity-manager.hpp>
Yingdi Yuede8eaf2013-10-14 14:07:03 -070018
Yingdi Yuaa8d7692013-10-18 17:05:02 -070019
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 Yuaa8d7692013-10-18 17:05:02 -070024 ContactStorage();
Yingdi Yuede8eaf2013-10-14 14:07:03 -070025
Yingdi Yuaa8d7692013-10-18 17:05:02 -070026 ~ContactStorage()
27 {sqlite3_close(m_db);}
Yingdi Yuede8eaf2013-10-14 14:07:03 -070028
29 void
Yingdi Yu49eea9f2013-10-17 15:07:17 -070030 setSelfProfileEntry(const ndn::Name& identity, const std::string& profileType, const ndn::Blob& profileValue);
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070031
Yingdi Yu64206112013-12-24 11:16:32 +080032 ndn::ptr_lib::shared_ptr<Profile>
Yingdi Yu49eea9f2013-10-17 15:07:17 -070033 getSelfProfile(const ndn::Name& identity);
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070034
35 void
Yingdi Yu908f8412013-11-09 00:03:26 -080036 removeContact(const ndn::Name& identity);
37
38 void
Yingdi Yu813d4e92013-11-03 16:22:05 -080039 addContact(const ContactItem& contactItem);
Yingdi Yuede8eaf2013-10-14 14:07:03 -070040
Yingdi Yu8dacdf22013-11-05 23:06:43 -080041 void
42 updateIsIntroducer(const ndn::Name& identity, bool isIntroducer);
43
Yingdi Yu79c25a22013-10-21 13:38:38 -070044 void
45 updateAlias(const ndn::Name& identity, std::string alias);
46
Yingdi Yu64206112013-12-24 11:16:32 +080047 void
48 getAllContacts(std::vector<ndn::ptr_lib::shared_ptr<ContactItem> >& contacts) const;
Yingdi Yud40226b2013-10-23 14:05:12 -070049
Yingdi Yu64206112013-12-24 11:16:32 +080050 ndn::ptr_lib::shared_ptr<ContactItem>
Yingdi Yu813d4e92013-11-03 16:22:05 -080051 getContact(const ndn::Name& name);
Yingdi Yuaa8d7692013-10-18 17:05:02 -070052
Yingdi Yu64206112013-12-24 11:16:32 +080053 ndn::ptr_lib::shared_ptr<Profile>
Yingdi Yuaa8d7692013-10-18 17:05:02 -070054 getSelfProfile(const ndn::Name& identity) const;
55
Yingdi Yu8dacdf22013-11-05 23:06:43 -080056
57 //SelfEndorse
Yingdi Yu64206112013-12-24 11:16:32 +080058 ndn::Blob
Yingdi Yuaa8d7692013-10-18 17:05:02 -070059 getSelfEndorseCertificate(const ndn::Name& identity);
Yingdi Yuede8eaf2013-10-14 14:07:03 -070060
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070061 void
Yingdi Yu64206112013-12-24 11:16:32 +080062 updateSelfEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity);
Yingdi Yuaa8d7692013-10-18 17:05:02 -070063
64 void
Yingdi Yu64206112013-12-24 11:16:32 +080065 addSelfEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -080066
67
68 //ProfileEndorse
Yingdi Yu64206112013-12-24 11:16:32 +080069 ndn::Blob
Yingdi Yu8dacdf22013-11-05 23:06:43 -080070 getEndorseCertificate(const ndn::Name& identity);
71
72 void
Yingdi Yu64206112013-12-24 11:16:32 +080073 updateEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -080074
75 void
Yingdi Yu64206112013-12-24 11:16:32 +080076 addEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -080077
Yingdi Yu64206112013-12-24 11:16:32 +080078 void
79 getEndorseList(const ndn::Name& identity, std::vector<std::string>& endorseList);
Yingdi Yu8dacdf22013-11-05 23:06:43 -080080
Yingdi Yuc26af3c2013-10-17 17:03:46 -070081
Yingdi Yu8dacdf22013-11-05 23:06:43 -080082 //CollectEndorse
83 void
84 updateCollectEndorse(const EndorseCertificate& endorseCertificate);
85
Yingdi Yu64206112013-12-24 11:16:32 +080086 void
87 getCollectEndorseList(const ndn::Name& name, std::vector<ndn::Blob>& endorseList);
Yingdi Yu8dacdf22013-11-05 23:06:43 -080088
89
Yingdi Yuede8eaf2013-10-14 14:07:03 -070090private:
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070091 bool
Yingdi Yu49eea9f2013-10-17 15:07:17 -070092 doesSelfEntryExist(const ndn::Name& identity, const std::string& profileType);
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070093
Yingdi Yuede8eaf2013-10-14 14:07:03 -070094 bool
Yingdi Yu813d4e92013-11-03 16:22:05 -080095 doesContactExist(const ndn::Name& name);
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070096
Yingdi Yuede8eaf2013-10-14 14:07:03 -070097private:
Yingdi Yuede8eaf2013-10-14 14:07:03 -070098 sqlite3 *m_db;
99};
100
101#endif