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