blob: 6de23d44db0b6a81e1ab23eeacddbbfddf34b573 [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 Yu590fa5d2013-10-18 18:35:09 -070021#include <ndn.cxx/wrapper/wrapper.h>
Yingdi Yuaa8d7692013-10-18 17:05:02 -070022#endif
23
24
25class ContactManager : public QObject
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070026{
Yingdi Yuaa8d7692013-10-18 17:05:02 -070027 Q_OBJECT
28
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070029public:
Yingdi Yub29f78c2013-11-09 20:12:31 -080030 ContactManager(QObject* parent = 0);
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070031
32 ~ContactManager();
33
Yingdi Yuaa8d7692013-10-18 17:05:02 -070034 void
Yingdi Yub29f78c2013-11-09 20:12:31 -080035 setWrapper();
36
37 void
Yingdi Yuaa8d7692013-10-18 17:05:02 -070038 fetchSelfEndorseCertificate(const ndn::Name& identity);
39
40 void
Yingdi Yu8dacdf22013-11-05 23:06:43 -080041 fetchKey(const ndn::Name& identity);
42
43 void
44 fetchCollectEndorse(const ndn::Name& identity);
45
46 void
Yingdi Yu908f8412013-11-09 00:03:26 -080047 fetchIdCertificate(const ndn::Name& certName);
48
49 void
Yingdi Yuaa8d7692013-10-18 17:05:02 -070050 updateProfileData(const ndn::Name& identity);
51
Yingdi Yu8dacdf22013-11-05 23:06:43 -080052 void
53 updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
54
Yingdi Yu79c25a22013-10-21 13:38:38 -070055 std::vector<ndn::Ptr<ContactItem> >
56 getContactItemList();
57
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070058 inline ndn::Ptr<ContactStorage>
59 getContactStorage()
60 { return m_contactStorage; }
61
Yingdi Yud40226b2013-10-23 14:05:12 -070062 ndn::Ptr<ContactItem>
63 getContact(const ndn::Name& contactNamespace);
64
Yingdi Yuaa8d7692013-10-18 17:05:02 -070065 inline ndn::Ptr<DnsStorage>
66 getDnsStorage()
67 { return m_dnsStorage; }
68
69 inline ndn::Name
70 getDefaultIdentity()
71 { return m_keychain->getDefaultIdentity(); }
72
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070073 inline ndn::Ptr<ndn::Wrapper>
74 getWrapper()
75 { return m_wrapper; }
76
Yingdi Yu8dacdf22013-11-05 23:06:43 -080077 void
78 publishEndorsedDataInDns(const ndn::Name& identity);
79
Yingdi Yu908f8412013-11-09 00:03:26 -080080 inline void
81 setDefaultIdentity(const ndn::Name& identity)
82 { m_defaultIdentity = identity; }
83
84 void
85 addContact(const ndn::security::IdentityCertificate& idCert, const Profile& profile);
86
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070087private:
Yingdi Yuaa8d7692013-10-18 17:05:02 -070088 void
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070089 setKeychain();
Yingdi Yuaa8d7692013-10-18 17:05:02 -070090
91 ndn::Ptr<EndorseCertificate>
92 getSignedSelfEndorseCertificate(const ndn::Name& identity, const Profile& profile);
93
Yingdi Yu8dacdf22013-11-05 23:06:43 -080094 ndn::Ptr<EndorseCertificate>
95 generateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
96
Yingdi Yuaa8d7692013-10-18 17:05:02 -070097 void
98 publishSelfEndorseCertificateInDNS(ndn::Ptr<EndorseCertificate> selfEndorseCertificate);
99
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800100 void
101 publishEndorseCertificateInDNS(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& signerIdentity);
102
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700103 void
104 onDnsSelfEndorseCertificateVerified(ndn::Ptr<ndn::Data> selfEndorseCertificate, const ndn::Name& identity);
105
106 void
107 onDnsSelfEndorseCertificateUnverified(ndn::Ptr<ndn::Data> selfEndorseCertificate, const ndn::Name& identity);
108
109 void
110 onDnsSelfEndorseCertificateTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
111
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800112 void
113 onKeyVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
114
115 void
116 onKeyUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
117
118 void
119 onKeyTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
120
121 void
122 onDnsCollectEndorseVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
123
124 void
125 onDnsCollectEndorseTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
126
127 void
128 onDnsCollectEndorseUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
129
Yingdi Yu908f8412013-11-09 00:03:26 -0800130 void
131 onIdCertificateVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
132
133 void
134 onIdCertificateUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
135
136 void
137 onIdCertificateTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800138
139
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700140signals:
Yingdi Yub29f78c2013-11-09 20:12:31 -0800141 void
142 noNdnConnection(const QString& msg);
143
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700144 void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700145 contactFetched(const EndorseCertificate& endorseCertificate);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700146
147 void
148 contactFetchFailed(const ndn::Name& identity);
149
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800150 void
151 contactKeyFetched(const EndorseCertificate& endorseCertificate);
152
153 void
154 contactKeyFetchFailed(const ndn::Name& identity);
155
156 void
Yingdi Yu908f8412013-11-09 00:03:26 -0800157 contactCertificateFetched(const ndn::security::IdentityCertificate& identityCertificate);
158
159 void
160 contactCertificateFetchFailed(const ndn::Name& identity);
161
162 void
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800163 collectEndorseFetched(const ndn::Data& data);
164
165 void
166 collectEndorseFetchFailed(const ndn::Name& identity);
167
Yingdi Yu908f8412013-11-09 00:03:26 -0800168 void
169 warning(QString msg);
170
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700171private slots:
172
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700173
174private:
175 ndn::Ptr<ContactStorage> m_contactStorage;
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700176 ndn::Ptr<DnsStorage> m_dnsStorage;
177 ndn::Ptr<ndn::security::Keychain> m_keychain;
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700178 ndn::Ptr<ndn::Wrapper> m_wrapper;
Yingdi Yu908f8412013-11-09 00:03:26 -0800179 ndn::Name m_defaultIdentity;
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700180};
181
182#endif