Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Teng Liang | 6f09ab6 | 2018-03-01 20:04:08 -0700 | [diff] [blame] | 2 | /* |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Alexander Afanasyev | 28d586a | 2014-07-10 20:10:54 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 25 | |
| 26 | #include "pit-entry.hpp" |
| 27 | #include <algorithm> |
| 28 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 29 | namespace nfd { |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 30 | namespace pit { |
| 31 | |
| 32 | Entry::Entry(const Interest& interest) |
Teng Liang | 6f09ab6 | 2018-03-01 20:04:08 -0700 | [diff] [blame] | 33 | : isSatisfied(false) |
| 34 | , dataFreshnessPeriod(0_ms) |
| 35 | , m_interest(interest.shared_from_this()) |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 36 | , m_nameTreeEntry(nullptr) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 37 | { |
| 38 | } |
| 39 | |
Junxiao Shi | a274292 | 2016-11-17 22:53:23 +0000 | [diff] [blame] | 40 | bool |
| 41 | Entry::canMatch(const Interest& interest, size_t nEqualNameComps) const |
| 42 | { |
| 43 | BOOST_ASSERT(m_interest->getName().compare(0, nEqualNameComps, |
| 44 | interest.getName(), 0, nEqualNameComps) == 0); |
| 45 | |
| 46 | return m_interest->getName().compare(nEqualNameComps, Name::npos, |
| 47 | interest.getName(), nEqualNameComps) == 0 && |
| 48 | m_interest->getSelectors() == interest.getSelectors(); |
| 49 | /// \todo #3162 match Link field |
| 50 | } |
| 51 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 52 | InRecordCollection::iterator |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 53 | Entry::getInRecord(const Face& face, uint64_t endpointId) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 54 | { |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 55 | return std::find_if(m_inRecords.begin(), m_inRecords.end(), |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 56 | [&face, endpointId] (const InRecord& inRecord) { |
| 57 | return &inRecord.getFace() == &face && inRecord.getEndpointId() == endpointId; |
| 58 | }); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 61 | InRecordCollection::iterator |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 62 | Entry::insertOrUpdateInRecord(Face& face, uint64_t endpointId, const Interest& interest) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 63 | { |
Junxiao Shi | a274292 | 2016-11-17 22:53:23 +0000 | [diff] [blame] | 64 | BOOST_ASSERT(this->canMatch(interest)); |
| 65 | |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 66 | auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(), |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 67 | [&face, endpointId] (const InRecord& inRecord) { |
| 68 | return &inRecord.getFace() == &face && inRecord.getEndpointId() == endpointId; |
| 69 | }); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 70 | if (it == m_inRecords.end()) { |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 71 | m_inRecords.emplace_front(face, endpointId); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 72 | it = m_inRecords.begin(); |
| 73 | } |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 74 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 75 | it->update(interest); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 76 | return it; |
| 77 | } |
| 78 | |
| 79 | void |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 80 | Entry::deleteInRecord(const Face& face, uint64_t endpointId) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 81 | { |
| 82 | auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(), |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 83 | [&face, endpointId] (const InRecord& inRecord) { |
| 84 | return &inRecord.getFace() == &face && inRecord.getEndpointId() == endpointId; |
| 85 | }); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 86 | if (it != m_inRecords.end()) { |
| 87 | m_inRecords.erase(it); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | void |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 92 | Entry::clearInRecords() |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 93 | { |
| 94 | m_inRecords.clear(); |
| 95 | } |
| 96 | |
| 97 | OutRecordCollection::iterator |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 98 | Entry::getOutRecord(const Face& face, uint64_t endpointId) |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 99 | { |
| 100 | return std::find_if(m_outRecords.begin(), m_outRecords.end(), |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 101 | [&face, endpointId] (const OutRecord& outRecord) { |
| 102 | return &outRecord.getFace() == &face && outRecord.getEndpointId() == endpointId; |
| 103 | }); |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | OutRecordCollection::iterator |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 107 | Entry::insertOrUpdateOutRecord(Face& face, uint64_t endpointId, const Interest& interest) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 108 | { |
Junxiao Shi | a274292 | 2016-11-17 22:53:23 +0000 | [diff] [blame] | 109 | BOOST_ASSERT(this->canMatch(interest)); |
| 110 | |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 111 | auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(), |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 112 | [&face, endpointId] (const OutRecord& outRecord) { |
| 113 | return &outRecord.getFace() == &face && outRecord.getEndpointId() == endpointId; |
| 114 | }); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 115 | if (it == m_outRecords.end()) { |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 116 | m_outRecords.emplace_front(face, endpointId); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 117 | it = m_outRecords.begin(); |
| 118 | } |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 119 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 120 | it->update(interest); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 121 | return it; |
| 122 | } |
| 123 | |
| 124 | void |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 125 | Entry::deleteOutRecord(const Face& face, uint64_t endpointId) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 126 | { |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 127 | auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(), |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 128 | [&face, endpointId] (const OutRecord& outRecord) { |
| 129 | return &outRecord.getFace() == &face && outRecord.getEndpointId() == endpointId; |
| 130 | }); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 131 | if (it != m_outRecords.end()) { |
| 132 | m_outRecords.erase(it); |
| 133 | } |
| 134 | } |
| 135 | |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 136 | void |
| 137 | Entry::deleteInOutRecordsByFace(const Face& face) |
| 138 | { |
| 139 | m_inRecords.remove_if([&face] (const InRecord& inRecord) { |
| 140 | return &inRecord.getFace() == &face; |
| 141 | }); |
| 142 | m_outRecords.remove_if([&face] (const OutRecord& outRecord) { |
| 143 | return &outRecord.getFace() == &face; |
| 144 | }); |
| 145 | } |
| 146 | |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 147 | } // namespace pit |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 148 | } // namespace nfd |