time: Adapt to ndn-cpp-dev's new time structure

Change-Id: I4117d4e7aea5347cbaf3ec2e5e5a110f94930262
diff --git a/src/chat-dialog.cpp b/src/chat-dialog.cpp
index 061c74f..ba2cda5 100644
--- a/src/chat-dialog.cpp
+++ b/src/chat-dialog.cpp
@@ -60,10 +60,10 @@
   , m_localPrefix(localPrefix)
   , m_useRoutablePrefix(false)
   , m_nick(nick)
-  , m_lastMsgTime(time::now())
+  , m_lastMsgTime(time::toUnixTimestamp(time::system_clock::now()).count())
   , m_joined(false)
   , m_sock(NULL)
-  , m_session(static_cast<uint64_t>(time::now()))
+  , m_session(static_cast<uint64_t>(time::toUnixTimestamp(time::system_clock::now()).count()))
   , m_inviteListDialog(new InviteListDialog)
 {
   qRegisterMetaType<std::vector<Sync::MissingDataInfo> >("std::vector<Sync::MissingDataInfo>");
@@ -566,7 +566,7 @@
   uint64_t nextSequence = m_sock->getNextSeq();
   m_sock->publishData(os.buf()->buf(), os.buf()->size(), FRESHNESS);
 
-  m_lastMsgTime = time::now();
+  m_lastMsgTime = time::toUnixTimestamp(time::system_clock::now()).count();
 
   Sync::MissingDataInfo mdi = {m_localChatPrefix.toUri(), Sync::SeqNo(0), Sync::SeqNo(nextSequence)};
   std::vector<Sync::MissingDataInfo> v;
@@ -705,7 +705,7 @@
   msg.set_from(m_nick);
   msg.set_to(m_chatroomName);
   msg.set_data(text.toStdString());
-  int32_t seconds = static_cast<int32_t>(time::now()/1000000000);
+  int32_t seconds = static_cast<int32_t>(time::toUnixTimestamp(time::system_clock::now()).count()/1000000000);
   msg.set_timestamp(seconds);
   msg.set_type(SyncDemo::ChatMessage::CHAT);
 }
@@ -715,7 +715,7 @@
 {
   msg.set_from(m_nick);
   msg.set_to(m_chatroomName);
-  int32_t seconds = static_cast<int32_t>(time::now()/1000000000);
+  int32_t seconds = static_cast<int32_t>(time::toUnixTimestamp(time::system_clock::now()).count()/1000000000);
   msg.set_timestamp(seconds);
   msg.set_type(type);
 }
