blob: ea6ce90975a8618728029d703b32c2293eb762eb [file] [log] [blame]
spirosmastorakis2f769c22016-03-12 11:46:04 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3* Copyright (c) 2016 Regents of the University of California.
4*
5* This file is part of the nTorrent codebase.
6*
7* nTorrent is free software: you can redistribute it and/or modify it under the
8* terms of the GNU Lesser General Public License as published by the Free Software
9* Foundation, either version 3 of the License, or (at your option) any later version.
10*
11* nTorrent is distributed in the hope that it will be useful, but WITHOUT ANY
12* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14*
15* You should have received copies of the GNU General Public License and GNU Lesser
16* General Public License along with nTorrent, e.g., in COPYING.md file. If not, see
17* <http://www.gnu.org/licenses/>.
18*
19* See AUTHORS for complete list of nTorrent authors and contributors.
20*/
21
22#ifndef SEQUENTIAL_DATA_FETCHER_HPP
23#define SEQUENTIAL_DATA_FETCHER_HPP
24
25#include "fetching-strategy-manager.hpp"
26#include "torrent-manager.hpp"
27
28#include <ndn-cxx/name.hpp>
29
30namespace ndn {
31namespace ntorrent {
32
33class SequentialDataFetcher : FetchingStrategyManager {
34 public:
35 class Error : public std::runtime_error
36 {
37 public:
38 explicit
39 Error(const std::string& what)
40 : std::runtime_error(what)
41 {
42 }
43 };
44 /**
45 * @brief Create a new SequentialDataFetcher
46 * @param torrentFileName The name of the torrent file
47 * @param dataPath The path that the manager would look for already stored data packets and
48 * will write new data packets
49 */
50 SequentialDataFetcher(const ndn::Name& torrentFileName,
51 const std::string& dataPath);
52
53 ~SequentialDataFetcher();
54
55 /**
56 * @brief Start the sequential data fetcher
57 */
58 void
59 start();
60
61 /**
62 * @brief Pause the sequential data fetcher
63 */
64 void
65 pause();
66
67 /**
68 * @brief Resume the sequential data fetcher
69 */
70 void
71 resume();
72
73 protected:
74 std::vector<ndn::Name>
75 downloadTorrentFile();
76
77 void
78 downloadManifestFiles(const std::vector<ndn::Name>& manifestsName);
79
80 void
81 downloadPackets(const std::vector<ndn::Name>& packetsName);
82
83 void
84 implementSequentialLogic();
85
86 virtual void
87 onDataPacketReceived(const ndn::Data& data);
88
89 virtual void
90 onDataRetrievalFailure(const ndn::Interest& interest, const std::string& errorCode);
91
92 virtual void
93 onManifestReceived(const std::vector<Name>& packetNames);
94
95 private:
96 std::string m_dataPath;
97 ndn::Name m_torrentFileName;
98 shared_ptr<TorrentManager> m_manager;
99};
100
101} // namespace ntorrent
102} // namespace ndn
103
104#endif // SEQUENTIAL_DATA_FETCHER_HPP