Abstracting testbed prepended name components

Change-Id: Ieb3b3971fb09e31ddb15d85b5907ee7be41ef6ae
diff --git a/src/file-manifest.cpp b/src/file-manifest.cpp
index 6310b20..1ccb4ef 100644
--- a/src/file-manifest.cpp
+++ b/src/file-manifest.cpp
@@ -65,7 +65,7 @@
                                               manifestPrefix.toUri() + " and "     +
                                               full_path.toUri()));
   }
-  ndn::Name manifestName = "/ndn/multicast/NTORRENT/";
+  ndn::Name manifestName(SharedConstants::commonPrefix + std::string("/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);
@@ -331,4 +331,4 @@
 }
 
 }  // end ntorrent
-}  // end ndn
\ No newline at end of file
+}  // end ndn
diff --git a/src/file-manifest.hpp b/src/file-manifest.hpp
index e11b560..ee04fdd 100644
--- a/src/file-manifest.hpp
+++ b/src/file-manifest.hpp
@@ -21,6 +21,8 @@
 #ifndef INCLUDED_FILE_MANIFEST_HPP
 #define INCLUDED_FILE_MANIFEST_HPP
 
+#include "util/shared-constants.hpp"
+
 #include <cstring>
 #include <memory>
 #include <string>
@@ -312,7 +314,9 @@
 inline std::string
 FileManifest::file_name() const
 {
-  return name().getSubName(3, name().size() - 4).toUri();
+  Name scheme(SharedConstants::commonPrefix);
+  return name().getSubName(1 + scheme.size(),
+         name().size() - (2 + scheme.size())).toUri();
 }
 
 
diff --git a/src/main.cpp b/src/main.cpp
index 2fd441d..2a0f69a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -50,6 +50,11 @@
   }
 };
 
+namespace ntorrent {
+
+const char * SharedConstants::commonPrefix = "/ndn";
+
+} // end ntorrent
 } // end ndn
 
 // TODO(msweatt) Add options verification
diff --git a/src/torrent-file.cpp b/src/torrent-file.cpp
index e5ef53e..544f9ce 100644
--- a/src/torrent-file.cpp
+++ b/src/torrent-file.cpp
@@ -252,7 +252,8 @@
   Name directoryPathName(directoryPath);
   fs::recursive_directory_iterator directoryPtr(fs::system_complete(directoryPath).string());
 
-  Name commonPrefix("/ndn/multicast/NTORRENT" +
+  std::string prefix = std::string(SharedConstants::commonPrefix) + "/NTORRENT";
+  Name commonPrefix(prefix +
                     directoryPathName.getSubName(directoryPathName.size() - 1).toUri());
 
   Name torrentName(commonPrefix.toUri() + "/torrent-file");
@@ -265,7 +266,7 @@
   }
   size_t manifestFileCounter = 0u;
   for (const auto& fileName : fileNames) {
-    Name manifestPrefix("/ndn/multicast/NTORRENT" +
+    Name manifestPrefix(prefix +
                         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 892228f..ad7f842 100644
--- a/src/torrent-manager.cpp
+++ b/src/torrent-manager.cpp
@@ -1,3 +1,24 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+* Copyright (c) 2016 Regents of the University of California.
+*
+* This file is part of the nTorrent codebase.
+*
+* nTorrent is free software: you can redistribute it and/or modify it under the
+* terms of the GNU Lesser General Public License as published by the Free Software
+* Foundation, either version 3 of the License, or (at your option) any later version.
+*
+* nTorrent is distributed in the hope that it will be useful, but WITHOUT ANY
+* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+*
+* You should have received copies of the GNU General Public License and GNU Lesser
+* General Public License along with nTorrent, e.g., in COPYING.md file. If not, see
+* <http://www.gnu.org/licenses/>.
+*
+* See AUTHORS for complete list of nTorrent authors and contributors.
+*/
+
 #include "torrent-manager.hpp"
 
 #include "file-manifest.hpp"
@@ -168,11 +189,12 @@
 
   // figure out the name of the torrent
   Name torrentName;
+  Name scheme(SharedConstants::commonPrefix);
   if (m_torrentFileName.get(m_torrentFileName.size() - 2).isSequenceNumber()) {
-    torrentName = m_torrentFileName.getSubName(3, m_torrentFileName.size() - 6);
+    torrentName = m_torrentFileName.getSubName(1 + scheme.size(), m_torrentFileName.size() - (4 + scheme.size()));
   }
   else {
-    torrentName = m_torrentFileName.getSubName(3, m_torrentFileName.size() - 5);
+    torrentName = m_torrentFileName.getSubName(1 + scheme.size(), m_torrentFileName.size() - (3 + scheme.size()));
   }
 
   // TODO(spyros) Get update manager working
diff --git a/src/torrent-manager.hpp b/src/torrent-manager.hpp
index 8c638dd..b1fd730 100644
--- a/src/torrent-manager.hpp
+++ b/src/torrent-manager.hpp
@@ -18,6 +18,7 @@
 *
 * See AUTHORS for complete list of nTorrent authors and contributors.
 */
+
 #ifndef INCLUDED_TORRENT_FILE_MANAGER_H
 #define INCLUDED_TORRENT_FILE_MANAGER_H
 
diff --git a/src/util/shared-constants.hpp b/src/util/shared-constants.hpp
new file mode 100644
index 0000000..e29491e
--- /dev/null
+++ b/src/util/shared-constants.hpp
@@ -0,0 +1,30 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+* Copyright (c) 2016 Regents of the University of California.
+*
+* This file is part of the nTorrent codebase.
+*
+* nTorrent is free software: you can redistribute it and/or modify it under the
+* terms of the GNU Lesser General Public License as published by the Free Software
+* Foundation, either version 3 of the License, or (at your option) any later version.
+*
+* nTorrent is distributed in the hope that it will be useful, but WITHOUT ANY
+* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+*
+* You should have received copies of the GNU General Public License and GNU Lesser
+* General Public License along with nTorrent, e.g., in COPYING.md file. If not, see
+* <http://www.gnu.org/licenses/>.
+*
+* See AUTHORS for complete list of nTorrent authors and contributors.
+*/
+
+namespace ndn {
+namespace ntorrent {
+
+struct SharedConstants {
+  static const char* commonPrefix;
+};
+
+} // namespace ntorrent
+} // namespace ndn