object-manager+fetcher: Use segmentNumber for file segments

Change-Id: Ib78ee034dba2a1ea9d140b091181694049655bb9
diff --git a/src/content-server.cpp b/src/content-server.cpp
index 382a029..968d8d1 100644
--- a/src/content-server.cpp
+++ b/src/content-server.cpp
@@ -117,14 +117,14 @@
 {
   Name forwardingHint = Name(interestFilter);
   Name interest = interestTrue.getName();
-  _LOG_DEBUG("I'm serving ForwardingHint: " << forwardingHint << " Interest: " << interest);
+  _LOG_TRACE("Serving ForwardingHint: " << forwardingHint << " Interest: " << interest);
   if (forwardingHint.size() > 0 && m_userName.size() >= forwardingHint.size() &&
       m_userName.getSubName(0, forwardingHint.size()) == forwardingHint) {
     _LOG_DEBUG("Triggered without Forwardinghint!");
     filterAndServeImpl(Name("/"), interest, interest); // try without forwarding hints
   }
 
-  _LOG_DEBUG("Triggered with Forwardinghint~!");
+  _LOG_TRACE("Triggered with Forwardinghint~!");
   filterAndServeImpl(forwardingHint, interest.getSubName(forwardingHint.size()),
                      interest); // always try with hint... :( have to
 }
diff --git a/src/dispatcher.cpp b/src/dispatcher.cpp
index cae79a2..d94c027 100644
--- a/src/dispatcher.cpp
+++ b/src/dispatcher.cpp
@@ -79,7 +79,7 @@
   m_actionFetcher =
     make_shared<FetchManager>(m_face, bind(&SyncLog::LookupLocator, &*m_syncLog, _1),
                               Name(BROADCAST_DOMAIN), // no appname suffix now
-                              3,
+                              3, false,
                               bind(&Dispatcher::Did_FetchManager_ActionFetch, this, _1, _2, _3, _4),
                               FetchManager::FinishCallback(), actionTaskDb);
 
