Added processEvents() call to TorrentManager and update clients to use it including adding a seed method to the FetchStratedegyManager to seed data.
Change-Id: I98e4c794c98ca35765df968c2cf7c4fe1e622595
diff --git a/src/fetching-strategy-manager.hpp b/src/fetching-strategy-manager.hpp
index 53de939..a34afa0 100644
--- a/src/fetching-strategy-manager.hpp
+++ b/src/fetching-strategy-manager.hpp
@@ -22,8 +22,9 @@
#ifndef FETCHING_STRATEGY_MANAGER_HPP
#define FETCHING_STRATEGY_MANAGER_HPP
-#include <ndn-cxx/interest.hpp>
#include <ndn-cxx/data.hpp>
+#include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/util/time.hpp>
namespace ndn {
namespace ntorrent {
@@ -66,6 +67,12 @@
struct status {
double downloadedPercent;
};
+ /**
+ * @brief Seed downloaded data for the specified timeout.
+ * By default this will go into an infinite loop.
+ */
+ virtual void
+ seed(const time::milliseconds& timeout = time::milliseconds::zero()) const = 0;
private:
/**
diff --git a/src/sequential-data-fetcher.cpp b/src/sequential-data-fetcher.cpp
index 971b59f..5873374 100644
--- a/src/sequential-data-fetcher.cpp
+++ b/src/sequential-data-fetcher.cpp
@@ -80,6 +80,7 @@
".appdata/manifests/",
bind(&SequentialDataFetcher::onManifestReceived, this, _1),
bind(&SequentialDataFetcher::onDataRetrievalFailure, this, _1, _2));
+ m_manager->processEvents();
}
}
@@ -90,6 +91,7 @@
m_manager->download_data_packet(*i,
bind(&SequentialDataFetcher::onDataPacketReceived, this, _1),
bind(&SequentialDataFetcher::onDataRetrievalFailure, this, _1, _2));
+ m_manager->processEvents();
}
}
@@ -133,7 +135,7 @@
const std::string& errorCode)
{
std::cerr << "Data Retrieval Failed: " << interest.getName() << std::endl;
-
+
// Data retrieval failure
uint32_t nameType = IoUtil::findType(interest.getName());
if (nameType == IoUtil::TORRENT_FILE) {
diff --git a/src/sequential-data-fetcher.hpp b/src/sequential-data-fetcher.hpp
index ea6ce90..8687d9c 100644
--- a/src/sequential-data-fetcher.hpp
+++ b/src/sequential-data-fetcher.hpp
@@ -70,6 +70,9 @@
void
resume();
+ void
+ seed(const time::milliseconds& timeout = time::milliseconds::zero()) const;
+
protected:
std::vector<ndn::Name>
downloadTorrentFile();
@@ -98,6 +101,13 @@
shared_ptr<TorrentManager> m_manager;
};
+inline
+void
+SequentialDataFetcher::seed(const time::milliseconds& timeout) const
+{
+ m_manager->processEvents(timeout);
+}
+
} // namespace ntorrent
} // namespace ndn
diff --git a/src/torrent-manager.hpp b/src/torrent-manager.hpp
index 17e59db..4a8beb4 100644
--- a/src/torrent-manager.hpp
+++ b/src/torrent-manager.hpp
@@ -147,8 +147,15 @@
void
seed(const Data& data);
+ /**
+ * @brief Process any data to receive or call timeout callbacks and update prefix list (if needed)
+ * By default only process pending events and return immediately, optionally specify a timeout.
+ */
+ void
+ processEvents(const time::milliseconds& timeout = time::milliseconds(-1));
+
protected:
- /*
+ /**
* \brief Write @p packet composed of torrent date to disk.
* @param packet The data packet to be written to the disk
* Write the Data packet to disk, return 'true' if data successfully written to disk 'false'
@@ -359,6 +366,13 @@
m_stats_table_iter = m_statsTable.begin();
}
+inline
+void
+TorrentManager::processEvents(const time::milliseconds& timeout)
+{
+ m_face->processEvents(timeout);
+}
+
} // end ntorrent
} // end ndn