blob: d096abf22164c4bfc7176771c175ccd2bb1f46d9 [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>
22#include <ndn-cpp/security/policy/validation-request.hpp>
23#include <ndn-cpp-et/policy-manager/simple-policy-manager.hpp>
Yingdi Yu4685b1b2013-10-18 17:05:02 -070024#endif
25
Yingdi Yu76dd8002013-12-24 11:16:32 +080026typedef ndn::func_lib::function<void()> TimeoutNotify;
Yingdi Yu4685b1b2013-10-18 17:05:02 -070027
28class ContactManager : public QObject
Yingdi Yu9236c432013-10-18 11:29:25 -070029{
Yingdi Yu4685b1b2013-10-18 17:05:02 -070030 Q_OBJECT
31
Yingdi Yu9236c432013-10-18 11:29:25 -070032public:
Yingdi Yu76dd8002013-12-24 11:16:32 +080033 ContactManager(ndn::ptr_lib::shared_ptr<ndn::IdentityManager> identityManager,
Yingdi Yu6eabbd72013-12-27 08:44:12 +080034 ndn::ptr_lib::shared_ptr<ndn::Face> m_face,
35 ndn::ptr_lib::shared_ptr<ndn::Transport> m_transport,
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 Yu76dd8002013-12-24 11:16:32 +080074 { return m_identityManager->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 Yu76dd8002013-12-24 11:16:32 +080089 ndn::ptr_lib::shared_ptr<ndn::IdentityManager>
90 getIdentityManager()
91 { return m_identityManager; }
Yingdi Yu72232692013-11-12 17:50:21 -080092
Yingdi Yu9236c432013-10-18 11:29:25 -070093private:
Yingdi Yu6eabbd72013-12-27 08:44:12 +080094 // void
95 // connectToDaemon();
Yingdi Yu4685b1b2013-10-18 17:05:02 -070096
Yingdi Yu6eabbd72013-12-27 08:44:12 +080097 // void
98 // onConnectionData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
99 // const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
Yingdi Yu76dd8002013-12-24 11:16:32 +0800100
Yingdi Yu6eabbd72013-12-27 08:44:12 +0800101 // void
102 // onConnectionDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest);
Yingdi Yu76dd8002013-12-24 11:16:32 +0800103
104 void
105 initializeSecurity();
106
107 ndn::ptr_lib::shared_ptr<EndorseCertificate>
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700108 getSignedSelfEndorseCertificate(const ndn::Name& identity, const Profile& profile);
109
Yingdi Yu76dd8002013-12-24 11:16:32 +0800110 ndn::ptr_lib::shared_ptr<EndorseCertificate>
Yingdi Yub2e747d2013-11-05 23:06:43 -0800111 generateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
112
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700113 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800114 publishSelfEndorseCertificateInDNS(const EndorseCertificate& selfEndorseCertificate);
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700115
Yingdi Yub2e747d2013-11-05 23:06:43 -0800116 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800117 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 Yub2e747d2013-11-05 23:06:43 -0800158
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700159 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800160 onDnsSelfEndorseCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity);
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700161
162 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800163 onDnsSelfEndorseCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity);
164
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700165
166 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800167 onDnsCollectEndorseVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700168
Yingdi Yub2e747d2013-11-05 23:06:43 -0800169 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800170 onDnsCollectEndorseVerifyFailed(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 onDnsCollectEndorseTimeoutNotify(const ndn::Name& identity);
174
Yingdi Yub2e747d2013-11-05 23:06:43 -0800175
176 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800177 onKeyVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800178
179 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800180 onKeyVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800181
182 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800183 onKeyTimeoutNotify(const ndn::Name& identity);
184
Yingdi Yub2e747d2013-11-05 23:06:43 -0800185
186 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800187 onIdCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800188
Yingdi Yuae8217c2013-11-09 00:03:26 -0800189 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800190 onIdCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yuae8217c2013-11-09 00:03:26 -0800191
192 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800193 onIdCertificateTimeoutNotify(const ndn::Name& identity);
Yingdi Yub2e747d2013-11-05 23:06:43 -0800194
195
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700196signals:
Yingdi Yu8e135832013-11-09 20:12:31 -0800197 void
198 noNdnConnection(const QString& msg);
199
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700200 void
Yingdi Yu2ac40fb2013-10-21 13:38:38 -0700201 contactFetched(const EndorseCertificate& endorseCertificate);
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700202
203 void
204 contactFetchFailed(const ndn::Name& identity);
205
Yingdi Yub2e747d2013-11-05 23:06:43 -0800206 void
207 contactKeyFetched(const EndorseCertificate& endorseCertificate);
208
209 void
210 contactKeyFetchFailed(const ndn::Name& identity);
211
212 void
Yingdi Yu76dd8002013-12-24 11:16:32 +0800213 contactCertificateFetched(const ndn::IdentityCertificate& identityCertificate);
Yingdi Yuae8217c2013-11-09 00:03:26 -0800214
215 void
216 contactCertificateFetchFailed(const ndn::Name& identity);
217
218 void
Yingdi Yub2e747d2013-11-05 23:06:43 -0800219 collectEndorseFetched(const ndn::Data& data);
220
221 void
222 collectEndorseFetchFailed(const ndn::Name& identity);
223
Yingdi Yuae8217c2013-11-09 00:03:26 -0800224 void
225 warning(QString msg);
226
Yingdi Yu72232692013-11-12 17:50:21 -0800227 void
228 contactRemoved(const ndn::Name& identity);
229
230 void
231 contactAdded(const ndn::Name& identity);
232
Yingdi Yu4685b1b2013-10-18 17:05:02 -0700233private slots:
234
Yingdi Yu9236c432013-10-18 11:29:25 -0700235
236private:
Yingdi Yu76dd8002013-12-24 11:16:32 +0800237 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 Yuae8217c2013-11-09 00:03:26 -0800243 ndn::Name m_defaultIdentity;
Yingdi Yu9236c432013-10-18 11:29:25 -0700244};
245
246#endif