Skip to content

Commit

Permalink
api-changes: Use ndn-cpp-dev
Browse files Browse the repository at this point in the history
Change-Id: I4540e601106598d51601e59e5fe9524a9080a572
  • Loading branch information
bruinfish authored and cawka committed May 9, 2014
1 parent b6fb030 commit fa4ce79
Show file tree
Hide file tree
Showing 56 changed files with 2,084 additions and 3,054 deletions.
2 changes: 1 addition & 1 deletion ChronoSync
86 changes: 25 additions & 61 deletions src/addcontactpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#include <QMessageBox>

#ifndef Q_MOC_RUN
#include <ndn-cpp-dev/security/verifier.hpp>
#include <ndn-cpp-dev/security/validator.hpp>
#include <boost/iostreams/stream.hpp>
#include "endorse-collection.pb.h"
#include "logging.h"
#endif

using namespace ndn;
using namespace ndn::ptr_lib;
using namespace chronos;
using namespace std;

INIT_LOGGER("AddContactPanel");
Expand All @@ -35,7 +35,7 @@ AddContactPanel::AddContactPanel(shared_ptr<ContactManager> contactManager,
ui->setupUi(this);

qRegisterMetaType<ndn::Name>("NdnName");
qRegisterMetaType<EndorseCertificate>("EndorseCertificate");
qRegisterMetaType<chronos::EndorseCertificate>("EndorseCertificate");
qRegisterMetaType<ndn::Data>("NdnData");

connect(ui->cancelButton, SIGNAL(clicked()),
Expand All @@ -44,16 +44,16 @@ AddContactPanel::AddContactPanel(shared_ptr<ContactManager> contactManager,
this, SLOT(onSearchClicked()));
connect(ui->addButton, SIGNAL(clicked()),
this, SLOT(onAddClicked()));
connect(&*m_contactManager, SIGNAL(contactFetched(const EndorseCertificate&)),
this, SLOT(selfEndorseCertificateFetched(const EndorseCertificate&)));
connect(&*m_contactManager, SIGNAL(contactFetched(const chronos::EndorseCertificate&)),
this, SLOT(selfEndorseCertificateFetched(const chronos::EndorseCertificate&)));
connect(&*m_contactManager, SIGNAL(contactFetchFailed(const ndn::Name&)),
this, SLOT(selfEndorseCertificateFetchFailed(const ndn::Name&)));
connect(&*m_contactManager, SIGNAL(collectEndorseFetched(const ndn::Data&)),
this, SLOT(onCollectEndorseFetched(const ndn::Data&)));
connect(&*m_contactManager, SIGNAL(collectEndorseFetchFailed(const ndn::Name&)),
this, SLOT(onCollectEndorseFetchFailed(const ndn::Name&)));
connect(&*m_contactManager, SIGNAL(contactKeyFetched(const EndorseCertificate&)),
this, SLOT(onContactKeyFetched(const EndorseCertificate&)));
connect(&*m_contactManager, SIGNAL(contactKeyFetched(const chronos::EndorseCertificate&)),
this, SLOT(onContactKeyFetched(const chronos::EndorseCertificate&)));
connect(&*m_contactManager, SIGNAL(contactKeyFetchFailed(const ndn::Name&)),
this, SLOT(onContactKeyFetchFailed(const ndn::Name&)));

Expand Down Expand Up @@ -100,16 +100,13 @@ AddContactPanel::onSearchClicked()
bool
AddContactPanel::isCorrectName(const Name& name)
{
string key("KEY");
string idCert("ID-CERT");

if(name.get(-1).toEscapedString() != idCert)
if(name.get(-1).toEscapedString() != "ID-CERT")
return false;

int keyIndex = -1;
for(int i = 0; i < name.size(); i++)
{
if(name.get(i).toEscapedString() == key)
if(name.get(i).toEscapedString() == "KEY")
{
keyIndex = i;
break;
Expand All @@ -128,7 +125,7 @@ AddContactPanel::onAddClicked()
ContactItem contactItem(*m_currentEndorseCertificate);
try{
m_contactManager->getContactStorage()->addContact(contactItem);
}catch(std::exception& e){
}catch(ContactStorage::Error& e){
QMessageBox::information(this, tr("Chronos"), QString::fromStdString(e.what()));
_LOG_ERROR("Exception: " << e.what());
return;
Expand All @@ -140,13 +137,9 @@ AddContactPanel::onAddClicked()
void
AddContactPanel::selfEndorseCertificateFetched(const EndorseCertificate& endorseCertificate)
{
try{
m_currentEndorseCertificate = make_shared<EndorseCertificate>(endorseCertificate);
}catch(std::exception& e){
QMessageBox::information(this, tr("Chronos"), QString::fromStdString(e.what()));
_LOG_ERROR("Exception: " << e.what());
return;
}

m_currentEndorseCertificate = make_shared<EndorseCertificate>(endorseCertificate);

m_currentEndorseCertificateReady = true;

if(m_currentCollectEndorseReady == true)
Expand All @@ -162,13 +155,7 @@ AddContactPanel::selfEndorseCertificateFetchFailed(const Name& identity)
void
AddContactPanel::onContactKeyFetched(const EndorseCertificate& endorseCertificate)
{
try{
m_currentEndorseCertificate = make_shared<EndorseCertificate>(endorseCertificate);
}catch(std::exception& e){
QMessageBox::information(this, tr("Chronos"), QString::fromStdString(e.what()));
_LOG_ERROR("Exception: " << e.what());
return;
}
m_currentEndorseCertificate = make_shared<EndorseCertificate>(endorseCertificate);

m_currentCollectEndorseReady = false;

Expand All @@ -185,6 +172,7 @@ void
AddContactPanel::onCollectEndorseFetched(const Data& data)
{
m_currentCollectEndorse = make_shared<Data>(data);

m_currentCollectEndorseReady = true;

if(m_currentEndorseCertificateReady == true)
Expand All @@ -195,6 +183,7 @@ void
AddContactPanel::onCollectEndorseFetchFailed(const Name& identity)
{
m_currentCollectEndorse = shared_ptr<Data>();

m_currentCollectEndorseReady = true;

if(m_currentEndorseCertificateReady == true)
Expand All @@ -205,13 +194,11 @@ void
AddContactPanel::displayContactInfo()
{
// _LOG_TRACE("displayContactInfo");
const Profile& profile = m_currentEndorseCertificate->getProfileData().getProfile();
const Block& profileContent = m_currentEndorseCertificate->getProfileData().getContent();
Buffer profileBlock(profileContent.value(), profileContent.value_size());
const Profile& profile = m_currentEndorseCertificate->getProfile();

map<string, int> endorseCount;

if(static_cast<bool>(m_currentCollectEndorse))
if(!static_cast<bool>(m_currentCollectEndorse))
{
Chronos::EndorseCollection endorseCollection;

Expand All @@ -229,29 +216,27 @@ AddContactPanel::displayContactInfo()
endorseCollection.endorsement(i).blob().size()));
EndorseCertificate endorseCert(data);

Name signerKeyName = endorseCert.getSigner();
Name signerName = signerKeyName.getPrefix(-1);
Name signerName = endorseCert.getSigner().getPrefix(-1);

shared_ptr<ContactItem> contact = m_contactManager->getContact(signerName);
if(static_cast<bool>(contact))
if(!static_cast<bool>(contact))
continue;

if(!contact->isIntroducer() || !contact->canBeTrustedFor(m_currentEndorseCertificate->getProfileData().getIdentityName()))
if(!contact->isIntroducer() || !contact->canBeTrustedFor(m_currentEndorseCertificate->getProfile().getIdentityName()))
continue;

if(!Verifier::verifySignature(data, data.getSignature(), contact->getSelfEndorseCertificate().getPublicKeyInfo()))
if(!Validator::verifySignature(data, data.getSignature(), contact->getSelfEndorseCertificate().getPublicKeyInfo()))
continue;

const Block& tmpProfileContent = endorseCert.getProfileData().getContent();
Buffer tmpProfileBlock(tmpProfileContent.value(), tmpProfileContent.value_size());
if(profileBlock != tmpProfileBlock)
const Profile& tmpProfile = endorseCert.getProfile();
if(!(profile == tmpProfile))
continue;

const vector<string>& endorseList = endorseCert.getEndorseList();
vector<string>::const_iterator it = endorseList.begin();
for(; it != endorseList.end(); it++)
endorseCount[*it] += 1;
}catch(std::exception& e){
}catch(std::runtime_error& e){
continue;
}
}
Expand Down Expand Up @@ -289,27 +274,6 @@ AddContactPanel::displayContactInfo()
}
}

// bool
// AddContactPanel::isSameBlob(const ndn::Blob& blobA, const ndn::Blob& blobB)
// {
// size_t size = blobA.size();

// if(size != blobB.size())
// return false;

// const uint8_t* ap = blobA.buf();
// const uint8_t* bp = blobB.buf();

// for(int i = 0; i < size; i++)
// {
// if(ap[i] != bp[i])
// return false;
// }

// return true;

// }


#if WAF
#include "addcontactpanel.moc"
Expand Down
14 changes: 7 additions & 7 deletions src/addcontactpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AddContactPanel;

Q_DECLARE_METATYPE(ndn::Name)

Q_DECLARE_METATYPE(EndorseCertificate)
Q_DECLARE_METATYPE(chronos::EndorseCertificate)

Q_DECLARE_METATYPE(ndn::Data)

Expand All @@ -36,7 +36,7 @@ class AddContactPanel : public QDialog
Q_OBJECT

public:
explicit AddContactPanel(ndn::ptr_lib::shared_ptr<ContactManager> contactManager,
explicit AddContactPanel(ndn::shared_ptr<chronos::ContactManager> contactManager,
QWidget *parent = 0);

~AddContactPanel();
Expand All @@ -62,13 +62,13 @@ private slots:
onAddClicked();

void
selfEndorseCertificateFetched(const EndorseCertificate& endorseCertificate);
selfEndorseCertificateFetched(const chronos::EndorseCertificate& endorseCertificate);

void
selfEndorseCertificateFetchFailed(const ndn::Name& identity);

void
onContactKeyFetched(const EndorseCertificate& endorseCertificate);
onContactKeyFetched(const chronos::EndorseCertificate& endorseCertificate);

void
onContactKeyFetchFailed(const ndn::Name& identity);
Expand All @@ -87,10 +87,10 @@ private slots:

Ui::AddContactPanel *ui;
ndn::Name m_searchIdentity;
ndn::ptr_lib::shared_ptr<ContactManager> m_contactManager;
ndn::shared_ptr<chronos::ContactManager> m_contactManager;
WarningDialog* m_warningDialog;
ndn::ptr_lib::shared_ptr<EndorseCertificate> m_currentEndorseCertificate;
ndn::ptr_lib::shared_ptr<ndn::Data> m_currentCollectEndorse;
ndn::shared_ptr<chronos::EndorseCertificate> m_currentEndorseCertificate;
ndn::shared_ptr<ndn::Data> m_currentCollectEndorse;
bool m_currentEndorseCertificateReady;
bool m_currentCollectEndorseReady;
};
Expand Down
11 changes: 5 additions & 6 deletions src/browsecontactdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
#include <boost/asio.hpp>
#include <boost/tokenizer.hpp>
#include "logging.h"
// #include "ndn.cxx/error.h"
#endif

using namespace std;
using namespace ndn;
using namespace ndn::ptr_lib;
using namespace chronos;

INIT_LOGGER("BrowseContactDialog");

Expand Down Expand Up @@ -65,7 +64,7 @@ BrowseContactDialog::~BrowseContactDialog()


void
BrowseContactDialog::getCertNames(std::vector<std::string> &names)
BrowseContactDialog::getCertNames(vector<string> &names)
{
try{
using namespace boost::asio::ip;
Expand Down Expand Up @@ -215,7 +214,7 @@ BrowseContactDialog::onCertificateFetched(const IdentityCertificate& identityCer
_LOG_DEBUG("Fetch: " << certNameNoVersion.toUri());
m_certificateMap.insert(pair<Name, IdentityCertificate>(certNameNoVersion, identityCertificate));
m_profileMap.insert(pair<Name, Profile>(certNameNoVersion, Profile(identityCertificate)));
string name = m_profileMap[certNameNoVersion].getProfileEntry("name");
string name = m_profileMap[certNameNoVersion].get("name");
// Name contactName = m_profileMap[certNameNoVersion].getIdentityName();
{
UniqueRecLock lock(m_mutex);
Expand Down Expand Up @@ -249,8 +248,8 @@ BrowseContactDialog::refreshList()
}

void
BrowseContactDialog::updateSelection(const QItemSelection &selected,
const QItemSelection &deselected)
BrowseContactDialog::updateSelection(const QItemSelection& selected,
const QItemSelection& deselected)
{
QModelIndexList items = selected.indexes();
Name certName = m_contactNameList[items.first().row()];
Expand Down
10 changes: 4 additions & 6 deletions src/browsecontactdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BrowseContactDialog : public QDialog
Q_OBJECT

public:
explicit BrowseContactDialog(ndn::ptr_lib::shared_ptr<ContactManager> contactManager,
explicit BrowseContactDialog(ndn::shared_ptr<chronos::ContactManager> contactManager,
QWidget *parent = 0);

~BrowseContactDialog();
Expand All @@ -46,7 +46,7 @@ class BrowseContactDialog : public QDialog

private:
void
getCertNames(std::vector<std::string> &names);
getCertNames(std::vector<std::string>& names);

void
updateCertificateMap(bool filter = false);
Expand Down Expand Up @@ -95,7 +95,7 @@ public slots:
private:
Ui::BrowseContactDialog *ui;

ndn::ptr_lib::shared_ptr<ContactManager> m_contactManager;
ndn::shared_ptr<chronos::ContactManager> m_contactManager;

WarningDialog* m_warningDialog;
QStringListModel* m_contactListModel;
Expand All @@ -104,11 +104,9 @@ public slots:
std::vector<ndn::Name> m_contactNameList;
std::vector<ndn::Name> m_certificateNameList;
std::map<ndn::Name, ndn::IdentityCertificate> m_certificateMap;
std::map<ndn::Name, Profile> m_profileMap;
std::map<ndn::Name, chronos::Profile> m_profileMap;

RecLock m_mutex;


};

#endif // BROWSECONTACTDIALOG_H
Loading

0 comments on commit fa4ce79

Please sign in to comment.