Skip to content

Commit

Permalink
Avoid deprecated ndn-cxx functions
Browse files Browse the repository at this point in the history
Also, waf is updated to version 2.0.23

Change-Id: I053d7dce733455ec352931a1614082542ca00570
  • Loading branch information
Pesa committed Mar 12, 2022
1 parent 26a0326 commit 5f5101a
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 74 deletions.
10 changes: 4 additions & 6 deletions src/leaf-container.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2012-2021 University of California, Los Angeles
* Copyright (c) 2012-2022 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
Expand Down Expand Up @@ -42,14 +42,12 @@ namespace mi = boost::multi_index;

struct SessionNameHash
{
static_assert(ndn::util::Sha256::DIGEST_SIZE >= sizeof(std::size_t), "");

std::size_t
operator()(const Name& prefix) const
{
ConstBufferPtr buffer =
ndn::util::Sha256::computeDigest(prefix.wireEncode().wire(), prefix.wireEncode().size());

BOOST_ASSERT(buffer->size() > sizeof(std::size_t));

auto buffer = ndn::util::Sha256::computeDigest(prefix.wireEncode());
return *reinterpret_cast<const std::size_t*>(buffer->data());
}
};
Expand Down
21 changes: 8 additions & 13 deletions src/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,7 @@ Logic::updateSeqNo(const SeqNo& seqNo, const Name& updatePrefix)
if (!m_isInReset) {
CHRONO_LOG_DBG("updateSeqNo: not in Reset");
ConstBufferPtr previousRoot = m_state.getRootDigest();
{
std::string hash = ndn::toHex(previousRoot->data(), previousRoot->size(), false);
CHRONO_LOG_DBG("Hash: " << hash);
}
printDigest(previousRoot);

bool isInserted = false;
bool isUpdated = false;
Expand Down Expand Up @@ -398,7 +395,7 @@ Logic::onSyncDataValidationFailed(const Data&)
void
Logic::onSyncDataValidated(const Data& data)
{
Name name = data.getName();
const auto& name = data.getName();
ConstBufferPtr digest = make_shared<ndn::Buffer>(name.get(-1).value(), name.get(-1).value_size());

try {
Expand All @@ -407,7 +404,7 @@ Logic::onSyncDataValidated(const Data& data)
processSyncData(name, digest, Block(std::move(contentBuffer)));
}
catch (const std::ios_base::failure& error) {
NDN_LOG_WARN("Error decompressing content of " << data.getName() << " (" << error.what() << ")");
NDN_LOG_WARN("Error decompressing content of " << name << " (" << error.what() << ")");
}
}

Expand All @@ -416,9 +413,8 @@ Logic::processSyncInterest(const Interest& interest, bool isTimedProcessing/*=fa
{
CHRONO_LOG_DBG(">> Logic::processSyncInterest");

Name name = interest.getName();
const auto& name = interest.getName();
ConstBufferPtr digest = make_shared<ndn::Buffer>(name.get(-1).value(), name.get(-1).value_size());

ConstBufferPtr rootDigest = m_state.getRootDigest();

// If the digest of the incoming interest is the same as root digest
Expand Down Expand Up @@ -669,7 +665,7 @@ Logic::encodeSyncReply(const Name& nodePrefix, const Name& name, const State& st
syncReply.setFreshnessPeriod(m_syncReplyFreshness);

auto finalizeReply = [this, &nodePrefix, &syncReply] (const State& state) {
auto contentBuffer = bzip2::compress(reinterpret_cast<const char*>(state.wireEncode().wire()),
auto contentBuffer = bzip2::compress(reinterpret_cast<const char*>(state.wireEncode().data()),
state.wireEncode().size());
syncReply.setContent(contentBuffer);

Expand Down Expand Up @@ -737,10 +733,9 @@ Logic::cancelReset()
}

void
Logic::printDigest(ConstBufferPtr digest)
Logic::printDigest(const ConstBufferPtr& digest) const
{
std::string hash = ndn::toHex(digest->data(), digest->size(), false);
CHRONO_LOG_DBG("Hash: " << hash);
CHRONO_LOG_DBG("Hash: " << ndn::toHex(*digest, false));
}

void
Expand Down Expand Up @@ -771,7 +766,7 @@ Logic::processRecoveryInterest(const Interest& interest)
{
CHRONO_LOG_DBG(">> Logic::processRecoveryInterest");

Name name = interest.getName();
const auto& name = interest.getName();
ConstBufferPtr digest = make_shared<ndn::Buffer>(name.get(-1).value(), name.get(-1).value_size());
ConstBufferPtr rootDigest = m_state.getRootDigest();

Expand Down
4 changes: 2 additions & 2 deletions src/logic.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2012-2021 University of California, Los Angeles
* Copyright (c) 2012-2022 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
Expand Down Expand Up @@ -399,7 +399,7 @@ class Logic : noncopyable
cancelReset();

void
printDigest(ConstBufferPtr digest);
printDigest(const ConstBufferPtr& digest) const;

/**
* @brief Helper method to send Recovery Interest
Expand Down
17 changes: 8 additions & 9 deletions src/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ Socket::Socket(const Name& syncPrefix,
if (m_userPrefix != DEFAULT_NAME)
m_registeredPrefixList[m_userPrefix] =
m_face.setInterestFilter(m_userPrefix,
bind(&Socket::onInterest, this, _1, _2),
[] (const Name&, const std::string&) {});
[this] (auto&&... args) { onInterest(std::forward<decltype(args)>(args)...); },
[] (auto&&...) {});
NDN_LOG_DEBUG("<< Socket::Socket");
}

Expand Down Expand Up @@ -84,8 +84,8 @@ Socket::addSyncNode(const Name& prefix, const Name& signingId, const name::Compo
m_logic.addUserNode(prefix, signingId, session);
m_registeredPrefixList[prefix] =
m_face.setInterestFilter(prefix,
bind(&Socket::onInterest, this, _1, _2),
[] (const Name&, const std::string&) {});
[this] (auto&&... args) { onInterest(std::forward<decltype(args)>(args)...); },
[] (auto&&...) {});

NDN_LOG_DEBUG("<< addSyncNode");
}
Expand All @@ -110,14 +110,14 @@ void
Socket::publishData(const uint8_t* buf, size_t len, const ndn::time::milliseconds& freshness,
const Name& prefix)
{
publishData(ndn::encoding::makeBinaryBlock(ndn::tlv::Content, buf, len), freshness, prefix);
publishData(ndn::makeBinaryBlock(ndn::tlv::Content, {buf, len}), freshness, prefix);
}

void
Socket::publishData(const uint8_t* buf, size_t len, const ndn::time::milliseconds& freshness,
const uint64_t& seqNo, const Name& prefix)
{
publishData(ndn::encoding::makeBinaryBlock(ndn::tlv::Content, buf, len), freshness, seqNo, prefix);
publishData(ndn::makeBinaryBlock(ndn::tlv::Content, {buf, len}), freshness, seqNo, prefix);
}

void
Expand Down Expand Up @@ -178,7 +178,7 @@ Socket::fetchData(const Name& sessionName, const SeqNo& seqNo,
interest.setMustBeFresh(true);

DataValidationErrorCallback failureCallback =
bind(&Socket::onDataValidationFailed, this, _1, _2);
[this] (auto&&... args) { onDataValidationFailed(std::forward<decltype(args)>(args)...); };

m_face.expressInterest(interest,
bind(&Socket::onData, this, _1, _2, dataCallback, failureCallback),
Expand Down Expand Up @@ -254,8 +254,7 @@ Socket::onDataTimeout(const Interest& interest, int nRetries,
}

void
Socket::onDataValidationFailed(const Data& data,
const ValidationError& error)
Socket::onDataValidationFailed(const Data&, const ValidationError&)
{
}

Expand Down
6 changes: 3 additions & 3 deletions src/state.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2012-2021 University of California, Los Angeles
* Copyright (c) 2012-2022 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
Expand Down Expand Up @@ -48,7 +48,7 @@ State::update(const Name& info, const SeqNo& seq)
}

SeqNo old = (*leaf)->getSeq();
m_leaves.modify(leaf, [=] (LeafPtr& leaf) { leaf->setSeq(seq); } );
m_leaves.modify(leaf, [seq] (LeafPtr& leaf) { leaf->setSeq(seq); } );
return std::make_tuple(false, true, old);
}
}
Expand All @@ -60,7 +60,7 @@ State::getRootDigest() const

for (const auto& leaf : m_leaves.get<ordered>()) {
BOOST_ASSERT(leaf != nullptr);
m_digest.update(leaf->getDigest()->data(), leaf->getDigest()->size());
m_digest.update(*leaf->getDigest());
}

return m_digest.computeDigest();
Expand Down
10 changes: 5 additions & 5 deletions tests/unit-tests/test-interest-table.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2012-2019 University of California, Los Angeles
* Copyright (c) 2012-2022 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
Expand Down Expand Up @@ -32,24 +32,24 @@ class InterestTableFixture : public ndn::tests::UnitTestTimeFixture
public:
InterestTableFixture()
{
uint8_t origin[4] = {0x01, 0x02, 0x03, 0x04};
const uint8_t origin[] = {0x01, 0x02, 0x03, 0x04};
Name prefix("/test/prefix");

Name interestName1;
digest1 = ndn::util::Sha256::computeDigest(origin, 1);
digest1 = ndn::util::Sha256::computeDigest({origin, 1});
interestName1.append(prefix).append(name::Component(digest1));

interest1 = Interest(interestName1);
interest1.setInterestLifetime(time::milliseconds(100));

Name interestName2;
digest2 = ndn::util::Sha256::computeDigest(origin, 2);
digest2 = ndn::util::Sha256::computeDigest({origin, 2});
interestName2.append(prefix).append(name::Component(digest2));
interest2 = Interest(interestName2);
interest2.setInterestLifetime(time::milliseconds(100));

Name interestName3;
digest3 = ndn::util::Sha256::computeDigest(origin, 3);
digest3 = ndn::util::Sha256::computeDigest({origin, 3});
interestName3.append(prefix).append(name::Component(digest3));
interest3 = Interest(interestName3);
interest3.setInterestLifetime(time::milliseconds(100));
Expand Down
7 changes: 2 additions & 5 deletions tests/unit-tests/test-leaf.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2012-2019 University of California, Los Angeles
* Copyright (c) 2012-2022 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
Expand Down Expand Up @@ -54,10 +54,7 @@ BOOST_AUTO_TEST_CASE(LeafDigest)
Name userPrefix("/test/name");
Leaf leaf(userPrefix, 1, 10);

BOOST_CHECK_NO_THROW(leaf.getDigest());

ndn::ConstBufferPtr digest = leaf.getDigest();
BOOST_CHECK_EQUAL(result, ndn::toHex(digest->data(), digest->size(), false));
BOOST_CHECK_EQUAL(result, ndn::toHex(*leaf.getDigest(), false));
}

BOOST_AUTO_TEST_CASE(Container)
Expand Down
18 changes: 6 additions & 12 deletions tests/unit-tests/test-logic.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2012-2021 University of California, Los Angeles
* Copyright (c) 2012-2022 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
Expand Down Expand Up @@ -29,17 +29,11 @@
namespace chronosync {
namespace test {

using ndn::chronosync::DummyForwarder;

class Handler
{
public:
Handler(ndn::Face& face,
const Name& syncPrefix,
const Name& userPrefix)
: logic(face,
syncPrefix,
userPrefix,
Handler(ndn::Face& face, const Name& syncPrefix, const Name& userPrefix)
: logic(face, syncPrefix, userPrefix,
bind(&Handler::onUpdate, this, _1))
{
}
Expand Down Expand Up @@ -87,7 +81,7 @@ class LogicFixture : public ndn::tests::IdentityManagementTimeFixture
Name syncPrefix;
Name userPrefix[4];

DummyForwarder fw;
ndn::chronosync::DummyForwarder fw;
// std::unique_ptr<DummyClientFace> faces[4];
shared_ptr<Handler> handler[4];

Expand All @@ -98,7 +92,7 @@ class LogicFixture : public ndn::tests::IdentityManagementTimeFixture
BOOST_FIXTURE_TEST_SUITE(LogicTests, LogicFixture)

static void
onUpdate(const std::vector<MissingDataInfo>& v)
onUpdate(const std::vector<MissingDataInfo>&)
{
}

Expand Down Expand Up @@ -407,7 +401,7 @@ BOOST_FIXTURE_TEST_CASE(VeryLargeState, ndn::tests::IdentityManagementTimeFixtur
Logic logic(face, syncPrefix, userPrefix, bind(onUpdate, _1));

State state;
for (size_t i = 0; i < 50000 && bzip2::compress(reinterpret_cast<const char*>(state.wireEncode().wire()),
for (size_t i = 0; i < 50000 && bzip2::compress(reinterpret_cast<const char*>(state.wireEncode().data()),
state.wireEncode().size())->size() < ndn::MAX_NDN_PACKET_SIZE;
i += 10) {
Name prefix("/to/trim");
Expand Down
19 changes: 6 additions & 13 deletions tests/unit-tests/test-state.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2012-2019 University of California, Los Angeles
* Copyright (c) 2012-2022 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
Expand Down Expand Up @@ -148,17 +148,16 @@ BOOST_AUTO_TEST_CASE(DecodeEncode)
0x04
};

Block block(wire, sizeof(wire));
Block block(wire);
State state;
BOOST_REQUIRE_NO_THROW(state.wireDecode(block));

BOOST_CHECK_EQUAL(state.getLeaves().size(), 2);
LeafContainer::index<ordered>::type::iterator it = state.getLeaves().get<ordered>().begin();
auto it = state.getLeaves().get<ordered>().begin();
BOOST_CHECK_EQUAL((*it)->getSeq(), 14);
it++;
BOOST_CHECK_EQUAL((*it)->getSeq(), 4);


State state2;

Name info1("/test/name");
Expand All @@ -169,15 +168,9 @@ BOOST_AUTO_TEST_CASE(DecodeEncode)
info2.appendNumber(1);
state2.update(info2, 4);

BOOST_REQUIRE_NO_THROW(state2.wireEncode());
Block block2 = state2.wireEncode();

BOOST_CHECK_EQUAL_COLLECTIONS(block.wire(),
block.wire() + block.size(),
block2.wire(),
block2.wire() + block2.size());

BOOST_CHECK(*state.getRootDigest() == *state2.getRootDigest());
BOOST_TEST(block == block2, boost::test_tools::per_element());
BOOST_TEST(*state.getRootDigest() == *state2.getRootDigest(), boost::test_tools::per_element());
}

BOOST_AUTO_TEST_CASE(Combine)
Expand Down Expand Up @@ -208,7 +201,7 @@ BOOST_AUTO_TEST_CASE(Combine)
BOOST_CHECK_EQUAL(state1.getLeaves().size(), 2);
BOOST_CHECK_EQUAL(state2.getLeaves().size(), 3);

LeafContainer::index<ordered>::type::iterator it = state2.getLeaves().get<ordered>().begin();
auto it = state2.getLeaves().get<ordered>().begin();
BOOST_CHECK_EQUAL((*it)->getSeq(), 4);
it++;
BOOST_CHECK_EQUAL((*it)->getSeq(), 15);
Expand Down
12 changes: 6 additions & 6 deletions waf

Large diffs are not rendered by default.

0 comments on commit 5f5101a

Please sign in to comment.