Add SyncPolicyManager
diff --git a/src/sync-policy-manager.cc b/src/sync-policy-manager.cc
index 86726d3..0c663b1 100644
--- a/src/sync-policy-manager.cc
+++ b/src/sync-policy-manager.cc
@@ -33,7 +33,7 @@
m_syncPrefixRegex = Regex::fromName(syncPrefix);
m_wotPrefixRegex = Regex::fromName(wotPrefix);
m_chatDataPolicy = Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^[^<FH>]*<FH>([^<chronos>]*)<chronos><>",
- "^(<>*)<KEY><DSK-.*><ID-CERT><>$",
+ "^(<>*)<KEY><dsk-.*><ID-CERT>$",
"==", "\\1", "\\1", true));
}
@@ -54,11 +54,11 @@
const DataCallback& verifiedCallback,
const UnverifiedCallback& unverifiedCallback)
{
-#ifdef _DEBUG
- _LOG_DEBUG("checkVerificationPolicy");
- verifiedCallback(data);
- return NULL;
-#else
+// #ifdef _DEBUG
+// _LOG_DEBUG("checkVerificationPolicy");
+// verifiedCallback(data);
+// return NULL;
+// #else
//TODO:
if(stepCount > m_stepLimit)
{
@@ -74,10 +74,13 @@
}
const Name& keyLocatorName = sha256sig->getKeyLocator().getKeyName();
+ _LOG_DEBUG("data name: " << data->getName());
+ _LOG_DEBUG("signer name: " << keyLocatorName);
// if data is intro cert
if(m_wotPrefixRegex->match(data->getName()))
{
+ _LOG_DEBUG("Intro Cert");
Name keyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName);
map<Name, Publickey>::const_iterator it = m_trustedIntroducers.find(keyName);
if(m_trustedIntroducers.end() != it)
@@ -95,11 +98,14 @@
// if data is sync data or chat data
if(m_syncPrefixRegex->match(data->getName()) || m_chatDataPolicy->satisfy(*data))
{
+ _LOG_DEBUG("Sync/Chat Data");
Name keyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName);
+ _LOG_DEBUG("keyName: " << keyName.toUri());
map<Name, Publickey>::const_iterator it = m_trustedIntroducers.find(keyName);
if(m_trustedIntroducers.end() != it)
{
+ _LOG_DEBUG("Find trusted introducer!");
if(verifySignature(*data, it->second))
verifiedCallback(data);
else
@@ -110,19 +116,21 @@
it = m_trustedProducers.find(keyName);
if(m_trustedProducers.end() != it)
{
+ _LOG_DEBUG("Find trusted producer!");
if(verifySignature(*data, it->second))
verifiedCallback(data);
else
unverifiedCallback(data);
return NULL;
}
-
+
+ _LOG_DEBUG("Did not find any trusted one!");
return prepareRequest(keyName, false, data, stepCount, verifiedCallback, unverifiedCallback);
}
unverifiedCallback(data);
return NULL;
-#endif
+// #endif
}
bool
@@ -130,12 +138,14 @@
const Name& certificateName)
{
-#ifdef _DEBUG
- _LOG_DEBUG("checkSigningPolicy");
return true;
-#else
- return (m_syncPrefixRegex->match(dataName) && certificateName == m_signingCertificateName) ? true : false;
-#endif
+
+// #ifdef _DEBUG
+// _LOG_DEBUG("checkSigningPolicy");
+// return true;
+// #else
+ // return (m_syncPrefixRegex->match(dataName) && certificateName.getPrefix(certificateName.size()-1) == m_signingCertificateName) ? true : false;
+// #endif
}
Name
@@ -145,6 +155,7 @@
void
SyncPolicyManager::addTrustAnchor(const IdentityCertificate& identityCertificate, bool isIntroducer)
{
+ _LOG_DEBUG("Add intro/producer: " << identityCertificate.getPublicKeyName());
if(isIntroducer)
m_trustedIntroducers.insert(pair <Name, Publickey > (identityCertificate.getPublicKeyName(), identityCertificate.getPublicKeyInfo()));
else
@@ -198,6 +209,11 @@
interestPrefixName->append("WOT").append(keyName).append("INTRO-CERT");
Ptr<const std::vector<ndn::Name> > nameList = getAllIntroducerName();
+ if(0 == nameList->size())
+ {
+ unverifiedCallback(data);
+ return NULL;
+ }
Name interestName = *interestPrefixName;
interestName.append(nameList->at(0));
@@ -206,6 +222,7 @@
interestName.append("INTRODUCER");
Ptr<Interest> interest = Ptr<Interest>(new Interest(interestName));
+ _LOG_DEBUG("send interest for intro cert: " << interest->getName());
interest->setChildSelector(Interest::CHILD_RIGHT);
DataCallback requestedCertVerifiedCallback = boost::bind(&SyncPolicyManager::onIntroCertVerified,
diff --git a/src/sync-policy-manager.h b/src/sync-policy-manager.h
index 418abc7..fac9b4a 100644
--- a/src/sync-policy-manager.h
+++ b/src/sync-policy-manager.h
@@ -58,7 +58,7 @@
bool isIntroducer);
inline void
- setWrapper(ndn::Wrapper* handler)
+ setWrapper(ndn::Ptr<ndn::Wrapper> handler)
{ m_handler = handler; }
private:
@@ -118,7 +118,7 @@
std::map<ndn::Name, ndn::security::Publickey> m_trustedProducers;
std::map<ndn::Name, SpecificPolicyRule> m_chatDataRules;
- ndn::Wrapper* m_handler;
+ ndn::Ptr<ndn::Wrapper> m_handler;
};
#endif