Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | f6fd2fb | 2022-03-18 21:00:36 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, The University of Memphis |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 4 | * |
| 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 Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 9 | * of the GNU Lesser General Public License as published by the Free Software Foundation, |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 10 | * 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 Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 14 | * PURPOSE. See the GNU Lesser General Public License for more details. |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 15 | * |
Ashlesh Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 16 | * You should have received a copy of the GNU Lesser General Public License along with |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 17 | * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
| 19 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 20 | #include "PSync/full-producer.hpp" |
Davide Pesavento | db78956 | 2020-12-19 23:01:08 -0500 | [diff] [blame] | 21 | #include "PSync/detail/util.hpp" |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 22 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 23 | #include "tests/boost-test.hpp" |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 24 | #include "tests/io-fixture.hpp" |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame^] | 25 | #include "tests/key-chain-fixture.hpp" |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 26 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 27 | #include <ndn-cxx/util/dummy-client-face.hpp> |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 28 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 29 | namespace psync { |
| 30 | |
| 31 | using namespace ndn; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 32 | |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame^] | 33 | class FullProducerFixture : public tests::IoFixture, public tests::KeyChainFixture |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 34 | { |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame^] | 35 | protected: |
| 36 | util::DummyClientFace m_face{m_io, m_keyChain, {true, true}}; |
| 37 | }; |
| 38 | |
| 39 | BOOST_FIXTURE_TEST_SUITE(TestFullProducer, FullProducerFixture) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 40 | |
| 41 | BOOST_AUTO_TEST_CASE(OnInterest) |
| 42 | { |
| 43 | Name syncPrefix("/psync"), userNode("/testUser"); |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame^] | 44 | FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 45 | |
| 46 | Name syncInterestName(syncPrefix); |
| 47 | syncInterestName.append("malicious-IBF"); |
| 48 | |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame^] | 49 | BOOST_CHECK_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName))); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 50 | } |
| 51 | |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame^] | 52 | BOOST_AUTO_TEST_CASE(ConstantTimeoutForFirstSegment) |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 53 | { |
| 54 | Name syncPrefix("/psync"), userNode("/testUser"); |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame^] | 55 | FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr, 8_s); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 56 | |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 57 | advanceClocks(10_ms); |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame^] | 58 | m_face.sentInterests.clear(); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 59 | |
| 60 | // full sync sends the next one in interest lifetime / 2 +- jitter |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 61 | advanceClocks(6_s); |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame^] | 62 | BOOST_CHECK_EQUAL(m_face.sentInterests.size(), 1); |
Ashlesh Gawande | 584e120 | 2019-05-19 16:15:33 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 65 | BOOST_AUTO_TEST_CASE(OnSyncDataDecodeFailure) |
| 66 | { |
| 67 | Name syncPrefix("/psync"), userNode("/testUser"); |
Davide Pesavento | c45a4ea | 2022-09-19 02:10:53 -0400 | [diff] [blame^] | 68 | FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 69 | |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 70 | Name syncInterestName(syncPrefix); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 71 | node.m_iblt.appendToName(syncInterestName); |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 72 | Interest syncInterest(syncInterestName); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 73 | |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 74 | auto badCompress = std::make_shared<const Buffer>(5); |
| 75 | BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, badCompress)); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 76 | |
| 77 | const uint8_t test[] = {'t', 'e', 's', 't'}; |
Davide Pesavento | f6fd2fb | 2022-03-18 21:00:36 -0400 | [diff] [blame] | 78 | auto goodCompressBadBlock = detail::compress(node.m_contentCompression, test); |
Davide Pesavento | f91d1df | 2020-11-25 14:50:41 -0500 | [diff] [blame] | 79 | BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, goodCompressBadBlock)); |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 80 | } |
| 81 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 82 | BOOST_AUTO_TEST_SUITE_END() |
| 83 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 84 | } // namespace psync |