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 | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame^] | 46 | fetchIdCertificate(const ndn::Name& certName); |
| 47 | |
| 48 | void |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 49 | updateProfileData(const ndn::Name& identity); |
| 50 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 51 | void |
| 52 | updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity); |
| 53 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 54 | std::vector<ndn::Ptr<ContactItem> > |
| 55 | getContactItemList(); |
| 56 | |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 57 | inline ndn::Ptr<ContactStorage> |
| 58 | getContactStorage() |
| 59 | { return m_contactStorage; } |
| 60 | |
Yingdi Yu | d40226b | 2013-10-23 14:05:12 -0700 | [diff] [blame] | 61 | ndn::Ptr<ContactItem> |
| 62 | getContact(const ndn::Name& contactNamespace); |
| 63 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 64 | inline ndn::Ptr<DnsStorage> |
| 65 | getDnsStorage() |
| 66 | { return m_dnsStorage; } |
| 67 | |
| 68 | inline ndn::Name |
| 69 | getDefaultIdentity() |
| 70 | { return m_keychain->getDefaultIdentity(); } |
| 71 | |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 72 | inline ndn::Ptr<ndn::Wrapper> |
| 73 | getWrapper() |
| 74 | { return m_wrapper; } |
| 75 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 76 | void |
| 77 | publishEndorsedDataInDns(const ndn::Name& identity); |
| 78 | |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame^] | 79 | inline void |
| 80 | setDefaultIdentity(const ndn::Name& identity) |
| 81 | { m_defaultIdentity = identity; } |
| 82 | |
| 83 | void |
| 84 | addContact(const ndn::security::IdentityCertificate& idCert, const Profile& profile); |
| 85 | |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 86 | private: |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 87 | void |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 88 | setKeychain(); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 89 | |
| 90 | ndn::Ptr<EndorseCertificate> |
| 91 | getSignedSelfEndorseCertificate(const ndn::Name& identity, const Profile& profile); |
| 92 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 93 | ndn::Ptr<EndorseCertificate> |
| 94 | generateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity); |
| 95 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 96 | void |
| 97 | publishSelfEndorseCertificateInDNS(ndn::Ptr<EndorseCertificate> selfEndorseCertificate); |
| 98 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 99 | void |
| 100 | publishEndorseCertificateInDNS(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& signerIdentity); |
| 101 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 102 | void |
| 103 | onDnsSelfEndorseCertificateVerified(ndn::Ptr<ndn::Data> selfEndorseCertificate, const ndn::Name& identity); |
| 104 | |
| 105 | void |
| 106 | onDnsSelfEndorseCertificateUnverified(ndn::Ptr<ndn::Data> selfEndorseCertificate, const ndn::Name& identity); |
| 107 | |
| 108 | void |
| 109 | onDnsSelfEndorseCertificateTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry); |
| 110 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 111 | void |
| 112 | onKeyVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity); |
| 113 | |
| 114 | void |
| 115 | onKeyUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity); |
| 116 | |
| 117 | void |
| 118 | onKeyTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry); |
| 119 | |
| 120 | void |
| 121 | onDnsCollectEndorseVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity); |
| 122 | |
| 123 | void |
| 124 | onDnsCollectEndorseTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry); |
| 125 | |
| 126 | void |
| 127 | onDnsCollectEndorseUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity); |
| 128 | |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame^] | 129 | void |
| 130 | onIdCertificateVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity); |
| 131 | |
| 132 | void |
| 133 | onIdCertificateUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity); |
| 134 | |
| 135 | void |
| 136 | onIdCertificateTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 137 | |
| 138 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 139 | signals: |
| 140 | void |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 141 | contactFetched(const EndorseCertificate& endorseCertificate); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 142 | |
| 143 | void |
| 144 | contactFetchFailed(const ndn::Name& identity); |
| 145 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 146 | void |
| 147 | contactKeyFetched(const EndorseCertificate& endorseCertificate); |
| 148 | |
| 149 | void |
| 150 | contactKeyFetchFailed(const ndn::Name& identity); |
| 151 | |
| 152 | void |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame^] | 153 | contactCertificateFetched(const ndn::security::IdentityCertificate& identityCertificate); |
| 154 | |
| 155 | void |
| 156 | contactCertificateFetchFailed(const ndn::Name& identity); |
| 157 | |
| 158 | void |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 159 | collectEndorseFetched(const ndn::Data& data); |
| 160 | |
| 161 | void |
| 162 | collectEndorseFetchFailed(const ndn::Name& identity); |
| 163 | |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame^] | 164 | void |
| 165 | warning(QString msg); |
| 166 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 167 | private slots: |
| 168 | |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 169 | |
| 170 | private: |
| 171 | ndn::Ptr<ContactStorage> m_contactStorage; |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 172 | ndn::Ptr<DnsStorage> m_dnsStorage; |
| 173 | ndn::Ptr<ndn::security::Keychain> m_keychain; |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 174 | ndn::Ptr<ndn::Wrapper> m_wrapper; |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame^] | 175 | ndn::Name m_defaultIdentity; |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | #endif |