@@ -1196,7 +1196,7 @@
 void
 ChatDialog::sendHello()
 {
-  int64_t now = time::now();
+  int64_t now = time::toUnixTimestamp(time::system_clock::now()).count();
   int elapsed = (now - m_lastMsgTime) / 1000000000;
   if (elapsed >= m_randomizedInterval / 1000)
   {
diff --git a/src/contact-manager.cpp b/src/contact-manager.cpp
index 7c8c62c..36a0705 100644
--- a/src/contact-manager.cpp
+++ b/src/contact-manager.cpp
@@ -137,7 +137,7 @@
   interestName.append("DNS").append("ENDORSED");
 
   Interest interest(interestName);
-  interest.setInterestLifetime(1000);
+  interest.setInterestLifetime(time::milliseconds(1000));
   interest.setMustBeFresh(true);
 
   OnDataValidated onValidated = bind(&ContactManager::onDnsCollectEndorseValidated, this, _1, identity);
@@ -158,7 +158,7 @@
   Name interestName(endorseCollection->endorsement(certIndex).certname());
 
   Interest interest(interestName);
-  interest.setInterestLifetime(1000);
+  interest.setInterestLifetime(time::milliseconds(1000));
   interest.setMustBeFresh(true);
 
   m_face->expressInterest(interest,
@@ -360,7 +360,7 @@
         interestName.append("DNS").append(m_identity.wireEncode()).append("ENDORSEE");
         
         Interest interest(interestName);
-        interest.setInterestLifetime(1000);
+        interest.setInterestLifetime(time::milliseconds(1000));
         
         OnDataValidated onValidated = bind(&ContactManager::onDnsEndorseeValidated, this, _1);
         OnDataValidationFailed onValidationFailed = bind(&ContactManager::onDnsEndorseeValidationFailed, this, _1, _2);
@@ -511,7 +511,7 @@
   Data data;
   data.setName(dnsName);
   data.setContent(selfEndorseCertificate.wireEncode());
-  data.setFreshnessPeriod(1000);
+  data.setFreshnessPeriod(time::milliseconds(1000));
 
   m_keyChain.signByIdentity(data, m_identity);
 
@@ -672,7 +672,7 @@
   // _LOG_DEBUG("onFetchContactInfo " << identity.toStdString() << " profile: " << interestName);
   
   Interest interest(interestName);
-  interest.setInterestLifetime(1000);
+  interest.setInterestLifetime(time::milliseconds(1000));
   interest.setMustBeFresh(true);
 
   OnDataValidated onValidated = bind(&ContactManager::onDnsSelfEndorseCertValidated, this, _1, identityName);
@@ -811,7 +811,7 @@
       Name certName(*it);
 
       Interest interest(certName);
-      interest.setInterestLifetime(1000);
+      interest.setInterestLifetime(time::milliseconds(1000));
       interest.setMustBeFresh(true);
       
       OnDataValidated onValidated = bind(&ContactManager::onIdentityCertValidated, this, _1);
diff --git a/src/contact-storage.cpp b/src/contact-storage.cpp
index e3c513f..4c1fe04 100644
--- a/src/contact-storage.cpp
+++ b/src/contact-storage.cpp
@@ -336,8 +336,8 @@
   sqlite3_bind_text(stmt, 2, contact.getAlias().c_str(), contact.getAlias().size(), SQLITE_TRANSIENT);
   sqlite3_bind_text(stmt, 3, contact.getPublicKeyName().toUri().c_str(), contact.getPublicKeyName().toUri().size(), SQLITE_TRANSIENT);
   sqlite3_bind_text(stmt, 4, reinterpret_cast<const char*>(contact.getPublicKey().get().buf()), contact.getPublicKey().get().size(), SQLITE_TRANSIENT);
-  sqlite3_bind_int64(stmt, 5, contact.getNotBefore());
-  sqlite3_bind_int64(stmt, 6, contact.getNotAfter());
+  sqlite3_bind_int64(stmt, 5, time::toUnixTimestamp(contact.getNotBefore()).count());
+  sqlite3_bind_int64(stmt, 6, time::toUnixTimestamp(contact.getNotAfter()).count());
   sqlite3_bind_int(stmt, 7, (isIntroducer ? 1 : 0));
 
   int res = sqlite3_step (stmt);
@@ -400,8 +400,8 @@
       string alias(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0));
       string keyName(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1));
       PublicKey key(sqlite3_column_text(stmt, 2), sqlite3_column_bytes (stmt, 2));
-      int64_t notBefore = sqlite3_column_int64 (stmt, 3);
-      int64_t notAfter = sqlite3_column_int64 (stmt, 4);
+      time::system_clock::TimePoint notBefore = time::fromUnixTimestamp(time::milliseconds(sqlite3_column_int64 (stmt, 3)));
+      time::system_clock::TimePoint notAfter = time::fromUnixTimestamp(time::milliseconds(sqlite3_column_int64 (stmt, 4)));
       int isIntroducer = sqlite3_column_int (stmt, 5);
 
       contact = shared_ptr<Contact>(new Contact(identity, alias, Name(keyName), notBefore, notAfter, key, isIntroducer));
diff --git a/src/contact.h b/src/contact.h
index 4960972..e7736bf 100644
--- a/src/contact.h
+++ b/src/contact.h
@@ -62,8 +62,8 @@
   Contact(const ndn::Name& identity,
           const std::string& alias,
           const ndn::Name& keyName,
-          ndn::MillisecondsSince1970 notBefore,
-          ndn::MillisecondsSince1970 notAfter,
+          const ndn::time::system_clock::TimePoint& notBefore,
+          const ndn::time::system_clock::TimePoint& notAfter,
           const ndn::PublicKey& key,
           bool isIntroducer)
     : m_namespace(identity)
@@ -130,13 +130,13 @@
     return m_publicKey;
   }
 
-  ndn::MillisecondsSince1970
+  const ndn::time::system_clock::TimePoint&
   getNotBefore() const
   {
     return m_notBefore;
   }
 
