bug+codestyle: Fix compile bugs and adjust code style
Change-Id: I008bb538441c099fa25b8b967fbf23ffce13a220
diff --git a/src/contact-manager.cpp b/src/contact-manager.cpp
index fb792db..7653cd0 100644
--- a/src/contact-manager.cpp
+++ b/src/contact-manager.cpp
@@ -12,7 +12,7 @@
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
-#include "contact-manager.h"
+#include "contact-manager.hpp"
#include <QStringList>
#include <QFile>
@@ -21,24 +21,33 @@
#include <ndn-cxx/util/io.hpp>
#include <ndn-cxx/security/sec-rule-relative.hpp>
#include <ndn-cxx/security/validator-regex.hpp>
-#include <cryptopp/base64.h>
-#include <cryptopp/files.h>
-#include <cryptopp/sha.h>
-#include <cryptopp/filters.h>
+#include "cryptopp.hpp"
#include <boost/asio.hpp>
#include <boost/tokenizer.hpp>
#include <boost/filesystem.hpp>
#include "logging.h"
#endif
-using namespace ndn;
namespace fs = boost::filesystem;
-INIT_LOGGER("chronos.ContactManager");
+// INIT_LOGGER("chronos.ContactManager");
namespace chronos{
-using ndn::shared_ptr;
+using std::string;
+using std::map;
+using std::vector;
+
+using ndn::Face;
+using ndn::OBufferStream;
+using ndn::IdentityCertificate;
+using ndn::Validator;
+using ndn::ValidatorRegex;
+using ndn::SecRuleRelative;
+using ndn::OnDataValidated;
+using ndn::OnDataValidationFailed;
+using ndn::OnInterestValidated;
+using ndn::OnInterestValidationFailed;
static const uint8_t DNS_RP_SEPARATOR[2] = {0xF0, 0x2E}; // %F0.
@@ -52,7 +61,8 @@
}
ContactManager::~ContactManager()
-{}
+{
+}
// private methods
shared_ptr<IdentityCertificate>
@@ -62,38 +72,33 @@
QFile anchorFile(":/security/anchor.cert");
- if (!anchorFile.open(QIODevice::ReadOnly))
- {
- emit warning(QString("Cannot load trust anchor!"));
-
- return anchor;
- }
+ if (!anchorFile.open(QIODevice::ReadOnly)) {
+ emit warning(QString("Cannot load trust anchor!"));
+ return anchor;
+ }
qint64 fileSize = anchorFile.size();
char* buf = new char[fileSize];
anchorFile.read(buf, fileSize);
- try
- {
- using namespace CryptoPP;
+ try {
+ using namespace CryptoPP;
- OBufferStream os;
- StringSource(reinterpret_cast<const uint8_t*>(buf), fileSize, true, new Base64Decoder(new FileSink(os)));
- anchor = make_shared<IdentityCertificate>();
- anchor->wireDecode(Block(os.buf()));
- }
- catch(CryptoPP::Exception& e)
- {
- emit warning(QString("Cannot load trust anchor!"));
- }
- catch(IdentityCertificate::Error& e)
- {
- emit warning(QString("Cannot load trust anchor!"));
- }
- catch(Block::Error& e)
- {
- emit warning(QString("Cannot load trust anchor!"));
- }
+ OBufferStream os;
+ StringSource(reinterpret_cast<const uint8_t*>(buf), fileSize, true,
+ new Base64Decoder(new FileSink(os)));
+ anchor = make_shared<IdentityCertificate>();
+ anchor->wireDecode(Block(os.buf()));
+ }
+ catch (CryptoPP::Exception& e) {
+ emit warning(QString("Cannot load trust anchor!"));
+ }
+ catch (IdentityCertificate::Error& e) {
+ emit warning(QString("Cannot load trust anchor!"));
+ }
+ catch(Block::Error& e) {
+ emit warning(QString("Cannot load trust anchor!"));
+ }
delete [] buf;
@@ -141,9 +146,12 @@
interest.setInterestLifetime(time::milliseconds(1000));
interest.setMustBeFresh(true);
- OnDataValidated onValidated = bind(&ContactManager::onDnsCollectEndorseValidated, this, _1, identity);
- OnDataValidationFailed onValidationFailed = bind(&ContactManager::onDnsCollectEndorseValidationFailed, this, _1, _2, identity);
- TimeoutNotify timeoutNotify = bind(&ContactManager::onDnsCollectEndorseTimeoutNotify, this, _1, identity);
+ OnDataValidated onValidated =
+ bind(&ContactManager::onDnsCollectEndorseValidated, this, _1, identity);
+ OnDataValidationFailed onValidationFailed =
+ bind(&ContactManager::onDnsCollectEndorseValidationFailed, this, _1, _2, identity);
+ TimeoutNotify timeoutNotify =
+ bind(&ContactManager::onDnsCollectEndorseTimeoutNotify, this, _1, identity);
sendInterest(interest, onValidated, onValidationFailed, timeoutNotify, 0);
}
@@ -151,7 +159,8 @@
void
ContactManager::fetchEndorseCertificateInternal(const Name& identity, int certIndex)
{
- shared_ptr<EndorseCollection> endorseCollection = m_bufferedContacts[identity].m_endorseCollection;
+ shared_ptr<EndorseCollection> endorseCollection =
+ m_bufferedContacts[identity].m_endorseCollection;
if(certIndex >= endorseCollection->endorsement_size())
prepareEndorseInfo(identity);
@@ -176,58 +185,51 @@
// _LOG_DEBUG("prepareEndorseInfo");
const Profile& profile = m_bufferedContacts[identity].m_selfEndorseCert->getProfile();
- shared_ptr<EndorseInfo> endorseInfo = make_shared<EndorseInfo>();
+ shared_ptr<Chronos::EndorseInfo> endorseInfo = make_shared<Chronos::EndorseInfo>();
m_bufferedContacts[identity].m_endorseInfo = endorseInfo;
- Profile::const_iterator pIt = profile.begin();
- Profile::const_iterator pEnd = profile.end();
-
- std::map<std::string, int> endorseCount;
- for(; pIt != pEnd; pIt++)
- {
- // _LOG_DEBUG("prepareEndorseInfo: profile[" << pIt->first << "]: " << pIt->second);
- endorseCount[pIt->first] = 0;
- }
+ map<string, int> endorseCount;
+ for (Profile::const_iterator pIt = profile.begin(); pIt != profile.end(); pIt++) {
+ // _LOG_DEBUG("prepareEndorseInfo: profile[" << pIt->first << "]: " << pIt->second);
+ endorseCount[pIt->first] = 0;
+ }
int endorseCertCount = 0;
- std::vector<shared_ptr<EndorseCertificate> >::const_iterator cIt = m_bufferedContacts[identity].m_endorseCertList.begin();
- std::vector<shared_ptr<EndorseCertificate> >::const_iterator cEnd = m_bufferedContacts[identity].m_endorseCertList.end();
+ vector<shared_ptr<EndorseCertificate> >::const_iterator cIt =
+ m_bufferedContacts[identity].m_endorseCertList.begin();
+ vector<shared_ptr<EndorseCertificate> >::const_iterator cEnd =
+ m_bufferedContacts[identity].m_endorseCertList.end();
- for(; cIt != cEnd; cIt++, endorseCertCount++)
- {
- shared_ptr<Contact> contact = getContact((*cIt)->getSigner().getPrefix(-1));
- if(!static_cast<bool>(contact))
- continue;
+ for (; cIt != cEnd; cIt++, endorseCertCount++) {
+ shared_ptr<Contact> contact = getContact((*cIt)->getSigner().getPrefix(-1));
+ if (!static_cast<bool>(contact))
+ continue;
- if(!contact->isIntroducer()
- || !contact->canBeTrustedFor(profile.getIdentityName()))
- continue;
+ if (!contact->isIntroducer() ||
+ !contact->canBeTrustedFor(profile.getIdentityName()))
+ continue;
- if(!Validator::verifySignature(**cIt, contact->getPublicKey()))
- continue;
+ if (!Validator::verifySignature(**cIt, contact->getPublicKey()))
+ continue;
- const Profile& tmpProfile = (*cIt)->getProfile();
- if(tmpProfile != profile)
- continue;
+ const Profile& tmpProfile = (*cIt)->getProfile();
+ if (tmpProfile != profile)
+ continue;
- const std::vector<std::string>& endorseList = (*cIt)->getEndorseList();
- std::vector<std::string>::const_iterator eIt = endorseList.begin();
- for(; eIt != endorseList.end(); eIt++)
- endorseCount[*eIt] += 1;
- }
+ const vector<string>& endorseList = (*cIt)->getEndorseList();
+ for (vector<string>::const_iterator eIt = endorseList.begin(); eIt != endorseList.end(); eIt++)
+ endorseCount[*eIt] += 1;
+ }
- pIt = profile.begin();
- pEnd = profile.end();
- for(; pIt != pEnd; pIt++)
- {
- EndorseInfo::Endorsement* endorsement = endorseInfo->add_endorsement();
- endorsement->set_type(pIt->first);
- endorsement->set_value(pIt->second);
- std::stringstream ss;
- ss << endorseCount[pIt->first] << "/" << endorseCertCount;
- endorsement->set_endorse(ss.str());
- }
+ for (Profile::const_iterator pIt = profile.begin(); pIt != profile.end(); pIt++) {
+ Chronos::EndorseInfo::Endorsement* endorsement = endorseInfo->add_endorsement();
+ endorsement->set_type(pIt->first);
+ endorsement->set_value(pIt->second);
+ std::stringstream ss;
+ ss << endorseCount[pIt->first] << "/" << endorseCertCount;
+ endorsement->set_endorse(ss.str());
+ }
emit contactEndorseInfoReady (*endorseInfo);
}
@@ -236,36 +238,32 @@
ContactManager::onDnsSelfEndorseCertValidated(const shared_ptr<const Data>& data,
const Name& identity)
{
- try
- {
- Data plainData;
- plainData.wireDecode(data->getContent().blockFromValue());
- shared_ptr<EndorseCertificate> selfEndorseCertificate = make_shared<EndorseCertificate>(boost::cref(plainData));
- if(Validator::verifySignature(plainData, selfEndorseCertificate->getPublicKeyInfo()))
- {
- m_bufferedContacts[identity].m_selfEndorseCert = selfEndorseCertificate;
- fetchCollectEndorse(identity);
- }
- else
- emit contactInfoFetchFailed(QString::fromStdString(identity.toUri()));
+ try {
+ Data plainData;
+ plainData.wireDecode(data->getContent().blockFromValue());
+ shared_ptr<EndorseCertificate> selfEndorseCertificate =
+ make_shared<EndorseCertificate>(boost::cref(plainData));
+ if (Validator::verifySignature(plainData, selfEndorseCertificate->getPublicKeyInfo())) {
+ m_bufferedContacts[identity].m_selfEndorseCert = selfEndorseCertificate;
+ fetchCollectEndorse(identity);
}
- catch(Block::Error& e)
- {
+ else
emit contactInfoFetchFailed(QString::fromStdString(identity.toUri()));
- }
- catch(Data::Error& e)
- {
- emit contactInfoFetchFailed(QString::fromStdString(identity.toUri()));
- }
- catch(EndorseCertificate::Error& e)
- {
- emit contactInfoFetchFailed(QString::fromStdString(identity.toUri()));
- }
+ }
+ catch(Block::Error& e) {
+ emit contactInfoFetchFailed(QString::fromStdString(identity.toUri()));
+ }
+ catch(Data::Error& e) {
+ emit contactInfoFetchFailed(QString::fromStdString(identity.toUri()));
+ }
+ catch(EndorseCertificate::Error& e) {
+ emit contactInfoFetchFailed(QString::fromStdString(identity.toUri()));
+ }
}
void
ContactManager::onDnsSelfEndorseCertValidationFailed(const shared_ptr<const Data>& data,
- const std::string& failInfo,
+ const string& failInfo,
const Name& identity)
{
// If we cannot validate the Self-Endorse-Certificate, we may retry or fetch id-cert,
@@ -287,37 +285,33 @@
const Name& identity)
{
shared_ptr<EndorseCollection> endorseCollection = make_shared<EndorseCollection>();
- if(!endorseCollection->ParseFromArray(data->getContent().value(), data->getContent().value_size()))
- {
- m_bufferedContacts[identity].m_endorseCollection = endorseCollection;
- fetchEndorseCertificateInternal(identity, 0);
- }
+ if (!endorseCollection->ParseFromArray(data->getContent().value(),
+ data->getContent().value_size())) {
+ m_bufferedContacts[identity].m_endorseCollection = endorseCollection;
+ fetchEndorseCertificateInternal(identity, 0);
+ }
else
prepareEndorseInfo(identity);
}
void
ContactManager::onDnsCollectEndorseValidationFailed(const shared_ptr<const Data>& data,
- const std::string& failInfo,
+ const string& failInfo,
const Name& identity)
{
prepareEndorseInfo(identity);
}
void
-ContactManager::onDnsCollectEndorseTimeoutNotify(const Interest& interest,
- const Name& identity)
+ContactManager::onDnsCollectEndorseTimeoutNotify(const Interest& interest, const Name& identity)
{
// _LOG_DEBUG("onDnsCollectEndorseTimeoutNotify: " << interest.getName());
prepareEndorseInfo(identity);
}
void
-ContactManager::onEndorseCertificateInternal(const Interest& interest,
- Data& data,
- const Name& identity,
- int certIndex,
- std::string hash)
+ContactManager::onEndorseCertificateInternal(const Interest& interest, Data& data,
+ const Name& identity, int certIndex, string hash)
{
std::stringstream ss;
{
@@ -328,11 +322,11 @@
new HashFilter(hash, new FileSink(ss)));
}
- if(ss.str() == hash)
- {
- shared_ptr<EndorseCertificate> endorseCertificate = make_shared<EndorseCertificate>(boost::cref(data));
- m_bufferedContacts[identity].m_endorseCertList.push_back(endorseCertificate);
- }
+ if (ss.str() == hash) {
+ shared_ptr<EndorseCertificate> endorseCertificate =
+ make_shared<EndorseCertificate>(boost::cref(data));
+ m_bufferedContacts[identity].m_endorseCertList.push_back(endorseCertificate);
+ }
fetchEndorseCertificateInternal(identity, certIndex+1);
}
@@ -352,23 +346,20 @@
boost::recursive_mutex::scoped_lock lock(m_collectCountMutex);
m_collectCount = m_contactList.size();
- ContactList::iterator it = m_contactList.begin();
- ContactList::iterator end = m_contactList.end();
+ for (ContactList::iterator it = m_contactList.begin(); it != m_contactList.end(); it++) {
+ Name interestName = (*it)->getNameSpace();
+ interestName.append("DNS").append(m_identity.wireEncode()).append("ENDORSEE");
- for(; it != end ; it++)
- {
- Name interestName = (*it)->getNameSpace();
- interestName.append("DNS").append(m_identity.wireEncode()).append("ENDORSEE");
+ Interest interest(interestName);
+ interest.setInterestLifetime(time::milliseconds(1000));
- Interest interest(interestName);
- interest.setInterestLifetime(time::milliseconds(1000));
+ OnDataValidated onValidated = bind(&ContactManager::onDnsEndorseeValidated, this, _1);
+ OnDataValidationFailed onValidationFailed =
+ bind(&ContactManager::onDnsEndorseeValidationFailed, this, _1, _2);
+ TimeoutNotify timeoutNotify = bind(&ContactManager::onDnsEndorseeTimeoutNotify, this, _1);
- OnDataValidated onValidated = bind(&ContactManager::onDnsEndorseeValidated, this, _1);
- OnDataValidationFailed onValidationFailed = bind(&ContactManager::onDnsEndorseeValidationFailed, this, _1, _2);
- TimeoutNotify timeoutNotify = bind(&ContactManager::onDnsEndorseeTimeoutNotify, this, _1);
-
- sendInterest(interest, onValidated, onValidationFailed, timeoutNotify, 0);
- }
+ sendInterest(interest, onValidated, onValidationFailed, timeoutNotify, 0);
+ }
}
}
@@ -385,7 +376,8 @@
}
void
-ContactManager::onDnsEndorseeValidationFailed(const shared_ptr<const Data>& data, const std::string& failInfo)
+ContactManager::onDnsEndorseeValidationFailed(const shared_ptr<const Data>& data,
+ const string& failInfo)
{
decreaseCollectStatus();
}
@@ -441,16 +433,17 @@
}
void
-ContactManager::onIdentityCertValidationFailed(const shared_ptr<const Data>& data, const std::string& failInfo)
+ContactManager::onIdentityCertValidationFailed(const shared_ptr<const Data>& data,
+ const string& failInfo)
{
- _LOG_DEBUG("ContactManager::onIdentityCertValidationFailed " << data->getName());
+ // _LOG_DEBUG("ContactManager::onIdentityCertValidationFailed " << data->getName());
decreaseIdCertCount();
}
void
ContactManager::onIdentityCertTimeoutNotify(const Interest& interest)
{
- _LOG_DEBUG("ContactManager::onIdentityCertTimeoutNotify: " << interest.getName());
+ // _LOG_DEBUG("ContactManager::onIdentityCertTimeoutNotify: " << interest.getName());
decreaseIdCertCount();
}
@@ -464,23 +457,20 @@
count = m_idCertCount;
}
- if(count == 0)
- {
- QStringList certNameList;
- QStringList nameList;
+ if (count == 0) {
+ QStringList certNameList;
+ QStringList nameList;
- BufferedIdCerts::const_iterator it = m_bufferedIdCerts.begin();
- BufferedIdCerts::const_iterator end = m_bufferedIdCerts.end();
- for(; it != end; it++)
- {
- certNameList << QString::fromStdString(it->second->getName().toUri());
- Profile profile(*(it->second));
- nameList << QString::fromStdString(profile.get("name"));
- }
-
- emit idCertNameListReady(certNameList);
- emit nameListReady(nameList);
+ for(BufferedIdCerts::const_iterator it = m_bufferedIdCerts.begin();
+ it != m_bufferedIdCerts.end(); it++) {
+ certNameList << QString::fromStdString(it->second->getName().toUri());
+ Profile profile(*(it->second));
+ nameList << QString::fromStdString(profile.get("name"));
}
+
+ emit idCertNameListReady(certNameList);
+ emit nameListReady(nameList);
+ }
}
shared_ptr<EndorseCertificate>
@@ -490,13 +480,14 @@
shared_ptr<IdentityCertificate> signingCert = m_keyChain.getCertificate(certificateName);
- std::vector<std::string> endorseList;
- Profile::const_iterator it = profile.begin();
- for(; it != profile.end(); it++)
+ vector<string> endorseList;
+ for (Profile::const_iterator it = profile.begin(); it != profile.end(); it++)
endorseList.push_back(it->first);
shared_ptr<EndorseCertificate> selfEndorseCertificate =
- shared_ptr<EndorseCertificate>(new EndorseCertificate(*signingCert, profile, endorseList));
+ make_shared<EndorseCertificate>(boost::cref(*signingCert),
+ boost::cref(profile),
+ boost::cref(endorseList));
m_keyChain.sign(*selfEndorseCertificate, certificateName);
@@ -524,12 +515,12 @@
ContactManager::generateEndorseCertificate(const Name& identity)
{
shared_ptr<Contact> contact = getContact(identity);
- if(!static_cast<bool>(contact))
+ if (!static_cast<bool>(contact))
return shared_ptr<EndorseCertificate>();
Name signerKeyName = m_keyChain.getDefaultKeyNameForIdentity(m_identity);
- std::vector<std::string> endorseList;
+ vector<string> endorseList;
m_contactStorage->getEndorseList(identity, endorseList);
shared_ptr<EndorseCertificate> cert =
@@ -561,7 +552,7 @@
m_keyChain.signByIdentity(data, m_identity);
- m_contactStorage->updateDnsEndorseOthers(data, dnsName.get(-3).toEscapedString());
+ m_contactStorage->updateDnsEndorseOthers(data, dnsName.get(-3).toUri());
m_face->put(data);
}
@@ -597,7 +588,7 @@
const TimeoutNotify& timeoutNotify)
{
// _LOG_DEBUG("On interest timeout: " << interest.getName());
- if(retry > 0)
+ if (retry > 0)
sendInterest(interest, onValidated, onValidationFailed, timeoutNotify, retry-1);
else
timeoutNotify(interest);
@@ -609,25 +600,23 @@
const Name& interestName = interest.getName();
shared_ptr<Data> data;
- if(interestName.size() <= prefix.size())
+ if (interestName.size() <= prefix.size())
return;
- if(interestName.size() == (prefix.size()+1))
- {
- data = m_contactStorage->getDnsData("N/A", interestName.get(prefix.size()).toEscapedString());
- if(static_cast<bool>(data))
- m_face->put(*data);
- return;
- }
+ if (interestName.size() == (prefix.size()+1)) {
+ data = m_contactStorage->getDnsData("N/A", interestName.get(prefix.size()).toUri());
+ if (static_cast<bool>(data))
+ m_face->put(*data);
+ return;
+ }
- if(interestName.size() == (prefix.size()+2))
- {
- data = m_contactStorage->getDnsData(interestName.get(prefix.size()).toEscapedString(),
- interestName.get(prefix.size()+1).toEscapedString());
- if(static_cast<bool>(data))
- m_face->put(*data);
- return;
- }
+ if (interestName.size() == (prefix.size()+2)) {
+ data = m_contactStorage->getDnsData(interestName.get(prefix.size()).toUri(),
+ interestName.get(prefix.size()+1).toUri());
+ if (static_cast<bool>(data))
+ m_face->put(*data);
+ return;
+ }
}
void
@@ -645,14 +634,16 @@
m_contactStorage = make_shared<ContactStorage>(m_identity);
- if(m_dnsListenerId)
+ if (m_dnsListenerId)
m_face->unsetInterestFilter(m_dnsListenerId);
Name dnsPrefix;
dnsPrefix.append(m_identity).append("DNS");
m_dnsListenerId = m_face->setInterestFilter(dnsPrefix,
- bind(&ContactManager::onDnsInterest, this, _1, _2),
- bind(&ContactManager::onDnsRegisterFailed, this, _1, _2));
+ bind(&ContactManager::onDnsInterest,
+ this, _1, _2),
+ bind(&ContactManager::onDnsRegisterFailed,
+ this, _1, _2));
m_contactList.clear();
m_contactStorage->getAllContacts(m_contactList);
@@ -676,9 +667,12 @@
interest.setInterestLifetime(time::milliseconds(1000));
interest.setMustBeFresh(true);
- OnDataValidated onValidated = bind(&ContactManager::onDnsSelfEndorseCertValidated, this, _1, identityName);
- OnDataValidationFailed onValidationFailed = bind(&ContactManager::onDnsSelfEndorseCertValidationFailed, this, _1, _2, identityName);
- TimeoutNotify timeoutNotify = bind(&ContactManager::onDnsSelfEndorseCertTimeoutNotify, this, _1, identityName);
+ OnDataValidated onValidated =
+ bind(&ContactManager::onDnsSelfEndorseCertValidated, this, _1, identityName);
+ OnDataValidationFailed onValidationFailed =
+ bind(&ContactManager::onDnsSelfEndorseCertValidationFailed, this, _1, _2, identityName);
+ TimeoutNotify timeoutNotify =
+ bind(&ContactManager::onDnsSelfEndorseCertTimeoutNotify, this, _1, identityName);
sendInterest(interest, onValidated, onValidationFailed, timeoutNotify, 0);
}
@@ -691,29 +685,24 @@
Name identityName(identity.toStdString());
BufferedContacts::const_iterator it = m_bufferedContacts.find(identityName);
- if(it != m_bufferedContacts.end())
- {
- Contact contact(*(it->second.m_selfEndorseCert));
- // _LOG_DEBUG("onAddFetchedContact: contact ready");
- try
- {
- m_contactStorage->addContact(contact);
- m_bufferedContacts.erase(identityName);
+ if (it != m_bufferedContacts.end()) {
+ Contact contact(*(it->second.m_selfEndorseCert));
+ // _LOG_DEBUG("onAddFetchedContact: contact ready");
+ try {
+ m_contactStorage->addContact(contact);
+ m_bufferedContacts.erase(identityName);
- m_contactList.clear();
- m_contactStorage->getAllContacts(m_contactList);
+ m_contactList.clear();
+ m_contactStorage->getAllContacts(m_contactList);
- onWaitForContactList();
- }
- catch(ContactStorage::Error& e)
- {
- emit warning(QString::fromStdString(e.what()));
- }
+ onWaitForContactList();
}
+ catch(ContactStorage::Error& e) {
+ emit warning(QString::fromStdString(e.what()));
+ }
+ }
else
- {
- emit warning(QString("Failure: no information of %1").arg(identity));
- }
+ emit warning(QString("Failure: no information of %1").arg(identity));
}
void
@@ -721,12 +710,13 @@
{
// Get current profile;
shared_ptr<Profile> newProfile = m_contactStorage->getSelfProfile();
- if(!static_cast<bool>(newProfile))
+ if (!static_cast<bool>(newProfile))
return;
- _LOG_DEBUG("ContactManager::onUpdateProfile: getProfile");
+ // _LOG_DEBUG("ContactManager::onUpdateProfile: getProfile");
- shared_ptr<EndorseCertificate> newEndorseCertificate = getSignedSelfEndorseCertificate(*newProfile);
+ shared_ptr<EndorseCertificate> newEndorseCertificate =
+ getSignedSelfEndorseCertificate(*newProfile);
m_contactStorage->addSelfEndorseCertificate(*newEndorseCertificate);
@@ -736,102 +726,98 @@
void
ContactManager::onRefreshBrowseContact()
{
- std::vector<std::string> bufferedIdCertNames;
- try
- {
- using namespace boost::asio::ip;
- tcp::iostream request_stream;
- request_stream.expires_from_now(boost::posix_time::milliseconds(5000));
- request_stream.connect("ndncert.named-data.net","80");
- if(!request_stream)
- {
- emit warning(QString::fromStdString("Fail to fetch certificate directory! #1"));
- return;
- }
-
- request_stream << "GET /cert/list/ HTTP/1.0\r\n";
- request_stream << "Host: ndncert.named-data.net\r\n\r\n";
- request_stream.flush();
-
- std::string line1;
- std::getline(request_stream,line1);
- if (!request_stream)
- {
- emit warning(QString::fromStdString("Fail to fetch certificate directory! #2"));
- return;
- }
-
- std::stringstream response_stream(line1);
- std::string http_version;
- response_stream >> http_version;
- unsigned int status_code;
- response_stream >> status_code;
- std::string status_message;
- std::getline(response_stream,status_message);
-
- if (!response_stream||http_version.substr(0,5)!="HTTP/")
- {
- emit warning(QString::fromStdString("Fail to fetch certificate directory! #3"));
- return;
- }
- if (status_code!=200)
- {
- emit warning(QString::fromStdString("Fail to fetch certificate directory! #4"));
- return;
- }
- std::vector<std::string> headers;
- std::string header;
- while (std::getline(request_stream, header) && header != "\r")
- headers.push_back(header);
-
- std::istreambuf_iterator<char> stream_iter (request_stream);
- std::istreambuf_iterator<char> end_of_stream;
-
- typedef boost::tokenizer< boost::escaped_list_separator<char>, std::istreambuf_iterator<char> > tokenizer_t;
- tokenizer_t certItems (stream_iter, end_of_stream,boost::escaped_list_separator<char>('\\', '\n', '"'));
-
- for (tokenizer_t::iterator it = certItems.begin(); it != certItems.end (); it++)
- if (!it->empty())
- bufferedIdCertNames.push_back(*it);
+ vector<string> bufferedIdCertNames;
+ try {
+ using namespace boost::asio::ip;
+ tcp::iostream request_stream;
+ request_stream.expires_from_now(boost::posix_time::milliseconds(5000));
+ request_stream.connect("ndncert.named-data.net","80");
+ if (!request_stream) {
+ emit warning(QString::fromStdString("Fail to fetch certificate directory! #1"));
+ return;
}
- catch(std::exception &e)
- {
- emit warning(QString::fromStdString("Fail to fetch certificate directory! #N"));
+
+ request_stream << "GET /cert/list/ HTTP/1.0\r\n";
+ request_stream << "Host: ndncert.named-data.net\r\n\r\n";
+ request_stream.flush();
+
+ string line1;
+ std::getline(request_stream,line1);
+ if (!request_stream) {
+ emit warning(QString::fromStdString("Fail to fetch certificate directory! #2"));
+ return;
}
+ std::stringstream response_stream(line1);
+ string http_version;
+ response_stream >> http_version;
+ unsigned int status_code;
+ response_stream >> status_code;
+ string status_message;
+ std::getline(response_stream,status_message);
+
+ if (!response_stream ||
+ http_version.substr(0,5) != "HTTP/") {
+ emit warning(QString::fromStdString("Fail to fetch certificate directory! #3"));
+ return;
+ }
+ if (status_code!=200) {
+ emit warning(QString::fromStdString("Fail to fetch certificate directory! #4"));
+ return;
+ }
+ vector<string> headers;
+ string header;
+ while (std::getline(request_stream, header) && header != "\r")
+ headers.push_back(header);
+
+ std::istreambuf_iterator<char> stream_iter (request_stream);
+ std::istreambuf_iterator<char> end_of_stream;
+
+ typedef boost::tokenizer< boost::escaped_list_separator<char>,
+ std::istreambuf_iterator<char> > tokenizer_t;
+ tokenizer_t certItems (stream_iter,
+ end_of_stream,
+ boost::escaped_list_separator<char>('\\', '\n', '"'));
+
+ for (tokenizer_t::iterator it = certItems.begin(); it != certItems.end (); it++)
+ if (!it->empty())
+ bufferedIdCertNames.push_back(*it);
+ }
+ catch(std::exception &e) {
+ emit warning(QString::fromStdString("Fail to fetch certificate directory! #N"));
+ }
+
{
boost::recursive_mutex::scoped_lock lock(m_idCertCountMutex);
m_idCertCount = bufferedIdCertNames.size();
}
m_bufferedIdCerts.clear();
- std::vector<std::string>::const_iterator it = bufferedIdCertNames.begin();
- std::vector<std::string>::const_iterator end = bufferedIdCertNames.end();
- for(; it != end; it++)
- {
- Name certName(*it);
+ for (vector<string>::const_iterator it = bufferedIdCertNames.begin();
+ it != bufferedIdCertNames.end(); it++) {
+ Name certName(*it);
- Interest interest(certName);
- interest.setInterestLifetime(time::milliseconds(1000));
- interest.setMustBeFresh(true);
+ Interest interest(certName);
+ interest.setInterestLifetime(time::milliseconds(1000));
+ interest.setMustBeFresh(true);
- OnDataValidated onValidated = bind(&ContactManager::onIdentityCertValidated, this, _1);
- OnDataValidationFailed onValidationFailed = bind(&ContactManager::onIdentityCertValidationFailed, this, _1, _2);
- TimeoutNotify timeoutNotify = bind(&ContactManager::onIdentityCertTimeoutNotify, this, _1);
+ OnDataValidated onValidated =
+ bind(&ContactManager::onIdentityCertValidated, this, _1);
+ OnDataValidationFailed onValidationFailed =
+ bind(&ContactManager::onIdentityCertValidationFailed, this, _1, _2);
+ TimeoutNotify timeoutNotify =
+ bind(&ContactManager::onIdentityCertTimeoutNotify, this, _1);
- sendInterest(interest, onValidated, onValidationFailed, timeoutNotify, 0);
- }
-
+ sendInterest(interest, onValidated, onValidationFailed, timeoutNotify, 0);
+ }
}
void
ContactManager::onFetchIdCert(const QString& qCertName)
{
Name certName(qCertName.toStdString());
- if(m_bufferedIdCerts.find(certName) != m_bufferedIdCerts.end())
- {
- emit idCertReady(*m_bufferedIdCerts[certName]);
- }
+ if (m_bufferedIdCerts.find(certName) != m_bufferedIdCerts.end())
+ emit idCertReady(*m_bufferedIdCerts[certName]);
}
void
@@ -841,41 +827,35 @@
Name identity = IdentityCertificate::certificateNameToPublicKeyName(certName).getPrefix(-1);
BufferedIdCerts::const_iterator it = m_bufferedIdCerts.find(certName);
- if(it != m_bufferedIdCerts.end())
- {
- Contact contact(*it->second);
- try
- {
- m_contactStorage->addContact(contact);
- m_bufferedIdCerts.erase(certName);
+ if (it != m_bufferedIdCerts.end()) {
+ Contact contact(*it->second);
+ try {
+ m_contactStorage->addContact(contact);
+ m_bufferedIdCerts.erase(certName);
- m_contactList.clear();
- m_contactStorage->getAllContacts(m_contactList);
+ m_contactList.clear();
+ m_contactStorage->getAllContacts(m_contactList);
- onWaitForContactList();
- }
- catch(ContactStorage::Error& e)
- {
- emit warning(QString::fromStdString(e.what()));
- }
+ onWaitForContactList();
}
+ catch(ContactStorage::Error& e) {
+ emit warning(QString::fromStdString(e.what()));
+ }
+ }
else
- emit warning(QString("Failure: no information of %1").arg(QString::fromStdString(identity.toUri())));
+ emit warning(QString("Failure: no information of %1")
+ .arg(QString::fromStdString(identity.toUri())));
}
void
ContactManager::onWaitForContactList()
{
- ContactList::const_iterator it = m_contactList.begin();
- ContactList::const_iterator end = m_contactList.end();
-
QStringList aliasList;
QStringList idList;
- for(; it != end; it++)
- {
- aliasList << QString((*it)->getAlias().c_str());
- idList << QString((*it)->getNameSpace().toUri().c_str());
- }
+ for (ContactList::const_iterator it = m_contactList.begin(); it != m_contactList.end(); it++) {
+ aliasList << QString((*it)->getAlias().c_str());
+ idList << QString((*it)->getNameSpace().toUri().c_str());
+ }
emit contactAliasListReady(aliasList);
emit contactIdListReady(idList);
@@ -884,11 +864,8 @@
void
ContactManager::onWaitForContactInfo(const QString& identity)
{
- ContactList::const_iterator it = m_contactList.begin();
- ContactList::const_iterator end = m_contactList.end();
-
- for(; it != end; it++)
- if((*it)->getNameSpace().toUri() == identity.toStdString())
+ for (ContactList::const_iterator it = m_contactList.begin(); it != m_contactList.end(); it++)
+ if ((*it)->getNameSpace().toUri() == identity.toStdString())
emit contactInfoReady(QString((*it)->getNameSpace().toUri().c_str()),
QString((*it)->getName().c_str()),
QString((*it)->getInstitution().c_str()),
@@ -927,7 +904,7 @@
Name identityName(identity.toStdString());
shared_ptr<EndorseCertificate> newEndorseCertificate = generateEndorseCertificate(identityName);
- if(!static_cast<bool>(newEndorseCertificate))
+ if (!static_cast<bool>(newEndorseCertificate))
return;
m_contactStorage->addEndorseCertificate(*newEndorseCertificate, identityName);