Yingdi Yu | 9236c43 | 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 | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 14 | #include <QObject> |
Yingdi Yu | 9236c43 | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 15 | |
Yingdi Yu | 4685b1b | 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 | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 20 | #include "profile.h" |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 21 | #include <ndn-cpp/face.hpp> |
| 22 | #include <ndn-cpp/security/policy/validation-request.hpp> |
| 23 | #include <ndn-cpp-et/policy-manager/simple-policy-manager.hpp> |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 24 | #endif |
| 25 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 26 | typedef ndn::func_lib::function<void()> TimeoutNotify; |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 27 | |
| 28 | class ContactManager : public QObject |
Yingdi Yu | 9236c43 | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 29 | { |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 30 | Q_OBJECT |
| 31 | |
Yingdi Yu | 9236c43 | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 32 | public: |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 33 | ContactManager(ndn::ptr_lib::shared_ptr<ndn::IdentityManager> identityManager, |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame^] | 34 | ndn::ptr_lib::shared_ptr<ndn::Face> m_face, |
| 35 | ndn::ptr_lib::shared_ptr<ndn::Transport> m_transport, |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 36 | QObject* parent = 0); |
Yingdi Yu | 9236c43 | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 37 | |
| 38 | ~ContactManager(); |
| 39 | |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 40 | void |
| 41 | fetchSelfEndorseCertificate(const ndn::Name& identity); |
| 42 | |
| 43 | void |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 44 | fetchKey(const ndn::Name& identity); |
| 45 | |
| 46 | void |
| 47 | fetchCollectEndorse(const ndn::Name& identity); |
| 48 | |
| 49 | void |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 50 | fetchIdCertificate(const ndn::Name& certName); |
| 51 | |
| 52 | void |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 53 | updateProfileData(const ndn::Name& identity); |
| 54 | |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 55 | void |
| 56 | updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity); |
| 57 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 58 | void |
| 59 | getContactItemList(std::vector<ndn::ptr_lib::shared_ptr<ContactItem> >& contacts); |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 60 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 61 | ndn::ptr_lib::shared_ptr<ContactStorage> |
Yingdi Yu | 9236c43 | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 62 | getContactStorage() |
| 63 | { return m_contactStorage; } |
| 64 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 65 | ndn::ptr_lib::shared_ptr<ContactItem> |
Yingdi Yu | 4ef8cf6 | 2013-10-23 14:05:12 -0700 | [diff] [blame] | 66 | getContact(const ndn::Name& contactNamespace); |
| 67 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 68 | ndn::ptr_lib::shared_ptr<DnsStorage> |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 69 | getDnsStorage() |
| 70 | { return m_dnsStorage; } |
| 71 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 72 | ndn::Name |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 73 | getDefaultIdentity() |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 74 | { return m_identityManager->getDefaultIdentity(); } |
Yingdi Yu | 9236c43 | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 75 | |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 76 | void |
| 77 | publishEndorsedDataInDns(const ndn::Name& identity); |
| 78 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 79 | void |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 80 | setDefaultIdentity(const ndn::Name& identity) |
| 81 | { m_defaultIdentity = identity; } |
| 82 | |
| 83 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 84 | addContact(const ndn::IdentityCertificate& idCert, const Profile& profile); |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 85 | |
Yingdi Yu | 7223269 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 86 | void |
| 87 | removeContact(const ndn::Name& contactNameSpace); |
| 88 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 89 | ndn::ptr_lib::shared_ptr<ndn::IdentityManager> |
| 90 | getIdentityManager() |
| 91 | { return m_identityManager; } |
Yingdi Yu | 7223269 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 92 | |
Yingdi Yu | 9236c43 | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 93 | private: |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame^] | 94 | // void |
| 95 | // connectToDaemon(); |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 96 | |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame^] | 97 | // void |
| 98 | // onConnectionData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, |
| 99 | // const ndn::ptr_lib::shared_ptr<ndn::Data>& data); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 100 | |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame^] | 101 | // void |
| 102 | // onConnectionDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 103 | |
| 104 | void |
| 105 | initializeSecurity(); |
| 106 | |
| 107 | ndn::ptr_lib::shared_ptr<EndorseCertificate> |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 108 | getSignedSelfEndorseCertificate(const ndn::Name& identity, const Profile& profile); |
| 109 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 110 | ndn::ptr_lib::shared_ptr<EndorseCertificate> |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 111 | generateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity); |
| 112 | |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 113 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 114 | publishSelfEndorseCertificateInDNS(const EndorseCertificate& selfEndorseCertificate); |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 115 | |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 116 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 117 | publishEndorseCertificateInDNS(const EndorseCertificate& endorseCertificate, const ndn::Name& signerIdentity); |
| 118 | |
| 119 | void |
| 120 | sendInterest(const ndn::Interest& interest, |
| 121 | const ndn::OnVerified& onVerified, |
| 122 | const ndn::OnVerifyFailed& onVerifyFailed, |
| 123 | const TimeoutNotify& timeoutNotify, |
| 124 | int retry = 1, |
| 125 | int stepCount = 0); |
| 126 | |
| 127 | void |
| 128 | onTargetData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, |
| 129 | const ndn::ptr_lib::shared_ptr<ndn::Data>& data, |
| 130 | int stepCount, |
| 131 | const ndn::OnVerified& onVerified, |
| 132 | const ndn::OnVerifyFailed& onVerifyFailed, |
| 133 | const TimeoutNotify& timeoutNotify); |
| 134 | |
| 135 | void |
| 136 | onTargetTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, |
| 137 | int retry, |
| 138 | int stepCount, |
| 139 | const ndn::OnVerified& onVerified, |
| 140 | const ndn::OnVerifyFailed& onVerifyFailed, |
| 141 | const TimeoutNotify& timeoutNotify); |
| 142 | |
| 143 | |
| 144 | void |
| 145 | onCertData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, |
| 146 | const ndn::ptr_lib::shared_ptr<ndn::Data>& cert, |
| 147 | ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> previousStep); |
| 148 | |
| 149 | void |
| 150 | onCertTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest, |
| 151 | const ndn::OnVerifyFailed& onVerifyFailed, |
| 152 | const ndn::ptr_lib::shared_ptr<ndn::Data>& data, |
| 153 | ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> nextStep); |
| 154 | |
| 155 | |
| 156 | void |
| 157 | onDnsSelfEndorseCertificateTimeoutNotify(const ndn::Name& identity); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 158 | |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 159 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 160 | onDnsSelfEndorseCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity); |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 161 | |
| 162 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 163 | onDnsSelfEndorseCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity); |
| 164 | |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 165 | |
| 166 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 167 | onDnsCollectEndorseVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity); |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 168 | |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 169 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 170 | onDnsCollectEndorseVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 171 | |
| 172 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 173 | onDnsCollectEndorseTimeoutNotify(const ndn::Name& identity); |
| 174 | |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 175 | |
| 176 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 177 | onKeyVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 178 | |
| 179 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 180 | onKeyVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 181 | |
| 182 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 183 | onKeyTimeoutNotify(const ndn::Name& identity); |
| 184 | |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 185 | |
| 186 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 187 | onIdCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 188 | |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 189 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 190 | onIdCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity); |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 191 | |
| 192 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 193 | onIdCertificateTimeoutNotify(const ndn::Name& identity); |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 194 | |
| 195 | |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 196 | signals: |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 197 | void |
| 198 | noNdnConnection(const QString& msg); |
| 199 | |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 200 | void |
Yingdi Yu | 2ac40fb | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 201 | contactFetched(const EndorseCertificate& endorseCertificate); |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 202 | |
| 203 | void |
| 204 | contactFetchFailed(const ndn::Name& identity); |
| 205 | |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 206 | void |
| 207 | contactKeyFetched(const EndorseCertificate& endorseCertificate); |
| 208 | |
| 209 | void |
| 210 | contactKeyFetchFailed(const ndn::Name& identity); |
| 211 | |
| 212 | void |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 213 | contactCertificateFetched(const ndn::IdentityCertificate& identityCertificate); |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 214 | |
| 215 | void |
| 216 | contactCertificateFetchFailed(const ndn::Name& identity); |
| 217 | |
| 218 | void |
Yingdi Yu | b2e747d | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 219 | collectEndorseFetched(const ndn::Data& data); |
| 220 | |
| 221 | void |
| 222 | collectEndorseFetchFailed(const ndn::Name& identity); |
| 223 | |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 224 | void |
| 225 | warning(QString msg); |
| 226 | |
Yingdi Yu | 7223269 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 227 | void |
| 228 | contactRemoved(const ndn::Name& identity); |
| 229 | |
| 230 | void |
| 231 | contactAdded(const ndn::Name& identity); |
| 232 | |
Yingdi Yu | 4685b1b | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 233 | private slots: |
| 234 | |
Yingdi Yu | 9236c43 | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 235 | |
| 236 | private: |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 237 | ndn::ptr_lib::shared_ptr<ContactStorage> m_contactStorage; |
| 238 | ndn::ptr_lib::shared_ptr<DnsStorage> m_dnsStorage; |
| 239 | ndn::ptr_lib::shared_ptr<ndn::SimplePolicyManager> m_policyManager; |
| 240 | ndn::ptr_lib::shared_ptr<ndn::IdentityManager> m_identityManager; |
| 241 | ndn::ptr_lib::shared_ptr<ndn::Face> m_face; |
| 242 | ndn::ptr_lib::shared_ptr<ndn::Transport> m_transport; |
Yingdi Yu | ae8217c | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 243 | ndn::Name m_defaultIdentity; |
Yingdi Yu | 9236c43 | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | #endif |