blob: ca43032f437a2f87b6871719e31d7f9c0b7dd385 [file] [log] [blame]
Ashlesh Gawande08784d42017-09-06 23:40:21 -05001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Davide Pesavento48dbab62023-08-12 16:06:52 -04003 * Copyright (c) 2012-2023 University of California, Los Angeles
Ashlesh Gawande08784d42017-09-06 23:40:21 -05004 *
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
Davide Pesavento1af79492023-09-22 15:45:21 -040022#include <boost/asio/io_context.hpp>
23#include <boost/asio/post.hpp>
Ashlesh Gawande08784d42017-09-06 23:40:21 -050024
25namespace ndn {
26namespace chronosync {
27
Davide Pesavento1af79492023-09-22 15:45:21 -040028DummyForwarder::DummyForwarder(boost::asio::io_context& io, KeyChain& keyChain)
Ashlesh Gawande08784d42017-09-06 23:40:21 -050029 : m_io(io)
30 , m_keyChain(keyChain)
31{
32}
33
34Face&
35DummyForwarder::addFace()
36{
Davide Pesavento48dbab62023-08-12 16:06:52 -040037 auto face = std::make_shared<DummyClientFace>(m_io, m_keyChain, DummyClientFace::Options{true, true});
38 DummyClientFace* self = &*face; // to prevent memory leak
39
Nick Gordon0b3beab2018-03-02 13:03:28 -060040 face->onSendInterest.connect([this, self] (const Interest& interest) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050041 Interest i(interest);
42 for (auto& otherFace : m_faces) {
Nick Gordon0b3beab2018-03-02 13:03:28 -060043 if (self == &*otherFace) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050044 continue;
45 }
Davide Pesavento1af79492023-09-22 15:45:21 -040046 boost::asio::post(m_io, [=] { otherFace->receive(i); });
Ashlesh Gawande08784d42017-09-06 23:40:21 -050047 }
48 });
Davide Pesavento48dbab62023-08-12 16:06:52 -040049
Nick Gordon0b3beab2018-03-02 13:03:28 -060050 face->onSendData.connect([this, self] (const Data& data) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050051 Data d(data);
52 for (auto& otherFace : m_faces) {
Nick Gordon0b3beab2018-03-02 13:03:28 -060053 if (self == &*otherFace) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050054 continue;
55 }
Davide Pesavento1af79492023-09-22 15:45:21 -040056 boost::asio::post(m_io, [=] { otherFace->receive(d); });
Ashlesh Gawande08784d42017-09-06 23:40:21 -050057 }
58 });
59
Nick Gordon0b3beab2018-03-02 13:03:28 -060060 face->onSendNack.connect([this, self] (const lp::Nack& nack) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050061 lp::Nack n(nack);
62 for (auto& otherFace : m_faces) {
Nick Gordon0b3beab2018-03-02 13:03:28 -060063 if (self == &*otherFace) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050064 continue;
65 }
Davide Pesavento1af79492023-09-22 15:45:21 -040066 boost::asio::post(m_io, [=] { otherFace->receive(n); });
Ashlesh Gawande08784d42017-09-06 23:40:21 -050067 }
68 });
69
70 m_faces.push_back(face);
71 return *face;
72}
73
Nick Gordon0b3beab2018-03-02 13:03:28 -060074void
75DummyForwarder::removeFaces()
76{
77 m_faces.clear();
78}
79
Ashlesh Gawande08784d42017-09-06 23:40:21 -050080} // namespace chronosync
81} // namespace ndn