Yumin Xia | fa2bce7 | 2017-04-09 16:20:25 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
| 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. |
| 10 | * |
| 11 | * This file is part of NDNS (Named Data Networking Domain Name Service) and is |
| 12 | * based on the code written as part of NFD (Named Data Networking Daemon). |
| 13 | * See AUTHORS.md for complete list of NDNS authors and contributors. |
| 14 | * |
| 15 | * NDNS is free software: you can redistribute it and/or modify it under the terms |
| 16 | * of the GNU General Public License as published by the Free Software Foundation, |
| 17 | * either version 3 of the License, or (at your option) any later version. |
| 18 | * |
| 19 | * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 20 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 21 | * PURPOSE. See the GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License along with |
| 24 | * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 25 | */ |
| 26 | |
| 27 | #include "dummy-forwarder.hpp" |
| 28 | |
| 29 | #include <boost/asio/io_service.hpp> |
| 30 | |
| 31 | namespace ndn { |
| 32 | namespace ndns { |
| 33 | namespace tests { |
| 34 | |
| 35 | DummyForwarder::DummyForwarder(boost::asio::io_service& io, KeyChain& keyChain) |
| 36 | : m_io(io) |
| 37 | , m_keyChain(keyChain) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | Face& |
| 42 | DummyForwarder::addFace() |
| 43 | { |
| 44 | auto face = std::make_shared<util::DummyClientFace>(m_io, m_keyChain, util:: |
| 45 | DummyClientFace::Options{true, true}); |
| 46 | face->onSendInterest.connect([this, face] (const Interest& interest) { |
| 47 | for (auto& otherFace : m_faces) { |
| 48 | if (&*face == &*otherFace) { |
| 49 | continue; |
| 50 | } |
| 51 | otherFace->receive(interest); |
| 52 | } |
| 53 | }); |
| 54 | |
| 55 | face->onSendData.connect([this, face] (const Data& data) { |
| 56 | for (auto& otherFace : m_faces) { |
| 57 | if (&*face == &*otherFace) { |
| 58 | continue; |
| 59 | } |
| 60 | otherFace->receive(data); |
| 61 | } |
| 62 | }); |
| 63 | |
| 64 | face->onSendNack.connect([this, face] (const lp::Nack& nack) { |
| 65 | for (auto& otherFace : m_faces) { |
| 66 | if (&*face == &*otherFace) { |
| 67 | continue; |
| 68 | } |
| 69 | otherFace->receive(nack); |
| 70 | } |
| 71 | }); |
| 72 | |
| 73 | m_faces.push_back(face); |
| 74 | return *face; |
| 75 | } |
| 76 | |
| 77 | } // namespace tests |
| 78 | } // namespace ndns |
| 79 | } // namespace ndn |