Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -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 | |
| 11 | #ifndef LINKNDN_CONTACT_MANAGER_H |
| 12 | #define LINKNDN_CONTACT_MANAGER_H |
| 13 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 14 | #include <QObject> |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 15 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 16 | #ifndef Q_MOC_RUN |
| 17 | #include "contact-storage.h" |
| 18 | #include "dns-storage.h" |
| 19 | #include "endorse-certificate.h" |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 20 | #include "profile.h" |
Yingdi Yu | 590fa5d | 2013-10-18 18:35:09 -0700 | [diff] [blame] | 21 | #include <ndn.cxx/wrapper/wrapper.h> |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 22 | #endif |
| 23 | |
| 24 | |
| 25 | class ContactManager : public QObject |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 26 | { |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 27 | Q_OBJECT |
| 28 | |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 29 | public: |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 30 | ContactManager(ndn::Ptr<ContactStorage> contactStorage, |
Yingdi Yu | 590fa5d | 2013-10-18 18:35:09 -0700 | [diff] [blame] | 31 | ndn::Ptr<DnsStorage> dnsStorage, |
| 32 | QObject* parent = 0); |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 33 | |
| 34 | ~ContactManager(); |
| 35 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 36 | void |
| 37 | fetchSelfEndorseCertificate(const ndn::Name& identity); |
| 38 | |
| 39 | void |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame^] | 40 | fetchKey(const ndn::Name& identity); |
| 41 | |
| 42 | void |
| 43 | fetchCollectEndorse(const ndn::Name& identity); |
| 44 | |
| 45 | void |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 46 | updateProfileData(const ndn::Name& identity); |
| 47 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame^] | 48 | void |
| 49 | updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity); |
| 50 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 51 | std::vector<ndn::Ptr<ContactItem> > |
| 52 | getContactItemList(); |
| 53 | |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 54 | inline ndn::Ptr<ContactStorage> |
| 55 | getContactStorage() |
| 56 | { return m_contactStorage; } |
| 57 | |
Yingdi Yu | d40226b | 2013-10-23 14:05:12 -0700 | [diff] [blame] | 58 | ndn::Ptr<ContactItem> |
| 59 | getContact(const ndn::Name& contactNamespace); |
| 60 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 61 | inline ndn::Ptr<DnsStorage> |
| 62 | getDnsStorage() |
| 63 | { return m_dnsStorage; } |
| 64 | |
| 65 | inline ndn::Name |
| 66 | getDefaultIdentity() |
| 67 | { return m_keychain->getDefaultIdentity(); } |
| 68 | |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 69 | inline ndn::Ptr<ndn::Wrapper> |
| 70 | getWrapper() |
| 71 | { return m_wrapper; } |
| 72 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame^] | 73 | void |
| 74 | publishEndorsedDataInDns(const ndn::Name& identity); |
| 75 | |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 76 | private: |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 77 | void |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 78 | setKeychain(); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 79 | |
| 80 | ndn::Ptr<EndorseCertificate> |
| 81 | getSignedSelfEndorseCertificate(const ndn::Name& identity, const Profile& profile); |
| 82 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame^] | 83 | ndn::Ptr<EndorseCertificate> |
| 84 | generateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity); |
| 85 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 86 | void |
| 87 | publishSelfEndorseCertificateInDNS(ndn::Ptr<EndorseCertificate> selfEndorseCertificate); |
| 88 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame^] | 89 | void |
| 90 | publishEndorseCertificateInDNS(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& signerIdentity); |
| 91 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 92 | void |
| 93 | onDnsSelfEndorseCertificateVerified(ndn::Ptr<ndn::Data> selfEndorseCertificate, const ndn::Name& identity); |
| 94 | |
| 95 | void |
| 96 | onDnsSelfEndorseCertificateUnverified(ndn::Ptr<ndn::Data> selfEndorseCertificate, const ndn::Name& identity); |
| 97 | |
| 98 | void |
| 99 | onDnsSelfEndorseCertificateTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry); |
| 100 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame^] | 101 | void |
| 102 | onKeyVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity); |
| 103 | |
| 104 | void |
| 105 | onKeyUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity); |
| 106 | |
| 107 | void |
| 108 | onKeyTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry); |
| 109 | |
| 110 | void |
| 111 | onDnsCollectEndorseVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity); |
| 112 | |
| 113 | void |
| 114 | onDnsCollectEndorseTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry); |
| 115 | |
| 116 | void |
| 117 | onDnsCollectEndorseUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity); |
| 118 | |
| 119 | |
| 120 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 121 | signals: |
| 122 | void |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 123 | contactFetched(const EndorseCertificate& endorseCertificate); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 124 | |
| 125 | void |
| 126 | contactFetchFailed(const ndn::Name& identity); |
| 127 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame^] | 128 | void |
| 129 | contactKeyFetched(const EndorseCertificate& endorseCertificate); |
| 130 | |
| 131 | void |
| 132 | contactKeyFetchFailed(const ndn::Name& identity); |
| 133 | |
| 134 | void |
| 135 | collectEndorseFetched(const ndn::Data& data); |
| 136 | |
| 137 | void |
| 138 | collectEndorseFetchFailed(const ndn::Name& identity); |
| 139 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 140 | private slots: |
| 141 | |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 142 | |
| 143 | private: |
| 144 | ndn::Ptr<ContactStorage> m_contactStorage; |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 145 | ndn::Ptr<DnsStorage> m_dnsStorage; |
| 146 | ndn::Ptr<ndn::security::Keychain> m_keychain; |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 147 | ndn::Ptr<ndn::Wrapper> m_wrapper; |
| 148 | }; |
| 149 | |
| 150 | #endif |