blob: 26a2a63430d006cfd6605ed5cd8a2f040a2e47c0 [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 Yuaa8d7692013-10-18 17:05:02 -070030 ContactManager(ndn::Ptr<ContactStorage> contactStorage,
Yingdi Yu590fa5d2013-10-18 18:35:09 -070031 ndn::Ptr<DnsStorage> dnsStorage,
32 QObject* parent = 0);
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070033
34 ~ContactManager();
35
Yingdi Yuaa8d7692013-10-18 17:05:02 -070036 void
37 fetchSelfEndorseCertificate(const ndn::Name& identity);
38
39 void
Yingdi Yu8dacdf22013-11-05 23:06:43 -080040 fetchKey(const ndn::Name& identity);
41
42 void
43 fetchCollectEndorse(const ndn::Name& identity);
44
45 void
Yingdi Yu908f8412013-11-09 00:03:26 -080046 fetchIdCertificate(const ndn::Name& certName);
47
48 void
Yingdi Yuaa8d7692013-10-18 17:05:02 -070049 updateProfileData(const ndn::Name& identity);
50
Yingdi Yu8dacdf22013-11-05 23:06:43 -080051 void
52 updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
53
Yingdi Yu79c25a22013-10-21 13:38:38 -070054 std::vector<ndn::Ptr<ContactItem> >
55 getContactItemList();
56
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070057 inline ndn::Ptr<ContactStorage>
58 getContactStorage()
59 { return m_contactStorage; }
60
Yingdi Yud40226b2013-10-23 14:05:12 -070061 ndn::Ptr<ContactItem>
62 getContact(const ndn::Name& contactNamespace);
63
Yingdi Yuaa8d7692013-10-18 17:05:02 -070064 inline ndn::Ptr<DnsStorage>
65 getDnsStorage()
66 { return m_dnsStorage; }
67
68 inline ndn::Name
69 getDefaultIdentity()
70 { return m_keychain->getDefaultIdentity(); }
71
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070072 inline ndn::Ptr<ndn::Wrapper>
73 getWrapper()
74 { return m_wrapper; }
75
Yingdi Yu8dacdf22013-11-05 23:06:43 -080076 void
77 publishEndorsedDataInDns(const ndn::Name& identity);
78
Yingdi Yu908f8412013-11-09 00:03:26 -080079 inline void
80 setDefaultIdentity(const ndn::Name& identity)
81 { m_defaultIdentity = identity; }
82
83 void
84 addContact(const ndn::security::IdentityCertificate& idCert, const Profile& profile);
85
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070086private:
Yingdi Yuaa8d7692013-10-18 17:05:02 -070087 void
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070088 setKeychain();
Yingdi Yuaa8d7692013-10-18 17:05:02 -070089
90 ndn::Ptr<EndorseCertificate>
91 getSignedSelfEndorseCertificate(const ndn::Name& identity, const Profile& profile);
92
Yingdi Yu8dacdf22013-11-05 23:06:43 -080093 ndn::Ptr<EndorseCertificate>
94 generateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
95
Yingdi Yuaa8d7692013-10-18 17:05:02 -070096 void
97 publishSelfEndorseCertificateInDNS(ndn::Ptr<EndorseCertificate> selfEndorseCertificate);
98
Yingdi Yu8dacdf22013-11-05 23:06:43 -080099 void
100 publishEndorseCertificateInDNS(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& signerIdentity);
101
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700102 void
103 onDnsSelfEndorseCertificateVerified(ndn::Ptr<ndn::Data> selfEndorseCertificate, const ndn::Name& identity);
104
105 void
106 onDnsSelfEndorseCertificateUnverified(ndn::Ptr<ndn::Data> selfEndorseCertificate, const ndn::Name& identity);
107
108 void
109 onDnsSelfEndorseCertificateTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
110
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800111 void
112 onKeyVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
113
114 void
115 onKeyUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
116
117 void
118 onKeyTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
119
120 void
121 onDnsCollectEndorseVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
122
123 void
124 onDnsCollectEndorseTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
125
126 void
127 onDnsCollectEndorseUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
128
Yingdi Yu908f8412013-11-09 00:03:26 -0800129 void
130 onIdCertificateVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
131
132 void
133 onIdCertificateUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
134
135 void
136 onIdCertificateTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800137
138
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700139signals:
140 void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700141 contactFetched(const EndorseCertificate& endorseCertificate);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700142
143 void
144 contactFetchFailed(const ndn::Name& identity);
145
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800146 void
147 contactKeyFetched(const EndorseCertificate& endorseCertificate);
148
149 void
150 contactKeyFetchFailed(const ndn::Name& identity);
151
152 void
Yingdi Yu908f8412013-11-09 00:03:26 -0800153 contactCertificateFetched(const ndn::security::IdentityCertificate& identityCertificate);
154
155 void
156 contactCertificateFetchFailed(const ndn::Name& identity);
157
158 void
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800159 collectEndorseFetched(const ndn::Data& data);
160
161 void
162 collectEndorseFetchFailed(const ndn::Name& identity);
163
Yingdi Yu908f8412013-11-09 00:03:26 -0800164 void
165 warning(QString msg);
166
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700167private slots:
168
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700169
170private:
171 ndn::Ptr<ContactStorage> m_contactStorage;
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700172 ndn::Ptr<DnsStorage> m_dnsStorage;
173 ndn::Ptr<ndn::security::Keychain> m_keychain;
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700174 ndn::Ptr<ndn::Wrapper> m_wrapper;
Yingdi Yu908f8412013-11-09 00:03:26 -0800175 ndn::Name m_defaultIdentity;
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700176};
177
178#endif