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