blob: a188fdbf1c46113964055b4c137eeb3c9e78bf60 [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 Yu7630f642014-01-16 19:13:03 -080023#include <ndn-cpp/security/verifier.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 Yuc9ffa9f2014-01-13 11:19:47 -080033 ContactManager(ndn::ptr_lib::shared_ptr<ndn::KeyChain> keyChain,
Yingdi Yuaccbda92013-12-27 08:44:12 +080034 ndn::ptr_lib::shared_ptr<ndn::Face> m_face,
Yingdi Yu64206112013-12-24 11:16:32 +080035 QObject* parent = 0);
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070036
37 ~ContactManager();
38
Yingdi Yuaa8d7692013-10-18 17:05:02 -070039 void
40 fetchSelfEndorseCertificate(const ndn::Name& identity);
41
42 void
Yingdi Yu8dacdf22013-11-05 23:06:43 -080043 fetchKey(const ndn::Name& identity);
44
45 void
46 fetchCollectEndorse(const ndn::Name& identity);
47
48 void
Yingdi Yu908f8412013-11-09 00:03:26 -080049 fetchIdCertificate(const ndn::Name& certName);
50
51 void
Yingdi Yuaa8d7692013-10-18 17:05:02 -070052 updateProfileData(const ndn::Name& identity);
53
Yingdi Yu8dacdf22013-11-05 23:06:43 -080054 void
55 updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
56
Yingdi Yu64206112013-12-24 11:16:32 +080057 void
58 getContactItemList(std::vector<ndn::ptr_lib::shared_ptr<ContactItem> >& contacts);
Yingdi Yu79c25a22013-10-21 13:38:38 -070059
Yingdi Yu64206112013-12-24 11:16:32 +080060 ndn::ptr_lib::shared_ptr<ContactStorage>
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070061 getContactStorage()
62 { return m_contactStorage; }
63
Yingdi Yu64206112013-12-24 11:16:32 +080064 ndn::ptr_lib::shared_ptr<ContactItem>
Yingdi Yud40226b2013-10-23 14:05:12 -070065 getContact(const ndn::Name& contactNamespace);
66
Yingdi Yu64206112013-12-24 11:16:32 +080067 ndn::ptr_lib::shared_ptr<DnsStorage>
Yingdi Yuaa8d7692013-10-18 17:05:02 -070068 getDnsStorage()
69 { return m_dnsStorage; }
70
Yingdi Yu64206112013-12-24 11:16:32 +080071 ndn::Name
Yingdi Yuaa8d7692013-10-18 17:05:02 -070072 getDefaultIdentity()
Yingdi Yuc9ffa9f2014-01-13 11:19:47 -080073 { return m_keyChain->getDefaultIdentity(); }
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070074
Yingdi Yu8dacdf22013-11-05 23:06:43 -080075 void
76 publishEndorsedDataInDns(const ndn::Name& identity);
77
Yingdi Yu64206112013-12-24 11:16:32 +080078 void
Yingdi Yu908f8412013-11-09 00:03:26 -080079 setDefaultIdentity(const ndn::Name& identity)
80 { m_defaultIdentity = identity; }
81
82 void
Yingdi Yu64206112013-12-24 11:16:32 +080083 addContact(const ndn::IdentityCertificate& idCert, const Profile& profile);
Yingdi Yu908f8412013-11-09 00:03:26 -080084
Yingdi Yu6ea54e42013-11-12 17:50:21 -080085 void
86 removeContact(const ndn::Name& contactNameSpace);
87
Yingdi Yuc9ffa9f2014-01-13 11:19:47 -080088 // ndn::ptr_lib::shared_ptr<ndn::KeyChain>
89 // getKeyChain()
90 // { return m_keyChain; }
Yingdi Yu6ea54e42013-11-12 17:50:21 -080091
Yingdi Yuc9ffa9f2014-01-13 11:19:47 -080092private:
Yingdi Yu64206112013-12-24 11:16:32 +080093 void
94 initializeSecurity();
95
96 ndn::ptr_lib::shared_ptr<EndorseCertificate>
Yingdi Yuaa8d7692013-10-18 17:05:02 -070097 getSignedSelfEndorseCertificate(const ndn::Name& identity, const Profile& profile);
98
Yingdi Yu64206112013-12-24 11:16:32 +080099 ndn::ptr_lib::shared_ptr<EndorseCertificate>
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800100 generateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
101
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700102 void
Yingdi Yu64206112013-12-24 11:16:32 +0800103 publishSelfEndorseCertificateInDNS(const EndorseCertificate& selfEndorseCertificate);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700104
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800105 void
Yingdi Yu64206112013-12-24 11:16:32 +0800106 publishEndorseCertificateInDNS(const EndorseCertificate& endorseCertificate, const ndn::Name& signerIdentity);
107
108 void
109 sendInterest(const ndn::Interest& interest,
110 const ndn::OnVerified& onVerified,
111 const ndn::OnVerifyFailed& onVerifyFailed,
112 const TimeoutNotify& timeoutNotify,
Yingdi Yu7630f642014-01-16 19:13:03 -0800113 int retry = 1);
Yingdi Yu64206112013-12-24 11:16:32 +0800114
115 void
116 onTargetData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
117 const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
Yingdi Yu64206112013-12-24 11:16:32 +0800118 const ndn::OnVerified& onVerified,
Yingdi Yu7630f642014-01-16 19:13:03 -0800119 const ndn::OnVerifyFailed& onVerifyFailed);
Yingdi Yu64206112013-12-24 11:16:32 +0800120
121 void
122 onTargetTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
123 int retry,
Yingdi Yu64206112013-12-24 11:16:32 +0800124 const ndn::OnVerified& onVerified,
125 const ndn::OnVerifyFailed& onVerifyFailed,
126 const TimeoutNotify& timeoutNotify);
127
128
129 void
Yingdi Yu64206112013-12-24 11:16:32 +0800130 onDnsSelfEndorseCertificateTimeoutNotify(const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800131
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700132 void
Yingdi Yu64206112013-12-24 11:16:32 +0800133 onDnsSelfEndorseCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700134
135 void
Yingdi Yu64206112013-12-24 11:16:32 +0800136 onDnsSelfEndorseCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& selfEndorseCertificate, const ndn::Name& identity);
137
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700138
139 void
Yingdi Yu64206112013-12-24 11:16:32 +0800140 onDnsCollectEndorseVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700141
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800142 void
Yingdi Yu64206112013-12-24 11:16:32 +0800143 onDnsCollectEndorseVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800144
145 void
Yingdi Yu64206112013-12-24 11:16:32 +0800146 onDnsCollectEndorseTimeoutNotify(const ndn::Name& identity);
147
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800148
149 void
Yingdi Yu64206112013-12-24 11:16:32 +0800150 onKeyVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800151
152 void
Yingdi Yu64206112013-12-24 11:16:32 +0800153 onKeyVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800154
155 void
Yingdi Yu64206112013-12-24 11:16:32 +0800156 onKeyTimeoutNotify(const ndn::Name& identity);
157
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800158
159 void
Yingdi Yu64206112013-12-24 11:16:32 +0800160 onIdCertificateVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800161
Yingdi Yu908f8412013-11-09 00:03:26 -0800162 void
Yingdi Yu64206112013-12-24 11:16:32 +0800163 onIdCertificateVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data, const ndn::Name& identity);
Yingdi Yu908f8412013-11-09 00:03:26 -0800164
165 void
Yingdi Yu64206112013-12-24 11:16:32 +0800166 onIdCertificateTimeoutNotify(const ndn::Name& identity);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800167
168
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700169signals:
Yingdi Yub29f78c2013-11-09 20:12:31 -0800170 void
171 noNdnConnection(const QString& msg);
172
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700173 void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700174 contactFetched(const EndorseCertificate& endorseCertificate);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700175
176 void
177 contactFetchFailed(const ndn::Name& identity);
178
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800179 void
180 contactKeyFetched(const EndorseCertificate& endorseCertificate);
181
182 void
183 contactKeyFetchFailed(const ndn::Name& identity);
184
185 void
Yingdi Yu64206112013-12-24 11:16:32 +0800186 contactCertificateFetched(const ndn::IdentityCertificate& identityCertificate);
Yingdi Yu908f8412013-11-09 00:03:26 -0800187
188 void
189 contactCertificateFetchFailed(const ndn::Name& identity);
190
191 void
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800192 collectEndorseFetched(const ndn::Data& data);
193
194 void
195 collectEndorseFetchFailed(const ndn::Name& identity);
196
Yingdi Yu908f8412013-11-09 00:03:26 -0800197 void
198 warning(QString msg);
199
Yingdi Yu6ea54e42013-11-12 17:50:21 -0800200 void
201 contactRemoved(const ndn::Name& identity);
202
203 void
204 contactAdded(const ndn::Name& identity);
205
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700206private slots:
207
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700208
209private:
Yingdi Yueaa84e22014-01-16 10:30:26 -0800210
Yingdi Yu64206112013-12-24 11:16:32 +0800211 ndn::ptr_lib::shared_ptr<ContactStorage> m_contactStorage;
212 ndn::ptr_lib::shared_ptr<DnsStorage> m_dnsStorage;
Yingdi Yu7630f642014-01-16 19:13:03 -0800213 ndn::ptr_lib::shared_ptr<ndn::Verifier> m_verifier;
Yingdi Yuc9ffa9f2014-01-13 11:19:47 -0800214 ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
Yingdi Yu64206112013-12-24 11:16:32 +0800215 ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
Yingdi Yu908f8412013-11-09 00:03:26 -0800216 ndn::Name m_defaultIdentity;
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700217};
218
219#endif