@@ -87,7 +87,7 @@
   m_fileFetcher =
     make_shared<FetchManager>(m_face, bind(&SyncLog::LookupLocator, &*m_syncLog, _1),
                               Name(BROADCAST_DOMAIN), // no appname suffix now
-                              3, bind(&Dispatcher::Did_FetchManager_FileSegmentFetch, this, _1, _2,
+                              3, true, bind(&Dispatcher::Did_FetchManager_FileSegmentFetch, this, _1, _2,
                                       _3, _4),
                               bind(&Dispatcher::Did_FetchManager_FileFetchComplete, this, _1, _2),
                               fileTaskDb);
@@ -329,8 +329,7 @@
 
     Name fileNameBase = Name("/");
     fileNameBase.append(deviceName).append(CHRONOSHARE_APP).append("file");
-    //      fileNameBase.append(name::Component(hash));
-    fileNameBase.appendImplicitSha256Digest(hash);
+    fileNameBase.append(name::Component(hash));
 
     std::string hashStr = toHex(*hash);
     if (ObjectDb::doesExist(m_rootDir / ".chronoshare", deviceName, hashStr)) {
diff --git a/src/fetch-manager.cpp b/src/fetch-manager.cpp
index d8dd6a6..f7e428f 100644
--- a/src/fetch-manager.cpp
+++ b/src/fetch-manager.cpp
@@ -40,6 +40,7 @@
 
 FetchManager::FetchManager(Face& face, const Mapping& mapping, const Name& broadcastForwardingHint,
                            uint32_t parallelFetches, // = 3
+                           bool isSegment,
                            const SegmentCallback& defaultSegmentCallback,
                            const FinishCallback& defaultFinishCallback, const FetchTaskDbPtr& taskDb)
   : m_face(face)
@@ -53,6 +54,7 @@
   , m_taskDb(taskDb)
   , m_broadcastHint(broadcastForwardingHint)
   , m_ioService(m_face.getIoService())
+  , m_isSegment(isSegment)
 {
   // no need to check to often. if needed, will be rescheduled
   m_scheduledFetchesEvent =
@@ -102,7 +104,7 @@
 
   _LOG_TRACE("++++ Create fetcher: " << baseName);
   Fetcher* fetcher =
-    new Fetcher(m_face, segmentCallback, finishCallback,
+    new Fetcher(m_face, m_isSegment, segmentCallback, finishCallback,
                 bind(&FetchManager::DidFetchComplete, this, _1, _2, _3),
                 bind(&FetchManager::DidNoDataTimeout, this, _1), deviceName, baseName, minSeqNo,
                 maxSeqNo, time::seconds(30), forwardingHint);
diff --git a/src/fetch-manager.hpp b/src/fetch-manager.hpp
index 5dae0ff..6cd84c9 100644
--- a/src/fetch-manager.hpp
+++ b/src/fetch-manager.hpp
@@ -18,8 +18,8 @@
  * See AUTHORS.md for complete list of ChronoShare authors and contributors.
  */
 
-#ifndef FETCH_MANAGER_H
-#define FETCH_MANAGER_H
+#ifndef CHRONOSHARE_SRC_FETCH_MANAGER_HPP
+#define CHRONOSHARE_SRC_FETCH_MANAGER_HPP
 
 #include "fetch-task-db.hpp"
 #include "fetcher.hpp"
@@ -54,6 +54,7 @@
 public:
   FetchManager(Face& face, const Mapping& mapping, const Name& broadcastForwardingHint,
                uint32_t parallelFetches = 3,
+               bool isSegment = true,
                const SegmentCallback& defaultSegmentCallback = SegmentCallback(),
                const FinishCallback& defaultFinishCallback = FinishCallback(),
                const FetchTaskDbPtr& taskDb = FetchTaskDbPtr());
@@ -110,6 +111,8 @@
 
   const Name m_broadcastHint;
   boost::asio::io_service& m_ioService;
+
+  bool m_isSegment;
 };
 
 typedef shared_ptr<FetchManager> FetchManagerPtr;
@@ -117,4 +120,4 @@
 } // namespace chronoshare
 } // namespace ndn
 
-#endif // FETCHER_H
+#endif // CHRONOSHARE_SRC_FETCH_MANAGER_HPP
diff --git a/src/fetcher.cpp b/src/fetcher.cpp
index 56899de..5a11074 100644
--- a/src/fetcher.cpp
+++ b/src/fetcher.cpp
@@ -31,6 +31,7 @@
 _LOG_INIT(Fetcher);
 
 Fetcher::Fetcher(Face& face,
+                 bool isSegment,
                  const SegmentCallback& segmentCallback,
                  const FinishCallback& finishCallback,
                  const OnFetchCompleteCallback& onFetchComplete,
@@ -67,6 +68,7 @@
   , m_nextScheduledRetry(time::steady_clock::now())
 
   , m_ioService(m_face.getIoService())
+  , m_isSegment(isSegment)
 {
 }
 
@@ -110,15 +112,21 @@
 
     // cout << ">>> " << m_minSendSeqNo+1 << endl;
 
-    Interest interest(
-      Name(m_forwardingHint).append(m_name).appendNumber(m_minSendSeqNo + 1)); // Alex: this lifetime should be changed to RTO
-    _LOG_DEBUG("interest Name: " << interest);
-    interest.setInterestLifetime(time::seconds(1));
+    Name name = Name(m_forwardingHint).append(m_name);
+    if (m_isSegment) {
+       name.appendSegment(m_minSendSeqNo + 1);
+    }
+    else {
+       name.appendNumber(m_minSendSeqNo + 1);
+    }
+    Interest interest(name);
+    interest.setInterestLifetime(time::seconds(1));  // Alex: this lifetime should be changed to RTO
+    _LOG_DEBUG("interest: " << interest);
     m_face.expressInterest(interest,
                            bind(&Fetcher::OnData, this, m_minSendSeqNo + 1, _1, _2),
                            bind(&Fetcher::OnTimeout, this, m_minSendSeqNo + 1, _1));
 
-    _LOG_DEBUG(" >>> i ok");
+    _LOG_TRACE(" >>> i ok");
 
     m_activePipeline++;
   }
diff --git a/src/fetcher.hpp b/src/fetcher.hpp
index 40d5258..cdee6c3 100644
--- a/src/fetcher.hpp
+++ b/src/fetcher.hpp
@@ -44,6 +44,7 @@
   typedef std::function<void(Fetcher&)> OnFetchFailedCallback;
 
   Fetcher(Face& face,
+          bool isSegment,
           const SegmentCallback& segmentCallback, // callback passed by caller of FetchManager
           const FinishCallback& finishCallback,   // callback passed by caller of FetchManager
           const OnFetchCompleteCallback& onFetchComplete,
@@ -166,6 +167,7 @@
   std::mutex m_seqNoMutex;
 
   boost::asio::io_service& m_ioService;
+  bool m_isSegment;
 };
 
 typedef shared_ptr<Fetcher> FetcherPtr;
diff --git a/src/object-manager.cpp b/src/object-manager.cpp
index 4ca0361..649c29f 100644
--- a/src/object-manager.cpp
+++ b/src/object-manager.cpp
@@ -75,8 +75,8 @@
     name.append(deviceName)
       .append(m_appName)
       .append("file")
-      .appendImplicitSha256Digest(fileHash.computeDigest())
-      .appendNumber(segment);
+      .append(name::Component(fileHash.computeDigest()))
+      .appendSegment(segment);
 
     shared_ptr<Data> data = make_shared<Data>();
     data->setName(name);
@@ -94,9 +94,9 @@
     Name name = Name("/");
     name.append(m_appName)
       .append("file")
-      .appendImplicitSha256Digest(fileHash.computeDigest())
+      .append(name::Component(fileHash.computeDigest()))
       .append(deviceName)
-      .appendNumber(0);
+      .appendSegment(0);
 
     shared_ptr<Data> data = make_shared<Data>();
     data->setName(name);
diff --git a/src/sync-core.cpp b/src/sync-core.cpp
index 23c65c3..8e781f1 100644
--- a/src/sync-core.cpp
+++ b/src/sync-core.cpp
@@ -108,7 +108,7 @@
   // reply sync Interest with oldDigest as last component
 
   Name syncName(m_syncPrefix);
-  syncName.appendImplicitSha256Digest(oldDigest);
+  syncName.append(name::Component(oldDigest));
 
   BufferPtr syncData = serializeGZipMsg(*msg);
 
@@ -150,7 +150,7 @@
 {
   Name syncInterest(m_syncPrefix);
   //  syncInterest.append(name::Component(*m_rootDigest));
-  syncInterest.appendImplicitSha256Digest(m_rootDigest);
+  syncInterest.append(name::Component(m_rootDigest));
 
   _LOG_DEBUG("[" << m_log->GetLocalName() << "] >>> send SYNC Interest for " << toHex(*m_rootDigest)
                  << ": "
@@ -178,7 +178,7 @@
     // unfortunately we still don't recognize this digest
     // append the unknown digest
     Name recoverInterest(m_syncPrefix);
-    recoverInterest.append(RECOVER).appendImplicitSha256Digest(digest);
+    recoverInterest.append(RECOVER).append(name::Component(digest));
 
     _LOG_DEBUG("[" << m_log->GetLocalName() << "] >>> send RECOVER Interests for " << toHex(*digest));
 
diff --git a/tests/unit-tests/fetch-manager.t.cpp b/tests/unit-tests/fetch-manager.t.cpp
index 32304fb..69d8a05 100644
--- a/tests/unit-tests/fetch-manager.t.cpp
+++ b/tests/unit-tests/fetch-manager.t.cpp
@@ -55,7 +55,7 @@
     recvData.insert(seqno);
     differentNames.insert(basename);
     Name name = basename;
-    name.appendNumber(seqno);
+    name.appendSegment(seqno);
     segmentNames.insert(name);
 
     Block block = data->getContent();
@@ -111,7 +111,7 @@
 
         auto data = make_shared<Data>();
         Name name(baseName);
-        name.appendNumber(requestedSeqNo);
+        name.appendSegment(requestedSeqNo);
 
         data->setName(name);
         data->setFreshnessPeriod(time::seconds(300));
@@ -122,7 +122,7 @@
       }
     });
 
-  Fetcher fetcher(face, bind(&FetcherTestData::onData, this, _1, _2, _3, _4),
+  Fetcher fetcher(face, true, bind(&FetcherTestData::onData, this, _1, _2, _3, _4),
                   bind(&FetcherTestData::finish, this, _1, _2),
                   bind(&FetcherTestData::onComplete, this, _1),
                   bind(&FetcherTestData::onFail, this, _1), deviceName, Name("/fetchtest"), 0, 26,