Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 11 | #include "contactpanel.h" |
| 12 | #include "ui_contactpanel.h" |
| 13 | |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 14 | |
| 15 | #include <QStringList> |
| 16 | #include <QItemSelectionModel> |
| 17 | #include <QModelIndex> |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 18 | #include <QDir> |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 19 | #include <QtSql/QSqlRecord> |
| 20 | #include <QtSql/QSqlField> |
| 21 | #include <QtSql/QSqlError> |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 22 | |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 23 | #ifndef Q_MOC_RUN |
Yingdi Yu | 6df6125 | 2014-01-21 11:05:11 -0800 | [diff] [blame^] | 24 | #include <ndn-cpp-dev/security/verifier.hpp> |
| 25 | #include <ndn-cpp-dev/security/signature-sha256-with-rsa.hpp> |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 26 | #include <boost/filesystem.hpp> |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 27 | #include <boost/random/random_device.hpp> |
| 28 | #include <boost/random/uniform_int_distribution.hpp> |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 29 | #include "logging.h" |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 30 | #endif |
| 31 | |
| 32 | namespace fs = boost::filesystem; |
| 33 | using namespace ndn; |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 34 | using namespace ndn::ptr_lib; |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 35 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 36 | using namespace std; |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 37 | |
| 38 | INIT_LOGGER("ContactPanel"); |
| 39 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 40 | Q_DECLARE_METATYPE(ndn::IdentityCertificate) |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 41 | Q_DECLARE_METATYPE(ChronosInvitation) |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 42 | |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 43 | ContactPanel::ContactPanel(QWidget *parent) |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 44 | : QDialog(parent) |
| 45 | , ui(new Ui::ContactPanel) |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 46 | , m_warningDialog(new WarningDialog) |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 47 | , m_contactListModel(new QStringListModel) |
| 48 | , m_startChatDialog(new StartChatDialog) |
| 49 | , m_invitationDialog(new InvitationDialog) |
| 50 | , m_settingDialog(new SettingDialog) |
Yingdi Yu | eaa84e2 | 2014-01-16 10:30:26 -0800 | [diff] [blame] | 51 | , m_policy(new SecPolicyChronoChatPanel()) |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 52 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 53 | qRegisterMetaType<IdentityCertificate>("IdentityCertificate"); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 54 | qRegisterMetaType<ChronosInvitation>("ChronosInvitation"); |
Yingdi Yu | accbda9 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 55 | |
| 56 | startFace(); |
| 57 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 58 | createAction(); |
| 59 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 60 | m_keyChain = make_shared<KeyChain>(); |
Yingdi Yu | 7630f64 | 2014-01-16 19:13:03 -0800 | [diff] [blame] | 61 | m_verifier = make_shared<Verifier>(m_policy); |
| 62 | m_verifier->setFace(m_face); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 63 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 64 | m_contactManager = make_shared<ContactManager>(m_keyChain, m_face); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 65 | |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 66 | connect(&*m_contactManager, SIGNAL(noNdnConnection(const QString&)), |
| 67 | this, SLOT(showError(const QString&))); |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 68 | |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 69 | openDB(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 70 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 71 | refreshContactList(); |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 72 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 73 | loadTrustAnchor(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 74 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 75 | m_defaultIdentity = m_keyChain->getDefaultIdentity(); |
Yingdi Yu | 1043689 | 2013-11-10 16:26:52 -0800 | [diff] [blame] | 76 | if(m_defaultIdentity.size() == 0) |
| 77 | showError(QString::fromStdString("certificate of ") + QString::fromStdString(m_defaultIdentity.toUri()) + " is missing!\nHave you installed the certificate?"); |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 78 | Name defaultCertName = m_keyChain->getDefaultCertificateNameForIdentity(m_defaultIdentity); |
Yingdi Yu | 71ec965 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 79 | if(defaultCertName.size() == 0) |
Yingdi Yu | cf1bdcb | 2013-11-10 10:54:16 -0800 | [diff] [blame] | 80 | showError(QString::fromStdString("certificate of ") + QString::fromStdString(m_defaultIdentity.toUri()) + " is missing!\nHave you installed the certificate?"); |
Yingdi Yu | 1043689 | 2013-11-10 16:26:52 -0800 | [diff] [blame] | 81 | |
| 82 | |
| 83 | m_contactManager->setDefaultIdentity(m_defaultIdentity); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 84 | m_nickName = m_defaultIdentity.get(-1).toEscapedString(); |
Yingdi Yu | 1043689 | 2013-11-10 16:26:52 -0800 | [diff] [blame] | 85 | m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName); |
Yingdi Yu | 71ec965 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 86 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 87 | |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 88 | m_profileEditor = new ProfileEditor(m_contactManager); |
| 89 | m_profileEditor->setCurrentIdentity(m_defaultIdentity); |
| 90 | |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 91 | m_addContactPanel = new AddContactPanel(m_contactManager); |
| 92 | m_browseContactDialog = new BrowseContactDialog(m_contactManager); |
| 93 | m_setAliasDialog = new SetAliasDialog(m_contactManager); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 94 | |
| 95 | ui->setupUi(this); |
| 96 | |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 97 | |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 98 | m_localPrefix = Name("/private/local"); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 99 | setLocalPrefix(); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 100 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 101 | setInvitationListener(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 102 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 103 | collectEndorsement(); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 104 | |
| 105 | ui->ContactList->setModel(m_contactListModel); |
| 106 | |
Yingdi Yu | c26af3c | 2013-10-17 17:03:46 -0700 | [diff] [blame] | 107 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 108 | connect(ui->ContactList->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 109 | this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &))); |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 110 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 111 | connect(ui->ContactList, SIGNAL(customContextMenuRequested(const QPoint&)), |
| 112 | this, SLOT(showContextMenu(const QPoint&))); |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 113 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 114 | connect(ui->EditProfileButton, SIGNAL(clicked()), |
| 115 | this, SLOT(openProfileEditor())); |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 116 | |
Yingdi Yu | 71ec965 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 117 | connect(m_profileEditor, SIGNAL(noKeyOrCert(const QString&)), |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 118 | this, SLOT(showWarning(const QString&))); |
Yingdi Yu | 71ec965 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 119 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 120 | connect(ui->AddContactButton, SIGNAL(clicked()), |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 121 | this, SLOT(openBrowseContactDialog())); |
| 122 | |
Yingdi Yu | 3cd30df | 2013-11-10 17:59:58 -0800 | [diff] [blame] | 123 | connect(m_browseContactDialog, SIGNAL(directAddClicked()), |
| 124 | this, SLOT(openAddContactPanel())); |
| 125 | |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 126 | connect(this, SIGNAL(refreshCertDirectory()), |
| 127 | m_browseContactDialog, SLOT(refreshList())); |
| 128 | |
| 129 | connect(ui->DeleteContactButton, SIGNAL(clicked()), |
| 130 | this, SLOT(removeContactButton())); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 131 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 132 | connect(ui->settingButton, SIGNAL(clicked()), |
| 133 | this, SLOT(openSettingDialog())); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 134 | |
Yingdi Yu | 3cd30df | 2013-11-10 17:59:58 -0800 | [diff] [blame] | 135 | connect(m_addContactPanel, SIGNAL(newContactAdded()), |
| 136 | this, SLOT(refreshContactList())); |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 137 | connect(m_browseContactDialog, SIGNAL(newContactAdded()), |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 138 | this, SLOT(refreshContactList())); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 139 | connect(m_setAliasDialog, SIGNAL(aliasChanged()), |
| 140 | this, SLOT(refreshContactList())); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 141 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 142 | connect(m_startChatDialog, SIGNAL(chatroomConfirmed(const QString&, const QString&, bool)), |
| 143 | this, SLOT(startChatroom(const QString&, const QString&, bool))); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 144 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 145 | connect(m_invitationDialog, SIGNAL(invitationAccepted(const ChronosInvitation&, const ndn::IdentityCertificate&)), |
| 146 | this, SLOT(acceptInvitation(const ChronosInvitation&, const ndn::IdentityCertificate&))); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 147 | connect(m_invitationDialog, SIGNAL(invitationRejected(const ChronosInvitation&)), |
| 148 | this, SLOT(rejectInvitation(const ChronosInvitation&))); |
Yingdi Yu | 6ea54e4 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 149 | |
| 150 | connect(&*m_contactManager, SIGNAL(contactAdded(const ndn::Name&)), |
| 151 | this, SLOT(addContactIntoPanelPolicy(const ndn::Name&))); |
| 152 | connect(&*m_contactManager, SIGNAL(contactRemoved(const ndn::Name&)), |
| 153 | this, SLOT(removeContactFromPanelPolicy(const ndn::Name&))); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 154 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 155 | connect(m_settingDialog, SIGNAL(identitySet(const QString&, const QString&)), |
| 156 | this, SLOT(updateDefaultIdentity(const QString&, const QString&))); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 157 | |
| 158 | connect(this, SIGNAL(newInvitationReady()), |
| 159 | this, SLOT(openInvitationDialog())); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 160 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 161 | connect(ui->isIntroducer, SIGNAL(stateChanged(int)), |
| 162 | this, SLOT(isIntroducerChanged(int))); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 163 | |
| 164 | connect(ui->addScope, SIGNAL(clicked()), |
| 165 | this, SLOT(addScopeClicked())); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 166 | connect(ui->deleteScope, SIGNAL(clicked()), |
| 167 | this, SLOT(deleteScopeClicked())); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 168 | connect(ui->saveButton, SIGNAL(clicked()), |
| 169 | this, SLOT(saveScopeClicked())); |
| 170 | |
| 171 | connect(ui->endorseButton, SIGNAL(clicked()), |
| 172 | this, SLOT(endorseButtonClicked())); |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | ContactPanel::~ContactPanel() |
| 176 | { |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 177 | delete ui; |
| 178 | delete m_contactListModel; |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 179 | delete m_startChatDialog; |
| 180 | delete m_invitationDialog; |
| 181 | delete m_settingDialog; |
| 182 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 183 | delete m_profileEditor; |
| 184 | delete m_addContactPanel; |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 185 | delete m_browseContactDialog; |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 186 | delete m_setAliasDialog; |
| 187 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 188 | delete m_trustScopeModel; |
| 189 | delete m_endorseDataModel; |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 190 | delete m_endorseComboBoxDelegate; |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 191 | |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 192 | delete m_menuInvite; |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 193 | delete m_menuAlias; |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 194 | |
| 195 | map<Name, ChatDialog*>::iterator it = m_chatDialogs.begin(); |
| 196 | for(; it != m_chatDialogs.end(); it++) |
| 197 | delete it->second; |
Yingdi Yu | accbda9 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 198 | |
| 199 | shutdownFace(); |
| 200 | } |
| 201 | |
| 202 | void |
| 203 | ContactPanel::startFace() |
| 204 | { |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 205 | m_face = make_shared<Face>(); |
Yingdi Yu | accbda9 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 206 | |
| 207 | connectToDaemon(); |
| 208 | |
| 209 | m_running = true; |
| 210 | m_thread = boost::thread (&ContactPanel::eventLoop, this); |
| 211 | } |
| 212 | |
| 213 | void |
| 214 | ContactPanel::shutdownFace() |
| 215 | { |
| 216 | { |
| 217 | boost::unique_lock<boost::recursive_mutex> lock(m_mutex); |
| 218 | m_running = false; |
| 219 | } |
| 220 | |
| 221 | m_thread.join(); |
| 222 | m_face->shutdown(); |
| 223 | } |
| 224 | |
| 225 | void |
| 226 | ContactPanel::eventLoop() |
| 227 | { |
| 228 | while (m_running) |
| 229 | { |
| 230 | try{ |
| 231 | m_face->processEvents(); |
| 232 | usleep(100); |
| 233 | }catch(std::exception& e){ |
| 234 | _LOG_DEBUG(" " << e.what() ); |
| 235 | } |
| 236 | } |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 237 | } |
Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 238 | |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 239 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 240 | ContactPanel::connectToDaemon() |
| 241 | { |
| 242 | //Hack! transport does not connect to daemon unless an interest is expressed. |
| 243 | Name name("/ndn"); |
| 244 | ndn::Interest interest(name); |
| 245 | m_face->expressInterest(interest, |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 246 | func_lib::bind(&ContactPanel::onConnectionData, this, _1, _2), |
| 247 | func_lib::bind(&ContactPanel::onConnectionDataTimeout, this, _1)); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void |
| 251 | ContactPanel::onConnectionData(const shared_ptr<const ndn::Interest>& interest, |
| 252 | const shared_ptr<Data>& data) |
| 253 | { _LOG_DEBUG("onConnectionData"); } |
| 254 | |
| 255 | void |
| 256 | ContactPanel::onConnectionDataTimeout(const shared_ptr<const ndn::Interest>& interest) |
| 257 | { _LOG_DEBUG("onConnectionDataTimeout"); } |
| 258 | |
| 259 | void |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 260 | ContactPanel::createAction() |
| 261 | { |
| 262 | m_menuInvite = new QAction("&Chat", this); |
| 263 | m_menuAlias = new QAction("&Set Alias", this); |
| 264 | } |
| 265 | |
| 266 | void |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 267 | ContactPanel::openDB() |
| 268 | { |
| 269 | QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); |
| 270 | QString path = (QDir::home().path()); |
| 271 | path.append(QDir::separator()).append(".chronos").append(QDir::separator()).append("chronos.db"); |
| 272 | db.setDatabaseName(path); |
| 273 | bool ok = db.open(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 274 | _LOG_DEBUG("DB opened: " << std::boolalpha << ok ); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 275 | |
| 276 | m_trustScopeModel = new QSqlTableModel; |
| 277 | m_endorseDataModel = new QSqlTableModel; |
| 278 | m_endorseComboBoxDelegate = new EndorseComboBoxDelegate; |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 282 | ContactPanel::loadTrustAnchor() |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 283 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 284 | vector<shared_ptr<ContactItem> >::const_iterator it = m_contactList.begin(); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 285 | for(; it != m_contactList.end(); it++) |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 286 | { |
Yingdi Yu | accbda9 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 287 | _LOG_DEBUG("load contact: " << (*it)->getNameSpace().toUri()); |
Yingdi Yu | eaa84e2 | 2014-01-16 10:30:26 -0800 | [diff] [blame] | 288 | m_policy->addTrustAnchor((*it)->getSelfEndorseCertificate()); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 289 | } |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | void |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 293 | ContactPanel::setLocalPrefix(int retry) |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 294 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 295 | Name interestName("/local/ndn/prefix"); |
| 296 | Interest interest(interestName); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 297 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 298 | m_face->expressInterest(interest, |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 299 | func_lib::bind(&ContactPanel::onLocalPrefix, this, _1, _2), |
| 300 | func_lib::bind(&ContactPanel::onLocalPrefixTimeout, this, _1, 10)); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 301 | |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 305 | ContactPanel::onLocalPrefix(const shared_ptr<const Interest>& interest, |
| 306 | const shared_ptr<Data>& data) |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 307 | { |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 308 | string originPrefix((const char*)data->getContent().value(), data->getContent().value_size()); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 309 | string prefix = QString::fromStdString (originPrefix).trimmed ().toUtf8().constData(); |
| 310 | string randomSuffix = getRandomString(); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 311 | m_localPrefix = Name(prefix); |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 312 | |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 316 | ContactPanel::onLocalPrefixTimeout(const shared_ptr<const Interest>& interest, |
| 317 | int retry) |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 318 | { |
Yingdi Yu | 2ab22e7 | 2013-11-10 01:38:21 -0800 | [diff] [blame] | 319 | if(retry > 0) |
Yingdi Yu | 0a953c3 | 2013-11-10 10:32:18 -0800 | [diff] [blame] | 320 | { |
| 321 | setLocalPrefix(retry - 1); |
| 322 | return; |
| 323 | } |
| 324 | else{ |
| 325 | m_localPrefix = Name("/private/local"); |
| 326 | } |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 327 | } |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 328 | |
| 329 | void |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 330 | ContactPanel::setInvitationListener() |
| 331 | { |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 332 | m_inviteListenPrefix = Name("/ndn/broadcast/chronos/invitation"); |
| 333 | m_inviteListenPrefix.append(m_defaultIdentity); |
| 334 | _LOG_DEBUG("Listening for invitation on prefix: " << m_inviteListenPrefix.toUri()); |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 335 | m_invitationListenerId = m_face->setInterestFilter(m_inviteListenPrefix, |
| 336 | func_lib::bind(&ContactPanel::onInvitation, this, _1, _2, _3, _4), |
| 337 | func_lib::bind(&ContactPanel::onInvitationRegisterFailed, this, _1)); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 341 | ContactPanel::sendInterest(const Interest& interest, |
| 342 | const OnVerified& onVerified, |
| 343 | const OnVerifyFailed& onVerifyFailed, |
| 344 | const TimeoutNotify& timeoutNotify, |
Yingdi Yu | 7630f64 | 2014-01-16 19:13:03 -0800 | [diff] [blame] | 345 | int retry /* = 1 */) |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 346 | { |
| 347 | m_face->expressInterest(interest, |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 348 | func_lib::bind(&ContactPanel::onTargetData, |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 349 | this, |
| 350 | _1, |
| 351 | _2, |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 352 | onVerified, |
Yingdi Yu | 7630f64 | 2014-01-16 19:13:03 -0800 | [diff] [blame] | 353 | onVerifyFailed), |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 354 | func_lib::bind(&ContactPanel::onTargetTimeout, |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 355 | this, |
| 356 | _1, |
| 357 | retry, |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 358 | onVerified, |
| 359 | onVerifyFailed, |
| 360 | timeoutNotify)); |
| 361 | } |
| 362 | |
| 363 | void |
| 364 | ContactPanel::onTargetData(const shared_ptr<const ndn::Interest>& interest, |
| 365 | const shared_ptr<Data>& data, |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 366 | const OnVerified& onVerified, |
Yingdi Yu | 7630f64 | 2014-01-16 19:13:03 -0800 | [diff] [blame] | 367 | const OnVerifyFailed& onVerifyFailed) |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 368 | { |
Yingdi Yu | 7630f64 | 2014-01-16 19:13:03 -0800 | [diff] [blame] | 369 | m_verifier->verifyData(data, onVerified, onVerifyFailed); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | void |
| 373 | ContactPanel::onTargetTimeout(const shared_ptr<const ndn::Interest>& interest, |
| 374 | int retry, |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 375 | const OnVerified& onVerified, |
| 376 | const OnVerifyFailed& onVerifyFailed, |
| 377 | const TimeoutNotify& timeoutNotify) |
| 378 | { |
| 379 | if(retry > 0) |
Yingdi Yu | 7630f64 | 2014-01-16 19:13:03 -0800 | [diff] [blame] | 380 | sendInterest(*interest, onVerified, onVerifyFailed, timeoutNotify, retry-1); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 381 | else |
| 382 | { |
| 383 | _LOG_DEBUG("Interest: " << interest->getName().toUri() << " eventually times out!"); |
| 384 | timeoutNotify(); |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 389 | ContactPanel::onInvitationRegisterFailed(const shared_ptr<const Name>& prefix) |
| 390 | { |
| 391 | showError(QString::fromStdString("Cannot register invitation listening prefix")); |
| 392 | } |
| 393 | |
| 394 | void |
| 395 | ContactPanel::onInvitation(const shared_ptr<const Name>& prefix, |
| 396 | const shared_ptr<const Interest>& interest, |
| 397 | Transport& transport, |
| 398 | uint64_t registeredPrefixId) |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 399 | { |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 400 | _LOG_DEBUG("Receive invitation!" << interest->getName().toUri()); |
Yingdi Yu | accbda9 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 401 | |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 402 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 403 | shared_ptr<ChronosInvitation> invitation; |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 404 | try{ |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 405 | invitation = make_shared<ChronosInvitation>(interest->getName()); |
| 406 | }catch(std::exception& e){ |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 407 | _LOG_ERROR("Exception: " << e.what()); |
| 408 | return; |
| 409 | } |
| 410 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 411 | Name chatroomName("/ndn/broadcast/chronos"); |
| 412 | chatroomName.append(invitation->getChatroom()); |
| 413 | map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName); |
| 414 | if(it != m_chatDialogs.end()) |
| 415 | { |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 416 | _LOG_ERROR("Exisiting chatroom!"); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 417 | return; |
| 418 | } |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 419 | |
Yingdi Yu | 6df6125 | 2014-01-21 11:05:11 -0800 | [diff] [blame^] | 420 | const SignatureSha256WithRsa& invitationSig = invitation->getSignature(); |
Yingdi Yu | eaa84e2 | 2014-01-16 10:30:26 -0800 | [diff] [blame] | 421 | shared_ptr<PublicKey> keyPtr = m_policy->getTrustedKey(invitation->getInviterCertificateName()); |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 422 | |
Yingdi Yu | eaa84e2 | 2014-01-16 10:30:26 -0800 | [diff] [blame] | 423 | if(static_cast<bool>(keyPtr) && Verifier::verifySignature(invitation->getSignedBlob(), invitationSig, *keyPtr)) |
Yingdi Yu | 6b56f09 | 2013-11-10 11:54:02 -0800 | [diff] [blame] | 424 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 425 | shared_ptr<IdentityCertificate> certificate = make_shared<IdentityCertificate>(); |
Yingdi Yu | 6df6125 | 2014-01-21 11:05:11 -0800 | [diff] [blame^] | 426 | // hack: incomplete certificate, we don't send it to the wire nor store it anywhere, we only use it to pass information |
Yingdi Yu | 6b56f09 | 2013-11-10 11:54:02 -0800 | [diff] [blame] | 427 | certificate->setName(invitation->getInviterCertificateName()); |
Yingdi Yu | 9f65724 | 2013-11-10 12:25:43 -0800 | [diff] [blame] | 428 | bool findCert = false; |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 429 | vector<shared_ptr<ContactItem> >::const_iterator it = m_contactList.begin(); |
Yingdi Yu | 9f65724 | 2013-11-10 12:25:43 -0800 | [diff] [blame] | 430 | for(; it != m_contactList.end(); it++) |
| 431 | { |
| 432 | if((*it)->getNameSpace() == invitation->getInviterNameSpace()) |
| 433 | { |
| 434 | certificate->setNotBefore((*it)->getSelfEndorseCertificate().getNotBefore()); |
| 435 | certificate->setNotAfter((*it)->getSelfEndorseCertificate().getNotAfter()); |
| 436 | findCert = true; |
| 437 | break; |
| 438 | } |
| 439 | } |
| 440 | if(findCert == false) |
| 441 | { |
| 442 | _LOG_ERROR("No SelfEndorseCertificate found!"); |
| 443 | return; |
| 444 | } |
Yingdi Yu | 6b56f09 | 2013-11-10 11:54:02 -0800 | [diff] [blame] | 445 | certificate->setPublicKeyInfo(*keyPtr); |
| 446 | popChatInvitation(invitation, invitation->getInviterNameSpace(), certificate); |
| 447 | return; |
| 448 | } |
| 449 | |
Yingdi Yu | accbda9 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 450 | _LOG_DEBUG("Cannot find the inviter's key in trust anchors"); |
| 451 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 452 | Interest newInterest(invitation->getInviterCertificateName()); |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 453 | OnVerified onVerified = func_lib::bind(&ContactPanel::onInvitationCertVerified, this, _1, invitation); |
| 454 | OnVerifyFailed onVerifyFailed = func_lib::bind(&ContactPanel::onInvitationCertVerifyFailed, this, _1); |
| 455 | TimeoutNotify timeoutNotify = func_lib::bind(&ContactPanel::onInvitationCertTimeoutNotify, this); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 456 | |
| 457 | sendInterest(newInterest, onVerified, onVerifyFailed, timeoutNotify); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 461 | ContactPanel::onInvitationCertVerified(const shared_ptr<Data>& data, |
| 462 | shared_ptr<ChronosInvitation> invitation) |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 463 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 464 | shared_ptr<IdentityCertificate> certificate = make_shared<IdentityCertificate>(*data); |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 465 | |
Yingdi Yu | 6df6125 | 2014-01-21 11:05:11 -0800 | [diff] [blame^] | 466 | SignatureSha256WithRsa invitationSig(invitation->getSignature()); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 467 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 468 | if(Verifier::verifySignature(invitation->getSignedBlob(), invitationSig, certificate->getPublicKeyInfo())) |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 469 | { |
| 470 | Name keyName = certificate->getPublicKeyName(); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 471 | Name inviterNameSpace = keyName.getPrefix(-1); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 472 | popChatInvitation(invitation, inviterNameSpace, certificate); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 477 | ContactPanel::onInvitationCertVerifyFailed(const shared_ptr<Data>& data) |
| 478 | { _LOG_DEBUG("Cannot verify invitation certificate!"); } |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 479 | |
| 480 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 481 | ContactPanel::onInvitationCertTimeoutNotify() |
| 482 | { _LOG_DEBUG("interest for invitation certificate times out eventually!"); } |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 483 | |
| 484 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 485 | ContactPanel::popChatInvitation(shared_ptr<ChronosInvitation> invitation, |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 486 | const Name& inviterNameSpace, |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 487 | shared_ptr<IdentityCertificate> certificate) |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 488 | { |
| 489 | string alias; |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 490 | vector<shared_ptr<ContactItem> >::iterator it = m_contactList.begin(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 491 | for(; it != m_contactList.end(); it++) |
| 492 | if((*it)->getNameSpace() == inviterNameSpace) |
| 493 | alias = (*it)->getAlias(); |
| 494 | |
| 495 | if(it != m_contactList.end()) |
| 496 | return; |
| 497 | |
| 498 | m_invitationDialog->setInvitation(alias, invitation, certificate); |
| 499 | emit newInvitationReady(); |
| 500 | } |
| 501 | |
| 502 | void |
| 503 | ContactPanel::collectEndorsement() |
| 504 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 505 | m_collectStatus = make_shared<vector<bool> >(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 506 | m_collectStatus->assign(m_contactList.size(), false); |
| 507 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 508 | vector<shared_ptr<ContactItem> >::iterator it = m_contactList.begin(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 509 | int count = 0; |
| 510 | for(; it != m_contactList.end(); it++, count++) |
| 511 | { |
| 512 | Name interestName = (*it)->getNameSpace(); |
| 513 | interestName.append("DNS").append(m_defaultIdentity).append("ENDORSEE"); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 514 | Interest interest(interestName); |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 515 | interest.setInterestLifetime(1000); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 516 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 517 | OnVerified onVerified = func_lib::bind(&ContactPanel::onDnsEndorseeVerified, this, _1, count); |
| 518 | OnVerifyFailed onVerifyFailed = func_lib::bind(&ContactPanel::onDnsEndorseeVerifyFailed, this, _1, count); |
| 519 | TimeoutNotify timeoutNotify = func_lib::bind(&ContactPanel::onDnsEndorseeTimeoutNotify, this, count); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 520 | |
| 521 | sendInterest(interest, onVerified, onVerifyFailed, timeoutNotify, 0); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | |
| 525 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 526 | ContactPanel::onDnsEndorseeVerified(const shared_ptr<Data>& data, int count) |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 527 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 528 | Data endorseData; |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 529 | endorseData.wireDecode(Block(data->getContent().value(), data->getContent().value_size())); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 530 | EndorseCertificate endorseCertificate(endorseData); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 531 | |
| 532 | m_contactManager->getContactStorage()->updateCollectEndorse(endorseCertificate); |
| 533 | |
| 534 | updateCollectStatus(count); |
| 535 | } |
| 536 | |
| 537 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 538 | ContactPanel::onDnsEndorseeTimeoutNotify(int count) |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 539 | { updateCollectStatus(count); } |
| 540 | |
| 541 | void |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 542 | ContactPanel::onDnsEndorseeVerifyFailed(const shared_ptr<Data>& data, int count) |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 543 | { updateCollectStatus(count); } |
| 544 | |
| 545 | void |
| 546 | ContactPanel::updateCollectStatus(int count) |
| 547 | { |
| 548 | m_collectStatus->at(count) = true; |
| 549 | vector<bool>::const_iterator it = m_collectStatus->begin(); |
| 550 | for(; it != m_collectStatus->end(); it++) |
| 551 | if(*it == false) |
| 552 | return; |
| 553 | |
| 554 | m_contactManager->publishEndorsedDataInDns(m_defaultIdentity); |
| 555 | } |
| 556 | |
| 557 | static std::string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789"); |
| 558 | |
| 559 | string |
| 560 | ContactPanel::getRandomString() |
| 561 | { |
| 562 | string randStr; |
| 563 | boost::random::random_device rng; |
| 564 | boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1); |
| 565 | for (int i = 0; i < 10; i ++) |
| 566 | { |
| 567 | randStr += chars[index_dist(rng)]; |
| 568 | } |
| 569 | return randStr; |
| 570 | } |
| 571 | |
| 572 | void |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 573 | ContactPanel::showError(const QString& msg){ |
| 574 | QMessageBox::critical(this, tr("Chronos"), msg, QMessageBox::Ok); |
| 575 | exit(1); |
| 576 | } |
| 577 | |
| 578 | void |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 579 | ContactPanel::showWarning(const QString& msg){ |
| 580 | QMessageBox::information(this, tr("Chronos"), msg); |
| 581 | } |
| 582 | |
| 583 | void |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 584 | ContactPanel::updateSelection(const QItemSelection &selected, |
| 585 | const QItemSelection &deselected) |
| 586 | { |
| 587 | QModelIndexList items = selected.indexes(); |
| 588 | QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString(); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 589 | string alias = text.toStdString(); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 590 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 591 | int i = 0; |
| 592 | for(; i < m_contactList.size(); i++) |
| 593 | { |
| 594 | if(alias == m_contactList[i]->getAlias()) |
| 595 | break; |
| 596 | } |
| 597 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 598 | m_currentSelectedContact = m_contactList[i]; |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 599 | ui->NameData->setText(QString::fromStdString(m_currentSelectedContact->getName())); |
| 600 | ui->NameSpaceData->setText(QString::fromStdString(m_currentSelectedContact->getNameSpace().toUri())); |
| 601 | ui->InstitutionData->setText(QString::fromStdString(m_currentSelectedContact->getInstitution())); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 602 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 603 | if(m_currentSelectedContact->isIntroducer()) |
| 604 | { |
| 605 | ui->isIntroducer->setChecked(true); |
| 606 | ui->addScope->setEnabled(true); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 607 | ui->deleteScope->setEnabled(true); |
| 608 | ui->trustScopeList->setEnabled(true); |
| 609 | |
| 610 | string filter("contact_namespace = '"); |
| 611 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 612 | |
| 613 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 614 | m_trustScopeModel->setTable("TrustScope"); |
| 615 | m_trustScopeModel->setFilter(filter.c_str()); |
| 616 | m_trustScopeModel->select(); |
| 617 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 618 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 619 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
| 620 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 621 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 622 | ui->trustScopeList->setColumnHidden(0, true); |
| 623 | ui->trustScopeList->setColumnHidden(1, true); |
| 624 | ui->trustScopeList->show(); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 625 | } |
| 626 | else |
| 627 | { |
| 628 | ui->isIntroducer->setChecked(false); |
| 629 | ui->addScope->setEnabled(false); |
| 630 | ui->deleteScope->setEnabled(false); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 631 | |
| 632 | string filter("contact_namespace = '"); |
| 633 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 634 | |
| 635 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 636 | m_trustScopeModel->setTable("TrustScope"); |
| 637 | m_trustScopeModel->setFilter(filter.c_str()); |
| 638 | m_trustScopeModel->select(); |
| 639 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 640 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 641 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
| 642 | |
| 643 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 644 | ui->trustScopeList->setColumnHidden(0, true); |
| 645 | ui->trustScopeList->setColumnHidden(1, true); |
| 646 | ui->trustScopeList->show(); |
| 647 | |
| 648 | ui->trustScopeList->setEnabled(false); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 649 | } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 650 | |
| 651 | string filter("profile_identity = '"); |
| 652 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 653 | |
| 654 | m_endorseDataModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 655 | m_endorseDataModel->setTable("ContactProfile"); |
| 656 | m_endorseDataModel->setFilter(filter.c_str()); |
| 657 | m_endorseDataModel->select(); |
| 658 | |
| 659 | m_endorseDataModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Identity")); |
| 660 | m_endorseDataModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Type")); |
| 661 | m_endorseDataModel->setHeaderData(2, Qt::Horizontal, QObject::tr("Value")); |
| 662 | m_endorseDataModel->setHeaderData(3, Qt::Horizontal, QObject::tr("Endorse")); |
| 663 | |
| 664 | ui->endorseList->setModel(m_endorseDataModel); |
| 665 | ui->endorseList->setColumnHidden(0, true); |
| 666 | ui->endorseList->resizeColumnToContents(1); |
| 667 | ui->endorseList->resizeColumnToContents(2); |
| 668 | ui->endorseList->setItemDelegateForColumn(3, m_endorseComboBoxDelegate); |
| 669 | ui->endorseList->show(); |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 670 | } |
Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 671 | |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 672 | void |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 673 | ContactPanel::updateDefaultIdentity(const QString& identity, const QString& nickName) |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 674 | { |
Yingdi Yu | 71ec965 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 675 | // _LOG_DEBUG(identity.toStdString()); |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 676 | Name defaultIdentity = Name(identity.toStdString()); |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 677 | Name defaultCertName = m_keyChain->getDefaultCertificateNameForIdentity(defaultIdentity); |
Yingdi Yu | 71ec965 | 2013-11-09 22:18:26 -0800 | [diff] [blame] | 678 | if(defaultCertName.size() == 0) |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 679 | { |
| 680 | showWarning(QString::fromStdString("Corresponding certificate is missing!\nHave you installed the certificate?")); |
| 681 | return; |
| 682 | } |
| 683 | m_defaultIdentity = defaultIdentity; |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 684 | m_profileEditor->setCurrentIdentity(m_defaultIdentity); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 685 | m_nickName = nickName.toStdString(); |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 686 | m_face->unsetInterestFilter(m_invitationListenerId); |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 687 | m_contactManager->setDefaultIdentity(m_defaultIdentity); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 688 | setInvitationListener(); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 689 | collectEndorsement(); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 690 | } |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 691 | |
| 692 | void |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 693 | ContactPanel::openProfileEditor() |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 694 | { m_profileEditor->show(); } |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 695 | |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 696 | void |
| 697 | ContactPanel::openAddContactPanel() |
| 698 | { m_addContactPanel->show(); } |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 699 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 700 | void |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 701 | ContactPanel::openBrowseContactDialog() |
| 702 | { |
| 703 | m_browseContactDialog->show(); |
| 704 | emit refreshCertDirectory(); |
| 705 | } |
| 706 | |
| 707 | void |
| 708 | ContactPanel::removeContactButton() |
| 709 | { |
| 710 | QItemSelectionModel* selectionModel = ui->ContactList->selectionModel(); |
| 711 | QModelIndexList selectedList = selectionModel->selectedIndexes(); |
| 712 | QModelIndexList::iterator it = selectedList.begin(); |
| 713 | for(; it != selectedList.end(); it++) |
| 714 | { |
| 715 | string alias = m_contactListModel->data(*it, Qt::DisplayRole).toString().toStdString(); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 716 | vector<shared_ptr<ContactItem> >::iterator contactIt = m_contactList.begin(); |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 717 | for(; contactIt != m_contactList.end(); contactIt++) |
| 718 | { |
| 719 | if((*contactIt)->getAlias() == alias) |
| 720 | { |
| 721 | m_contactManager->getContactStorage()->removeContact((*contactIt)->getNameSpace()); |
| 722 | m_contactList.erase(contactIt); |
| 723 | break; |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | refreshContactList(); |
| 728 | } |
| 729 | |
| 730 | void |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 731 | ContactPanel::openInvitationDialog() |
| 732 | { m_invitationDialog->show(); } |
| 733 | |
| 734 | void |
Yingdi Yu | 6ea54e4 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 735 | ContactPanel::addContactIntoPanelPolicy(const Name& contactNameSpace) |
| 736 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 737 | shared_ptr<ContactItem> contact = m_contactManager->getContact(contactNameSpace); |
Yingdi Yu | eaa84e2 | 2014-01-16 10:30:26 -0800 | [diff] [blame] | 738 | if(static_cast<bool>(contact)) |
| 739 | m_policy->addTrustAnchor(contact->getSelfEndorseCertificate()); |
Yingdi Yu | 6ea54e4 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | void |
| 743 | ContactPanel::removeContactFromPanelPolicy(const Name& keyName) |
Yingdi Yu | eaa84e2 | 2014-01-16 10:30:26 -0800 | [diff] [blame] | 744 | { m_policy->removeTrustAnchor(keyName); } |
Yingdi Yu | 6ea54e4 | 2013-11-12 17:50:21 -0800 | [diff] [blame] | 745 | |
| 746 | void |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 747 | ContactPanel::refreshContactList() |
| 748 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 749 | m_contactList.clear(); |
| 750 | m_contactManager->getContactItemList(m_contactList); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 751 | QStringList contactNameList; |
| 752 | for(int i = 0; i < m_contactList.size(); i++) |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 753 | contactNameList << QString::fromStdString(m_contactList[i]->getAlias()); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 754 | |
| 755 | m_contactListModel->setStringList(contactNameList); |
| 756 | } |
| 757 | |
| 758 | void |
| 759 | ContactPanel::showContextMenu(const QPoint& pos) |
| 760 | { |
| 761 | QMenu menu(ui->ContactList); |
| 762 | menu.addAction(m_menuInvite); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 763 | connect(m_menuInvite, SIGNAL(triggered()), |
| 764 | this, SLOT(openStartChatDialog())); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 765 | menu.addSeparator(); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 766 | menu.addAction(m_menuAlias); |
| 767 | connect(m_menuAlias, SIGNAL(triggered()), |
| 768 | this, SLOT(openSetAliasDialog())); |
| 769 | menu.exec(ui->ContactList->mapToGlobal(pos)); |
| 770 | |
| 771 | } |
| 772 | |
| 773 | void |
| 774 | ContactPanel::openSetAliasDialog() |
| 775 | { |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 776 | m_setAliasDialog->setTargetIdentity(m_currentSelectedContact->getNameSpace().toUri()); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 777 | m_setAliasDialog->show(); |
| 778 | } |
| 779 | |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 780 | void |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 781 | ContactPanel::openSettingDialog() |
| 782 | { |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 783 | m_settingDialog->setIdentity(m_defaultIdentity.toUri(), m_nickName); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 784 | m_settingDialog->show(); |
| 785 | } |
| 786 | |
| 787 | void |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 788 | ContactPanel::openStartChatDialog() |
| 789 | { |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 790 | Name chatroom("/ndn/broadcast/chronos"); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 791 | chatroom.append(string("chatroom-") + getRandomString()); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 792 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 793 | m_startChatDialog->setInvitee(m_currentSelectedContact->getNameSpace().toUri(), chatroom.toUri()); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 794 | m_startChatDialog->show(); |
| 795 | } |
| 796 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 797 | // For inviter |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 798 | void |
| 799 | ContactPanel::startChatroom(const QString& chatroom, const QString& invitee, bool isIntroducer) |
| 800 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 801 | Name chatroomName(chatroom.toStdString()); |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 802 | |
| 803 | Name inviteeNamespace(invitee.toStdString()); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 804 | shared_ptr<ContactItem> inviteeItem = m_contactManager->getContact(inviteeNamespace); |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 805 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 806 | ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 807 | m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog)); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 808 | |
| 809 | connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)), |
| 810 | this, SLOT(removeChatDialog(const ndn::Name&))); |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 811 | connect(chatDialog, SIGNAL(noNdnConnection(const QString&)), |
| 812 | this, SLOT(showError(const QString&))); |
Yingdi Yu | 3e87bd8 | 2013-11-10 10:47:44 -0800 | [diff] [blame] | 813 | connect(chatDialog, SIGNAL(inivationRejection(const QString&)), |
| 814 | this, SLOT(showWarning(const QString&))); |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 815 | |
Yingdi Yu | c90deb1 | 2013-11-06 18:51:19 -0800 | [diff] [blame] | 816 | // send invitation |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 817 | chatDialog->sendInvitation(inviteeItem, isIntroducer); |
Yingdi Yu | c4d08d2 | 2013-10-23 23:07:29 -0700 | [diff] [blame] | 818 | |
| 819 | chatDialog->show(); |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 822 | // For Invitee |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 823 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 824 | ContactPanel::startChatroom2(const ChronosInvitation& invitation, |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 825 | const IdentityCertificate& identityCertificate) |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 826 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 827 | shared_ptr<ContactItem> inviterItem = m_contactManager->getContact(invitation.getInviterNameSpace()); |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 828 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 829 | Name chatroomName("/ndn/broadcast/chronos"); |
| 830 | chatroomName.append(invitation.getChatroom()); |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 831 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 832 | ChatDialog* chatDialog = new ChatDialog(m_contactManager, chatroomName, m_localPrefix, m_defaultIdentity, m_nickName, true); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 833 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 834 | connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)), |
| 835 | this, SLOT(removeChatDialog(const ndn::Name&))); |
Yingdi Yu | b29f78c | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 836 | connect(chatDialog, SIGNAL(noNdnConnection(const QString&)), |
| 837 | this, SLOT(showError(const QString&))); |
Yingdi Yu | 3e87bd8 | 2013-11-10 10:47:44 -0800 | [diff] [blame] | 838 | connect(chatDialog, SIGNAL(inivationRejection(const QString&)), |
| 839 | this, SLOT(showWarning(const QString&))); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 840 | |
Yingdi Yu | 6df6125 | 2014-01-21 11:05:11 -0800 | [diff] [blame^] | 841 | chatDialog->addChatDataRule(invitation.getInviterRoutingPrefix(), identityCertificate, true); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 842 | chatDialog->publishIntroCert(identityCertificate, true); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 843 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 844 | chatDialog->addTrustAnchor(inviterItem->getSelfEndorseCertificate()); |
| 845 | |
| 846 | m_chatDialogs.insert(pair <Name, ChatDialog*> (chatroomName, chatDialog)); |
| 847 | |
| 848 | chatDialog->show(); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 852 | ContactPanel::acceptInvitation(const ChronosInvitation& invitation, |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 853 | const IdentityCertificate& identityCertificate) |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 854 | { |
Yingdi Yu | accbda9 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 855 | Name dataName = invitation.getInterestName(); |
| 856 | time_t nowSeconds = time(NULL); |
| 857 | struct tm current = *gmtime(&nowSeconds); |
| 858 | MillisecondsSince1970 version = timegm(¤t) * 1000.0; |
| 859 | dataName.appendVersion(version); |
| 860 | Data data(dataName); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 861 | string content = m_localPrefix.toUri(); |
| 862 | data.setContent((const uint8_t *)&content[0], content.size()); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 863 | |
| 864 | Name certificateName; |
Yingdi Yu | eaa84e2 | 2014-01-16 10:30:26 -0800 | [diff] [blame] | 865 | Name inferredIdentity = m_policy->inferSigningIdentity(data.getName()); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 866 | |
| 867 | if(inferredIdentity.getComponentCount() == 0) |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 868 | certificateName = m_keyChain->getDefaultCertificateName(); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 869 | else |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 870 | certificateName = m_keyChain->getDefaultCertificateNameForIdentity(inferredIdentity); |
| 871 | m_keyChain->sign(data, certificateName); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 872 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 873 | m_face->put(data); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 874 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 875 | startChatroom2(invitation, identityCertificate); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | void |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 879 | ContactPanel::rejectInvitation(const ChronosInvitation& invitation) |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 880 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 881 | Data data(invitation.getInterestName()); |
| 882 | string content("nack"); |
| 883 | data.setContent((const uint8_t *)&content[0], content.size()); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 884 | |
| 885 | Name certificateName; |
Yingdi Yu | eaa84e2 | 2014-01-16 10:30:26 -0800 | [diff] [blame] | 886 | Name inferredIdentity = m_policy->inferSigningIdentity(data.getName()); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 887 | if(inferredIdentity.getComponentCount() == 0) |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 888 | certificateName = m_keyChain->getDefaultCertificateName(); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 889 | else |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 890 | certificateName = m_keyChain->getDefaultCertificateNameForIdentity(inferredIdentity); |
| 891 | m_keyChain->sign(data, certificateName); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 892 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 893 | m_face->put(data); |
Yingdi Yu | 53eb8a7 | 2013-10-23 11:50:51 -0700 | [diff] [blame] | 894 | } |
| 895 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 896 | void |
| 897 | ContactPanel::isIntroducerChanged(int state) |
| 898 | { |
| 899 | if(state == Qt::Checked) |
| 900 | { |
| 901 | ui->addScope->setEnabled(true); |
| 902 | ui->deleteScope->setEnabled(true); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 903 | ui->trustScopeList->setEnabled(true); |
| 904 | |
| 905 | string filter("contact_namespace = '"); |
| 906 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 907 | |
| 908 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 909 | m_trustScopeModel->setTable("TrustScope"); |
| 910 | m_trustScopeModel->setFilter(filter.c_str()); |
| 911 | m_trustScopeModel->select(); |
| 912 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 913 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 914 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 915 | |
| 916 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 917 | ui->trustScopeList->setColumnHidden(0, true); |
| 918 | ui->trustScopeList->setColumnHidden(1, true); |
| 919 | ui->trustScopeList->show(); |
| 920 | |
| 921 | m_currentSelectedContact->setIsIntroducer(true); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 922 | } |
| 923 | else |
| 924 | { |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 925 | ui->addScope->setEnabled(false); |
| 926 | ui->deleteScope->setEnabled(false); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 927 | |
| 928 | string filter("contact_namespace = '"); |
| 929 | filter.append(m_currentSelectedContact->getNameSpace().toUri()).append("'"); |
| 930 | |
| 931 | m_trustScopeModel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
| 932 | m_trustScopeModel->setTable("TrustScope"); |
| 933 | m_trustScopeModel->setFilter(filter.c_str()); |
| 934 | m_trustScopeModel->select(); |
| 935 | m_trustScopeModel->setHeaderData(0, Qt::Horizontal, QObject::tr("ID")); |
| 936 | m_trustScopeModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Contact")); |
| 937 | m_trustScopeModel->setHeaderData(2, Qt::Horizontal, QObject::tr("TrustScope")); |
| 938 | |
| 939 | ui->trustScopeList->setModel(m_trustScopeModel); |
| 940 | ui->trustScopeList->setColumnHidden(0, true); |
| 941 | ui->trustScopeList->setColumnHidden(1, true); |
| 942 | ui->trustScopeList->show(); |
| 943 | |
| 944 | ui->trustScopeList->setEnabled(false); |
| 945 | |
| 946 | m_currentSelectedContact->setIsIntroducer(false); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 947 | } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 948 | m_contactManager->getContactStorage()->updateIsIntroducer(m_currentSelectedContact->getNameSpace(), m_currentSelectedContact->isIntroducer()); |
| 949 | } |
| 950 | |
| 951 | void |
| 952 | ContactPanel::addScopeClicked() |
| 953 | { |
| 954 | int rowCount = m_trustScopeModel->rowCount(); |
| 955 | QSqlRecord record; |
| 956 | QSqlField identityField("contact_namespace", QVariant::String); |
| 957 | record.append(identityField); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 958 | record.setValue("contact_namespace", QString::fromStdString(m_currentSelectedContact->getNameSpace().toUri())); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 959 | m_trustScopeModel->insertRow(rowCount); |
| 960 | m_trustScopeModel->setRecord(rowCount, record); |
| 961 | } |
| 962 | |
| 963 | void |
| 964 | ContactPanel::deleteScopeClicked() |
| 965 | { |
| 966 | QItemSelectionModel* selectionModel = ui->trustScopeList->selectionModel(); |
| 967 | QModelIndexList indexList = selectionModel->selectedIndexes(); |
| 968 | |
| 969 | int i = indexList.size() - 1; |
| 970 | for(; i >= 0; i--) |
| 971 | m_trustScopeModel->removeRow(indexList[i].row()); |
| 972 | |
| 973 | m_trustScopeModel->submitAll(); |
| 974 | } |
| 975 | |
| 976 | void |
| 977 | ContactPanel::saveScopeClicked() |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 978 | { m_trustScopeModel->submitAll(); } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 979 | |
| 980 | void |
| 981 | ContactPanel::endorseButtonClicked() |
| 982 | { |
| 983 | m_endorseDataModel->submitAll(); |
| 984 | m_contactManager->updateEndorseCertificate(m_currentSelectedContact->getNameSpace(), m_defaultIdentity); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 985 | } |
Yingdi Yu | 100267f | 2013-10-21 15:01:40 -0700 | [diff] [blame] | 986 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 987 | void |
| 988 | ContactPanel::removeChatDialog(const ndn::Name& chatroomName) |
| 989 | { |
| 990 | map<Name, ChatDialog*>::iterator it = m_chatDialogs.find(chatroomName); |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 991 | |
| 992 | ChatDialog* deletedChat = NULL; |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 993 | if(it != m_chatDialogs.end()) |
| 994 | { |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 995 | deletedChat = it->second; |
| 996 | m_chatDialogs.erase(it); |
| 997 | } |
Yingdi Yu | a059409 | 2013-11-06 22:07:38 -0800 | [diff] [blame] | 998 | if (deletedChat != NULL) |
| 999 | delete deletedChat; |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 1000 | } |
| 1001 | |
Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 1002 | #if WAF |
| 1003 | #include "contactpanel.moc" |
| 1004 | #include "contactpanel.cpp.moc" |
| 1005 | #endif |