Alexander Afanasyev | 6e3d1ac | 2014-07-21 12:47:49 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014, Regents of the University of California. |
| 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 | #ifndef NDNS_RESPONSE_HPP |
| 21 | #define NDNS_RESPONSE_HPP |
| 22 | |
| 23 | #include <boost/asio.hpp> |
| 24 | #include <boost/bind.hpp> |
| 25 | #include <boost/date_time/posix_time/posix_time.hpp> |
| 26 | #include <boost/noncopyable.hpp> |
| 27 | |
| 28 | #include <ndn-cxx/face.hpp> // /usr/local/include |
| 29 | #include <ndn-cxx/name.hpp> |
| 30 | #include <ndn-cxx/data.hpp> |
| 31 | |
| 32 | #include <ndn-cxx/encoding/block-helpers.hpp> |
| 33 | #include <ndn-cxx/encoding/block.hpp> |
| 34 | #include <ndn-cxx/encoding/tlv-ndnd.hpp> |
| 35 | |
| 36 | #include <vector> |
| 37 | |
| 38 | #include "ndns-tlv.hpp" |
| 39 | |
| 40 | namespace ndn { |
| 41 | namespace ndns { |
| 42 | |
| 43 | enum ResponseType |
| 44 | { |
| 45 | NDNS_Resp, |
| 46 | NDNS_Nack, |
| 47 | NDNS_Auth |
| 48 | }; |
| 49 | |
| 50 | |
| 51 | static std::string |
| 52 | toString(ResponseType responseType) const |
| 53 | { |
| 54 | string label; |
| 55 | switch (responseType) |
| 56 | { |
| 57 | case ResponseType::NDNS_Resp: |
| 58 | label = "NDNS Resp"; |
| 59 | break; |
| 60 | case ResponseType::NDNS_Nack: |
| 61 | label = "NDNS Nack"; |
| 62 | break; |
| 63 | case ResponseType::NDNS_Auth: |
| 64 | label = "NDNS Auth"; |
| 65 | break; |
| 66 | default: |
| 67 | label = "Default"; |
| 68 | break; |
| 69 | } |
| 70 | return label; |
| 71 | } |
| 72 | |
| 73 | class Response { |
| 74 | public: |
| 75 | Response(); |
| 76 | virtual ~Response(); |
| 77 | |
| 78 | Data |
| 79 | toWire() const; |
| 80 | |
| 81 | void |
| 82 | fromWire(const Interest &interest, const Data &data); |
| 83 | |
| 84 | private: |
| 85 | Name m_queryName; |
| 86 | std::string m_serial; |
| 87 | ResponseType m_responseType; |
| 88 | |
| 89 | time::milliseconds m_freshness; |
| 90 | |
| 91 | unsigned int m_numberOfRR; |
| 92 | vector<RR> m_rrs; |
| 93 | |
| 94 | }; |
| 95 | |
| 96 | } // namespace ndns |
| 97 | } // namespace ndn |
| 98 | |
| 99 | #endif // NDNS_RESPONSE_HPP |