| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /* |
| * Copyright (c) 2014-2018, The University of Memphis |
| * |
| * This file is part of PSync. |
| * See AUTHORS.md for complete list of PSync authors and contributors. |
| * |
| * PSync is free software: you can redistribute it and/or modify it under the terms |
| * of the GNU General Public License as published by the Free Software Foundation, |
| * either version 3 of the License, or (at your option) any later version. |
| * |
| * PSync 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 General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License along with |
| * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| **/ |
| |
| #ifndef PSYNC_SEGMENT_PUBLISHER_HPP |
| #define PSYNC_SEGMENT_PUBLISHER_HPP |
| |
| #include "detail/test-access-control.hpp" |
| |
| #include <ndn-cxx/face.hpp> |
| #include <ndn-cxx/name.hpp> |
| #include <ndn-cxx/security/key-chain.hpp> |
| #include <ndn-cxx/util/scheduler-scoped-event-id.hpp> |
| #include <ndn-cxx/util/scheduler.hpp> |
| #include <ndn-cxx/util/time.hpp> |
| #include <ndn-cxx/ims/in-memory-storage-fifo.hpp> |
| |
| namespace psync { |
| |
| const int MAX_SEGMENTS_STORED = 100; |
| |
| /** |
| * @brief Segment Publisher to publish segmented data |
| * |
| */ |
| class SegmentPublisher |
| { |
| public: |
| SegmentPublisher(ndn::Face& face, ndn::KeyChain& keyChain, |
| size_t imsLimit = MAX_SEGMENTS_STORED); |
| |
| /** |
| * @brief Put all the segments in memory. |
| * |
| * @param interestName the interest name, to determine the sequence to be answered immediately |
| * @param dataName the data name, has components after interest name |
| * @param block the content of the data |
| * @param freshness freshness of the segments |
| */ |
| void |
| publish(const ndn::Name& interestName, const ndn::Name& dataName, |
| const ndn::Block& block, ndn::time::milliseconds freshness); |
| |
| /** |
| * @brief Try to reply from memory, return false if we cannot find the segment. |
| * |
| * The caller is then expected to use publish if this returns false. |
| */ |
| bool |
| replyFromStore(const ndn::Name& interestName); |
| |
| private: |
| ndn::Face& m_face; |
| ndn::util::Scheduler m_scheduler; |
| ndn::KeyChain& m_keyChain; |
| |
| PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| ndn::InMemoryStorageFifo m_ims; |
| }; |
| |
| } // namespace psync |
| |
| #endif // PSYNC_SEGMENT_PUBLISHER_HPP |