Integrate name change (add /ndn/multicast/ prefix). Additionally updated unit tests to test cases of
many torrent segments and many manifests.

Change-Id: Ieb3b3971fb09e31ddb15d85b5907ee7be41ef1ba
diff --git a/src/file-manifest.cpp b/src/file-manifest.cpp
index 2e6dcd2..6310b20 100644
--- a/src/file-manifest.cpp
+++ b/src/file-manifest.cpp
@@ -65,7 +65,7 @@
                                               manifestPrefix.toUri() + " and "     +
                                               full_path.toUri()));
   }
-  ndn::Name manifestName = "/NTORRENT/";
+  ndn::Name manifestName = "/ndn/multicast/NTORRENT/";
   // Rebuild the name to be the suffix from the matching component
   for (auto it = (name_component_iter.base() - 1); full_path.end() != it; ++it) {
     manifestName.append(*it);
@@ -204,7 +204,6 @@
 {
   BOOST_ASSERT(name != m_catalogPrefix);
   BOOST_ASSERT(m_catalogPrefix.isPrefixOf(name));
-  // TODO(msweatt) Change this to use the copy constructor once bug fixed in Name()
   m_catalog.push_back(name.toUri());
 }
 
diff --git a/src/file-manifest.hpp b/src/file-manifest.hpp
index 8366db2..e11b560 100644
--- a/src/file-manifest.hpp
+++ b/src/file-manifest.hpp
@@ -312,7 +312,7 @@
 inline std::string
 FileManifest::file_name() const
 {
-  return name().getSubName(1, name().size() - 2).toUri();
+  return name().getSubName(3, name().size() - 4).toUri();
 }
 
 
diff --git a/src/main.cpp b/src/main.cpp
index c4240d9..2fd441d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -103,7 +103,7 @@
           manifests.insert(manifests.end(), ms.first.begin(), ms.first.end());
         }
         auto torrentPrefix = fs::canonical(dataPath).filename().string();
-        outputPath += torrentPrefix;
+        outputPath += ("/" + torrentPrefix);
         auto torrentPath =  outputPath + "/torrent_files/";
         // write all the torrent segments
         for (const TorrentFile& t : torrentSegments) {
diff --git a/src/torrent-file.cpp b/src/torrent-file.cpp
index 30957bf..e5ef53e 100644
--- a/src/torrent-file.cpp
+++ b/src/torrent-file.cpp
@@ -252,7 +252,7 @@
   Name directoryPathName(directoryPath);
   fs::recursive_directory_iterator directoryPtr(fs::system_complete(directoryPath).string());
 
-  Name commonPrefix("/NTORRENT" +
+  Name commonPrefix("/ndn/multicast/NTORRENT" +
                     directoryPathName.getSubName(directoryPathName.size() - 1).toUri());
 
   Name torrentName(commonPrefix.toUri() + "/torrent-file");
@@ -265,7 +265,7 @@
   }
   size_t manifestFileCounter = 0u;
   for (const auto& fileName : fileNames) {
-    Name manifestPrefix("/NTORRENT" +
+    Name manifestPrefix("/ndn/multicast/NTORRENT" +
                         directoryPathName.getSubName(directoryPathName.size() - 1).toUri());
     std::pair<std::vector<FileManifest>, std::vector<Data>> currentManifestPair =
                                                     FileManifest::generate(fileName,
diff --git a/src/torrent-manager.cpp b/src/torrent-manager.cpp
index 110d90f..892228f 100644
--- a/src/torrent-manager.cpp
+++ b/src/torrent-manager.cpp
@@ -17,6 +17,7 @@
 #include <string>
 #include <unordered_map>
 #include <vector>
+#include <boost/asio/io_service.hpp>
 
 namespace fs = boost::filesystem;
 
@@ -32,7 +33,6 @@
   security::KeyChain key_chain;
   Name currSegmentFullName = initialSegmentName;
   vector<TorrentFile> torrentSegments = IoUtil::load_directory<TorrentFile>(torrentFilePath);
-
   // Starting with the initial segment name, verify the names, loading next name from torrentSegment
   for (auto it = torrentSegments.begin(); it != torrentSegments.end(); ++it) {
     TorrentFile& segment = *it;
@@ -169,10 +169,10 @@
   // figure out the name of the torrent
   Name torrentName;
   if (m_torrentFileName.get(m_torrentFileName.size() - 2).isSequenceNumber()) {
-    torrentName = m_torrentFileName.getSubName(1, m_torrentFileName.size() - 4);
+    torrentName = m_torrentFileName.getSubName(3, m_torrentFileName.size() - 6);
   }
   else {
-    torrentName = m_torrentFileName.getSubName(1, m_torrentFileName.size() - 3);
+    torrentName = m_torrentFileName.getSubName(3, m_torrentFileName.size() - 5);
   }
 
   // TODO(spyros) Get update manager working
@@ -406,7 +406,6 @@
       this->sendInterest();
       if (m_pendingInterests.empty() && m_interestQueue->empty() && !m_seedFlag) {
         shutdown();
-        return;
       }
   };
 
@@ -520,6 +519,12 @@
                            bind(&TorrentManager::onRegisterFailed, this, _1, _2));
 }
 
+void
+TorrentManager::shutdown()
+{
+  m_face->getIoService().stop();
+}
+
 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
 //                                Protected Helpers
 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
@@ -650,7 +655,6 @@
     this->sendInterest();
     if (m_pendingInterests.empty() && m_interestQueue->empty() && !m_seedFlag) {
       shutdown();
-      return;
     }
   };
 
diff --git a/src/torrent-manager.hpp b/src/torrent-manager.hpp
index 12096c3..8c638dd 100644
--- a/src/torrent-manager.hpp
+++ b/src/torrent-manager.hpp
@@ -341,9 +341,9 @@
   uint64_t                                                            m_sortingCounter;
   // Keychain instance
   shared_ptr<KeyChain>                                                m_keyChain;
-
+  // A collection for all interests that have been sent for which we have not received a response
   std::unordered_set<ndn::Name>                                       m_pendingInterests;
-
+  // A queue to hold all interests for requested data that we have yet to send
   shared_ptr<InterestQueue>                                           m_interestQueue;
   // TODO(spyros) Fix and reintegrate update handler
   // // Update Handler instance
@@ -393,14 +393,6 @@
   return findTorrentFileSegmentToDownload() == nullptr;
 }
 
-inline
-void
-TorrentManager::shutdown()
-{
-  // TODO(msweatt) Consider unregistering all prefix to exit more gracefully
-  m_face->shutdown();
-}
-
 }  // end ntorrent
 }  // end ndn