blob: a19135f363ca3a8171aabb8bec4b15195e8889e7 [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 Yu6ea54e42013-11-12 17:50:21 -080087 void
88 removeContact(const ndn::Name& contactNameSpace);
89
90
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070091private:
Yingdi Yuaa8d7692013-10-18 17:05:02 -070092 void
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070093 setKeychain();
Yingdi Yuaa8d7692013-10-18 17:05:02 -070094
95 ndn::Ptr<EndorseCertificate>
96 getSignedSelfEndorseCertificate(const ndn::Name& identity, const Profile& profile);
97
Yingdi Yu8dacdf22013-11-05 23:06:43 -080098 ndn::Ptr<EndorseCertificate>
99 generateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
100
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700101 void
102 publishSelfEndorseCertificateInDNS(ndn::Ptr<EndorseCertificate> selfEndorseCertificate);
103
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800104 void
105 publishEndorseCertificateInDNS(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& signerIdentity);
106
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700107 void
108 onDnsSelfEndorseCertificateVerified(ndn::Ptr<ndn::Data> selfEndorseCertificate, const ndn::Name& identity);
109
110 void
111 onDnsSelfEndorseCertificateUnverified(ndn::Ptr<ndn::Data> selfEndorseCertificate, const ndn::Name& identity);
112
113 void
114 onDnsSelfEndorseCertificateTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
115
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800116 void
117 onKeyVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
118
119 void
120 onKeyUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
121
122 void
123 onKeyTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
124
125 void
126 onDnsCollectEndorseVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
127
128 void
129 onDnsCollectEndorseTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
130
131 void
132 onDnsCollectEndorseUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
133
Yingdi Yu908f8412013-11-09 00:03:26 -0800134 void
135 onIdCertificateVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
136
137 void
138 onIdCertificateUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
139
140 void
141 onIdCertificateTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800142
143
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700144signals:
Yingdi Yub29f78c2013-11-09 20:12:31 -0800145 void
146 noNdnConnection(const QString& msg);
147
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700148 void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700149 contactFetched(const EndorseCertificate& endorseCertificate);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700150
151 void
152 contactFetchFailed(const ndn::Name& identity);
153
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800154 void
155 contactKeyFetched(const EndorseCertificate& endorseCertificate);
156
157 void
158 contactKeyFetchFailed(const ndn::Name& identity);
159
160 void
Yingdi Yu908f8412013-11-09 00:03:26 -0800161 contactCertificateFetched(const ndn::security::IdentityCertificate& identityCertificate);
162
163 void
164 contactCertificateFetchFailed(const ndn::Name& identity);
165
166 void
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800167 collectEndorseFetched(const ndn::Data& data);
168
169 void
170 collectEndorseFetchFailed(const ndn::Name& identity);
171
Yingdi Yu908f8412013-11-09 00:03:26 -0800172 void
173 warning(QString msg);
174
Yingdi Yu6ea54e42013-11-12 17:50:21 -0800175 void
176 contactRemoved(const ndn::Name& identity);
177
178 void
179 contactAdded(const ndn::Name& identity);
180
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700181private slots:
182
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700183
184private:
185 ndn::Ptr<ContactStorage> m_contactStorage;
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700186 ndn::Ptr<DnsStorage> m_dnsStorage;
187 ndn::Ptr<ndn::security::Keychain> m_keychain;
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700188 ndn::Ptr<ndn::Wrapper> m_wrapper;
Yingdi Yu908f8412013-11-09 00:03:26 -0800189 ndn::Name m_defaultIdentity;
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700190};
191
192#endif