blob: 899ddbddc9e8f13644dd1bf122f2120a314b9b7e [file] [log] [blame]
akmhoque66e66182014-02-21 17:56:03 -06001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
19 * Chaoyi Bian <bcy@pku.edu.cn>
Vince Lehman0a7da612014-10-29 14:39:29 -050020 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
akmhoque66e66182014-02-21 17:56:03 -060021 */
22
dmcoomese689dd62017-03-29 11:05:12 -050023#ifndef NLSR_NSYNC_SYNC_INTEREST_TABLE_H
24#define NLSR_NSYNC_SYNC_INTEREST_TABLE_H
akmhoque66e66182014-02-21 17:56:03 -060025
akmhoquec8a10f72014-04-25 18:42:55 -050026#include <ndn-cxx/util/scheduler.hpp>
akmhoque66e66182014-02-21 17:56:03 -060027
28#include <string>
29#include <vector>
30
31#include "sync-digest.h"
32#include "sync-interest-container.h"
33
34namespace Sync {
35
36/**
37 * \ingroup sync
38 * @brief A table to keep unanswered Sync Interest
Vince Lehman0a7da612014-10-29 14:39:29 -050039 * all access operation to the table should grab the
akmhoque66e66182014-02-21 17:56:03 -060040 * mutex first
41 */
42class SyncInterestTable
43{
44public:
akmhoque05d5fcf2014-04-15 14:58:45 -050045 SyncInterestTable (boost::asio::io_service& io, ndn::time::system_clock::Duration lifetime);
akmhoque66e66182014-02-21 17:56:03 -060046 ~SyncInterestTable ();
47
48 /**
49 * @brief Insert an interest, if interest already exists, update the
50 * timestamp
51 */
52 bool
53 insert (DigestConstPtr interest, const std::string &name, bool unknownState=false);
54
55 /**
56 * @brief Remove interest by digest (e.g., when it was satisfied)
57 */
58 bool
59 remove (DigestConstPtr interest);
60
61 /**
62 * @brief Remove interest by name (e.g., when it was satisfied)
63 */
64 bool
65 remove (const std::string &name);
Vince Lehman0a7da612014-10-29 14:39:29 -050066
akmhoque66e66182014-02-21 17:56:03 -060067 /**
68 * @brief pop a non-expired Interest from PIT
69 */
70 Interest
71 pop ();
72
73 uint32_t
74 size () const;
75
76private:
77 /**
78 * @brief periodically called to expire Interest
79 */
80 void
81 expireInterests ();
82
83private:
akmhoque05d5fcf2014-04-15 14:58:45 -050084 ndn::time::system_clock::Duration m_entryLifetime;
akmhoque66e66182014-02-21 17:56:03 -060085 InterestContainer m_table;
86
87 ndn::Scheduler m_scheduler;
88};
89
90namespace Error {
91struct InterestTableIsEmpty : virtual boost::exception, virtual std::exception { };
92}
93
94} // Sync
95
dmcoomese689dd62017-03-29 11:05:12 -050096#endif // NLSR_NSYNC_SYNC_INTEREST_TABLE_H