Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Davide Pesavento | 48dbab6 | 2023-08-12 16:06:52 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2012-2023 University of California, Los Angeles |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ChronoSync, synchronization library for distributed realtime |
| 6 | * applications for NDN. |
| 7 | * |
| 8 | * ChronoSync 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, either |
| 10 | * version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * ChronoSync 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 | * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "dummy-forwarder.hpp" |
| 21 | |
| 22 | #include <boost/asio/io_service.hpp> |
| 23 | |
| 24 | namespace ndn { |
| 25 | namespace chronosync { |
| 26 | |
| 27 | DummyForwarder::DummyForwarder(boost::asio::io_service& io, KeyChain& keyChain) |
| 28 | : m_io(io) |
| 29 | , m_keyChain(keyChain) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | Face& |
| 34 | DummyForwarder::addFace() |
| 35 | { |
Davide Pesavento | 48dbab6 | 2023-08-12 16:06:52 -0400 | [diff] [blame^] | 36 | auto face = std::make_shared<DummyClientFace>(m_io, m_keyChain, DummyClientFace::Options{true, true}); |
| 37 | DummyClientFace* self = &*face; // to prevent memory leak |
| 38 | |
Nick Gordon | 0b3beab | 2018-03-02 13:03:28 -0600 | [diff] [blame] | 39 | face->onSendInterest.connect([this, self] (const Interest& interest) { |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 40 | Interest i(interest); |
| 41 | for (auto& otherFace : m_faces) { |
Nick Gordon | 0b3beab | 2018-03-02 13:03:28 -0600 | [diff] [blame] | 42 | if (self == &*otherFace) { |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 43 | continue; |
| 44 | } |
| 45 | m_io.post([=] { otherFace->receive(i); }); |
| 46 | } |
| 47 | }); |
Davide Pesavento | 48dbab6 | 2023-08-12 16:06:52 -0400 | [diff] [blame^] | 48 | |
Nick Gordon | 0b3beab | 2018-03-02 13:03:28 -0600 | [diff] [blame] | 49 | face->onSendData.connect([this, self] (const Data& data) { |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 50 | Data d(data); |
| 51 | for (auto& otherFace : m_faces) { |
Nick Gordon | 0b3beab | 2018-03-02 13:03:28 -0600 | [diff] [blame] | 52 | if (self == &*otherFace) { |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 53 | continue; |
| 54 | } |
| 55 | m_io.post([=] { otherFace->receive(d); }); |
| 56 | } |
| 57 | }); |
| 58 | |
Nick Gordon | 0b3beab | 2018-03-02 13:03:28 -0600 | [diff] [blame] | 59 | face->onSendNack.connect([this, self] (const lp::Nack& nack) { |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 60 | lp::Nack n(nack); |
| 61 | for (auto& otherFace : m_faces) { |
Nick Gordon | 0b3beab | 2018-03-02 13:03:28 -0600 | [diff] [blame] | 62 | if (self == &*otherFace) { |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 63 | continue; |
| 64 | } |
| 65 | m_io.post([=] { otherFace->receive(n); }); |
| 66 | } |
| 67 | }); |
| 68 | |
| 69 | m_faces.push_back(face); |
| 70 | return *face; |
| 71 | } |
| 72 | |
Nick Gordon | 0b3beab | 2018-03-02 13:03:28 -0600 | [diff] [blame] | 73 | void |
| 74 | DummyForwarder::removeFaces() |
| 75 | { |
| 76 | m_faces.clear(); |
| 77 | } |
| 78 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 79 | } // namespace chronosync |
| 80 | } // namespace ndn |