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