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