blob: 2bcc3bc7f46648870673e15ef7e2f30dbc6bd76a [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
22#include <boost/asio/io_service.hpp>
23
24namespace ndn {
25namespace chronosync {
26
27DummyForwarder::DummyForwarder(boost::asio::io_service& io, KeyChain& keyChain)
28 : m_io(io)
29 , m_keyChain(keyChain)
30{
31}
32
33Face&
34DummyForwarder::addFace()
35{
Davide Pesavento48dbab62023-08-12 16:06:52 -040036 auto face = std::make_shared<DummyClientFace>(m_io, m_keyChain, DummyClientFace::Options{true, true});
37 DummyClientFace* self = &*face; // to prevent memory leak
38
Nick Gordon0b3beab2018-03-02 13:03:28 -060039 face->onSendInterest.connect([this, self] (const Interest& interest) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050040 Interest i(interest);
41 for (auto& otherFace : m_faces) {
Nick Gordon0b3beab2018-03-02 13:03:28 -060042 if (self == &*otherFace) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050043 continue;
44 }
45 m_io.post([=] { otherFace->receive(i); });
46 }
47 });
Davide Pesavento48dbab62023-08-12 16:06:52 -040048
Nick Gordon0b3beab2018-03-02 13:03:28 -060049 face->onSendData.connect([this, self] (const Data& data) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050050 Data d(data);
51 for (auto& otherFace : m_faces) {
Nick Gordon0b3beab2018-03-02 13:03:28 -060052 if (self == &*otherFace) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050053 continue;
54 }
55 m_io.post([=] { otherFace->receive(d); });
56 }
57 });
58
Nick Gordon0b3beab2018-03-02 13:03:28 -060059 face->onSendNack.connect([this, self] (const lp::Nack& nack) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050060 lp::Nack n(nack);
61 for (auto& otherFace : m_faces) {
Nick Gordon0b3beab2018-03-02 13:03:28 -060062 if (self == &*otherFace) {
Ashlesh Gawande08784d42017-09-06 23:40:21 -050063 continue;
64 }
65 m_io.post([=] { otherFace->receive(n); });
66 }
67 });
68
69 m_faces.push_back(face);
70 return *face;
71}
72
Nick Gordon0b3beab2018-03-02 13:03:28 -060073void
74DummyForwarder::removeFaces()
75{
76 m_faces.clear();
77}
78
Ashlesh Gawande08784d42017-09-06 23:40:21 -050079} // namespace chronosync
80} // namespace ndn