Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 2 | /* |
Junxiao Shi | 81e9876 | 2022-01-11 18:17:24 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, Regents of the University of California. |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NDNS (Named Data Networking Domain Name Service). |
| 6 | * See AUTHORS.md for complete list of NDNS authors and contributors. |
| 7 | * |
| 8 | * NDNS 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 | * NDNS 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 | * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "query.hpp" |
| 21 | |
| 22 | namespace ndn { |
| 23 | namespace ndns { |
| 24 | |
| 25 | Query::Query() |
| 26 | : m_interestLifetime(ndn::DEFAULT_INTEREST_LIFETIME) |
| 27 | { |
| 28 | } |
| 29 | |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 30 | Query::Query(const Name& zone, const name::Component& queryType) |
| 31 | : m_zone(zone) |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 32 | , m_queryType(queryType) |
| 33 | , m_interestLifetime(ndn::DEFAULT_INTEREST_LIFETIME) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | |
| 38 | bool |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 39 | Query::fromInterest(const Name& zone, const Interest& interest) |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 40 | { |
| 41 | label::MatchResult re; |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 42 | if (!matchName(interest, zone, re)) |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 43 | return false; |
| 44 | |
| 45 | m_rrLabel = re.rrLabel; |
| 46 | m_rrType = re.rrType; |
| 47 | |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 48 | m_zone = zone; |
| 49 | |
Junxiao Shi | 81e9876 | 2022-01-11 18:17:24 +0000 | [diff] [blame^] | 50 | m_forwardingHint.assign(interest.getForwardingHint().begin(), interest.getForwardingHint().end()); |
Yumin Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 51 | |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 52 | size_t len = zone.size(); |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 53 | m_queryType = interest.getName().get(len); |
| 54 | |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | Interest |
| 59 | Query::toInterest() const |
| 60 | { |
Yumin Xia | 918343d | 2017-03-17 19:04:55 -0700 | [diff] [blame] | 61 | // <zone> [<NDNS>|<NDNS-R>] <rrLabel> <rrType> |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 62 | Name name; |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 63 | |
| 64 | name.append(this->m_zone) |
| 65 | .append(this->m_queryType) |
| 66 | .append(this->m_rrLabel) |
| 67 | .append(this->m_rrType); |
| 68 | |
Eric Newberry | c196a16 | 2020-09-13 14:05:16 -0700 | [diff] [blame] | 69 | Interest interest(name); |
| 70 | interest.setCanBePrefix(true); |
Yumin Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 71 | interest.setInterestLifetime(m_interestLifetime); |
Junxiao Shi | 81e9876 | 2022-01-11 18:17:24 +0000 | [diff] [blame^] | 72 | interest.setForwardingHint(m_forwardingHint); |
Yumin Xia | 4e56189 | 2016-10-21 10:48:01 -0700 | [diff] [blame] | 73 | |
| 74 | return interest; |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 77 | void |
Junxiao Shi | 81e9876 | 2022-01-11 18:17:24 +0000 | [diff] [blame^] | 78 | Query::setForwardingHintFromLink(const Link& link) |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 79 | { |
Junxiao Shi | 81e9876 | 2022-01-11 18:17:24 +0000 | [diff] [blame^] | 80 | m_forwardingHint.assign(link.getDelegationList().begin(), link.getDelegationList().end()); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 83 | std::ostream& |
| 84 | operator<<(std::ostream& os, const Query& query) |
| 85 | { |
| 86 | os << "Query: zone=" << query.getZone() |
Shock Jiang | 01712f3 | 2014-10-01 14:34:16 -0700 | [diff] [blame] | 87 | << " queryType=" << query.getQueryType() |
| 88 | << " rrLabel=" << query.getRrLabel() |
| 89 | << " rrType=" << query.getRrType() |
| 90 | << " Lifetime=" << query.getInterestLifetime() |
| 91 | ; |
| 92 | return os; |
| 93 | } |
| 94 | |
| 95 | } // namespace ndns |
| 96 | } // namespace ndn |