blob: b23ac526942bc954585cc28bf582b8bf02108f61 [file] [log] [blame]
Ashlesh Gawandeec43b362018-08-01 15:15:01 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2018, The University of Memphis
4 *
5 * This file is part of PSync.
6 * See AUTHORS.md for complete list of PSync authors and contributors.
7 *
8 * PSync is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20#ifndef PSYNC_SEGMENT_PUBLISHER_HPP
21#define PSYNC_SEGMENT_PUBLISHER_HPP
22
23#include "detail/test-access-control.hpp"
24
25#include <ndn-cxx/face.hpp>
26#include <ndn-cxx/name.hpp>
27#include <ndn-cxx/security/key-chain.hpp>
28#include <ndn-cxx/util/scheduler-scoped-event-id.hpp>
29#include <ndn-cxx/util/scheduler.hpp>
30#include <ndn-cxx/util/time.hpp>
31#include <ndn-cxx/ims/in-memory-storage-fifo.hpp>
32
33namespace psync {
34
35const int MAX_SEGMENTS_STORED = 100;
36
37/**
38 * @brief Segment Publisher to publish segmented data
39 *
40 */
41class SegmentPublisher
42{
43public:
44 SegmentPublisher(ndn::Face& face, ndn::KeyChain& keyChain,
45 size_t imsLimit = MAX_SEGMENTS_STORED);
46
47 /**
48 * @brief Put all the segments in memory.
49 *
50 * @param interestName the interest name, to determine the sequence to be answered immediately
51 * @param dataName the data name, has components after interest name
52 * @param block the content of the data
53 * @param freshness freshness of the segments
54 */
55 void
56 publish(const ndn::Name& interestName, const ndn::Name& dataName,
57 const ndn::Block& block, ndn::time::milliseconds freshness);
58
59 /**
60 * @brief Try to reply from memory, return false if we cannot find the segment.
61 *
62 * The caller is then expected to use publish if this returns false.
63 */
64 bool
65 replyFromStore(const ndn::Name& interestName);
66
67private:
68 ndn::Face& m_face;
69 ndn::util::Scheduler m_scheduler;
70 ndn::KeyChain& m_keyChain;
71
72PUBLIC_WITH_TESTS_ELSE_PRIVATE:
73 ndn::InMemoryStorageFifo m_ims;
74};
75
76} // namespace psync
77
78#endif // PSYNC_SEGMENT_PUBLISHER_HPP