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