bug+codestyle: Fix compile bugs and adjust code style
Change-Id: I008bb538441c099fa25b8b967fbf23ffce13a220
diff --git a/src/chat-dialog.cpp b/src/chat-dialog.cpp
index aabbcc2..407349a 100644
--- a/src/chat-dialog.cpp
+++ b/src/chat-dialog.cpp
@@ -10,7 +10,7 @@
* Yingdi Yu <yingdi@cs.ucla.edu>
*/
-#include "chat-dialog.h"
+#include "chat-dialog.hpp"
#include "ui_chat-dialog.h"
#include <QScrollBar>
@@ -22,26 +22,39 @@
#include <boost/random/random_device.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <ndn-cxx/util/random.hpp>
-#include <cryptopp/hex.h>
-#include <cryptopp/files.h>
+#include <ndn-cxx/encoding/buffer-stream.hpp>
+#include "cryptopp.hpp"
#include <queue>
#include "logging.h"
#endif
-using namespace ndn;
-using ndn::shared_ptr;
-using namespace chronos;
-INIT_LOGGER("ChatDialog");
-
-static const int HELLO_INTERVAL = FRESHNESS * 3 / 4;
-static const uint8_t CHRONOS_RP_SEPARATOR[2] = {0xF0, 0x2E}; // %F0.
+// INIT_LOGGER("ChatDialog");
Q_DECLARE_METATYPE(std::vector<Sync::MissingDataInfo> )
Q_DECLARE_METATYPE(ndn::shared_ptr<const ndn::Data>)
Q_DECLARE_METATYPE(ndn::Interest)
Q_DECLARE_METATYPE(size_t)
+
+namespace chronos {
+
+using std::vector;
+using std::string;
+using std::map;
+using std::queue;
+
+using ndn::IdentityCertificate;
+using ndn::SecRuleRelative;
+using ndn::Face;
+using ndn::OBufferStream;
+using ndn::OnDataValidated;
+using ndn::OnDataValidationFailed;
+
+
+static const int HELLO_INTERVAL = FRESHNESS * 3 / 4;
+static const uint8_t CHRONOS_RP_SEPARATOR[2] = {0xF0, 0x2E}; // %F0.
+
ChatDialog::ChatDialog(ContactManager* contactManager,
shared_ptr<Face> face,
const IdentityCertificate& myCertificate,
@@ -55,7 +68,7 @@
, m_contactManager(contactManager)
, m_face(face)
, m_myCertificate(myCertificate)
- , m_chatroomName(chatroomPrefix.get(-1).toEscapedString())
+ , m_chatroomName(chatroomPrefix.get(-1).toUri())
, m_chatroomPrefix(chatroomPrefix)
, m_localPrefix(localPrefix)
, m_useRoutablePrefix(false)
@@ -85,7 +98,8 @@
ui->trustTreeViewer->hide();
ui->listView->setModel(m_rosterModel);
- m_identity = IdentityCertificate::certificateNameToPublicKeyName(m_myCertificate.getName()).getPrefix(-1);
+ m_identity =
+ IdentityCertificate::certificateNameToPublicKeyName(m_myCertificate.getName()).getPrefix(-1);
updatePrefix();
updateLabels();
@@ -109,8 +123,12 @@
this, SLOT(onProcessData(const ndn::shared_ptr<const ndn::Data>&, bool, bool)));
connect(this, SIGNAL(processTreeUpdate(const std::vector<Sync::MissingDataInfo>)),
this, SLOT(onProcessTreeUpdate(const std::vector<Sync::MissingDataInfo>)));
- connect(this, SIGNAL(reply(const ndn::Interest&, const ndn::shared_ptr<const ndn::Data>&, size_t, bool)),
- this, SLOT(onReply(const ndn::Interest&, const ndn::shared_ptr<const ndn::Data>&, size_t, bool)));
+ connect(this, SIGNAL(reply(const ndn::Interest&,
+ const ndn::shared_ptr<const ndn::Data>&,
+ size_t, bool)),
+ this, SLOT(onReply(const ndn::Interest&,
+ const ndn::shared_ptr<const ndn::Data>&,
+ size_t, bool)));
connect(this, SIGNAL(replyTimeout(const ndn::Interest&, size_t)),
this, SLOT(onReplyTimeout(const ndn::Interest&, size_t)));
connect(this, SIGNAL(introCert(const ndn::Interest&, const ndn::shared_ptr<const ndn::Data>&)),
@@ -118,28 +136,26 @@
connect(this, SIGNAL(introCertTimeout(const ndn::Interest&, int, const QString&)),
this, SLOT(onIntroCertTimeout(const ndn::Interest&, int, const QString&)));
- if(withSecurity)
- {
+ if (withSecurity) {
+ m_invitationValidator = make_shared<chronos::ValidatorInvitation>();
+ m_dataRule = make_shared<SecRuleRelative>("([^<CHRONOCHAT-DATA>]*)<CHRONOCHAT-DATA><>",
+ "^([^<KEY>]*)<KEY>(<>*)<><ID-CERT>$",
+ "==", "\\1", "\\1", true);
- m_invitationValidator = make_shared<chronos::ValidatorInvitation>();
- m_dataRule = make_shared<SecRuleRelative>("([^<CHRONOCHAT-DATA>]*)<CHRONOCHAT-DATA><>",
- "^([^<KEY>]*)<KEY>(<>*)<><ID-CERT>$",
- "==", "\\1", "\\1", true);
+ ui->inviteButton->setEnabled(true);
+ ui->trustTreeButton->setEnabled(true);
- ui->inviteButton->setEnabled(true);
- ui->trustTreeButton->setEnabled(true);
-
- connect(ui->inviteButton, SIGNAL(clicked()),
- this, SLOT(onInviteListDialogRequested()));
- connect(m_inviteListDialog, SIGNAL(sendInvitation(const QString&)),
- this, SLOT(onSendInvitation(const QString&)));
- connect(this, SIGNAL(waitForContactList()),
- m_contactManager, SLOT(onWaitForContactList()));
- connect(m_contactManager, SIGNAL(contactAliasListReady(const QStringList&)),
- m_inviteListDialog, SLOT(onContactAliasListReady(const QStringList&)));
- connect(m_contactManager, SIGNAL(contactIdListReady(const QStringList&)),
- m_inviteListDialog, SLOT(onContactIdListReady(const QStringList&)));
- }
+ connect(ui->inviteButton, SIGNAL(clicked()),
+ this, SLOT(onInviteListDialogRequested()));
+ connect(m_inviteListDialog, SIGNAL(sendInvitation(const QString&)),
+ this, SLOT(onSendInvitation(const QString&)));
+ connect(this, SIGNAL(waitForContactList()),
+ m_contactManager, SLOT(onWaitForContactList()));
+ connect(m_contactManager, SIGNAL(contactAliasListReady(const QStringList&)),
+ m_inviteListDialog, SLOT(onContactAliasListReady(const QStringList&)));
+ connect(m_contactManager, SIGNAL(contactIdListReady(const QStringList&)),
+ m_inviteListDialog, SLOT(onContactIdListReady(const QStringList&)));
+ }
initializeSync();
}
@@ -147,46 +163,48 @@
ChatDialog::~ChatDialog()
{
- if(m_certListPrefixId)
+ if (m_certListPrefixId)
m_face->unsetInterestFilter(m_certListPrefixId);
- if(m_certSinglePrefixId)
+ if (m_certSinglePrefixId)
m_face->unsetInterestFilter(m_certSinglePrefixId);
- if(m_sock != NULL)
- {
- sendLeave();
- delete m_sock;
- m_sock = NULL;
- }
+ if (m_sock != NULL) {
+ sendLeave();
+ delete m_sock;
+ m_sock = NULL;
+ }
}
// public methods:
void
ChatDialog::addSyncAnchor(const Invitation& invitation)
{
- _LOG_DEBUG("Add sync anchor from invation");
+ // _LOG_DEBUG("Add sync anchor from invation");
// Add inviter certificate as trust anchor.
m_sock->addParticipant(invitation.getInviterCertificate());
plotTrustTree();
// Ask inviter for IntroCertificate
- Name inviterNameSpace = IdentityCertificate::certificateNameToPublicKeyName(invitation.getInviterCertificate().getName()).getPrefix(-1);
+ Name inviterNameSpace =
+ IdentityCertificate::certificateNameToPublicKeyName(
+ invitation.getInviterCertificate().getName()).getPrefix(-1);
fetchIntroCert(inviterNameSpace, invitation.getInviterRoutingPrefix());
}
void
-ChatDialog::processTreeUpdateWrapper(const std::vector<Sync::MissingDataInfo>& v, Sync::SyncSocket *sock)
+ChatDialog::processTreeUpdateWrapper(const vector<Sync::MissingDataInfo>& v,
+ Sync::SyncSocket *sock)
{
emit processTreeUpdate(v);
- _LOG_DEBUG("<<< Tree update signal emitted");
+ // _LOG_DEBUG("<<< Tree update signal emitted");
}
void
ChatDialog::processDataWrapper(const shared_ptr<const Data>& data)
{
emit processData(data, true, false);
- _LOG_DEBUG("<<< " << data->getName() << " fetched");
+ // _LOG_DEBUG("<<< " << data->getName() << " fetched");
}
void
@@ -196,9 +214,9 @@
}
void
-ChatDialog::processRemoveWrapper(std::string prefix)
+ChatDialog::processRemoveWrapper(const string& prefix)
{
- _LOG_DEBUG("Sync REMOVE signal received for prefix: " << prefix);
+ // _LOG_DEBUG("Sync REMOVE signal received for prefix: " << prefix);
}
// protected methods:
@@ -217,11 +235,9 @@
void
ChatDialog::changeEvent(QEvent *e)
{
- switch(e->type())
- {
+ switch(e->type()) {
case QEvent::ActivationChange:
- if (isActiveWindow())
- {
+ if (isActiveWindow()) {
emit resetIcon();
}
break;
@@ -250,29 +266,35 @@
m_certSinglePrefix.clear();
m_localChatPrefix.clear();
m_chatPrefix.clear();
- m_chatPrefix.append(m_identity).append("CHRONOCHAT-DATA").append(m_chatroomName).append(getRandomString());
- if(!m_localPrefix.isPrefixOf(m_identity))
- {
- m_useRoutablePrefix = true;
- m_certListPrefix.append(m_localPrefix).append(CHRONOS_RP_SEPARATOR, 2);
- m_certSinglePrefix.append(m_localPrefix).append(CHRONOS_RP_SEPARATOR, 2);
- m_localChatPrefix.append(m_localPrefix).append(CHRONOS_RP_SEPARATOR, 2);
- }
+ m_chatPrefix.append(m_identity)
+ .append("CHRONOCHAT-DATA")
+ .append(m_chatroomName)
+ .append(getRandomString());
+ if (!m_localPrefix.isPrefixOf(m_identity)) {
+ m_useRoutablePrefix = true;
+ m_certListPrefix.append(m_localPrefix).append(CHRONOS_RP_SEPARATOR, 2);
+ m_certSinglePrefix.append(m_localPrefix).append(CHRONOS_RP_SEPARATOR, 2);
+ m_localChatPrefix.append(m_localPrefix).append(CHRONOS_RP_SEPARATOR, 2);
+ }
m_certListPrefix.append(m_identity).append("CHRONOCHAT-CERT-LIST").append(m_chatroomName);
m_certSinglePrefix.append(m_identity).append("CHRONOCHAT-CERT-SINGLE").append(m_chatroomName);
m_localChatPrefix.append(m_chatPrefix);
- if(m_certListPrefixId)
+ if (m_certListPrefixId)
m_face->unsetInterestFilter(m_certListPrefixId);
- m_certListPrefixId = m_face->setInterestFilter (m_certListPrefix,
- bind(&ChatDialog::onCertListInterest, this, _1, _2),
- bind(&ChatDialog::onCertListRegisterFailed, this, _1, _2));
+ m_certListPrefixId = m_face->setInterestFilter(m_certListPrefix,
+ bind(&ChatDialog::onCertListInterest,
+ this, _1, _2),
+ bind(&ChatDialog::onCertListRegisterFailed,
+ this, _1, _2));
- if(m_certSinglePrefixId)
+ if (m_certSinglePrefixId)
m_face->unsetInterestFilter(m_certSinglePrefixId);
- m_certSinglePrefixId = m_face->setInterestFilter (m_certSinglePrefix,
- bind(&ChatDialog::onCertSingleInterest, this, _1, _2),
- bind(&ChatDialog::onCertSingleRegisterFailed, this, _1, _2));
+ m_certSinglePrefixId = m_face->setInterestFilter(m_certSinglePrefix,
+ bind(&ChatDialog::onCertSingleInterest,
+ this, _1, _2),
+ bind(&ChatDialog::onCertSingleRegisterFailed,
+ this, _1, _2));
}
void
@@ -283,19 +305,20 @@
ui->infoLabel->setText(settingDisp);
QString prefixDisp;
Name privatePrefix("/private/local");
- if(privatePrefix.isPrefixOf(m_localChatPrefix))
- {
- prefixDisp =
- QString("<Warning: no connection to hub or hub does not support prefix autoconfig.>\n <Prefix = %1>")
- .arg(QString::fromStdString(m_localChatPrefix.toUri()));
- ui->prefixLabel->setStyleSheet("QLabel {color: red; font-size: 12px; font: bold \"Verdana\";}");
- }
- else
- {
- prefixDisp = QString("<Prefix = %1>")
- .arg(QString::fromStdString(m_localChatPrefix.toUri()));
- ui->prefixLabel->setStyleSheet("QLabel {color: Green; font-size: 12px; font: bold \"Verdana\";}");
- }
+ if (privatePrefix.isPrefixOf(m_localChatPrefix)) {
+ prefixDisp =
+ QString("<Warning: no connection to hub or hub does not support prefix autoconfig.>\n"
+ "<Prefix = %1>")
+ .arg(QString::fromStdString(m_localChatPrefix.toUri()));
+ ui->prefixLabel->setStyleSheet(
+ "QLabel {color: red; font-size: 12px; font: bold \"Verdana\";}");
+ }
+ else {
+ prefixDisp = QString("<Prefix = %1>")
+ .arg(QString::fromStdString(m_localChatPrefix.toUri()));
+ ui->prefixLabel->setStyleSheet(
+ "QLabel {color: Green; font-size: 12px; font: bold \"Verdana\";}");
+ }
ui->prefixLabel->setText(prefixDisp);
}
@@ -337,28 +360,30 @@
Interest tmpInterest(invitation.getUnsignedInterestName());
m_keyChain.sign(tmpInterest, m_myCertificate.getName());
- // Get invitee's routable prefix (ideally it will do some DNS lookup, but we assume everyone use /ndn/broadcast
+ // Get invitee's routable prefix
+ // (ideally it will do some DNS lookup, but we assume everyone use /ndn/broadcast
Name routablePrefix = getInviteeRoutablePrefix(contact->getNameSpace());
// Check if we need to prepend the routable prefix to the interest name.
bool requireRoutablePrefix = false;
Name interestName;
size_t routablePrefixOffset = 0;
- if(!routablePrefix.isPrefixOf(tmpInterest.getName()))
- {
- interestName.append(routablePrefix).append(CHRONOS_RP_SEPARATOR, 2);
- requireRoutablePrefix = true;
- routablePrefixOffset = routablePrefix.size() + 1;
- }
+ if (!routablePrefix.isPrefixOf(tmpInterest.getName())) {
+ interestName.append(routablePrefix).append(CHRONOS_RP_SEPARATOR, 2);
+ requireRoutablePrefix = true;
+ routablePrefixOffset = routablePrefix.size() + 1;
+ }
interestName.append(tmpInterest.getName());
// Send the invitation out
Interest interest(interestName);
interest.setMustBeFresh(true);
- _LOG_DEBUG("sendInvitation: " << interest.getName());
+ // _LOG_DEBUG("sendInvitation: " << interest.getName());
m_face->expressInterest(interest,
- bind(&ChatDialog::replyWrapper, this, _1, _2, routablePrefixOffset, isIntroducer),
- bind(&ChatDialog::replyTimeoutWrapper, this, _1, routablePrefixOffset));
+ bind(&ChatDialog::replyWrapper,
+ this, _1, _2, routablePrefixOffset, isIntroducer),
+ bind(&ChatDialog::replyTimeoutWrapper,
+ this, _1, routablePrefixOffset));
}
void
@@ -367,16 +392,16 @@
size_t routablePrefixOffset,
bool isIntroducer)
{
- _LOG_DEBUG("ChatDialog::replyWrapper");
+ // _LOG_DEBUG("ChatDialog::replyWrapper");
emit reply(interest, data.shared_from_this(), routablePrefixOffset, isIntroducer);
- _LOG_DEBUG("OK?");
+ // _LOG_DEBUG("OK?");
}
void
ChatDialog::replyTimeoutWrapper(const Interest& interest,
size_t routablePrefixOffset)
{
- _LOG_DEBUG("ChatDialog::replyTimeoutWrapper");
+ // _LOG_DEBUG("ChatDialog::replyTimeoutWrapper");
emit replyTimeout(interest, routablePrefixOffset);
}
@@ -385,26 +410,25 @@
size_t inviteeRoutablePrefixOffset,
bool isIntroducer)
{
- if(data->getName().size() <= inviteeRoutablePrefixOffset)
- {
- Invitation invitation(data->getName());
- invitationRejected(invitation.getInviteeNameSpace());
- }
- else
- {
- Name inviteePrefix;
- inviteePrefix.wireDecode(data->getName().get(inviteeRoutablePrefixOffset).blockFromValue());
- IdentityCertificate inviteeCert;
- inviteeCert.wireDecode(data->getContent().blockFromValue());
- invitationAccepted(inviteeCert, inviteePrefix, isIntroducer);
- }
+ if (data->getName().size() <= inviteeRoutablePrefixOffset) {
+ Invitation invitation(data->getName());
+ invitationRejected(invitation.getInviteeNameSpace());
+ }
+ else {
+ Name inviteePrefix;
+ inviteePrefix.wireDecode(data->getName().get(inviteeRoutablePrefixOffset).blockFromValue());
+ IdentityCertificate inviteeCert;
+ inviteeCert.wireDecode(data->getContent().blockFromValue());
+ invitationAccepted(inviteeCert, inviteePrefix, isIntroducer);
+ }
}
void
ChatDialog::onReplyValidationFailed(const shared_ptr<const Data>& data,
- const std::string& failureInfo)
+ const string& failureInfo)
{
- _LOG_DEBUG("Invitation reply cannot be validated: " + failureInfo + " ==> " + data->getName().toUri());
+ // _LOG_DEBUG("Invitation reply cannot be validated: " + failureInfo + " ==> " +
+ // data->getName().toUri());
}
void
@@ -424,7 +448,8 @@
plotTrustTree();
// Ask invitee for IntroCertificate.
- Name inviteeNameSpace = IdentityCertificate::certificateNameToPublicKeyName(inviteeCert.getName()).getPrefix(-1);
+ Name inviteeNameSpace =
+ IdentityCertificate::certificateNameToPublicKeyName(inviteeCert.getName()).getPrefix(-1);
fetchIntroCert(inviteeNameSpace, inviteePrefix);
}
@@ -433,7 +458,7 @@
{
Name interestName;
- if(!prefix.isPrefixOf(identity))
+ if (!prefix.isPrefixOf(identity))
interestName.append(prefix).append(CHRONOS_RP_SEPARATOR, 2);
interestName.append(identity)
@@ -454,33 +479,34 @@
ChatDialog::onIntroCertList(const Interest& interest, const Data& data)
{
Chronos::IntroCertListMsg introCertList;
- if(!introCertList.ParseFromArray(data.getContent().value(), data.getContent().value_size()))
+ if (!introCertList.ParseFromArray(data.getContent().value(), data.getContent().value_size()))
return;
- for(int i = 0; i < introCertList.certname_size(); i++)
- {
- Name certName(introCertList.certname(i));
- Interest interest(certName);
- interest.setMustBeFresh(true);
+ for (int i = 0; i < introCertList.certname_size(); i++) {
+ Name certName(introCertList.certname(i));
+ Interest interest(certName);
+ interest.setMustBeFresh(true);
- _LOG_DEBUG("onIntroCertList: to fetch " << certName);
+ // _LOG_DEBUG("onIntroCertList: to fetch " << certName);
- m_face->expressInterest(interest,
- bind(&ChatDialog::introCertWrapper, this, _1, _2),
- bind(&ChatDialog::introCertTimeoutWrapper, this, _1, 0,
- QString("IntroCert: %1").arg(introCertList.certname(i).c_str())));
- }
+ m_face->expressInterest(interest,
+ bind(&ChatDialog::introCertWrapper, this, _1, _2),
+ bind(&ChatDialog::introCertTimeoutWrapper, this, _1, 0,
+ QString("IntroCert: %1").arg(introCertList.certname(i).c_str())));
+ }
}
void
-ChatDialog::onIntroCertListTimeout(const Interest& interest, int retry, const std::string& msg)
+ChatDialog::onIntroCertListTimeout(const Interest& interest, int retry, const string& msg)
{
- if(retry > 0)
+ if (retry > 0) {
m_face->expressInterest(interest,
bind(&ChatDialog::onIntroCertList, this, _1, _2),
bind(&ChatDialog::onIntroCertListTimeout, this, _1, retry - 1, msg));
- else
- _LOG_DEBUG(msg << " TIMEOUT!");
+ }
+ else {
+ // _LOG_DEBUG(msg << " TIMEOUT!");
+ }
}
void
@@ -496,21 +522,18 @@
}
void
-ChatDialog::onCertListInterest(const Name& prefix, const ndn::Interest& interest)
+ChatDialog::onCertListInterest(const Name& prefix, const Interest& interest)
{
- std::vector<Name> certNameList;
+ vector<Name> certNameList;
m_sock->getIntroCertNames(certNameList);
Chronos::IntroCertListMsg msg;
- std::vector<Name>::const_iterator it = certNameList.begin();
- std::vector<Name>::const_iterator end = certNameList.end();
- for(; it != end; it++)
- {
- Name certName;
- certName.append(m_certSinglePrefix).append(*it);
- msg.add_certname(certName.toUri());
- }
+ for (vector<Name>::const_iterator it = certNameList.begin(); it != certNameList.end(); it++) {
+ Name certName;
+ certName.append(m_certSinglePrefix).append(*it);
+ msg.add_certname(certName.toUri());
+ }
OBufferStream os;
msg.SerializeToOstream(&os);
@@ -522,33 +545,31 @@
}
void
-ChatDialog::onCertListRegisterFailed(const Name& prefix, const std::string& msg)
+ChatDialog::onCertListRegisterFailed(const Name& prefix, const string& msg)
{
- _LOG_DEBUG("ChatDialog::onCertListRegisterFailed failed: " + msg);
+ // _LOG_DEBUG("ChatDialog::onCertListRegisterFailed failed: " + msg);
}
void
-ChatDialog::onCertSingleInterest(const Name& prefix, const ndn::Interest& interest)
+ChatDialog::onCertSingleInterest(const Name& prefix, const Interest& interest)
{
- try
- {
- Name certName = interest.getName().getSubName(prefix.size());
- const Sync::IntroCertificate& introCert = m_sock->getIntroCertificate(certName);
- Data data(interest.getName());
- data.setContent(introCert.wireEncode());
- m_keyChain.sign(data, m_myCertificate.getName());
- m_face->put(data);
- }
- catch(Sync::SyncSocket::Error& e)
- {
- return;
- }
+ try {
+ Name certName = interest.getName().getSubName(prefix.size());
+ const Sync::IntroCertificate& introCert = m_sock->getIntroCertificate(certName);
+ Data data(interest.getName());
+ data.setContent(introCert.wireEncode());
+ m_keyChain.sign(data, m_myCertificate.getName());
+ m_face->put(data);
+ }
+ catch(Sync::SyncSocket::Error& e) {
+ return;
+ }
}
void
-ChatDialog::onCertSingleRegisterFailed(const Name& prefix, const std::string& msg)
+ChatDialog::onCertSingleRegisterFailed(const Name& prefix, const string& msg)
{
- _LOG_DEBUG("ChatDialog::onCertListRegisterFailed failed: " + msg);
+ // _LOG_DEBUG("ChatDialog::onCertListRegisterFailed failed: " + msg);
}
void
@@ -558,9 +579,9 @@
OBufferStream os;
msg.SerializeToOstream(&os);
- if (!msg.IsInitialized())
- {
- _LOG_DEBUG("Errrrr.. msg was not probally initialized "<<__FILE__ <<":"<<__LINE__<<". what is happening?");
+ if (!msg.IsInitialized()) {
+ // _LOG_DEBUG("Errrrr.. msg was not probally initialized " << __FILE__ <<
+ // ":" << __LINE__ << ". what is happening?");
abort();
}
uint64_t nextSequence = m_sock->getNextSeq();
@@ -568,8 +589,10 @@
m_lastMsgTime = time::toUnixTimestamp(time::system_clock::now()).count();
- Sync::MissingDataInfo mdi = {m_localChatPrefix.toUri(), Sync::SeqNo(0), Sync::SeqNo(nextSequence)};
- std::vector<Sync::MissingDataInfo> v;
+ Sync::MissingDataInfo mdi = {m_localChatPrefix.toUri(),
+ Sync::SeqNo(0),
+ Sync::SeqNo(nextSequence)};
+ vector<Sync::MissingDataInfo> v;
v.push_back(mdi);
{
boost::recursive_mutex::scoped_lock lock(m_sceneMutex);
@@ -591,21 +614,16 @@
{
boost::recursive_mutex::scoped_lock lock(m_msgMutex);
- if (msg.type() == SyncDemo::ChatMessage::CHAT)
- {
-
- if (!msg.has_data())
- {
+ if (msg.type() == SyncDemo::ChatMessage::CHAT) {
+ if (!msg.has_data()) {
return;
}
- if (msg.from().empty() || msg.data().empty())
- {
+ if (msg.from().empty() || msg.data().empty()) {
return;
}
- if (!msg.has_timestamp())
- {
+ if (!msg.has_timestamp()) {
return;
}
@@ -639,14 +657,12 @@
nextCursor.movePosition(QTextCursor::End);
table = nextCursor.insertTable(1, 1, tableFormat);
table->cellAt(0, 0).firstCursorPosition().insertText(QString::fromUtf8(msg.data().c_str()));
- if (!isHistory)
- {
+ if (!isHistory) {
showMessage(from, QString::fromUtf8(msg.data().c_str()));
}
}
- if (msg.type() == SyncDemo::ChatMessage::JOIN || msg.type() == SyncDemo::ChatMessage::LEAVE)
- {
+ if (msg.type() == SyncDemo::ChatMessage::JOIN || msg.type() == SyncDemo::ChatMessage::LEAVE) {
QTextCharFormat nickFormat;
nickFormat.setForeground(Qt::gray);
nickFormat.setFontWeight(QFont::Bold);
@@ -659,12 +675,10 @@
tableFormat.setBorder(0);
QTextTable *table = cursor.insertTable(1, 2, tableFormat);
QString action;
- if (msg.type() == SyncDemo::ChatMessage::JOIN)
- {
+ if (msg.type() == SyncDemo::ChatMessage::JOIN) {
action = "enters room";
}
- else
- {
+ else {
action = "leaves room";
}
@@ -684,11 +698,10 @@
void
ChatDialog::processRemove(QString prefix)
{
- _LOG_DEBUG("<<< remove node for prefix" << prefix.toStdString());
+ // _LOG_DEBUG("<<< remove node for prefix" << prefix.toStdString());
bool removed = m_scene->removeNode(prefix);
- if (removed)
- {
+ if (removed) {
boost::recursive_mutex::scoped_lock lock(m_sceneMutex);
m_scene->plot(m_sock->getRootDigest().c_str());
}
@@ -697,7 +710,7 @@
Name
ChatDialog::getInviteeRoutablePrefix(const Name& invitee)
{
- return ndn::Name("/ndn/broadcast");
+ return Name("/ndn/broadcast");
}
void
@@ -705,17 +718,20 @@
msg.set_from(m_nick);
msg.set_to(m_chatroomName);
msg.set_data(text.toStdString());
- int32_t seconds = static_cast<int32_t>(time::toUnixTimestamp(time::system_clock::now()).count()/1000000000);
+ int32_t seconds =
+ static_cast<int32_t>(time::toUnixTimestamp(time::system_clock::now()).count()/1000000000);
msg.set_timestamp(seconds);
msg.set_type(SyncDemo::ChatMessage::CHAT);
}
void
-ChatDialog::formControlMessage(SyncDemo::ChatMessage &msg, SyncDemo::ChatMessage::ChatMessageType type)
+ChatDialog::formControlMessage(SyncDemo::ChatMessage &msg,
+ SyncDemo::ChatMessage::ChatMessageType type)
{
msg.set_from(m_nick);
msg.set_to(m_chatroomName);
- int32_t seconds = static_cast<int32_t>(time::toUnixTimestamp(time::system_clock::now()).count()/1000000000);
+ int32_t seconds =
+ static_cast<int32_t>(time::toUnixTimestamp(time::system_clock::now()).count()/1000000000);
msg.set_timestamp(seconds);
msg.set_type(type);
}
@@ -726,22 +742,20 @@
struct tm *tm_time = localtime(×tamp);
int hour = tm_time->tm_hour;
QString amOrPM;
- if (hour > 12)
- {
+ if (hour > 12) {
hour -= 12;
amOrPM = "PM";
}
- else
- {
+ else {
amOrPM = "AM";
- if (hour == 0)
- {
+ if (hour == 0) {
hour = 12;
}
}
char textTime[12];
- sprintf(textTime, "%d:%02d:%02d %s", hour, tm_time->tm_min, tm_time->tm_sec, amOrPM.toStdString().c_str());
+ sprintf(textTime, "%d:%02d:%02d %s",
+ hour, tm_time->tm_min, tm_time->tm_sec, amOrPM.toStdString().c_str());
return QString(textTime);
}
@@ -757,10 +771,10 @@
timeCell.firstCursorPosition().insertText(formatTime(timestamp));
}
-std::string
+string
ChatDialog::getRandomString()
{
- uint32_t r = random::generateWord32();
+ uint32_t r = ndn::random::generateWord32();
std::stringstream ss;
{
using namespace CryptoPP;
@@ -797,32 +811,27 @@
ChatDialog::summonReaper()
{
Sync::SyncLogic &logic = m_sock->getLogic ();
- std::map<std::string, bool> branches = logic.getBranchPrefixes();
+ map<string, bool> branches = logic.getBranchPrefixes();
QMap<QString, DisplayUserPtr> roster = m_scene->getRosterFull();
m_zombieList.clear();
QMapIterator<QString, DisplayUserPtr> it(roster);
- std::map<std::string, bool>::iterator mapIt;
- while(it.hasNext())
- {
+ map<string, bool>::iterator mapIt;
+ while (it.hasNext()) {
it.next();
DisplayUserPtr p = it.value();
- if (p != DisplayUserNullPtr)
- {
+ if (p != DisplayUserNullPtr) {
mapIt = branches.find(p->getPrefix().toStdString());
- if (mapIt != branches.end())
- {
+ if (mapIt != branches.end()) {
mapIt->second = true;
}
}
}
- for (mapIt = branches.begin(); mapIt != branches.end(); ++mapIt)
- {
+ for (mapIt = branches.begin(); mapIt != branches.end(); ++mapIt) {
// this is zombie. all active users should have been marked true
- if (! mapIt->second)
- {
+ if (! mapIt->second) {
m_zombieList.append(mapIt->first.c_str());
}
}
@@ -836,77 +845,70 @@
void
ChatDialog::getTree(TrustTreeNodeList& nodeList)
{
- typedef std::map<Name, shared_ptr<TrustTreeNode> > NodeMap;
+ typedef map<Name, shared_ptr<TrustTreeNode> > NodeMap;
- std::vector<Name> certNameList;
+ vector<Name> certNameList;
NodeMap nodeMap;
m_sock->getIntroCertNames(certNameList);
- std::vector<Name>::const_iterator it = certNameList.begin();
- std::vector<Name>::const_iterator end = certNameList.end();
- for(; it != end; it++)
- {
- Name introducerCertName;
- Name introduceeCertName;
+ for (vector<Name>::const_iterator it = certNameList.begin(); it != certNameList.end(); it++) {
+ Name introducerCertName;
+ Name introduceeCertName;
- introducerCertName.wireDecode(it->get(-2).blockFromValue());
- introduceeCertName.wireDecode(it->get(-3).blockFromValue());
+ introducerCertName.wireDecode(it->get(-2).blockFromValue());
+ introduceeCertName.wireDecode(it->get(-3).blockFromValue());
- Name introducerName = IdentityCertificate::certificateNameToPublicKeyName(introducerCertName).getPrefix(-1);
- Name introduceeName = IdentityCertificate::certificateNameToPublicKeyName(introduceeCertName).getPrefix(-1);
+ Name introducerName =
+ IdentityCertificate::certificateNameToPublicKeyName(introducerCertName).getPrefix(-1);
+ Name introduceeName =
+ IdentityCertificate::certificateNameToPublicKeyName(introduceeCertName).getPrefix(-1);
- NodeMap::iterator introducerIt = nodeMap.find(introducerName);
- if(introducerIt == nodeMap.end())
- {
- shared_ptr<TrustTreeNode> introducerNode(new TrustTreeNode(introducerName));
- nodeMap[introducerName] = introducerNode;
- }
- shared_ptr<TrustTreeNode> erNode = nodeMap[introducerName];
-
- NodeMap::iterator introduceeIt = nodeMap.find(introduceeName);
- if(introduceeIt == nodeMap.end())
- {
- shared_ptr<TrustTreeNode> introduceeNode(new TrustTreeNode(introduceeName));
- nodeMap[introduceeName] = introduceeNode;
- }
- shared_ptr<TrustTreeNode> eeNode = nodeMap[introduceeName];
-
- erNode->addIntroducee(eeNode);
- eeNode->addIntroducer(erNode);
+ NodeMap::iterator introducerIt = nodeMap.find(introducerName);
+ if (introducerIt == nodeMap.end()) {
+ shared_ptr<TrustTreeNode> introducerNode(new TrustTreeNode(introducerName));
+ nodeMap[introducerName] = introducerNode;
}
+ shared_ptr<TrustTreeNode> erNode = nodeMap[introducerName];
+
+ NodeMap::iterator introduceeIt = nodeMap.find(introduceeName);
+ if (introduceeIt == nodeMap.end()) {
+ shared_ptr<TrustTreeNode> introduceeNode(new TrustTreeNode(introduceeName));
+ nodeMap[introduceeName] = introduceeNode;
+ }
+ shared_ptr<TrustTreeNode> eeNode = nodeMap[introduceeName];
+
+ erNode->addIntroducee(eeNode);
+ eeNode->addIntroducer(erNode);
+ }
nodeList.clear();
- std::queue<shared_ptr<TrustTreeNode> > nodeQueue;
+ queue<shared_ptr<TrustTreeNode> > nodeQueue;
NodeMap::iterator nodeIt = nodeMap.find(m_identity);
- if(nodeIt == nodeMap.end())
+ if (nodeIt == nodeMap.end())
return;
nodeQueue.push(nodeIt->second);
nodeIt->second->setLevel(0);
- while(!nodeQueue.empty())
- {
- shared_ptr<TrustTreeNode>& node = nodeQueue.front();
- node->setVisited();
+ while (!nodeQueue.empty()) {
+ shared_ptr<TrustTreeNode>& node = nodeQueue.front();
+ node->setVisited();
- TrustTreeNodeList& introducees = node->getIntroducees();
- TrustTreeNodeList::iterator eeIt = introducees.begin();
- TrustTreeNodeList::iterator eeEnd = introducees.end();
-
- for(; eeIt != eeEnd; eeIt++)
- {
- _LOG_DEBUG("introducee: " << (*eeIt)->name() << " visited: " << boolalpha << (*eeIt)->visited());
- if(!(*eeIt)->visited())
- {
- nodeQueue.push(*eeIt);
- (*eeIt)->setLevel(node->level()+1);
- }
- }
-
- nodeList.push_back(node);
- nodeQueue.pop();
+ TrustTreeNodeList& introducees = node->getIntroducees();
+ for (TrustTreeNodeList::iterator eeIt = introducees.begin();
+ eeIt != introducees.end(); eeIt++) {
+ // _LOG_DEBUG("introducee: " << (*eeIt)->name() <<
+ // " visited: " << std::boolalpha << (*eeIt)->visited());
+ if (!(*eeIt)->visited()) {
+ nodeQueue.push(*eeIt);
+ (*eeIt)->setLevel(node->level()+1);
+ }
}
+
+ nodeList.push_back(node);
+ nodeQueue.pop();
+ }
}
void
@@ -927,53 +929,50 @@
ChatDialog::onLocalPrefixUpdated(const QString& localPrefix)
{
Name newLocalPrefix(localPrefix.toStdString());
- if(!newLocalPrefix.empty() && newLocalPrefix != m_localPrefix)
- {
- // Update localPrefix
- m_localPrefix = newLocalPrefix;
+ if (!newLocalPrefix.empty() && newLocalPrefix != m_localPrefix) {
+ // Update localPrefix
+ m_localPrefix = newLocalPrefix;
- updatePrefix();
- updateLabels();
- m_scene->setCurrentPrefix(QString(m_localChatPrefix.toUri().c_str()));
+ updatePrefix();
+ updateLabels();
+ m_scene->setCurrentPrefix(QString(m_localChatPrefix.toUri().c_str()));
- if(m_sock != NULL)
- {
- {
- boost::recursive_mutex::scoped_lock lock(m_sceneMutex);
- m_scene->clearAll();
- m_scene->plot("Empty");
- }
+ if (m_sock != NULL) {
+ {
+ boost::recursive_mutex::scoped_lock lock(m_sceneMutex);
+ m_scene->clearAll();
+ m_scene->plot("Empty");
+ }
- ui->textEdit->clear();
+ ui->textEdit->clear();
- if (m_joined)
- {
- sendLeave();
- }
+ if (m_joined) {
+ sendLeave();
+ }
- delete m_sock;
- m_sock = NULL;
+ delete m_sock;
+ m_sock = NULL;
- usleep(100000);
- m_sock = new Sync::SyncSocket(m_chatroomPrefix,
- m_chatPrefix,
- m_session,
- m_useRoutablePrefix,
- m_localPrefix,
- m_face,
- m_myCertificate,
- m_dataRule,
- bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2),
- bind(&ChatDialog::processRemoveWrapper, this, _1));
- usleep(100000);
- QTimer::singleShot(600, this, SLOT(sendJoin()));
- m_timer->start(FRESHNESS * 1000);
- disableSyncTreeDisplay();
- QTimer::singleShot(2200, this, SLOT(enableSyncTreeDisplay()));
- }
- else
- initializeSync();
+ usleep(100000);
+ m_sock = new Sync::SyncSocket(m_chatroomPrefix,
+ m_chatPrefix,
+ m_session,
+ m_useRoutablePrefix,
+ m_localPrefix,
+ m_face,
+ m_myCertificate,
+ m_dataRule,
+ bind(&ChatDialog::processTreeUpdateWrapper, this, _1, _2),
+ bind(&ChatDialog::processRemoveWrapper, this, _1));
+ usleep(100000);
+ QTimer::singleShot(600, this, SLOT(sendJoin()));
+ m_timer->start(FRESHNESS * 1000);
+ disableSyncTreeDisplay();
+ QTimer::singleShot(2200, this, SLOT(enableSyncTreeDisplay()));
}
+ else
+ initializeSync();
+ }
else
if (m_sock == NULL)
initializeSync();
@@ -999,16 +998,14 @@
ui->lineEdit->clear();
- if (text.startsWith("boruoboluomi"))
- {
+ if (text.startsWith("boruoboluomi")) {
summonReaper ();
// reapButton->show();
fitView();
return;
}
- if (text.startsWith("minimanihong"))
- {
+ if (text.startsWith("minimanihong")) {
// reapButton->hide();
fitView();
return;
@@ -1027,13 +1024,11 @@
void
ChatDialog::onSyncTreeButtonPressed()
{
- if (ui->syncTreeViewer->isVisible())
- {
+ if (ui->syncTreeViewer->isVisible()) {
ui->syncTreeViewer->hide();
ui->syncTreeButton->setText("Show ChronoSync Tree");
}
- else
- {
+ else {
ui->syncTreeViewer->show();
ui->syncTreeButton->setText("Hide ChronoSync Tree");
}
@@ -1044,13 +1039,11 @@
void
ChatDialog::onTrustTreeButtonPressed()
{
- if (ui->trustTreeViewer->isVisible())
- {
+ if (ui->trustTreeViewer->isVisible()) {
ui->trustTreeViewer->hide();
ui->trustTreeButton->setText("Show Trust Tree");
}
- else
- {
+ else {
ui->trustTreeViewer->show();
ui->trustTreeButton->setText("Hide Trust Tree");
}
@@ -1063,9 +1056,9 @@
{
SyncDemo::ChatMessage msg;
bool corrupted = false;
- if (!msg.ParseFromArray(data->getContent().value(), data->getContent().value_size()))
- {
- _LOG_DEBUG("Errrrr.. Can not parse msg with name: " << data->getName() << ". what is happening?");
+ if (!msg.ParseFromArray(data->getContent().value(), data->getContent().value_size())) {
+ // _LOG_DEBUG("Errrrr.. Can not parse msg with name: " <<
+ // data->getName() << ". what is happening?");
// nasty stuff: as a remedy, we'll form some standard msg for inparsable msgs
msg.set_from("inconnu");
msg.set_type(SyncDemo::ChatMessage::OTHER);
@@ -1077,22 +1070,18 @@
// so if we call appendMsg directly
// Qt crash as "QObject: Cannot create children for a parent that is in a different thread"
// the "cannonical" way to is use signal-slot
- if (show && !corrupted)
- {
+ if (show && !corrupted) {
appendMessage(msg, isHistory);
}
- if (!isHistory)
- {
+ if (!isHistory) {
// update the tree view
- std::string prefix = data->getName().getPrefix(-2).toUri();
- _LOG_DEBUG("<<< updating scene for" << prefix << ": " << msg.from());
- if (msg.type() == SyncDemo::ChatMessage::LEAVE)
- {
+ string prefix = data->getName().getPrefix(-2).toUri();
+ // _LOG_DEBUG("<<< updating scene for" << prefix << ": " << msg.from());
+ if (msg.type() == SyncDemo::ChatMessage::LEAVE) {
processRemove(prefix.c_str());
}
- else
- {
+ else {
boost::recursive_mutex::scoped_lock lock(m_sceneMutex);
m_scene->msgReceived(prefix.c_str(), msg.from().c_str());
}
@@ -1101,12 +1090,11 @@
}
void
-ChatDialog::onProcessTreeUpdate(const std::vector<Sync::MissingDataInfo>& v)
+ChatDialog::onProcessTreeUpdate(const vector<Sync::MissingDataInfo>& v)
{
- _LOG_DEBUG("<<< processing Tree Update");
+ // _LOG_DEBUG("<<< processing Tree Update");
- if (v.empty())
- {
+ if (v.empty()) {
return;
}
@@ -1118,24 +1106,20 @@
int n = v.size();
int totalMissingPackets = 0;
- for (int i = 0; i < n; i++)
- {
+ for (int i = 0; i < n; i++) {
totalMissingPackets += v[i].high.getSeq() - v[i].low.getSeq() + 1;
}
- for (int i = 0; i < n; i++)
- {
- if (totalMissingPackets < 4)
- {
- for (Sync::SeqNo seq = v[i].low; seq <= v[i].high; ++seq)
- {
+ for (int i = 0; i < n; i++) {
+ if (totalMissingPackets < 4) {
+ for (Sync::SeqNo seq = v[i].low; seq <= v[i].high; ++seq) {
m_sock->fetchData(v[i].prefix, seq, bind(&ChatDialog::processDataWrapper, this, _1), 2);
- _LOG_DEBUG("<<< Fetching " << v[i].prefix << "/" <<seq.getSession() <<"/" << seq.getSeq());
+ // _LOG_DEBUG("<<< Fetching " << v[i].prefix << "/" <<seq.getSession() <<"/" << seq.getSeq());
}
}
- else
- {
- m_sock->fetchData(v[i].prefix, v[i].high, bind(&ChatDialog::processDataNoShowWrapper, this, _1), 2);
+ else {
+ m_sock->fetchData(v[i].prefix, v[i].high,
+ bind(&ChatDialog::processDataNoShowWrapper, this, _1), 2);
}
}
// adjust the view
@@ -1158,9 +1142,8 @@
m_rosterModel->setStringList(rosterList);
QString user;
QStringListIterator it(staleUserList);
- while(it.hasNext())
- {
- std::string nick = it.next().toStdString();
+ while (it.hasNext()) {
+ string nick = it.next().toStdString();
if (nick.empty())
continue;
@@ -1198,8 +1181,7 @@
{
int64_t now = time::toUnixTimestamp(time::system_clock::now()).count();
int elapsed = (now - m_lastMsgTime) / 1000000000;
- if (elapsed >= m_randomizedInterval / 1000)
- {
+ if (elapsed >= m_randomizedInterval / 1000) {
SyncDemo::ChatMessage msg;
formControlMessage(msg, SyncDemo::ChatMessage::HELLO);
sendMsg(msg);
@@ -1208,8 +1190,7 @@
m_randomizedInterval = HELLO_INTERVAL * 1000 + uniform(rng);
QTimer::singleShot(m_randomizedInterval, this, SLOT(sendHello()));
}
- else
- {
+ else {
QTimer::singleShot((m_randomizedInterval - elapsed * 1000), this, SLOT(sendHello()));
}
}
@@ -1224,7 +1205,7 @@
m_sock->leave();
usleep(5000);
m_joined = false;
- _LOG_DEBUG("Sync REMOVE signal sent");
+ // _LOG_DEBUG("Sync REMOVE signal sent");
}
void ChatDialog::enableSyncTreeDisplay()
@@ -1237,11 +1218,10 @@
void
ChatDialog::reap()
{
- if (m_zombieIndex < m_zombieList.size())
- {
- std::string prefix = m_zombieList.at(m_zombieIndex).toStdString();
+ if (m_zombieIndex < m_zombieList.size()) {
+ string prefix = m_zombieList.at(m_zombieIndex).toStdString();
m_sock->remove(prefix);
- _LOG_DEBUG("Reaped: prefix = " << prefix);
+ // _LOG_DEBUG("Reaped: prefix = " << prefix);
m_zombieIndex++;
// reap again in 10 seconds
QTimer::singleShot(10000, this, SLOT(reap()));
@@ -1264,19 +1244,19 @@
{
OnDataValidated onValidated = bind(&ChatDialog::onReplyValidated,
this, _1,
- interest.getName().size()-routablePrefixOffset, //RoutablePrefix will be removed before data is passed to the validator
+ //RoutablePrefix will be removed before passing to validator
+ interest.getName().size()-routablePrefixOffset,
isIntroducer);
OnDataValidationFailed onFailed = bind(&ChatDialog::onReplyValidationFailed,
this, _1, _2);
- if(routablePrefixOffset > 0)
- {
- // It is an encapsulated packet, we only validate the inner packet.
- shared_ptr<Data> innerData = make_shared<Data>();
- innerData->wireDecode(data->getContent().blockFromValue());
- m_invitationValidator->validate(*innerData, onValidated, onFailed);
- }
+ if (routablePrefixOffset > 0) {
+ // It is an encapsulated packet, we only validate the inner packet.
+ shared_ptr<Data> innerData = make_shared<Data>();
+ innerData->wireDecode(data->getContent().blockFromValue());
+ m_invitationValidator->validate(*innerData, onValidated, onFailed);
+ }
else
m_invitationValidator->validate(*data, onValidated, onFailed);
}
@@ -1286,14 +1266,15 @@
size_t routablePrefixOffset)
{
Name interestName;
- if(routablePrefixOffset > 0)
+ if (routablePrefixOffset > 0)
interestName = interest.getName().getSubName(routablePrefixOffset);
else
interestName = interest.getName();
Invitation invitation(interestName);
- QString msg = QString::fromUtf8("Your invitation to ") + QString::fromStdString(invitation.getInviteeNameSpace().toUri()) + " times out!";
+ QString msg = QString::fromUtf8("Your invitation to ") +
+ QString::fromStdString(invitation.getInviteeNameSpace().toUri()) + " times out!";
emit inivationRejection(msg);
}
@@ -1310,9 +1291,10 @@
void
ChatDialog::onIntroCertTimeout(const Interest& interest, int retry, const QString& msg)
{
- _LOG_DEBUG("onIntroCertTimeout: " << msg.toStdString());
+ // _LOG_DEBUG("onIntroCertTimeout: " << msg.toStdString());
}
+} // namespace chronos
#if WAF
#include "chat-dialog.moc"