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