blob: 67d4ac8448cfd91b819baa685d6f39739f66361f [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>
Yingdi Yuc9ffa9f2014-01-13 11:19:47 -080022#include <ndn-cpp/security/key-chain.hpp>
Yingdi Yueaa84e22014-01-16 10:30:26 -080023#include <ndn-cpp/security/validation-request.hpp>
24#include <ndn-cpp-et/policy/sec-policy-simple.hpp>
Yingdi Yuaa8d7692013-10-18 17:05:02 -070025#endif
26
Yingdi Yu64206112013-12-24 11:16:32 +080027typedef ndn::func_lib::function<void()> TimeoutNotify;
Yingdi Yuaa8d7692013-10-18 17:05:02 -070028
29class ContactManager : public QObject
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070030{
Yingdi Yuaa8d7692013-10-18 17:05:02 -070031 Q_OBJECT
32
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070033public:
Yingdi Yuc9ffa9f2014-01-13 11:19:47 -080034 ContactManager(ndn::ptr_lib::shared_ptr<ndn::KeyChain> keyChain,
Yingdi Yuaccbda92013-12-27 08:44:12 +080035 ndn::ptr_lib::shared_ptr<ndn::Face> m_face,
Yingdi Yu64206112013-12-24 11:16:32 +080036 QObject* parent = 0);
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070037
38 ~ContactManager();
39
Yingdi Yuaa8d7692013-10-18 17:05:02 -070040 void
41 fetchSelfEndorseCertificate(const ndn::Name& identity);
42
43 void
Yingdi Yu8dacdf22013-11-05 23:06:43 -080044 fetchKey(const ndn::Name& identity);
45
46 void
47 fetchCollectEndorse(const ndn::Name& identity);
48
49 void
Yingdi Yu908f8412013-11-09 00:03:26 -080050 fetchIdCertificate(const ndn::Name& certName);
51
52 void
Yingdi Yuaa8d7692013-10-18 17:05:02 -070053 updateProfileData(const ndn::Name& identity);
54
Yingdi Yu8dacdf22013-11-05 23:06:43 -080055 void
56 updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
57
Yingdi Yu64206112013-12-24 11:16:32 +080058 void
59 getContactItemList(std::vector<ndn::ptr_lib::shared_ptr<ContactItem> >& contacts);
Yingdi Yu79c25a22013-10-21 13:38:38 -070060
Yingdi Yu64206112013-12-24 11:16:32 +080061 ndn::ptr_lib::shared_ptr<ContactStorage>
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070062 getContactStorage()
63 { return m_contactStorage; }
64
Yingdi Yu64206112013-12-24 11:16:32 +080065 ndn::ptr_lib::shared_ptr<ContactItem>
Yingdi Yud40226b2013-10-23 14:05:12 -070066 getContact(const ndn::Name& contactNamespace);
67
Yingdi Yu64206112013-12-24 11:16:32 +080068 ndn::ptr_lib::shared_ptr<DnsStorage>
Yingdi Yuaa8d7692013-10-18 17:05:02 -070069 getDnsStorage()
70 { return m_dnsStorage; }
71
Yingdi Yu64206112013-12-24 11:16:32 +080072 ndn::Name
Yingdi Yuaa8d7692013-10-18 17:05:02 -070073 getDefaultIdentity()
Yingdi Yuc9ffa9f2014-01-13 11:19:47 -080074 { return m_keyChain->getDefaultIdentity(); }
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070075
Yingdi Yu8dacdf22013-11-05 23:06:43 -080076 void
77 publishEndorsedDataInDns(const ndn::Name& identity);
78
Yingdi Yu64206112013-12-24 11:16:32 +080079 void
Yingdi Yu908f8412013-11-09 00:03:26 -080080 setDefaultIdentity(const ndn::Name& identity)
81 { m_defaultIdentity = identity; }
82
83 void
Yingdi Yu64206112013-12-24 11:16:32 +080084 addContact(const ndn::IdentityCertificate& idCert, const Profile& profile);
Yingdi Yu908f8412013-11-09 00:03:26 -080085
Yingdi Yu6ea54e42013-11-12 17:50:21 -080086 void
87 removeContact(const ndn::Name& contactNameSpace);
88
Yingdi Yuc9ffa9f2014-01-13 11:19:47 -080089 // ndn::ptr_lib::shared_ptr<ndn::KeyChain>
90 // getKeyChain()
91 // { return m_keyChain; }
Yingdi Yu6ea54e42013-11-12 17:50:21 -080092
Yingdi Yuc9ffa9f2014-01-13 11:19:47 -080093private:
Yingdi Yu64206112013-12-24 11:16:32 +080094 void
95 initializeSecurity();
96
97 ndn::ptr_lib::shared_ptr<EndorseCertificate>
Yingdi Yuaa8d7692013-10-18 17:05:02 -070098 getSignedSelfEndorseCertificate(const ndn::Name& identity, const Profile& profile);
99
Yingdi Yu64206112013-12-24 11:16:32 +0800100 ndn::ptr_lib::shared_ptr<EndorseCertificate>
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800101 generateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
102
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700103 void
Yingdi Yu64206112013-12-24 11:16:32 +0800104 publishSelfEndorseCertificateInDNS(const EndorseCertificate& selfEndorseCertificate);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700105
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800106 void
Yingdi Yu64206112013-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 Yu8dacdf22013-11-05 23:06:43 -0800148
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700149 void
Yingdi Yu64206112013-12-24 11:16:32 +0800150 onDnsSelfEndorseCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700151
152 void
Yingdi Yu64206112013-12-24 11:16:32 +0800153 onDnsSelfEndorseCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity);
154
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700155
156 void
Yingdi Yu64206112013-12-24 11:16:32 +0800157 onDnsCollectEndorseVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700158
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800159 void
Yingdi Yu64206112013-12-24 11:16:32 +0800160 onDnsCollectEndorseVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800161
162 void
Yingdi Yu64206112013-12-24 11:16:32 +0800163 onDnsCollectEndorseTimeoutNotify(const ndn::Name& identity);
164
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800165
166 void
Yingdi Yu64206112013-12-24 11:16:32 +0800167 onKeyVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800168
169 void
Yingdi Yu64206112013-12-24 11:16:32 +0800170 onKeyVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800171
172 void
Yingdi Yu64206112013-12-24 11:16:32 +0800173 onKeyTimeoutNotify(const ndn::Name& identity);
174
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800175
176 void
Yingdi Yu64206112013-12-24 11:16:32 +0800177 onIdCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800178
Yingdi Yu908f8412013-11-09 00:03:26 -0800179 void
Yingdi Yu64206112013-12-24 11:16:32 +0800180 onIdCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu908f8412013-11-09 00:03:26 -0800181
182 void
Yingdi Yu64206112013-12-24 11:16:32 +0800183 onIdCertificateTimeoutNotify(const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800184
185
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700186signals:
Yingdi Yub29f78c2013-11-09 20:12:31 -0800187 void
188 noNdnConnection(const QString& msg);
189
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700190 void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700191 contactFetched(const EndorseCertificate& endorseCertificate);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700192
193 void
194 contactFetchFailed(const ndn::Name& identity);
195
Yingdi Yu8dacdf22013-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 Yu64206112013-12-24 11:16:32 +0800203 contactCertificateFetched(const ndn::IdentityCertificate& identityCertificate);
Yingdi Yu908f8412013-11-09 00:03:26 -0800204
205 void
206 contactCertificateFetchFailed(const ndn::Name& identity);
207
208 void
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800209 collectEndorseFetched(const ndn::Data& data);
210
211 void
212 collectEndorseFetchFailed(const ndn::Name& identity);
213
Yingdi Yu908f8412013-11-09 00:03:26 -0800214 void
215 warning(QString msg);
216
Yingdi Yu6ea54e42013-11-12 17:50:21 -0800217 void
218 contactRemoved(const ndn::Name& identity);
219
220 void
221 contactAdded(const ndn::Name& identity);
222
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700223private slots:
224
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700225
226private:
Yingdi Yueaa84e22014-01-16 10:30:26 -0800227
Yingdi Yu64206112013-12-24 11:16:32 +0800228 ndn::ptr_lib::shared_ptr<ContactStorage> m_contactStorage;
229 ndn::ptr_lib::shared_ptr<DnsStorage> m_dnsStorage;
Yingdi Yueaa84e22014-01-16 10:30:26 -0800230 ndn::ptr_lib::shared_ptr<ndn::SecPolicySimple> m_policy;
Yingdi Yuc9ffa9f2014-01-13 11:19:47 -0800231 ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
Yingdi Yu64206112013-12-24 11:16:32 +0800232 ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
Yingdi Yu908f8412013-11-09 00:03:26 -0800233 ndn::Name m_defaultIdentity;
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700234};
235
236#endif