-  ndn::MillisecondsSince1970
+  const ndn::time::system_clock::TimePoint&
   getNotAfter() const
   {
     return m_notAfter;
@@ -224,8 +224,8 @@
   std::string m_institution;
   ndn::Name m_keyName;
   ndn::PublicKey m_publicKey;
-  ndn::MillisecondsSince1970 m_notBefore;
-  ndn::MillisecondsSince1970 m_notAfter;
+  ndn::time::system_clock::TimePoint m_notBefore;
+  ndn::time::system_clock::TimePoint m_notAfter;
 
   bool m_isIntroducer;
   Profile m_profile;
diff --git a/src/controller.cpp b/src/controller.cpp
index 646dfc1..4d80604 100644
--- a/src/controller.cpp
+++ b/src/controller.cpp
@@ -257,7 +257,7 @@
       m_identity.clear();
       // TODO: change below to system default;
       m_identity.append("chronochat-tmp-identity")
-        .append(boost::lexical_cast<std::string>(random::generateWord64()));
+        .append(getRandomString());
       
       m_nick = m_identity.get(-1).toUri();
     }
@@ -608,7 +608,7 @@
 {
   // Name interestName();
   Interest interest("/local/ndn/prefix");
-  interest.setInterestLifetime(1000);
+  interest.setInterestLifetime(time::milliseconds(1000));
   interest.setMustBeFresh(true);
 
   m_face->expressInterest(interest, 
@@ -650,7 +650,7 @@
   delete m_browseContactDialog;
   delete m_addContactPanel;
 
-  m_face->shutdown();
+  m_face->ioService()->stop();
 
   QApplication::quit();
 }
@@ -699,12 +699,12 @@
       chatroomCert = m_keyChain.getCertificate(m_keyChain.getDefaultCertificateNameForIdentity(m_identity));
 
       response.setContent(chatroomCert->wireEncode());
-      response.setFreshnessPeriod(1000);      
+      response.setFreshnessPeriod(time::milliseconds(1000));
     }
   else
     {
       response.setName(invitationName);
-      response.setFreshnessPeriod(1000);
+      response.setFreshnessPeriod(time::milliseconds(1000));
     }
   m_keyChain.signByIdentity(response, m_identity);
   
@@ -725,7 +725,7 @@
       
       Data wrappedData(wrappedName);
       wrappedData.setContent(response.wireEncode());
-      wrappedData.setFreshnessPeriod(1000);
+      wrappedData.setFreshnessPeriod(time::milliseconds(1000));
 
       m_keyChain.signByIdentity(wrappedData, m_identity);
       m_face->put(wrappedData);
diff --git a/src/endorse-certificate.cpp b/src/endorse-certificate.cpp
index 3d1f298..3aef18e 100644
--- a/src/endorse-certificate.cpp
+++ b/src/endorse-certificate.cpp
@@ -106,8 +106,8 @@
 
 EndorseCertificate::EndorseCertificate(const Name& keyName,
                                        const PublicKey& key,
-                                       MillisecondsSince1970 notBefore,
-                                       MillisecondsSince1970 notAfter,
+                                       const time::system_clock::TimePoint& notBefore,
+                                       const time::system_clock::TimePoint& notAfter,
                                        const Name& signer,
                                        const Profile& profile,
                                        const vector<string>& endorseList)
diff --git a/src/endorse-certificate.h b/src/endorse-certificate.h
index 42f255f..82ac8ba 100644
--- a/src/endorse-certificate.h
+++ b/src/endorse-certificate.h
@@ -38,8 +38,8 @@
 
   EndorseCertificate(const ndn::Name& keyName,
                      const ndn::PublicKey& key,
-                     ndn::MillisecondsSince1970 notBefore,
-                     ndn::MillisecondsSince1970 notAfter,
+                     const ndn::time::system_clock::TimePoint& notBefore,
+                     const ndn::time::system_clock::TimePoint& notAfter,
                      const ndn::Name& signer,
                      const Profile& profile,
                      const std::vector<std::string>& endorseList = DEFAULT_ENDORSE_LIST);
diff --git a/src/invitation.cpp b/src/invitation.cpp
index 4aa3358..851010b 100644
--- a/src/invitation.cpp
+++ b/src/invitation.cpp
@@ -59,7 +59,7 @@
   , m_chatroom(chatroom)
   , m_inviterRoutingPrefix(inviterRoutingPrefix)
   , m_inviterCertificate(inviterCertificate)
-  , m_timestamp(time::now())
+  , m_timestamp(time::toUnixTimestamp(time::system_clock::now()).count())
 {
   m_interestName = m_inviteeNameSpace;
   m_interestName.append("CHRONOCHAT-INVITATION")