blob: b8498ccc88136bf50412f1e5271a032fecb62e9d [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 Yuaa8d7692013-10-18 17:05:02 -070046 updateProfileData(const ndn::Name& identity);
47
Yingdi Yu8dacdf22013-11-05 23:06:43 -080048 void
49 updateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
50
Yingdi Yu79c25a22013-10-21 13:38:38 -070051 std::vector<ndn::Ptr<ContactItem> >
52 getContactItemList();
53
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070054 inline ndn::Ptr<ContactStorage>
55 getContactStorage()
56 { return m_contactStorage; }
57
Yingdi Yud40226b2013-10-23 14:05:12 -070058 ndn::Ptr<ContactItem>
59 getContact(const ndn::Name& contactNamespace);
60
Yingdi Yuaa8d7692013-10-18 17:05:02 -070061 inline ndn::Ptr<DnsStorage>
62 getDnsStorage()
63 { return m_dnsStorage; }
64
65 inline ndn::Name
66 getDefaultIdentity()
67 { return m_keychain->getDefaultIdentity(); }
68
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070069 inline ndn::Ptr<ndn::Wrapper>
70 getWrapper()
71 { return m_wrapper; }
72
Yingdi Yu8dacdf22013-11-05 23:06:43 -080073 void
74 publishEndorsedDataInDns(const ndn::Name& identity);
75
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070076private:
Yingdi Yuaa8d7692013-10-18 17:05:02 -070077 void
Yingdi Yu0b82a4e2013-10-18 11:29:25 -070078 setKeychain();
Yingdi Yuaa8d7692013-10-18 17:05:02 -070079
80 ndn::Ptr<EndorseCertificate>
81 getSignedSelfEndorseCertificate(const ndn::Name& identity, const Profile& profile);
82
Yingdi Yu8dacdf22013-11-05 23:06:43 -080083 ndn::Ptr<EndorseCertificate>
84 generateEndorseCertificate(const ndn::Name& identity, const ndn::Name& signerIdentity);
85
Yingdi Yuaa8d7692013-10-18 17:05:02 -070086 void
87 publishSelfEndorseCertificateInDNS(ndn::Ptr<EndorseCertificate> selfEndorseCertificate);
88
Yingdi Yu8dacdf22013-11-05 23:06:43 -080089 void
90 publishEndorseCertificateInDNS(ndn::Ptr<EndorseCertificate> endorseCertificate, const ndn::Name& signerIdentity);
91
Yingdi Yuaa8d7692013-10-18 17:05:02 -070092 void
93 onDnsSelfEndorseCertificateVerified(ndn::Ptr<ndn::Data> selfEndorseCertificate, const ndn::Name& identity);
94
95 void
96 onDnsSelfEndorseCertificateUnverified(ndn::Ptr<ndn::Data> selfEndorseCertificate, const ndn::Name& identity);
97
98 void
99 onDnsSelfEndorseCertificateTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
100
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800101 void
102 onKeyVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
103
104 void
105 onKeyUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
106
107 void
108 onKeyTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
109
110 void
111 onDnsCollectEndorseVerified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
112
113 void
114 onDnsCollectEndorseTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, const ndn::Name& identity, int retry);
115
116 void
117 onDnsCollectEndorseUnverified(ndn::Ptr<ndn::Data> data, const ndn::Name& identity);
118
119
120
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700121signals:
122 void
Yingdi Yu79c25a22013-10-21 13:38:38 -0700123 contactFetched(const EndorseCertificate& endorseCertificate);
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700124
125 void
126 contactFetchFailed(const ndn::Name& identity);
127
Yingdi Yu8dacdf22013-11-05 23:06:43 -0800128 void
129 contactKeyFetched(const EndorseCertificate& endorseCertificate);
130
131 void
132 contactKeyFetchFailed(const ndn::Name& identity);
133
134 void
135 collectEndorseFetched(const ndn::Data& data);
136
137 void
138 collectEndorseFetchFailed(const ndn::Name& identity);
139
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700140private slots:
141
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700142
143private:
144 ndn::Ptr<ContactStorage> m_contactStorage;
Yingdi Yuaa8d7692013-10-18 17:05:02 -0700145 ndn::Ptr<DnsStorage> m_dnsStorage;
146 ndn::Ptr<ndn::security::Keychain> m_keychain;
Yingdi Yu0b82a4e2013-10-18 11:29:25 -0700147 ndn::Ptr<ndn::Wrapper> m_wrapper;
148};
149
150#endif