Content Verification and Certificate Verification Done
diff --git a/src/communication/nlsr_dm.cpp b/src/communication/nlsr_dm.cpp
index e425767..ffb85e3 100644
--- a/src/communication/nlsr_dm.cpp
+++ b/src/communication/nlsr_dm.cpp
@@ -191,21 +191,26 @@
   void
   DataManager::processContentKeys(Nlsr& pnlsr, const ndn::Data& data)
   {
-    cout<<" processContentKeys called "<<endl;
+    std::cout<<" processContentKeys called "<<endl;
     ndn::shared_ptr<ndn::IdentityCertificate> cert=
       ndn::make_shared<ndn::IdentityCertificate>();
     cert->wireDecode(data.getContent().blockFromValue());
-    cout<<*(cert)<<endl;
+    std::cout<<*(cert)<<endl;
     std::string dataName=data.getName().toUri();
     nlsrTokenizer nt(dataName,"/");
     std::string certName=nt.getTokenString(0,nt.getTokenNumber()-3);
     uint32_t seqNum=boost::lexical_cast<uint32_t>(nt.getToken(
                       nt.getTokenNumber()-2));
     cout<<"Cert Name: "<<certName<<" Seq Num: "<<seqNum<<std::endl;
-    if ( pnlsr.getKeyManager().verify(*(cert)))
+    if ( pnlsr.getKeyManager().verify(pnlsr, *(cert)))
     {
       pnlsr.getKeyManager().addCertificate(cert, seqNum, true);
-      //pnlsr.getKeyManager().printCertStore();
     }
+    else
+    {
+      pnlsr.getKeyManager().addCertificate(cert, seqNum, false);
+    }
+    
+    pnlsr.getKeyManager().printCertStore();
   }
 }//namespace nlsr
diff --git a/src/communication/nlsr_im.cpp b/src/communication/nlsr_im.cpp
index b22b445..16d0c72 100644
--- a/src/communication/nlsr_im.cpp
+++ b/src/communication/nlsr_im.cpp
@@ -43,12 +43,6 @@
     {
       processInterestKeys(pnlsr,interest);
     }
-    //Data data(ndn::Name(interest->getName()).append("testApp").appendVersion());
-    //data.setFreshnessPeriod(1000); // 10 sec
-    //data.setContent((const uint8_t*)"HELLO KITTY", sizeof("HELLO KITTY"));
-    //pnlsr.getKeyChain().sign(data);
-    //cout << ">> D: " << data << endl;
-    //pnlsr.getNlsrFace().put(data);
   }
 
   void
@@ -190,31 +184,54 @@
     string intName=interest.getName().toUri();
     cout<<"Interest Name for Key: "<<intName<<std::endl;
     nlsrTokenizer nt(intName,"/");
-    std::string certName=nt.getTokenString(0,nt.getTokenNumber()-2);
-    uint32_t seqNum=boost::lexical_cast<uint32_t>(nt.getToken(
-                      nt.getTokenNumber()-1));
-    cout<<"Cert Name: "<<certName<<" Seq Num: "<<seqNum<<std::endl;
-    std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool> chkCert=
-      pnlsr.getKeyManager().getCertificateFromStore(certName,seqNum);
+    std::string chkString("ID-CERT");
+    std::string certName;
+    uint32_t seqNum;
+    ndn::Name dataName;
+    std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool> chkCert;
+    if( nt.getTokenPosition(chkString) == nt.getTokenNumber()-1 )
+    {
+      certName=nt.getTokenString(0,nt.getTokenNumber()-1);
+      cout<<"Cert Name: "<<certName<<std::endl;
+      chkCert=pnlsr.getKeyManager().getCertificateFromStore(certName);
+    }
+    else
+    {
+      certName=nt.getTokenString(0,nt.getTokenNumber()-2);
+      seqNum=boost::lexical_cast<uint32_t>(nt.getToken(nt.getTokenNumber()-1));
+      cout<<"Cert Name: "<<certName<<" Seq Num: "<<seqNum<<std::endl;
+      chkCert=pnlsr.getKeyManager().getCertificateFromStore(certName,seqNum);
+    }
     if( chkCert.second )
     {
-      Data data(ndn::Name(interest.getName()).appendVersion());
+      if(nt.getTokenPosition(chkString) == nt.getTokenNumber()-1)
+      {
+        std::string dn;
+        dataName=ndn::Name(interest.getName()).appendVersion();
+        std::pair<uint32_t, bool> seqChk = 
+                           pnlsr.getKeyManager().getCertificateSeqNum(certName);
+        if( seqChk.second )
+        {
+          dn=dataName.toUri()+"/"+boost::lexical_cast<std::string>(seqChk.first);
+          dataName=ndn::Name(dn);
+        }
+        else
+        {
+          dn=dataName.toUri()+"/"+boost::lexical_cast<std::string>(10);
+          dataName=ndn::Name(dn);
+        }
+        
+      }
+      else
+      {
+        dataName=ndn::Name(interest.getName());
+      }
+      Data data(dataName.appendVersion());
       data.setFreshnessPeriod(1000); //10 sec
       data.setContent(chkCert.first->wireEncode());
       pnlsr.getKeyManager().signData(data);
       pnlsr.getNlsrFace()->put(data);
     }
-    //std::pair<ndn::shared_ptr<ndn::IdentityCertificate>, bool> chkCert=
-    /*
-    ndn::shared_ptr<ndn::IdentityCertificate> cert=pnlsr.getKeyManager().getCertificate();
-    Data data(ndn::Name(interest.getName()).appendVersion());
-    data.setFreshnessPeriod(1000); // 10 sec
-    data.setContent(cert->wireEncode());
-    pnlsr.getKeyManager().signData(data);
-    //std::ofstream outFile("data_sent");
-    //ndn::io::save(data,outFile,ndn::io::NO_ENCODING);
-    pnlsr.getNlsrFace()->put(data);
-    */
   }
 
 
diff --git a/src/communication/nlsr_slh.cpp b/src/communication/nlsr_slh.cpp
index 098610d..189612a 100644
--- a/src/communication/nlsr_slh.cpp
+++ b/src/communication/nlsr_slh.cpp
@@ -130,10 +130,10 @@
   void
   SyncLogicHandler::publishKeyUpdate(KeyManager& km)
   {
-    publishSyncUpdate(km.getRootCertName().toUri(), 10);
-    publishSyncUpdate(km.getSiteCertName().toUri(), 10);
-    publishSyncUpdate(km.getOperatorCertName().toUri(), 10);
-    publishSyncUpdate(km.getRouterCertName().toUri(), km.getCertSeqNo());
+    //publishSyncUpdate(km.getRootCertName().toUri(), 10);
+    //publishSyncUpdate(km.getSiteCertName().toUri(), 10);
+    //publishSyncUpdate(km.getOperatorCertName().toUri(), 10);
+    //publishSyncUpdate(km.getRouterCertName().toUri(), km.getCertSeqNo());
     publishSyncUpdate(km.getProcessCertName().toUri(),km.getCertSeqNo());
   }