blob: ee5f032280fae3c3a3d68b086d3f3640551b8341 [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 Yu3b318c12013-10-15 17:54:00 -070017#include <ndn.cxx/security/identity/identity-manager.h>
18#include <ndn.cxx/fields/signature-sha256-with-rsa.h>
Yingdi Yud04ed1a2013-10-14 14:07:03 -070019
Yingdi Yu4685b1b2013-10-18 17:05:02 -070020
Yingdi Yud04ed1a2013-10-14 14:07:03 -070021class ContactStorage
22{
Yingdi Yu4685b1b2013-10-18 17:05:02 -070023
Yingdi Yud04ed1a2013-10-14 14:07:03 -070024public:
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 Yu54dcecc2013-10-17 15:07:17 -070031 setSelfProfileEntry(const ndn::Name& identity, const std::string& profileType, const ndn::Blob& profileValue);
Yingdi Yu3b318c12013-10-15 17:54:00 -070032
33 ndn::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 Yu71c01872013-11-03 16:22:05 -080037 addContact(const ContactItem& contactItem);
Yingdi Yud04ed1a2013-10-14 14:07:03 -070038
Yingdi Yub2e747d2013-11-05 23:06:43 -080039 void
40 updateIsIntroducer(const ndn::Name& identity, bool isIntroducer);
41
Yingdi Yu2ac40fb2013-10-21 13:38:38 -070042 void
43 updateAlias(const ndn::Name& identity, std::string alias);
44
Yingdi Yud04ed1a2013-10-14 14:07:03 -070045 std::vector<ndn::Ptr<ContactItem> >
Yingdi Yu71c01872013-11-03 16:22:05 -080046 getAllContacts() const;
Yingdi Yu4ef8cf62013-10-23 14:05:12 -070047
48 ndn::Ptr<ContactItem>
Yingdi Yu71c01872013-11-03 16:22:05 -080049 getContact(const ndn::Name& name);
Yingdi Yu4685b1b2013-10-18 17:05:02 -070050
51 ndn::Ptr<Profile>
52 getSelfProfile(const ndn::Name& identity) const;
53
Yingdi Yub2e747d2013-11-05 23:06:43 -080054
55 //SelfEndorse
Yingdi Yu4685b1b2013-10-18 17:05:02 -070056 ndn::Ptr<ndn::Blob>
57 getSelfEndorseCertificate(const ndn::Name& identity);
Yingdi Yud04ed1a2013-10-14 14:07:03 -070058
Yingdi Yu3b318c12013-10-15 17:54:00 -070059 void
Yingdi Yu4685b1b2013-10-18 17:05:02 -070060 updateSelfEndorseCertificate(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& identity);
61
62 void
63 addSelfEndorseCertificate(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& identity);
Yingdi Yub2e747d2013-11-05 23:06:43 -080064
65
66 //ProfileEndorse
67 ndn::Ptr<ndn::Blob>
68 getEndorseCertificate(const ndn::Name& identity);
69
70 void
71 updateEndorseCertificate(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& identity);
72
73 void
74 addEndorseCertificate(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& identity);
75
76 std::vector<std::string>
77 getEndorseList(const ndn::Name& identity);
78
Yingdi Yu8f7325a2013-10-17 17:03:46 -070079
Yingdi Yub2e747d2013-11-05 23:06:43 -080080 //CollectEndorse
81 void
82 updateCollectEndorse(const EndorseCertificate& endorseCertificate);
83
84 ndn::Ptr<std::vector<ndn::Blob> >
85 getCollectEndorseList(const ndn::Name& name);
86
87
Yingdi Yud04ed1a2013-10-14 14:07:03 -070088private:
Yingdi Yu3b318c12013-10-15 17:54:00 -070089 bool
Yingdi Yu54dcecc2013-10-17 15:07:17 -070090 doesSelfEntryExist(const ndn::Name& identity, const std::string& profileType);
Yingdi Yu3b318c12013-10-15 17:54:00 -070091
Yingdi Yud04ed1a2013-10-14 14:07:03 -070092 bool
Yingdi Yu71c01872013-11-03 16:22:05 -080093 doesContactExist(const ndn::Name& name);
Yingdi Yu3b318c12013-10-15 17:54:00 -070094
Yingdi Yud04ed1a2013-10-14 14:07:03 -070095private:
Yingdi Yud04ed1a2013-10-14 14:07:03 -070096 sqlite3 *m_db;
97};
98
99#endif