| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| /* |
| * Copyright (c) 2013, Regents of the University of California |
| * Yingdi Yu |
| * |
| * BSD license, See the LICENSE file for more information |
| * |
| * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
| */ |
| |
| #ifndef CHRONOS_CONTACT_STORAGE_H |
| #define CHRONOS_CONTACT_STORAGE_H |
| |
| #include "contact.h" |
| #include "endorse-collection.pb.h" |
| #include <sqlite3.h> |
| |
| namespace chronos{ |
| |
| class ContactStorage |
| { |
| |
| public: |
| struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} }; |
| |
| ContactStorage(const ndn::Name& identity); |
| |
| ~ContactStorage() |
| { |
| sqlite3_close(m_db); |
| } |
| |
| ndn::shared_ptr<Profile> |
| getSelfProfile(); |
| |
| void |
| addSelfEndorseCertificate(const EndorseCertificate& endorseCertificate); |
| |
| void |
| addEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity); |
| |
| void |
| updateCollectEndorse(const EndorseCertificate& endorseCertificate); |
| |
| void |
| getCollectEndorse(EndorseCollection& endorseCollection); |
| |
| void |
| getEndorseList(const ndn::Name& identity, std::vector<std::string>& endorseList); |
| |
| |
| |
| void |
| removeContact(const ndn::Name& identity); |
| |
| void |
| addContact(const Contact& contact); |
| |
| ndn::shared_ptr<Contact> |
| getContact(const ndn::Name& identity) const; |
| |
| void |
| updateIsIntroducer(const ndn::Name& identity, bool isIntroducer); |
| |
| void |
| updateAlias(const ndn::Name& identity, std::string alias); |
| |
| void |
| getAllContacts(std::vector<ndn::shared_ptr<Contact> >& contacts) const; |
| |
| void |
| updateDnsSelfProfileData(const ndn::Data& data) |
| { |
| updateDnsData(data.wireEncode(), "N/A", "PROFILE", data.getName().toUri()); |
| } |
| |
| void |
| updateDnsEndorseOthers(const ndn::Data& data, const std::string& endorsee) |
| { |
| updateDnsData(data.wireEncode(), endorsee, "ENDORSEE", data.getName().toUri()); |
| } |
| |
| void |
| updateDnsOthersEndorse(const ndn::Data& data) |
| { |
| updateDnsData(data.wireEncode(), "N/A", "ENDORSED", data.getName().toUri()); |
| } |
| |
| ndn::shared_ptr<ndn::Data> |
| getDnsData(const ndn::Name& name); |
| |
| ndn::shared_ptr<ndn::Data> |
| getDnsData(const std::string& name, const std::string& type); |
| |
| private: |
| std::string |
| getDBName(); |
| |
| void |
| initializeTable(const std::string& tableName, const std::string& sqlCreateStmt); |
| |
| bool |
| doesContactExist(const ndn::Name& name); |
| |
| void |
| updateDnsData(const ndn::Block& data, const std::string& name, const std::string& type, const std::string& dataName); |
| |
| private: |
| ndn::Name m_identity; |
| |
| sqlite3 *m_db; |
| }; |
| |
| }//chronos |
| #endif |