blob: 7218e6beceeb81b4d2e0ba2584ef8f728bb99909 [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventof6fd2fb2022-03-18 21:00:36 -04003 * Copyright (c) 2014-2022, The University of Memphis
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05004 *
5 * This file is part of PSync.
6 * See AUTHORS.md for complete list of PSync authors and contributors.
7 *
8 * PSync is free software: you can redistribute it and/or modify it under the terms
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -06009 * of the GNU Lesser General Public License as published by the Free Software Foundation,
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050010 * either version 3 of the License, or (at your option) any later version.
11 *
12 * PSync 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
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -060014 * PURPOSE. See the GNU Lesser General Public License for more details.
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050015 *
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -060016 * You should have received a copy of the GNU Lesser General Public License along with
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050017 * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060020#include "PSync/full-producer.hpp"
Davide Pesaventodb789562020-12-19 23:01:08 -050021#include "PSync/detail/util.hpp"
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050022
Davide Pesavento5b3cf762020-04-03 16:20:04 -040023#include "tests/boost-test.hpp"
Davide Pesaventof91d1df2020-11-25 14:50:41 -050024#include "tests/io-fixture.hpp"
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040025#include "tests/key-chain-fixture.hpp"
Davide Pesavento5b3cf762020-04-03 16:20:04 -040026
Davide Pesavento5b3cf762020-04-03 16:20:04 -040027#include <ndn-cxx/util/dummy-client-face.hpp>
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050028
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050029namespace psync {
30
31using namespace ndn;
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050032
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040033class FullProducerFixture : public tests::IoFixture, public tests::KeyChainFixture
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050034{
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040035protected:
36 util::DummyClientFace m_face{m_io, m_keyChain, {true, true}};
37};
38
39BOOST_FIXTURE_TEST_SUITE(TestFullProducer, FullProducerFixture)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050040
41BOOST_AUTO_TEST_CASE(OnInterest)
42{
43 Name syncPrefix("/psync"), userNode("/testUser");
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040044 FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050045
46 Name syncInterestName(syncPrefix);
47 syncInterestName.append("malicious-IBF");
48
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040049 BOOST_CHECK_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName)));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050050}
51
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040052BOOST_AUTO_TEST_CASE(ConstantTimeoutForFirstSegment)
Ashlesh Gawande584e1202019-05-19 16:15:33 -070053{
54 Name syncPrefix("/psync"), userNode("/testUser");
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040055 FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr, 8_s);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070056
Davide Pesaventof91d1df2020-11-25 14:50:41 -050057 advanceClocks(10_ms);
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040058 m_face.sentInterests.clear();
Ashlesh Gawande584e1202019-05-19 16:15:33 -070059
60 // full sync sends the next one in interest lifetime / 2 +- jitter
Davide Pesaventof91d1df2020-11-25 14:50:41 -050061 advanceClocks(6_s);
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040062 BOOST_CHECK_EQUAL(m_face.sentInterests.size(), 1);
Ashlesh Gawande584e1202019-05-19 16:15:33 -070063}
64
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060065BOOST_AUTO_TEST_CASE(OnSyncDataDecodeFailure)
66{
67 Name syncPrefix("/psync"), userNode("/testUser");
Davide Pesaventoc45a4ea2022-09-19 02:10:53 -040068 FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060069
Davide Pesaventof91d1df2020-11-25 14:50:41 -050070 Name syncInterestName(syncPrefix);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060071 node.m_iblt.appendToName(syncInterestName);
Davide Pesaventof91d1df2020-11-25 14:50:41 -050072 Interest syncInterest(syncInterestName);
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060073
Davide Pesaventof91d1df2020-11-25 14:50:41 -050074 auto badCompress = std::make_shared<const Buffer>(5);
75 BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, badCompress));
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060076
77 const uint8_t test[] = {'t', 'e', 's', 't'};
Davide Pesaventof6fd2fb2022-03-18 21:00:36 -040078 auto goodCompressBadBlock = detail::compress(node.m_contentCompression, test);
Davide Pesaventof91d1df2020-11-25 14:50:41 -050079 BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, goodCompressBadBlock));
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060080}
81
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050082BOOST_AUTO_TEST_SUITE_END()
83
Davide Pesavento5b3cf762020-04-03 16:20:04 -040084} // namespace psync