blob: d27e1cb595d907315c5e4e84fd732ceee7f56d67 [file] [log] [blame]
Yingdi Yu9236c432013-10-18 11:29:25 -07001/* -*- 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 Yu4685b1b2013-10-18 17:05:02 -070014#include <QObject>
Yingdi Yu9236c432013-10-18 11:29:25 -070015
Yingdi Yu4685b1b2013-10-18 17:05:02 -070016#ifndef Q_MOC_RUN
17#include "contact-storage.h"
18#include "dns-storage.h"
19#include "endorse-certificate.h"
Yingdi Yu2ac40fb2013-10-21 13:38:38 -070020#include "profile.h"
Yingdi Yu76dd8002013-12-24 11:16:32 +080021#include <ndn-cpp/face.hpp>
Yingdi Yuf8f572d2014-01-13 11:19:47 -080022#include <ndn-cpp/security/key-chain.hpp>
Yingdi Yu76dd8002013-12-24 11:16:32 +080023#include <ndn-cpp/security/policy/validation-request.hpp>
24#include <ndn-cpp-et/policy-manager/simple-policy-manager.hpp>
Yingdi Yu4685b1b2013-10-18 17:05:02 -070025#endif
26
Yingdi Yu76dd8002013-12-24 11:16:32 +080027typedef ndn::func_lib::function<void()> TimeoutNotify;
Yingdi Yu4685b1b2013-10-18 17:05:02 -070028
29class ContactManager : public QObject
Yingdi Yu9236c432013-10-18 11:29:25 -070030{
Yingdi Yu4685b1b2013-10-18 17:05:02 -070031 Q_OBJECT
32
Yingdi Yu9236c432013-10-18 11:29:25 -070033public:
Yingdi Yuf8f572d2014-01-13 11:19:47 -080034 ContactManager(ndn::ptr_lib::shared_ptr<ndn::KeyChain> keyChain,
Yingdi Yu6eabbd72013-12-27 08:44:12 +080035 ndn::ptr_lib::shared_ptr<ndn::Face> m_face,
Yingdi Yu76dd8002013-12-24 11:16:32 +080036 QObject* parent = 0);
Yingdi Yu9236c432013-10-18 11:29:25 -070037
38 ~ContactManager();
39
Yingdi Yu4685b1b2013-10-18 17:05:02 -070040 void
41 fetchSelfEndorseCertificate(const ndn::Name& identity);
42
43 void
Yingdi Yub2e747d2013-11-05 23:06:43 -080044 fetchKey(const ndn::Name& identity);
45
46 void
47 fetchCollectEndorse(const ndn::Name& identity);
48
49 void
Yingdi Yuae8217c2013-11-09 00:03:26 -080050 fetchIdCertificate(const ndn::Name& certName);
51
52 void
Yingdi Yu4685b1b2013-10-18 17:05:02 -070053 updateProfileData(const ndn::Name& identity);
54
Yingdi Yub2e747d2013-11-05 23:06:43 -080055 void
56 updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
57
Yingdi Yu76dd8002013-12-24 11:16:32 +080058 void
59 getContactItemList(std::vector<ndn::ptr_lib::shared_ptr<ContactItem> >& contacts);
Yingdi Yu2ac40fb2013-10-21 13:38:38 -070060
Yingdi Yu76dd8002013-12-24 11:16:32 +080061 ndn::ptr_lib::shared_ptr<ContactStorage>
Yingdi Yu9236c432013-10-18 11:29:25 -070062 getContactStorage()
63 { return m_contactStorage; }
64
Yingdi Yu76dd8002013-12-24 11:16:32 +080065 ndn::ptr_lib::shared_ptr<ContactItem>
Yingdi Yu4ef8cf62013-10-23 14:05:12 -070066 getContact(const ndn::Name& contactNamespace);
67
Yingdi Yu76dd8002013-12-24 11:16:32 +080068 ndn::ptr_lib::shared_ptr<DnsStorage>
Yingdi Yu4685b1b2013-10-18 17:05:02 -070069 getDnsStorage()
70 { return m_dnsStorage; }
71
Yingdi Yu76dd8002013-12-24 11:16:32 +080072 ndn::Name
Yingdi Yu4685b1b2013-10-18 17:05:02 -070073 getDefaultIdentity()
Yingdi Yuf8f572d2014-01-13 11:19:47 -080074 { return m_keyChain->getDefaultIdentity(); }
Yingdi Yu9236c432013-10-18 11:29:25 -070075
Yingdi Yub2e747d2013-11-05 23:06:43 -080076 void
77 publishEndorsedDataInDns(const ndn::Name& identity);
78
Yingdi Yu76dd8002013-12-24 11:16:32 +080079 void
Yingdi Yuae8217c2013-11-09 00:03:26 -080080 setDefaultIdentity(const ndn::Name& identity)
81 { m_defaultIdentity = identity; }
82
83 void
Yingdi Yu76dd8002013-12-24 11:16:32 +080084 addContact(const ndn::IdentityCertificate& idCert, const Profile& profile);
Yingdi Yuae8217c2013-11-09 00:03:26 -080085
Yingdi Yu72232692013-11-12 17:50:21 -080086 void
87 removeContact(const ndn::Name& contactNameSpace);
88
Yingdi Yuf8f572d2014-01-13 11:19:47 -080089 // ndn::ptr_lib::shared_ptr<ndn::KeyChain>
90 // getKeyChain()
91 // { return m_keyChain; }
Yingdi Yu72232692013-11-12 17:50:21 -080092
Yingdi Yuf8f572d2014-01-13 11:19:47 -080093private:
Yingdi Yu76dd8002013-12-24 11:16:32 +080094 void
95 initializeSecurity();
96
97 ndn::ptr_lib::shared_ptr<EndorseCertificate>
Yingdi Yu4685b1b2013-10-18 17:05:02 -070098 getSignedSelfEndorseCertificate(const ndn::Name& identity, const Profile& profile);
99
Yingdi Yu76dd8002013-12-24 11:16:32 +0800100 ndn::ptr_lib::shared_ptr<EndorseCertificate>
Yingdi Yub2e747d2013-11-05 23:06:43 -0800101 generateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
102
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700103 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800104 publishSelfEndorseCertificateInDNS(const EndorseCertificate& selfEndorseCertificate);
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700105
Yingdi Yub2e747d2013-11-05 23:06:43 -0800106 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800107 publishEndorseCertificateInDNS(const EndorseCertificate& endorseCertificate, const ndn::Name& signerIdentity);
108
109 void
110 sendInterest(const ndn::Interest& interest,
111 const ndn::OnVerified& onVerified,
112 const ndn::OnVerifyFailed& onVerifyFailed,
113 const TimeoutNotify& timeoutNotify,
114 int retry = 1,
115 int stepCount = 0);
116
117 void
118 onTargetData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
119 const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
120 int stepCount,
121 const ndn::OnVerified& onVerified,
122 const ndn::OnVerifyFailed& onVerifyFailed,
123 const TimeoutNotify& timeoutNotify);
124
125 void
126 onTargetTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
127 int retry,
128 int stepCount,
129 const ndn::OnVerified& onVerified,
130 const ndn::OnVerifyFailed& onVerifyFailed,
131 const TimeoutNotify& timeoutNotify);
132
133
134 void
135 onCertData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
136 const ndn::ptr_lib::shared_ptr<ndn::Data>& cert,
137 ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> previousStep);
138
139 void
140 onCertTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
141 const ndn::OnVerifyFailed& onVerifyFailed,
142 const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
143 ndn::ptr_lib::shared_ptr<ndn::ValidationRequest> nextStep);
144
145
146 void
147 onDnsSelfEndorseCertificateTimeoutNotify(const ndn::Name& identity);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800148
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700149 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800150 onDnsSelfEndorseCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity);
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700151
152 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800153 onDnsSelfEndorseCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity);
154
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700155
156 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800157 onDnsCollectEndorseVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700158
Yingdi Yub2e747d2013-11-05 23:06:43 -0800159 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800160 onDnsCollectEndorseVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800161
162 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800163 onDnsCollectEndorseTimeoutNotify(const ndn::Name& identity);
164
Yingdi Yub2e747d2013-11-05 23:06:43 -0800165
166 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800167 onKeyVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800168
169 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800170 onKeyVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800171
172 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800173 onKeyTimeoutNotify(const ndn::Name& identity);
174
Yingdi Yub2e747d2013-11-05 23:06:43 -0800175
176 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800177 onIdCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800178
Yingdi Yuae8217c2013-11-09 00:03:26 -0800179 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800180 onIdCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yuae8217c2013-11-09 00:03:26 -0800181
182 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800183 onIdCertificateTimeoutNotify(const ndn::Name& identity);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800184
185
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700186signals:
Yingdi Yu8e135832013-11-09 20:12:31 -0800187 void
188 noNdnConnection(const QString& msg);
189
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700190 void
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700191 contactFetched(const EndorseCertificate& endorseCertificate);
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700192
193 void
194 contactFetchFailed(const ndn::Name& identity);
195
Yingdi Yub2e747d2013-11-05 23:06:43 -0800196 void
197 contactKeyFetched(const EndorseCertificate& endorseCertificate);
198
199 void
200 contactKeyFetchFailed(const ndn::Name& identity);
201
202 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800203 contactCertificateFetched(const ndn::IdentityCertificate& identityCertificate);
Yingdi Yuae8217c2013-11-09 00:03:26 -0800204
205 void
206 contactCertificateFetchFailed(const ndn::Name& identity);
207
208 void
Yingdi Yub2e747d2013-11-05 23:06:43 -0800209 collectEndorseFetched(const ndn::Data& data);
210
211 void
212 collectEndorseFetchFailed(const ndn::Name& identity);
213
Yingdi Yuae8217c2013-11-09 00:03:26 -0800214 void
215 warning(QString msg);
216
Yingdi Yu72232692013-11-12 17:50:21 -0800217 void
218 contactRemoved(const ndn::Name& identity);
219
220 void
221 contactAdded(const ndn::Name& identity);
222
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700223private slots:
224
Yingdi Yu9236c432013-10-18 11:29:25 -0700225
226private:
Yingdi Yu76dd8002013-12-24 11:16:32 +0800227 ndn::ptr_lib::shared_ptr<ContactStorage> m_contactStorage;
228 ndn::ptr_lib::shared_ptr<DnsStorage> m_dnsStorage;
229 ndn::ptr_lib::shared_ptr<ndn::SimplePolicyManager> m_policyManager;
Yingdi Yuf8f572d2014-01-13 11:19:47 -0800230 ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
Yingdi Yu76dd8002013-12-24 11:16:32 +0800231 ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
Yingdi Yuae8217c2013-11-09 00:03:26 -0800232 ndn::Name m_defaultIdentity;
Yingdi Yu9236c432013-10-18 11:29:25 -0700233};
234
235#endif