Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 1 | /* -*- 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 Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 11 | #ifndef CHRONOS_CONTACT_STORAGE_H |
| 12 | #define CHRONOS_CONTACT_STORAGE_H |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 13 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 14 | #include "contact.h" |
| 15 | #include "endorse-collection.pb.h" |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 16 | #include <sqlite3.h> |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 17 | |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 18 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 19 | namespace chronos{ |
| 20 | |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 21 | class ContactStorage |
| 22 | { |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 23 | |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 24 | public: |
Yingdi Yu | f8f572d | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 25 | struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} }; |
| 26 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 27 | ContactStorage(const ndn::Name& identity); |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 28 | |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 29 | ~ContactStorage() |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 30 | { |
| 31 | sqlite3_close(m_db); |
| 32 | } |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 33 | |
| 34 | ndn::shared_ptr<Profile> |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 35 | getSelfProfile(); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 36 | |
| 37 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 38 | addSelfEndorseCertificate(const EndorseCertificate& endorseCertificate); |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 39 | |
| 40 | void |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 41 | addEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity); |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 42 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 43 | void |
| 44 | updateCollectEndorse(const EndorseCertificate& endorseCertificate); |
| 45 | |
| 46 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 47 | getCollectEndorse(EndorseCollection& endorseCollection); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 48 | |
| 49 | void |
| 50 | getEndorseList(const ndn::Name& identity, std::vector<std::string>& endorseList); |
| 51 | |
| 52 | |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 53 | |
| 54 | void |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 55 | removeContact(const ndn::Name& identity); |
| 56 | |
| 57 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 58 | addContact(const Contact& contact); |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 59 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 60 | ndn::shared_ptr<Contact> |
| 61 | getContact(const ndn::Name& identity) const; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 62 | |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 63 | void |
| 64 | updateIsIntroducer(const ndn::Name& identity, bool isIntroducer); |
| 65 | |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 66 | void |
| 67 | updateAlias(const ndn::Name& identity, std::string alias); |
| 68 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 69 | void |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 70 | getAllContacts(std::vector<ndn::shared_ptr<Contact> >& contacts) const; |
Yingdi Yu | 4ef8cf6 | 2013-10-23 14:05:12 -0700 | [diff] [blame] | 71 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 72 | void |
| 73 | updateDnsSelfProfileData(const ndn::Data& data) |
| 74 | { |
| 75 | updateDnsData(data.wireEncode(), "N/A", "PROFILE", data.getName().toUri()); |
| 76 | } |
| 77 | |
| 78 | void |
| 79 | updateDnsEndorseOthers(const ndn::Data& data, const std::string& endorsee) |
| 80 | { |
| 81 | updateDnsData(data.wireEncode(), endorsee, "ENDORSEE", data.getName().toUri()); |
| 82 | } |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 83 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 84 | void |
| 85 | updateDnsOthersEndorse(const ndn::Data& data) |
| 86 | { |
| 87 | updateDnsData(data.wireEncode(), "N/A", "ENDORSED", data.getName().toUri()); |
| 88 | } |
| 89 | |
| 90 | ndn::shared_ptr<ndn::Data> |
| 91 | getDnsData(const ndn::Name& name); |
| 92 | |
| 93 | ndn::shared_ptr<ndn::Data> |
| 94 | getDnsData(const std::string& name, const std::string& type); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 95 | |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 96 | private: |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 97 | std::string |
| 98 | getDBName(); |
| 99 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 100 | void |
| 101 | initializeTable(const std::string& tableName, const std::string& sqlCreateStmt); |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 102 | |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 103 | bool |
Yingdi Yu | 71c0187 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 104 | doesContactExist(const ndn::Name& name); |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 105 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 106 | void |
| 107 | updateDnsData(const ndn::Block& data, const std::string& name, const std::string& type, const std::string& dataName); |
| 108 | |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 109 | private: |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 110 | ndn::Name m_identity; |
| 111 | |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 112 | sqlite3 *m_db; |
| 113 | }; |
| 114 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 115 | }//chronos |
Yingdi Yu | d04ed1a | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 116 | #endif |