blob: 0c4cc06f5ec670e80b98d4b873df7ddf96df66e5 [file] [log] [blame]
Yingdi Yu0b82a4e2013-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 Yuaa8d7692013-10-18 17:05:02 -070014#include <QObject>
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070015
Yingdi Yuaa8d7692013-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 Yu79c25a22013-10-21 13:38:38 -070020#include "profile.h"
Yingdi Yu64206112013-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 Yuaa8d7692013-10-18 17:05:02 -070024#endif
25
Yingdi Yu64206112013-12-24 11:16:32 +080026typedef ndn::func_lib::function<void()> TimeoutNotify;
Yingdi Yuaa8d7692013-10-18 17:05:02 -070027
28class ContactManager : public QObject
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070029{
Yingdi Yuaa8d7692013-10-18 17:05:02 -070030 Q_OBJECT
31
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070032public:
Yingdi Yu64206112013-12-24 11:16:32 +080033 ContactManager(ndn::ptr_lib::shared_ptr<ndn::IdentityManager> identityManager,
34 QObject* parent = 0);
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070035
36 ~ContactManager();
37
Yingdi Yuaa8d7692013-10-18 17:05:02 -070038 void
39 fetchSelfEndorseCertificate(const ndn::Name& identity);
40
41 void
Yingdi Yu8dacdf22013-11-05 23:06:43 -080042 fetchKey(const ndn::Name& identity);
43
44 void
45 fetchCollectEndorse(const ndn::Name& identity);
46
47 void
Yingdi Yu908f8412013-11-09 00:03:26 -080048 fetchIdCertificate(const ndn::Name& certName);
49
50 void
Yingdi Yuaa8d7692013-10-18 17:05:02 -070051 updateProfileData(const ndn::Name& identity);
52
Yingdi Yu8dacdf22013-11-05 23:06:43 -080053 void
54 updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
55
Yingdi Yu64206112013-12-24 11:16:32 +080056 void
57 getContactItemList(std::vector<ndn::ptr_lib::shared_ptr<ContactItem> >& contacts);
Yingdi Yu79c25a22013-10-21 13:38:38 -070058
Yingdi Yu64206112013-12-24 11:16:32 +080059 ndn::ptr_lib::shared_ptr<ContactStorage>
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070060 getContactStorage()
61 { return m_contactStorage; }
62
Yingdi Yu64206112013-12-24 11:16:32 +080063 ndn::ptr_lib::shared_ptr<ContactItem>
Yingdi Yud40226b2013-10-23 14:05:12 -070064 getContact(const ndn::Name& contactNamespace);
65
Yingdi Yu64206112013-12-24 11:16:32 +080066 ndn::ptr_lib::shared_ptr<DnsStorage>
Yingdi Yuaa8d7692013-10-18 17:05:02 -070067 getDnsStorage()
68 { return m_dnsStorage; }
69
Yingdi Yu64206112013-12-24 11:16:32 +080070 ndn::Name
Yingdi Yuaa8d7692013-10-18 17:05:02 -070071 getDefaultIdentity()
Yingdi Yu64206112013-12-24 11:16:32 +080072 { return m_identityManager->getDefaultIdentity(); }
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070073
Yingdi Yu8dacdf22013-11-05 23:06:43 -080074 void
75 publishEndorsedDataInDns(const ndn::Name& identity);
76
Yingdi Yu64206112013-12-24 11:16:32 +080077 void
Yingdi Yu908f8412013-11-09 00:03:26 -080078 setDefaultIdentity(const ndn::Name& identity)
79 { m_defaultIdentity = identity; }
80
81 void
Yingdi Yu64206112013-12-24 11:16:32 +080082 addContact(const ndn::IdentityCertificate& idCert, const Profile& profile);
Yingdi Yu908f8412013-11-09 00:03:26 -080083
Yingdi Yu6ea54e42013-11-12 17:50:21 -080084 void
85 removeContact(const ndn::Name& contactNameSpace);
86
Yingdi Yu64206112013-12-24 11:16:32 +080087 ndn::ptr_lib::shared_ptr<ndn::IdentityManager>
88 getIdentityManager()
89 { return m_identityManager; }
Yingdi Yu6ea54e42013-11-12 17:50:21 -080090
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070091private:
Yingdi Yu64206112013-12-24 11:16:32 +080092 void
93 connectToDaemon();
Yingdi Yuaa8d7692013-10-18 17:05:02 -070094
Yingdi Yu64206112013-12-24 11:16:32 +080095 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 Yuaa8d7692013-10-18 17:05:02 -0700106 getSignedSelfEndorseCertificate(const ndn::Name& identity, const Profile& profile);
107
Yingdi Yu64206112013-12-24 11:16:32 +0800108 ndn::ptr_lib::shared_ptr<EndorseCertificate>
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800109 generateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
110
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700111 void
Yingdi Yu64206112013-12-24 11:16:32 +0800112 publishSelfEndorseCertificateInDNS(const EndorseCertificate& selfEndorseCertificate);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700113
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800114 void
Yingdi Yu64206112013-12-24 11:16:32 +0800115 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 Yu8dacdf22013-11-05 23:06:43 -0800156
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700157 void
Yingdi Yu64206112013-12-24 11:16:32 +0800158 onDnsSelfEndorseCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700159
160 void
Yingdi Yu64206112013-12-24 11:16:32 +0800161 onDnsSelfEndorseCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity);
162
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700163
164 void
Yingdi Yu64206112013-12-24 11:16:32 +0800165 onDnsCollectEndorseVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700166
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800167 void
Yingdi Yu64206112013-12-24 11:16:32 +0800168 onDnsCollectEndorseVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800169
170 void
Yingdi Yu64206112013-12-24 11:16:32 +0800171 onDnsCollectEndorseTimeoutNotify(const ndn::Name& identity);
172
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800173
174 void
Yingdi Yu64206112013-12-24 11:16:32 +0800175 onKeyVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800176
177 void
Yingdi Yu64206112013-12-24 11:16:32 +0800178 onKeyVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800179
180 void
Yingdi Yu64206112013-12-24 11:16:32 +0800181 onKeyTimeoutNotify(const ndn::Name& identity);
182
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800183
184 void
Yingdi Yu64206112013-12-24 11:16:32 +0800185 onIdCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800186
Yingdi Yu908f8412013-11-09 00:03:26 -0800187 void
Yingdi Yu64206112013-12-24 11:16:32 +0800188 onIdCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu908f8412013-11-09 00:03:26 -0800189
190 void
Yingdi Yu64206112013-12-24 11:16:32 +0800191 onIdCertificateTimeoutNotify(const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800192
193
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700194signals:
Yingdi Yub29f78c2013-11-09 20:12:31 -0800195 void
196 noNdnConnection(const QString& msg);
197
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700198 void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700199 contactFetched(const EndorseCertificate& endorseCertificate);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700200
201 void
202 contactFetchFailed(const ndn::Name& identity);
203
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800204 void
205 contactKeyFetched(const EndorseCertificate& endorseCertificate);
206
207 void
208 contactKeyFetchFailed(const ndn::Name& identity);
209
210 void
Yingdi Yu64206112013-12-24 11:16:32 +0800211 contactCertificateFetched(const ndn::IdentityCertificate& identityCertificate);
Yingdi Yu908f8412013-11-09 00:03:26 -0800212
213 void
214 contactCertificateFetchFailed(const ndn::Name& identity);
215
216 void
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800217 collectEndorseFetched(const ndn::Data& data);
218
219 void
220 collectEndorseFetchFailed(const ndn::Name& identity);
221
Yingdi Yu908f8412013-11-09 00:03:26 -0800222 void
223 warning(QString msg);
224
Yingdi Yu6ea54e42013-11-12 17:50:21 -0800225 void
226 contactRemoved(const ndn::Name& identity);
227
228 void
229 contactAdded(const ndn::Name& identity);
230
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700231private slots:
232
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700233
234private:
Yingdi Yu64206112013-12-24 11:16:32 +0800235 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 Yu908f8412013-11-09 00:03:26 -0800241 ndn::Name m_defaultIdentity;
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700242};
243
244#endif