security: Cleaning up all security stuff...
diff --git a/src/sec-policy-sync.cc b/src/sec-policy-sync.cc
deleted file mode 100644
index 0f4db3e..0000000
--- a/src/sec-policy-sync.cc
+++ /dev/null
@@ -1,440 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- * Yingdi Yu
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Yingdi Yu <yingdi@cs.ucla.edu>
- */
-
-#include "sync-intro-certificate.h"
-#include "sync-logging.h"
-#include <ndn-cpp-dev/security/verifier.hpp>
-#include <ndn-cpp-dev/security/signature-sha256-with-rsa.hpp>
-
-#include "sec-policy-sync.h"
-
-using namespace ndn;
-using namespace ndn::ptr_lib;
-using namespace std;
-
-INIT_LOGGER("SecPolicySync");
-
-SecPolicySync::SecPolicySync(const Name& signingIdentity,
- const Name& signingCertificateName,
- const Name& syncPrefix,
- shared_ptr<Face> face,
- int stepLimit)
- : m_signingIdentity(signingIdentity)
- , m_signingCertificateName(signingCertificateName.getPrefix(signingCertificateName.size()-1))
- , m_syncPrefix(syncPrefix)
- , m_stepLimit(stepLimit)
- , m_keyChain(new KeyChain())
-{
- m_introCertPrefix = syncPrefix;
- m_introCertPrefix.append("WOT");
-
- m_syncDataPolicy = make_shared<SecRuleRelative>("^[^<%F0\\.>]*<%F0\\.>([^<chronos>]*)<chronos><>",
- "^([^<KEY>]*)<KEY>(<>*)[<dsk-.*><ksk-.*>]<ID-CERT>$",
- "==", "\\1", "\\1", true);
-}
-
-SecPolicySync::~SecPolicySync()
-{}
-
-bool
-SecPolicySync::skipVerifyAndTrust (const Data& data)
-{ return false; }
-
-bool
-SecPolicySync::requireVerify (const Data& data)
-{ return true; }
-
-shared_ptr<ValidationRequest>
-SecPolicySync::checkVerificationPolicy(const shared_ptr<Data>& data,
- int stepCount,
- const OnVerified& onVerified,
- const OnVerifyFailed& onVerifyFailed)
-{
- if(stepCount > m_stepLimit)
- {
- onVerifyFailed(data);
- return shared_ptr<ValidationRequest>();
- }
-
- try{
- SignatureSha256WithRsa sig(data->getSignature());
- const Name& keyLocatorName = sig.getKeyLocator().getName();
-
- // if data is intro cert
- if(m_introCertPrefix.isPrefixOf(data->getName()))
- {
- Name keyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName);
- map<Name, PublicKey>::const_iterator it = m_trustedIntroducers.find(keyName);
- if(m_trustedIntroducers.end() != it)
- {
- if(Verifier::verifySignature(*data, sig, it->second))
- onVerified(data);
- else
- onVerifyFailed(data);
- return shared_ptr<ValidationRequest>();
- }
- else
- return prepareRequest(keyName, true, data, stepCount, onVerified, onVerifyFailed);
- }
-
- // if data is diff data or sync data
- if(m_syncPrefix.isPrefixOf(data->getName()) || m_syncDataPolicy->satisfy(*data))
- {
- Name keyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName);
-
- map<Name, PublicKey>::const_iterator it = m_trustedIntroducers.find(keyName);
- if(m_trustedIntroducers.end() != it)
- {
- if(Verifier::verifySignature(*data, sig, it->second))
- onVerified(data);
- else
- onVerifyFailed(data);
- return shared_ptr<ValidationRequest>();
- }
-
- it = m_trustedProducers.find(keyName);
- if(m_trustedProducers.end() != it)
- {
- if(Verifier::verifySignature(*data, sig, it->second))
- onVerified(data);
- else
- onVerifyFailed(data);
- return shared_ptr<ValidationRequest>();
- }
-
- return prepareRequest(keyName, false, data, stepCount, onVerified, onVerifyFailed);
- }
-
- }catch(SignatureSha256WithRsa::Error &e){
- _LOG_DEBUG("SecPolicySync Error: " << e.what());
- onVerifyFailed(data);
- return shared_ptr<ValidationRequest>();
- }catch(KeyLocator::Error &e){
- _LOG_DEBUG("SecPolicySync Error: " << e.what());
- onVerifyFailed(data);
- return shared_ptr<ValidationRequest>();
- }
-
- onVerifyFailed(data);
- return shared_ptr<ValidationRequest>();
-}
-
-bool
-SecPolicySync::checkSigningPolicy(const Name& dataName,
- const Name& certificateName)
-{
- return true;
-}
-
-Name
-SecPolicySync::inferSigningIdentity(const ndn::Name& dataName)
-{ return m_signingIdentity; }
-
-void
-SecPolicySync::addTrustAnchor(const IdentityCertificate& identityCertificate, bool isIntroducer)
-{
- Name publicKeyName = identityCertificate.getPublicKeyName();
-
- _LOG_DEBUG("Add intro/producer: " << publicKeyName);
-
- if(isIntroducer)
- m_trustedIntroducers[publicKeyName] = identityCertificate.getPublicKeyInfo();
- else
- m_trustedProducers[publicKeyName] = identityCertificate.getPublicKeyInfo();
-}
-
-void
-SecPolicySync::addSyncDataRule(const Name& prefix,
- const IdentityCertificate& identityCertificate,
- bool isIntroducer)
-{ addTrustAnchor(identityCertificate, isIntroducer); }
-
-
-shared_ptr<const vector<Name> >
-SecPolicySync::getAllIntroducerName()
-{
- shared_ptr<vector<Name> > nameList = make_shared<vector<Name> >();
-
- map<Name, PublicKey>::iterator it = m_trustedIntroducers.begin();
- for(; it != m_trustedIntroducers.end(); it++)
- nameList->push_back(it->first);
-
- return nameList;
-}
-
-shared_ptr<ValidationRequest>
-SecPolicySync::prepareRequest(const Name& keyName,
- bool forIntroducer,
- shared_ptr<Data> data,
- const int & stepCount,
- const OnVerified& onVerified,
- const OnVerifyFailed& onVerifyFailed)
-{
- Name interestPrefix = m_syncPrefix;
- interestPrefix.append("WOT").append(keyName.wireEncode()).append("INTRO-CERT");
-
- shared_ptr<const vector<Name> > nameList = getAllIntroducerName();
- if(0 == nameList->size())
- {
- onVerifyFailed(data);
- return shared_ptr<ValidationRequest>();
- }
-
- Name interestName = interestPrefix;
- interestName.append(nameList->at(0).wireEncode());
-
- if(forIntroducer)
- interestName.append("INTRODUCER");
-
- shared_ptr<ndn::Interest> interest = make_shared<ndn::Interest>(interestName);
-
- OnVerified introCertVerified = func_lib::bind(&SecPolicySync::onIntroCertVerified,
- this,
- _1,
- forIntroducer,
- data,
- onVerified,
- onVerifyFailed);
-
- OnVerifyFailed introCertVerifyFailed = func_lib::bind(&SecPolicySync::onIntroCertVerifyFailed,
- this,
- _1,
- interestPrefix,
- forIntroducer,
- nameList,
- 1,
- data,
- onVerified,
- onVerifyFailed);
-
-
- shared_ptr<ValidationRequest> nextStep = make_shared<ValidationRequest>(interest,
- introCertVerified,
- introCertVerifyFailed,
- 1,
- m_stepLimit-1);
- return nextStep;
-}
-
-void
-SecPolicySync::OnIntroCertInterest(const shared_ptr<const Name>& prefix,
- const shared_ptr<const ndn::Interest>& interest,
- Transport& transport,
- uint64_t registeredPrefixId)
-{
- map<Name, Data>::const_iterator it = m_introCert.find(*prefix);
-
- if(m_introCert.end() != it)
- m_face->put(it->second);
-}
-
-void
-SecPolicySync::OnIntroCertRegisterFailed(const shared_ptr<const Name>& prefix)
-{
-}
-
-void
-SecPolicySync::onIntroCertVerified(const shared_ptr<Data>& introCertificateData,
- bool forIntroducer,
- shared_ptr<Data> originalData,
- const OnVerified& onVerified,
- const OnVerifyFailed& onVerifyFailed)
-{
- shared_ptr<SyncIntroCertificate> introCertificate = make_shared<SyncIntroCertificate>(*introCertificateData);
- Name subjectKeyName = introCertificate->getPublicKeyName();
-
- if(forIntroducer)
- {
- //Add the intro cert subject as trusted introducer.
- m_trustedIntroducers[subjectKeyName] = introCertificate->getPublicKeyInfo();
-
- //Generate another intro cert for the cert subject.
- SyncIntroCertificate syncIntroCertificate(m_syncPrefix,
- subjectKeyName,
- m_keyChain->getDefaultKeyNameForIdentity(m_signingIdentity),
- introCertificate->getNotBefore(),
- introCertificate->getNotAfter(),
- introCertificate->getPublicKeyInfo(),
- SyncIntroCertificate::INTRODUCER);
- m_keyChain->signByIdentity(syncIntroCertificate, m_signingIdentity);
- m_face->put(syncIntroCertificate);
-
- // Name prefix = syncIntroCertificate.getName().getPrefix(syncIntroCertificate.getName().size()-1);
-
- // map<string, Data>::const_iterator it = m_introCert.find(prefix);
- // if(m_introCert.end() != it)
- // {
- // it->second = syncIntroCertificate;
- // }
- // else
- // {
- // m_introCert.insert(pair <Name, Data> (prefix, syncIntroCertificate));
- // m_face->registerPrefix(prefix,
- // boost::bind(&SecPolicySync::onIntroCertInterest, this, _1, _2, _3, _4),
- // boost::bind(&SecPolicySync::onIntroCertRegisterFailed, this, _1));
- // }
- }
- else
- {
- //Add the intro cert subject as trusted producer.
- m_trustedProducers[subjectKeyName] = introCertificate->getPublicKeyInfo();
-
- //Generate another intro cert for the cert subject.
- SyncIntroCertificate syncIntroCertificate(m_syncPrefix,
- subjectKeyName,
- m_keyChain->getDefaultKeyNameForIdentity(m_signingIdentity),
- introCertificate->getNotBefore(),
- introCertificate->getNotAfter(),
- introCertificate->getPublicKeyInfo(),
- SyncIntroCertificate::PRODUCER);
- m_keyChain->signByIdentity(syncIntroCertificate, m_signingIdentity);
- m_face->put(syncIntroCertificate);
-
- // Name prefix = syncIntroCertificate.getName().getPrefix(syncIntroCertificate.getName().size()-1);
-
- // map<string, Data>::const_iterator it = m_introCert.find(prefix);
- // if(m_introCert.end() != it)
- // {
- // it->second = syncIntroCertificate;
- // }
- // else
- // {
- // m_introCert.insert(pair <Name, Data> (prefix, syncIntroCertificate));
- // m_face->registerPrefix(prefix,
- // boost::bind(&SecPolicySync::onIntroCertInterest, this, _1, _2, _3, _4),
- // boost::bind(&SecPolicySync::onIntroCertRegisterFailed, this, _1));
- // }
- }
-
- try{
- SignatureSha256WithRsa sig(originalData->getSignature());
- if(Verifier::verifySignature(*originalData, sig, introCertificate->getPublicKeyInfo()))
- onVerified(originalData);
- else
- onVerifyFailed(originalData);
- }catch(SignatureSha256WithRsa::Error &e){
- onVerifyFailed(originalData);
- }catch(KeyLocator::Error &e){
- onVerifyFailed(originalData);
- }
-}
-
-void
-SecPolicySync::onIntroCertVerifyFailed(const shared_ptr<Data>& introCertificateData,
- Name interestPrefix,
- bool forIntroducer,
- shared_ptr<const vector<Name> > introNameList,
- int nextIntroducerIndex,
- shared_ptr<Data> originalData,
- const OnVerified& onVerified,
- const OnVerifyFailed& onVerifyFailed)
-{
- Name interestName = interestPrefix;
- if(nextIntroducerIndex < introNameList->size())
- interestName.append(introNameList->at(nextIntroducerIndex).wireEncode());
- else
- onVerifyFailed(originalData);
-
- if(forIntroducer)
- interestName.append("INTRODUCER");
-
- ndn::Interest interest(interestName);
-
- OnVerified introCertVerified = func_lib::bind(&SecPolicySync::onIntroCertVerified,
- this,
- _1,
- forIntroducer,
- originalData,
- onVerified,
- onVerifyFailed);
-
- OnVerifyFailed introCertVerifyFailed = func_lib::bind(&SecPolicySync::onIntroCertVerifyFailed,
- this,
- _1,
- interestPrefix,
- forIntroducer,
- introNameList,
- nextIntroducerIndex + 1,
- originalData,
- onVerified,
- onVerifyFailed);
-
- m_face->expressInterest(interest,
- func_lib::bind(&SecPolicySync::onIntroCertData,
- this,
- _1,
- _2,
- m_stepLimit-1,
- introCertVerified,
- introCertVerifyFailed),
- func_lib::bind(&SecPolicySync::onIntroCertTimeout,
- this,
- _1,
- 1,
- m_stepLimit-1,
- introCertVerified,
- introCertVerifyFailed)
- );
-}
-
-void
-SecPolicySync::onIntroCertData(const shared_ptr<const ndn::Interest> &interest,
- const shared_ptr<Data>& introCertificateData,
- int stepCount,
- const OnVerified& introCertVerified,
- const OnVerifyFailed& introCertVerifyFailed)
-{
- shared_ptr<ValidationRequest> nextStep = checkVerificationPolicy(introCertificateData, stepCount, introCertVerified, introCertVerifyFailed);
- if (nextStep)
- m_face->expressInterest(*nextStep->interest_,
- func_lib::bind(&SecPolicySync::onIntroCertData,
- this,
- _1,
- _2,
- nextStep->stepCount_,
- nextStep->onVerified_,
- nextStep->onVerifyFailed_),
- func_lib::bind(&SecPolicySync::onIntroCertTimeout,
- this,
- _1,
- nextStep->retry_,
- nextStep->stepCount_,
- nextStep->onVerified_,
- nextStep->onVerifyFailed_)
- );
-}
-
-void
-SecPolicySync::onIntroCertTimeout(const shared_ptr<const ndn::Interest>& interest,
- int retry,
- int stepCount,
- const OnVerified& introCertVerified,
- const OnVerifyFailed& introCertVerifyFailed)
-{
- if(retry > 0)
- m_face->expressInterest(*interest,
- func_lib::bind(&SecPolicySync::onIntroCertData,
- this,
- _1,
- _2,
- stepCount,
- introCertVerified,
- introCertVerifyFailed),
- func_lib::bind(&SecPolicySync::onIntroCertTimeout,
- this,
- _1,
- retry - 1,
- stepCount,
- introCertVerified,
- introCertVerifyFailed)
- );
- else
- introCertVerifyFailed(shared_ptr<Data>());
-}
diff --git a/src/sec-policy-sync.h b/src/sec-policy-sync.h
deleted file mode 100644
index 2ecac0f..0000000
--- a/src/sec-policy-sync.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- * Yingdi Yu
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Yingdi Yu <yingdi@cs.ucla.edu>
- */
-
-#ifndef SEC_POLICY_SYNC_H
-#define SEC_POLICY_SYNC_H
-
-#include <ndn-cpp-dev/face.hpp>
-#include <ndn-cpp-dev/security/key-chain.hpp>
-#include <ndn-cpp-dev/security/verifier.hpp>
-#include <ndn-cpp-dev/security/sec-policy.hpp>
-#include <ndn-cpp-dev/security/identity-certificate.hpp>
-#include <ndn-cpp-et/policy/sec-rule-relative.hpp>
-// #include <ndn-cpp-et/policy/sec-rule-specific.hpp>
-#include <map>
-
-class SecPolicySync : public ndn::SecPolicy
-{
-public:
- SecPolicySync(const ndn::Name& signingIdentity,
- const ndn::Name& signingCertificateName,
- const ndn::Name& syncPrefix,
- ndn::ptr_lib::shared_ptr<ndn::Face> face,
- int m_stepLimit = 3);
-
- virtual
- ~SecPolicySync();
-
- bool
- skipVerifyAndTrust (const ndn::Data& data);
-
- bool
- requireVerify (const ndn::Data& data);
-
- ndn::ptr_lib::shared_ptr<ndn::ValidationRequest>
- checkVerificationPolicy(const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
- int stepCount,
- const ndn::OnVerified& onVerified,
- const ndn::OnVerifyFailed& onVerifyFailed);
-
- bool
- checkSigningPolicy(const ndn::Name& dataName,
- const ndn::Name& certificateName);
-
- ndn::Name
- inferSigningIdentity(const ndn::Name& dataName);
-
- void
- addTrustAnchor(const ndn::IdentityCertificate& identityCertificate, bool isIntroducer);
-
- void
- addSyncDataRule(const ndn::Name& prefix,
- const ndn::IdentityCertificate& identityCertificate,
- bool isIntroducer);
-
-private:
-
- ndn::ptr_lib::shared_ptr<ndn::ValidationRequest>
- prepareIntroducerRequest(const ndn::Name& keyName,
- ndn::ptr_lib::shared_ptr<ndn::Data> data,
- const int & stepCount,
- const ndn::OnVerified& onVerified,
- const ndn::OnVerifyFailed& onVerifyFailed);
-
- ndn::ptr_lib::shared_ptr<const std::vector<ndn::Name> >
- getAllIntroducerName();
-
- ndn::ptr_lib::shared_ptr<ndn::ValidationRequest>
- prepareRequest(const ndn::Name& keyName,
- bool forIntroducer,
- ndn::ptr_lib::shared_ptr<ndn::Data> data,
- const int & stepCount,
- const ndn::OnVerified& onVerified,
- const ndn::OnVerifyFailed& onVerifyFailed);
-
- void
- OnIntroCertInterest(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix,
- const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
- ndn::Transport& transport,
- uint64_t registeredPrefixId);
-
- void
- OnIntroCertRegisterFailed(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix);
-
- void
- onIntroCertVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& introCertificateData,
- bool forIntroducer,
- ndn::ptr_lib::shared_ptr<ndn::Data> originalData,
- const ndn::OnVerified& onVerified,
- const ndn::OnVerifyFailed& onVerifyFailed);
-
- void
- onIntroCertVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& introCertificateData,
- ndn::Name interestPrefix,
- bool forIntroducer,
- ndn::ptr_lib::shared_ptr<const std::vector<ndn::Name> > introNameList,
- int nextIntroducerIndex,
- ndn::ptr_lib::shared_ptr<ndn::Data> originalData,
- const ndn::OnVerified& onVerified,
- const ndn::OnVerifyFailed& onVerifyFailed);
-
- void
- onIntroCertData(const ndn::ptr_lib::shared_ptr<const ndn::Interest> &interest,
- const ndn::ptr_lib::shared_ptr<ndn::Data>& introCertificateData,
- int stepCount,
- const ndn::OnVerified& introCertVerified,
- const ndn::OnVerifyFailed& introCertVerifyFailed);
-
- void
- onIntroCertTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
- int retry,
- int stepCount,
- const ndn::OnVerified& introCertVerified,
- const ndn::OnVerifyFailed& introCertVerifyFailed);
-
-
-
-private:
- ndn::Name m_signingIdentity;
- ndn::Name m_signingCertificateName;
- ndn::Name m_syncPrefix;
- ndn::Name m_introCertPrefix;
- int m_stepLimit;
- ndn::ptr_lib::shared_ptr<ndn::SecRuleRelative> m_syncDataPolicy;
- std::map<ndn::Name, ndn::PublicKey> m_trustedIntroducers;
- std::map<ndn::Name, ndn::PublicKey> m_trustedProducers;
- // std::map<ndn::Name, SecRuleSyncSpecific> m_chatDataRules;
- std::map<ndn::Name, ndn::Data> m_introCert;
-
- ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
- ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
-
-};
-
-#endif
diff --git a/src/sync-digest.h b/src/sync-digest.h
index 7cef28f..ecc8522 100644
--- a/src/sync-digest.h
+++ b/src/sync-digest.h
@@ -103,11 +103,11 @@
operator << (const std::string &str);
/**
- * @brief Add uint32_t value to digest calculation
- * @param value uint32_t value to put into digest
+ * @brief Add uint64_t value to digest calculation
+ * @param value uint64_t value to put into digest
*/
inline Digest &
- operator << (uint32_t value);
+ operator << (uint64_t value);
/**
* @brief Checks if the stored hash is zero-root hash
@@ -153,9 +153,9 @@
}
inline Digest &
-Digest::operator << (uint32_t value)
+Digest::operator << (uint64_t value)
{
- update (reinterpret_cast<const uint8_t*> (&value), sizeof (uint32_t));
+ update (reinterpret_cast<const uint8_t*> (&value), sizeof (uint64_t));
return *this;
}
diff --git a/src/sync-intro-certificate.cc b/src/sync-intro-certificate.cc
deleted file mode 100644
index f335933..0000000
--- a/src/sync-intro-certificate.cc
+++ /dev/null
@@ -1,146 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- * Yingdi Yu
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Yingdi Yu <yingdi@cs.ucla.edu>
- */
-
-#include "sync-intro-certificate.h"
-
-using namespace ndn;
-using namespace std;
-using namespace boost;
-
-SyncIntroCertificate::SyncIntroCertificate ()
- : Certificate()
-{}
-
-SyncIntroCertificate::SyncIntroCertificate (const Name& nameSpace,
- const Name& keyName,
- const Name& signerName,
- const MillisecondsSince1970& notBefore,
- const MillisecondsSince1970& notAfter,
- const PublicKey& key,
- const IntroType& introType)
- : m_nameSpace(nameSpace)
- , m_keyName(keyName)
- , m_introType(introType)
-{
- Name certificateName = nameSpace;
- certificateName.append("WOT").append(keyName.wireEncode()).append("INTRO-CERT").append(signerName.wireEncode());
- switch(introType)
- {
- case PRODUCER:
- certificateName.append("PRODUCER");
- break;
- case INTRODUCER:
- certificateName.append("INTRODUCER");
- break;
- default:
- throw Error("Wrong Introduction Type!");
- }
- certificateName.appendVersion();
-
- Data::setName(certificateName);
- setNotBefore(notBefore);
- setNotAfter(notAfter);
- setPublicKeyInfo(key);
- addSubjectDescription(CertificateSubjectDescription("2.5.4.41", keyName.toUri()));
- encode();
-}
-
-SyncIntroCertificate::SyncIntroCertificate (const Name& nameSpace,
- const IdentityCertificate& identityCertificate,
- const Name& signerName,
- const IntroType& introType)
- : m_nameSpace(nameSpace)
- , m_introType(introType)
-{
- m_keyName = identityCertificate.getPublicKeyName();
-
- Name certificateName = nameSpace;
- certificateName.append("WOT").append(m_keyName.wireEncode()).append("INTRO-CERT").append(signerName.wireEncode());
- switch(introType)
- {
- case PRODUCER:
- certificateName.append("PRODUCER");
- break;
- case INTRODUCER:
- certificateName.append("INTRODUCER");
- break;
- default:
- throw Error("Wrong Introduction Type!");
- }
- certificateName.appendVersion();
-
- Data::setName(certificateName);
- setNotBefore(identityCertificate.getNotBefore());
- setNotAfter(identityCertificate.getNotAfter());
- setPublicKeyInfo(identityCertificate.getPublicKeyInfo());
- addSubjectDescription(CertificateSubjectDescription("2.5.4.41", m_keyName.toUri()));
-}
-
-SyncIntroCertificate::SyncIntroCertificate (const Data& data)
- : Certificate(data)
-{ setName(getName()); }
-
-SyncIntroCertificate::SyncIntroCertificate (const SyncIntroCertificate& chronosIntroCertificate)
- : Certificate(chronosIntroCertificate)
- , m_nameSpace(chronosIntroCertificate.m_nameSpace)
- , m_keyName(chronosIntroCertificate.m_keyName)
- , m_introType(chronosIntroCertificate.m_introType)
-{}
-
-Data &
-SyncIntroCertificate::setName (const Name& certificateName)
-{
- int nameLength = certificateName.size();
-
- if(nameLength < 6)
- throw Error("Wrong SyncIntroCertificate Name!");
-
- m_nameSpace = certificateName.getPrefix(-6);
-
- if(!certificateName.get(-6).equals("WOT"))
- throw Error("Wrong SyncIntroCertificate Name!");
-
- m_keyName.wireDecode(Block(certificateName.get(-5).getValue().buf(),
- certificateName.get(-5).getValue().size()));
-
- if(!certificateName.get(-4).equals("INTRO-CERT"))
- throw Error("Wrong SyncIntroCertificate Name!");
-
- if(certificateName.get(-2).equals("PRODUCER"))
- m_introType = PRODUCER;
- else if(certificateName.get(-2).equals("INTRODUCER"))
- m_introType = INTRODUCER;
- else
- throw Error("Wrong SyncIntroCertificate Name!");
-
- return *this;
-}
-
-bool
-SyncIntroCertificate::isSyncIntroCertificate(const Certificate& certificate)
-{
- const Name& certificateName = certificate.getName();
-
- int nameLength = certificateName.size();
-
- if(nameLength < 6)
- return false;
-
- if(!certificateName.get(-6).equals("WOT"))
- return false;
-
- if(!certificateName.get(-4).equals("INTRO-CERT"))
- return false;
-
- if(!certificateName.get(-2).equals("PRODUCER") && !certificateName.get(-2).equals("INTRODUCER"))
- return false;
-
- return true;
-}
diff --git a/src/sync-intro-certificate.h b/src/sync-intro-certificate.h
deleted file mode 100644
index c9560ec..0000000
--- a/src/sync-intro-certificate.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- * Yingdi Yu
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Yingdi Yu <yingdi@cs.ucla.edu>
- */
-
-#ifndef SYNC_INTRO_CERTIFICATE_H
-#define SYNC_INTRO_CERTIFICATE_H
-
-#include <ndn-cpp-dev/security/certificate.hpp>
-#include <ndn-cpp-dev/security/identity-certificate.hpp>
-
-class SyncIntroCertificate : public ndn::Certificate
-{
-public:
- struct Error : public ndn::Certificate::Error { Error(const std::string &what) : ndn::Certificate::Error(what) {} };
-
- enum IntroType{
- PRODUCER,
- INTRODUCER
- };
-
-public:
- SyncIntroCertificate ();
-
- SyncIntroCertificate (const ndn::Name& nameSpace,
- const ndn::Name& keyName,
- const ndn::Name& signerName,
- const ndn::MillisecondsSince1970& notBefore,
- const ndn::MillisecondsSince1970& notAfter,
- const ndn::PublicKey& key,
- const IntroType& introType = PRODUCER);
-
- SyncIntroCertificate (const ndn::Name& nameSpace,
- const ndn::IdentityCertificate& identityCertificate,
- const ndn::Name& signerName,
- const IntroType& introType);
-
- SyncIntroCertificate (const ndn::Data& data);
-
- SyncIntroCertificate (const SyncIntroCertificate& chronosIntroCertificate);
-
-
- virtual
- ~SyncIntroCertificate ()
- {}
-
- ndn::Data&
- setName (const ndn::Name& name);
-
- inline const ndn::Name &
- getPublicKeyName() const;
-
- inline IntroType
- getIntroType();
-
- inline const ndn::Name &
- getNameSpace() const;
-
- static bool
- isSyncIntroCertificate(const ndn::Certificate& certificate);
-
-protected:
- ndn::Name m_nameSpace;
- ndn::Name m_keyName;
- IntroType m_introType;
-};
-
-SyncIntroCertificate::IntroType
-SyncIntroCertificate::getIntroType()
-{ return m_introType; }
-
-const ndn::Name &
-SyncIntroCertificate::getPublicKeyName () const
-{ return m_keyName; }
-
-const ndn::Name &
-SyncIntroCertificate::getNameSpace() const
-{ return m_nameSpace; }
-
-#endif
diff --git a/src/sync-logic.cc b/src/sync-logic.cc
index 67fb342..293d90c 100644
--- a/src/sync-logic.cc
+++ b/src/sync-logic.cc
@@ -39,8 +39,6 @@
using namespace std;
using namespace ndn;
-using namespace ndn::ptr_lib;
-using namespace ndn::func_lib;
INIT_LOGGER ("SyncLogic");
@@ -61,7 +59,7 @@
{
SyncLogic::SyncLogic (const Name& syncPrefix,
- shared_ptr<SecPolicySync> policy,
+ shared_ptr<Validator> validator,
shared_ptr<Face> face,
LogicUpdateCallback onUpdate,
LogicRemoveCallback onRemove)
@@ -71,14 +69,14 @@
, m_onUpdate (onUpdate)
, m_onRemove (onRemove)
, m_perBranch (false)
- , m_policy(policy)
- , m_verifier(new Verifier(policy))
+ , m_validator(validator)
, m_keyChain(new KeyChain())
, m_face(face)
+ , m_scheduler(*face->ioService())
#ifndef NS3_MODULE
, m_randomGenerator (static_cast<unsigned int> (std::time (0)))
- , m_rangeUniformRandom (m_randomGenerator, uniform_int<> (200,1000))
- , m_reexpressionJitter (m_randomGenerator, uniform_int<> (100,500))
+ , m_rangeUniformRandom (m_randomGenerator, boost::uniform_int<> (200,1000))
+ , m_reexpressionJitter (m_randomGenerator, boost::uniform_int<> (100,500))
#else
, m_rangeUniformRandom (200,1000)
, m_reexpressionJitter (10,500)
@@ -88,19 +86,18 @@
#ifndef NS3_MODULE
// In NS3 module these functions are moved to StartApplication method
- m_syncRegisteredPrefixId = m_face->setInterestFilter(m_syncPrefix,
- func_lib::bind(&SyncLogic::onSyncInterest, this, _1, _2, _3, _4),
- func_lib::bind(&SyncLogic::onSyncRegisterFailed, this, _1));
+ m_syncRegisteredPrefixId = m_face->setInterestFilter (m_syncPrefix,
+ bind(&SyncLogic::onSyncInterest, this, _1, _2),
+ bind(&SyncLogic::onSyncRegisterFailed, this, _1));
+
-
- m_scheduler.schedule (TIME_SECONDS (0), // no need to add jitter
- func_lib::bind (&SyncLogic::sendSyncInterest, this),
- REEXPRESSING_INTEREST);
+ m_reexpressingInterestId = m_scheduler.scheduleEvent (time::seconds (0), // no need to add jitter
+ bind (&SyncLogic::sendSyncInterest, this));
#endif
}
SyncLogic::SyncLogic (const Name& syncPrefix,
- shared_ptr<SecPolicySync> policy,
+ shared_ptr<Validator> validator,
shared_ptr<Face> face,
LogicPerBranchCallback onUpdateBranch)
: m_state (new FullState)
@@ -108,14 +105,14 @@
, m_syncPrefix (syncPrefix)
, m_onUpdateBranch (onUpdateBranch)
, m_perBranch(true)
- , m_policy(policy)
- , m_verifier(new Verifier(policy))
+ , m_validator(validator)
, m_keyChain(new KeyChain())
, m_face(face)
+ , m_scheduler(*face->ioService())
#ifndef NS3_MODULE
, m_randomGenerator (static_cast<unsigned int> (std::time (0)))
- , m_rangeUniformRandom (m_randomGenerator, uniform_int<> (200,1000))
- , m_reexpressionJitter (m_randomGenerator, uniform_int<> (100,500))
+ , m_rangeUniformRandom (m_randomGenerator, boost::uniform_int<> (200,1000))
+ , m_reexpressionJitter (m_randomGenerator, boost::uniform_int<> (100,500))
#else
, m_rangeUniformRandom (200,1000)
, m_reexpressionJitter (10,500)
@@ -125,19 +122,18 @@
#ifndef NS3_MODULE
// In NS3 module these functions are moved to StartApplication method
- m_syncRegisteredPrefixId = m_face->setInterestFilter(m_syncPrefix,
- func_lib::bind(&SyncLogic::onSyncInterest, this, _1, _2, _3, _4),
- func_lib::bind(&SyncLogic::onSyncRegisterFailed, this, _1));
+ m_syncRegisteredPrefixId = m_face->setInterestFilter (m_syncPrefix,
+ bind(&SyncLogic::onSyncInterest, this, _1, _2),
+ bind(&SyncLogic::onSyncRegisterFailed, this, _1));
- m_scheduler.schedule (TIME_SECONDS (0), // no need to add jitter
- func_lib::bind (&SyncLogic::sendSyncInterest, this),
- REEXPRESSING_INTEREST);
+ m_reexpressingInterestId = m_scheduler.scheduleEvent (time::seconds (0), // no need to add jitter
+ bind (&SyncLogic::sendSyncInterest, this));
#endif
}
SyncLogic::~SyncLogic ()
-{
- m_face->unsetInterestFilter(m_syncRegisteredPrefixId);
+{
+ // m_face->unsetInterestFilter(m_syncRegisteredPrefixId);
}
#ifdef NS3_MODULE
@@ -169,8 +165,8 @@
SyncLogic::stop()
{
m_face->unsetInterestFilter(m_syncRegisteredPrefixId);
- m_scheduler.cancel (REEXPRESSING_INTEREST);
- m_scheduler.cancel (DELAYED_INTEREST_PROCESSING);
+ m_scheduler.cancelEvent (m_reexpressingInterestId);
+ m_scheduler.cancelEvent (m_delayedInterestProcessingId);
}
/**
@@ -207,9 +203,7 @@
void
SyncLogic::onSyncInterest (const shared_ptr<const Name>& prefix,
- const shared_ptr<const ndn::Interest>& interest,
- Transport& transport,
- uint64_t registeredPrefixId)
+ const shared_ptr<const ndn::Interest>& interest)
{
Name name = interest->getName();
@@ -249,46 +243,24 @@
void
SyncLogic::onSyncData(const shared_ptr<const ndn::Interest>& interest,
const shared_ptr<Data>& data,
- const OnVerified& onVerified,
- const OnVerifyFailed& onVerifyFailed)
-{
- m_verifier->verifyData(data, onVerified, onVerifyFailed);
+ const OnDataValidated& onValidated,
+ const OnDataValidationFailed& onValidationFailed)
+{ m_validator->validate(data, onValidated, onValidationFailed); }
+
+void
+SyncLogic::onSyncTimeout(const shared_ptr<const ndn::Interest>& interest)
+{
+ // It is OK. Others will handle the time out situation.
}
void
-SyncLogic::onSyncDataTimeout(const shared_ptr<const ndn::Interest>& interest,
- int retry,
- const OnVerified& onVerified,
- const OnVerifyFailed& onVerifyFailed)
-{
- if(retry > 0)
- {
- m_face->expressInterest(*interest,
- func_lib::bind(&SyncLogic::onSyncData,
- this,
- _1,
- _2,
- onVerified,
- onVerifyFailed),
- func_lib::bind(&SyncLogic::onSyncDataTimeout,
- this,
- _1,
- retry - 1,
- onVerified,
- onVerifyFailed));
- }
- else
- _LOG_DEBUG("Sync interest eventually times out!");
-}
-
-void
-SyncLogic::onSyncDataVerifyFailed(const shared_ptr<Data>& data)
+SyncLogic::onSyncDataValidationFailed(const shared_ptr<const Data>& data)
{
_LOG_DEBUG("Sync data cannot be verified!");
}
void
-SyncLogic::onSyncDataVerified(const shared_ptr<Data>& data)
+SyncLogic::onSyncDataValidated(const shared_ptr<const Data>& data)
{
Name name = data->getName();
const char* wireData = (const char*)data->getContent().value();
@@ -309,7 +281,7 @@
else
{
// timer is always restarted when we schedule recovery
- m_scheduler.cancel (REEXPRESSING_RECOVERY_INTEREST);
+ m_scheduler.cancelEvent (m_reexpressingRecoveryInterestId);
processSyncData (name, digest, wireData, len);
}
}
@@ -367,15 +339,14 @@
if (exists) // somebody else replied, so restart random-game timer
{
_LOG_DEBUG ("Unknown digest, but somebody may have already replied, so restart our timer");
- m_scheduler.cancel (DELAYED_INTEREST_PROCESSING);
+ m_scheduler.cancelEvent (m_delayedInterestProcessingId);
}
uint32_t waitDelay = GET_RANDOM (m_rangeUniformRandom);
_LOG_DEBUG ("Digest is not in the log. Schedule processing after small delay: " << waitDelay << "ms");
- m_scheduler.schedule (TIME_MILLISECONDS (waitDelay),
- func_lib::bind (&SyncLogic::processSyncInterest, this, name, digest, true),
- DELAYED_INTEREST_PROCESSING);
+ m_delayedInterestProcessingId = m_scheduler.scheduleEvent (time::milliseconds (waitDelay),
+ bind (&SyncLogic::processSyncInterest, this, name, digest, true));
}
else
{
@@ -411,7 +382,7 @@
vector<MissingDataInfo> v;
BOOST_FOREACH (LeafConstPtr leaf, diff.getLeaves().get<ordered>())
{
- DiffLeafConstPtr diffLeaf = dynamic_pointer_cast<const DiffLeaf> (leaf);
+ DiffLeafConstPtr diffLeaf = boost::dynamic_pointer_cast<const DiffLeaf> (leaf);
BOOST_ASSERT (diffLeaf != 0);
NameInfoConstPtr info = diffLeaf->getInfo();
@@ -424,7 +395,7 @@
SeqNo oldSeq;
{
boost::recursive_mutex::scoped_lock lock (m_stateMutex);
- tie (inserted, updated, oldSeq) = m_state->update (info, seq);
+ boost::tie (inserted, updated, oldSeq) = m_state->update (info, seq);
}
if (inserted || updated)
@@ -499,10 +470,9 @@
// satisfyPendingSyncInterests (diffLog); // if there are interests in PIT, there is a point to satisfy them using new state
// if state has changed, then it is safe to express a new interest
- m_scheduler.cancel (REEXPRESSING_INTEREST);
- m_scheduler.schedule (TIME_SECONDS_WITH_JITTER (0),
- func_lib::bind (&SyncLogic::sendSyncInterest, this),
- REEXPRESSING_INTEREST);
+ m_scheduler.cancelEvent (m_reexpressingInterestId);
+ m_reexpressingInterestId = m_scheduler.scheduleEvent (time::milliseconds(GET_RANDOM (m_reexpressionJitter)),
+ bind (&SyncLogic::sendSyncInterest, this));
}
}
@@ -580,7 +550,7 @@
}
void
-SyncLogic::addLocalNames (const Name &prefix, uint32_t session, uint32_t seq)
+SyncLogic::addLocalNames (const Name &prefix, uint64_t session, uint64_t seq)
{
DiffStatePtr diff;
{
@@ -651,19 +621,19 @@
_LOG_DEBUG("sendSyncInterest: " << m_outstandingInterestName);
- m_scheduler.cancel (REEXPRESSING_INTEREST);
- m_scheduler.schedule (TIME_SECONDS_WITH_JITTER (m_syncInterestReexpress),
- func_lib::bind (&SyncLogic::sendSyncInterest, this),
- REEXPRESSING_INTEREST);
+ m_scheduler.cancelEvent (m_reexpressingInterestId);
+ m_reexpressingInterestId = m_scheduler.scheduleEvent (time::seconds(m_syncInterestReexpress)+time::milliseconds(GET_RANDOM (m_reexpressionJitter)),
+ bind (&SyncLogic::sendSyncInterest, this));
ndn::Interest interest(m_outstandingInterestName);
+ interest.setMustBeFresh(true);
- OnVerified onVerified = func_lib::bind(&SyncLogic::onSyncDataVerified, this, _1);
- OnVerifyFailed onVerifyFailed = func_lib::bind(&SyncLogic::onSyncDataVerifyFailed, this, _1);
+ OnDataValidated onValidated = bind(&SyncLogic::onSyncDataValidated, this, _1);
+ OnDataValidationFailed onValidationFailed = bind(&SyncLogic::onSyncDataValidationFailed, this, _1);
m_face->expressInterest(interest,
- func_lib::bind(&SyncLogic::onSyncData, this, _1, _2, onVerified, onVerifyFailed),
- func_lib::bind(&SyncLogic::onSyncDataTimeout, this, _1, 0, onVerified, onVerifyFailed));
+ bind(&SyncLogic::onSyncData, this, _1, _2, onValidated, onValidationFailed),
+ bind(&SyncLogic::onSyncTimeout, this, _1));
}
void
@@ -675,25 +645,24 @@
Name interestName = m_syncPrefix;
interestName.append("recovery").append(os.str());
- TimeDuration nextRetransmission = TIME_MILLISECONDS_WITH_JITTER (m_recoveryRetransmissionInterval);
+ time::Duration nextRetransmission = time::milliseconds (m_recoveryRetransmissionInterval + GET_RANDOM (m_reexpressionJitter));
+
m_recoveryRetransmissionInterval <<= 1;
- m_scheduler.cancel (REEXPRESSING_RECOVERY_INTEREST);
+ m_scheduler.cancelEvent (m_reexpressingRecoveryInterestId);
if (m_recoveryRetransmissionInterval < 100*1000) // <100 seconds
- {
- m_scheduler.schedule (nextRetransmission,
- func_lib::bind (&SyncLogic::sendSyncRecoveryInterests, this, digest),
- REEXPRESSING_RECOVERY_INTEREST);
- }
+ m_reexpressingRecoveryInterestId = m_scheduler.scheduleEvent (nextRetransmission,
+ bind (&SyncLogic::sendSyncRecoveryInterests, this, digest));
ndn::Interest interest(interestName);
+ interest.setMustBeFresh(true);
- OnVerified onVerified = func_lib::bind(&SyncLogic::onSyncDataVerified, this, _1);
- OnVerifyFailed onVerifyFailed = func_lib::bind(&SyncLogic::onSyncDataVerifyFailed, this, _1);
+ OnDataValidated onValidated = bind(&SyncLogic::onSyncDataValidated, this, _1);
+ OnDataValidationFailed onValidationFailed = bind(&SyncLogic::onSyncDataValidationFailed, this, _1);
m_face->expressInterest(interest,
- func_lib::bind(&SyncLogic::onSyncData, this, _1, _2, onVerified, onVerifyFailed),
- func_lib::bind(&SyncLogic::onSyncDataTimeout, this, _1, 0, onVerified, onVerifyFailed));
+ bind(&SyncLogic::onSyncData, this, _1, _2, onValidated, onValidationFailed),
+ bind(&SyncLogic::onSyncTimeout, this, _1));
}
@@ -713,12 +682,12 @@
_LOG_TRACE (">> D " << name);
int size = ssm.ByteSize();
char *wireData = new char[size];
- Name signingIdentity = m_policy->inferSigningIdentity(name);
+ ssm.SerializeToArray(wireData, size);
Data syncData(name);
syncData.setContent(reinterpret_cast<const uint8_t*>(wireData), size);
- m_keyChain->signByIdentity(syncData, signingIdentity);
+ m_keyChain->sign(syncData);
m_face->put(syncData);
@@ -735,10 +704,9 @@
{
_LOG_TRACE ("Satisfied our own Interest. Re-expressing (hopefully with a new digest)");
- m_scheduler.cancel (REEXPRESSING_INTEREST);
- m_scheduler.schedule (TIME_SECONDS_WITH_JITTER (0),
- bind (&SyncLogic::sendSyncInterest, this),
- REEXPRESSING_INTEREST);
+ m_scheduler.cancelEvent (m_reexpressingInterestId);
+ m_reexpressingInterestId = m_scheduler.scheduleEvent (time::milliseconds(GET_RANDOM (m_reexpressionJitter)),
+ bind (&SyncLogic::sendSyncInterest, this));
}
}
diff --git a/src/sync-logic.h b/src/sync-logic.h
index d3e70c1..5efb81e 100644
--- a/src/sync-logic.h
+++ b/src/sync-logic.h
@@ -31,15 +31,14 @@
#include <map>
#include <ndn-cpp-dev/face.hpp>
-#include <ndn-cpp-dev/security/verifier.hpp>
+#include <ndn-cpp-dev/security/validator.hpp>
#include <ndn-cpp-dev/security/key-chain.hpp>
+#include <ndn-cpp-dev/util/scheduler.hpp>
#include "sync-interest-table.h"
#include "sync-diff-state.h"
#include "sync-full-state.h"
#include "sync-std-name-info.h"
-#include "sync-scheduler.h"
-#include "sec-policy-sync.h"
#include "sync-diff-state-container.h"
@@ -88,14 +87,14 @@
* the app data when new remote names are learned
*/
SyncLogic (const ndn::Name& syncPrefix,
- ndn::ptr_lib::shared_ptr<SecPolicySync> syncPolicyManager,
- ndn::ptr_lib::shared_ptr<ndn::Face> face,
+ ndn::shared_ptr<ndn::Validator> validator,
+ ndn::shared_ptr<ndn::Face> face,
LogicUpdateCallback onUpdate,
LogicRemoveCallback onRemove);
SyncLogic (const ndn::Name& syncPrefix,
- ndn::ptr_lib::shared_ptr<SecPolicySync> syncPolicyManager,
- ndn::ptr_lib::shared_ptr<ndn::Face> face,
+ ndn::shared_ptr<ndn::Validator> validator,
+ ndn::shared_ptr<ndn::Face> face,
LogicPerBranchCallback onUpdateBranch);
~SyncLogic ();
@@ -103,20 +102,20 @@
/**
* a wrapper for the same func in SyncApp
*/
- void addLocalNames (const ndn::Name &prefix, uint32_t session, uint32_t seq);
+ void addLocalNames (const ndn::Name &prefix, uint64_t session, uint64_t seq);
/**
* @brief respond to the Sync Interest; a lot of logic needs to go in here
* @param interest the Sync Interest in string format
*/
- void respondSyncInterest (ndn::ptr_lib::shared_ptr<ndn::Interest> interest);
+ void respondSyncInterest (ndn::shared_ptr<ndn::Interest> interest);
/**
* @brief process the fetched sync data
* @param name the data name
* @param dataBuffer the sync data
*/
- void respondSyncData (ndn::ptr_lib::shared_ptr<ndn::Data> data);
+ void respondSyncData (ndn::shared_ptr<ndn::Data> data);
/**
* @brief remove a participant's subtree from the sync tree
@@ -128,7 +127,7 @@
getRootDigest();
#ifdef _DEBUG
- Scheduler &
+ ndn::Scheduler &
getScheduler () { return m_scheduler; }
#endif
@@ -146,46 +145,31 @@
std::map<std::string, bool>
getBranchPrefixes() const;
-private:
- // void
- // connectToDaemon();
-
- // void
- // onConnectionData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
- // const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
-
- // void
- // onConnectionDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest);
-
+private:
void
delayedChecksLoop ();
void
- onSyncInterest (const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix,
- const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
- ndn::Transport& transport,
- uint64_t registeredPrefixId);
+ onSyncInterest (const ndn::shared_ptr<const ndn::Name>& prefix,
+ const ndn::shared_ptr<const ndn::Interest>& interest);
void
- onSyncRegisterFailed(const ndn::ptr_lib::shared_ptr<const ndn::Name>& prefix);
+ onSyncRegisterFailed(const ndn::shared_ptr<const ndn::Name>& prefix);
void
- onSyncData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
- const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
- const ndn::OnVerified& onVerified,
- const ndn::OnVerifyFailed& onVerifyFailed);
+ onSyncData(const ndn::shared_ptr<const ndn::Interest>& interest,
+ const ndn::shared_ptr<ndn::Data>& data,
+ const ndn::OnDataValidated& onValidated,
+ const ndn::OnDataValidationFailed& onValidationFailed);
void
- onSyncDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
- int retry,
- const ndn::OnVerified& onVerified,
- const ndn::OnVerifyFailed& onVerifyFailed);
+ onSyncTimeout(const ndn::shared_ptr<const ndn::Interest>& interest);
void
- onSyncDataVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
+ onSyncDataValidationFailed(const ndn::shared_ptr<const ndn::Data>& data);
void
- onSyncDataVerified(const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
+ onSyncDataValidated(const ndn::shared_ptr<const ndn::Data>& data);
void
processSyncInterest (const ndn::Name &name,
@@ -238,13 +222,12 @@
LogicRemoveCallback m_onRemove;
LogicPerBranchCallback m_onUpdateBranch;
bool m_perBranch;
- ndn::ptr_lib::shared_ptr<SecPolicySync> m_policy;
- ndn::ptr_lib::shared_ptr<ndn::Verifier> m_verifier;
+ ndn::ptr_lib::shared_ptr<ndn::Validator> m_validator;
ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
- uint64_t m_syncRegisteredPrefixId;
+ const ndn::RegisteredPrefixId* m_syncRegisteredPrefixId;
- Scheduler m_scheduler;
+ ndn::Scheduler m_scheduler;
#ifndef NS3_MODULE
boost::mt19937 m_randomGenerator;
@@ -268,12 +251,9 @@
static const int m_defaultRecoveryRetransmitInterval = 200; // milliseconds
uint32_t m_recoveryRetransmissionInterval; // milliseconds
- enum EventLabels
- {
- DELAYED_INTEREST_PROCESSING = 1,
- REEXPRESSING_INTEREST = 2,
- REEXPRESSING_RECOVERY_INTEREST = 3
- };
+ ndn::EventId m_delayedInterestProcessingId;
+ ndn::EventId m_reexpressingInterestId;
+ ndn::EventId m_reexpressingRecoveryInterestId;
};
diff --git a/src/sync-seq-no.h b/src/sync-seq-no.h
index e2ed016..bf21704 100644
--- a/src/sync-seq-no.h
+++ b/src/sync-seq-no.h
@@ -18,6 +18,7 @@
* Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
* Chaoyi Bian <bcy@pku.edu.cn>
* Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * Yingdi Yu <yingdi@cs.ucla.edu>
*/
#ifndef SYNC_SEQ_NO_H
@@ -72,7 +73,7 @@
* @brief Constructor with just sequence number. Session assumed to be zero
* @param seq Sequence number
*/
- SeqNo (uint32_t seq)
+ SeqNo (uint64_t seq)
: m_valid (true)
, m_session (0)
, m_seq (seq)
@@ -83,7 +84,7 @@
* @param session Session ID
* @param seq Sequence number
*/
- SeqNo (uint32_t session, uint32_t seq)
+ SeqNo (uint64_t session, uint64_t seq)
: m_valid (true)
, m_session (session)
, m_seq (seq)
@@ -148,20 +149,20 @@
/**
* @brief Get session id
*/
- uint32_t getSession () const
+ uint64_t getSession () const
{ return m_session; }
/**
* @brief Get sequence number
*/
- uint32_t getSeq () const
+ uint64_t getSeq () const
{ return m_seq; }
/**
* @brief Set sequence number
*/
void
- setSeq(uint32_t seq)
+ setSeq(uint64_t seq)
{ m_seq = seq; }
private:
@@ -173,7 +174,7 @@
* Note that session IDs for the same name should always increase. So, the good choice
* for the session ID is client's timestamp
*/
- uint32_t m_session;
+ uint64_t m_session;
/**
* @brief Sequence number
@@ -182,7 +183,7 @@
*
* For now, wrapping sequence number after max to zero is not supported
*/
- uint32_t m_seq;
+ uint64_t m_seq;
};
inline std::ostream &
diff --git a/src/sync-socket.cc b/src/sync-socket.cc
index 02fb85d..259e730 100644
--- a/src/sync-socket.cc
+++ b/src/sync-socket.cc
@@ -23,53 +23,44 @@
using namespace std;
using namespace ndn;
-using namespace ndn::ptr_lib;
INIT_LOGGER ("SyncSocket");
namespace Sync {
-SyncSocket::SyncSocket (const string &syncPrefix,
- shared_ptr<SecPolicySync> policy,
+SyncSocket::SyncSocket (const Name &syncPrefix,
+ shared_ptr<Validator> validator,
shared_ptr<Face> face,
NewDataCallback dataCallback,
RemoveCallback rmCallback )
: m_newDataCallback(dataCallback)
- , m_policy(policy)
- , m_verifier(new Verifier(policy))
+ , m_validator(validator)
, m_keyChain(new KeyChain())
, m_face(face)
, m_syncLogic (syncPrefix,
- policy,
+ validator,
face,
bind(&SyncSocket::passCallback, this, _1),
rmCallback)
-{
- m_verifier->setFace(face);
-}
+{}
SyncSocket::~SyncSocket()
{
}
bool
-SyncSocket::publishData(const Name &prefix, uint32_t session, const char *buf, size_t len, int freshness)
+SyncSocket::publishData(const Name &prefix, uint64_t session, const char *buf, size_t len, int freshness)
{
- uint32_t sequence = getNextSeq(prefix, session);
- ostringstream sessionStream;
- ostringstream seqStream;
- sessionStream << session;
- seqStream << sequence;
+ uint64_t sequence = getNextSeq(prefix, session);
Name dataName = prefix;
- dataName.append(sessionStream.str()).append(seqStream.str());
-
- Name signingIdentity = m_policy->inferSigningIdentity(dataName);
+ dataName.append(boost::lexical_cast<string>(session)).append(boost::lexical_cast<string>(sequence));
Data data(dataName);
data.setContent(reinterpret_cast<const uint8_t*>(buf), len);
+ data.setFreshnessPeriod(freshness);
- m_keyChain->signByIdentity(data, signingIdentity);
+ m_keyChain->sign(data);
m_face->put(data);
@@ -80,40 +71,35 @@
}
void
-SyncSocket::fetchData(const Name &prefix, const SeqNo &seq, const OnVerified& onVerified, int retry)
+SyncSocket::fetchData(const Name &prefix, const SeqNo &seq, const OnDataValidated& onValidated, int retry)
{
- ostringstream sessionStream;
- ostringstream seqStream;
- sessionStream << seq.getSession();
- seqStream << seq.getSeq();
-
Name interestName = prefix;
- interestName.append(sessionStream.str()).append(seqStream.str());
+ interestName.append(boost::lexical_cast<string>(seq.getSession())).append(boost::lexical_cast<string>(seq.getSeq()));
- const OnVerifyFailed& onVerifyFailed = bind(&SyncSocket::onDataVerifyFailed, this, _1);
-
+ const OnDataValidationFailed& onValidationFailed = bind(&SyncSocket::onDataValidationFailed, this, _1);
ndn::Interest interest(interestName);
+ interest.setMustBeFresh(true);
m_face->expressInterest(interest,
- bind(&SyncSocket::onData, this, _1, _2, onVerified, onVerifyFailed),
- bind(&SyncSocket::onDataTimeout, this, _1, retry, onVerified, onVerifyFailed));
+ bind(&SyncSocket::onData, this, _1, _2, onValidated, onValidationFailed),
+ bind(&SyncSocket::onDataTimeout, this, _1, retry, onValidated, onValidationFailed));
}
void
SyncSocket::onData(const shared_ptr<const ndn::Interest>& interest,
const shared_ptr<Data>& data,
- const OnVerified& onVerified,
- const OnVerifyFailed& onVerifyFailed)
+ const OnDataValidated& onValidated,
+ const OnDataValidationFailed& onValidationFailed)
{
- m_verifier->verifyData(data, onVerified, onVerifyFailed);
+ m_validator->validate(data, onValidated, onValidationFailed);
}
void
SyncSocket::onDataTimeout(const shared_ptr<const ndn::Interest>& interest,
int retry,
- const OnVerified& onVerified,
- const OnVerifyFailed& onVerifyFailed)
+ const OnDataValidated& onValidated,
+ const OnDataValidationFailed& onValidationFailed)
{
if(retry > 0)
{
@@ -122,14 +108,14 @@
this,
_1,
_2,
- onVerified,
- onVerifyFailed),
+ onValidated,
+ onValidationFailed),
bind(&SyncSocket::onDataTimeout,
this,
_1,
retry - 1,
- onVerified,
- onVerifyFailed));
+ onValidated,
+ onValidationFailed));
}
else
@@ -137,14 +123,14 @@
}
void
-SyncSocket::onDataVerifyFailed(const shared_ptr<Data>& data)
+SyncSocket::onDataValidationFailed(const shared_ptr<const Data>& data)
{
_LOG_DEBUG("data cannot be verified!");
}
-uint32_t
-SyncSocket::getNextSeq (const Name &prefix, uint32_t session)
+uint64_t
+SyncSocket::getNextSeq (const Name &prefix, uint64_t session)
{
SequenceLog::iterator i = m_sequenceLog.find (prefix);
diff --git a/src/sync-socket.h b/src/sync-socket.h
index b558ff9..f1af423 100644
--- a/src/sync-socket.h
+++ b/src/sync-socket.h
@@ -22,11 +22,12 @@
#define SYNC_SOCKET_H
#include "sync-logic.h"
-#include <boost/function.hpp>
#include "sync-seq-no.h"
+
#include <ndn-cpp-dev/face.hpp>
-#include <ndn-cpp-dev/security/verifier.hpp>
+#include <ndn-cpp-dev/security/validator.hpp>
#include <ndn-cpp-dev/security/key-chain.hpp>
+
#include <utility>
#include <map>
#include <vector>
@@ -41,8 +42,9 @@
class SyncSocket
{
public:
- typedef boost::function< void (const std::vector<MissingDataInfo> &, SyncSocket * ) > NewDataCallback;
- typedef boost::function< void ( const std::string &/*prefix*/ ) > RemoveCallback;
+ typedef ndn::function< void (const std::vector<MissingDataInfo> &, SyncSocket * ) > NewDataCallback;
+ typedef ndn::function< void (const std::string &/*prefix*/ ) > RemoveCallback;
+
/**
* @brief the constructor for SyncAppSocket; the parameter syncPrefix
* should be passed to the constructor of m_syncAppWrapper; the other
@@ -54,30 +56,30 @@
* @param syncPrefix the name prefix for Sync Interest
* @param dataCallback the callback to process data
*/
- SyncSocket (const std::string &syncPrefix,
- ndn::ptr_lib::shared_ptr<SecPolicySync> policy,
- ndn::ptr_lib::shared_ptr<ndn::Face> face,
+ SyncSocket (const ndn::Name &syncPrefix,
+ ndn::shared_ptr<ndn::Validator> validator,
+ ndn::shared_ptr<ndn::Face> face,
NewDataCallback dataCallback,
RemoveCallback rmCallback);
~SyncSocket ();
bool
- publishData(const ndn::Name &prefix, uint32_t session, const char *buf, size_t len, int freshness);
+ publishData(const ndn::Name &prefix, uint64_t session, const char *buf, size_t len, int freshness);
void
remove (const ndn::Name &prefix)
{ m_syncLogic.remove(prefix); }
void
- fetchData(const ndn::Name &prefix, const SeqNo &seq, const ndn::OnVerified& onVerified, int retry = 0);
+ fetchData(const ndn::Name &prefix, const SeqNo &seq, const ndn::OnDataValidated& onValidated, int retry = 0);
std::string
getRootDigest()
{ return m_syncLogic.getRootDigest(); }
- uint32_t
- getNextSeq (const ndn::Name &prefix, uint32_t session);
+ uint64_t
+ getNextSeq (const ndn::Name &prefix, uint64_t session);
SyncLogic &
getLogic ()
@@ -94,28 +96,27 @@
{ m_newDataCallback(v, this); }
void
- onData(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
- const ndn::ptr_lib::shared_ptr<ndn::Data>& data,
- const ndn::OnVerified& onVerified,
- const ndn::OnVerifyFailed& onVerifyFailed);
+ onData(const ndn::shared_ptr<const ndn::Interest>& interest,
+ const ndn::shared_ptr<ndn::Data>& data,
+ const ndn::OnDataValidated& onValidated,
+ const ndn::OnDataValidationFailed& onValidationFailed);
void
- onDataTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest,
- int retry,
- const ndn::OnVerified& onVerified,
- const ndn::OnVerifyFailed& onVerifyFailed);
+ onDataTimeout(const ndn::shared_ptr<const ndn::Interest>& interest,
+ int retry,
+ const ndn::OnDataValidated& onValidated,
+ const ndn::OnDataValidationFailed& onValidationFailed);
void
- onDataVerifyFailed(const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
+ onDataValidationFailed(const ndn::shared_ptr<const ndn::Data>& data);
private:
typedef std::map<ndn::Name, SeqNo> SequenceLog;
NewDataCallback m_newDataCallback;
SequenceLog m_sequenceLog;
- ndn::ptr_lib::shared_ptr<SecPolicySync> m_policy;
- ndn::ptr_lib::shared_ptr<ndn::Verifier> m_verifier;
- ndn::ptr_lib::shared_ptr<ndn::KeyChain> m_keyChain;
- ndn::ptr_lib::shared_ptr<ndn::Face> m_face;
+ ndn::shared_ptr<ndn::Validator> m_validator;
+ ndn::shared_ptr<ndn::KeyChain> m_keyChain;
+ ndn::shared_ptr<ndn::Face> m_face;
SyncLogic m_syncLogic;
};
diff --git a/src/sync-state.cc b/src/sync-state.cc
index 71d664e..6c374a4 100644
--- a/src/sync-state.cc
+++ b/src/sync-state.cc
@@ -156,8 +156,8 @@
NameInfoConstPtr info = StdNameInfo::FindOrCreate (ss.name());
if (ss.type() == SyncState::UPDATE)
{
- uint32_t session = lexical_cast<uint32_t>(ss.seqno().session());
- uint32_t seq = lexical_cast<uint32_t>(ss.seqno().seq());
+ uint64_t session = lexical_cast<uint64_t>(ss.seqno().session());
+ uint64_t seq = lexical_cast<uint64_t>(ss.seqno().seq());
SeqNo seqNo(session, seq);
state.update(info, seqNo);
}
diff --git a/src/sync-state.proto b/src/sync-state.proto
index 18892fb..7cc6b18 100644
--- a/src/sync-state.proto
+++ b/src/sync-state.proto
@@ -12,8 +12,8 @@
required ActionType type = 2;
message SeqNo
{
- required uint32 seq = 1;
- required uint32 session = 2;
+ required uint64 seq = 1;
+ required uint64 session = 2;
}
optional SeqNo seqno = 3;
}