blob: db67fb10ebaf0a9e121986a935dc980bb6e5069a [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
*
* NLSR is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NLSR_SYNC_PROTOCOL_ADAPTER_HPP
#define NLSR_SYNC_PROTOCOL_ADAPTER_HPP
#include "conf-parameter.hpp"
#include <ndn-cxx/face.hpp>
#ifdef HAVE_CHRONOSYNC
#include <ChronoSync/logic.hpp>
#endif
#include <PSync/full-producer.hpp>
namespace nlsr {
typedef std::function<void(const ndn::Name& updateName,
uint64_t seqNo, uint64_t incomingFaceId)> SyncUpdateCallback;
class SyncProtocolAdapter
{
public:
SyncProtocolAdapter(ndn::Face& facePtr,
SyncProtocol syncProtocol,
const ndn::Name& syncPrefix,
const ndn::Name& userPrefix,
ndn::time::milliseconds syncInterestLifetime,
const SyncUpdateCallback& syncUpdateCallback);
/*! \brief Add user node to ChronoSync or PSync
*
* \param userPrefix the Name under which the application will publishData
*/
void
addUserNode(const ndn::Name& userPrefix);
/*! \brief Publish update to ChronoSync or PSync
*
* NLSR forces sequences number on the sync protocol
* as it manages is its own sequence number by storing it in a file.
*
* \param userPrefix the Name to be updated
* \param seq the sequence of userPrefix
*/
void
publishUpdate(const ndn::Name& userPrefix, uint64_t seq);
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
#ifdef HAVE_CHRONOSYNC
/*! \brief Hook function to call whenever ChronoSync detects new data.
*
* This function packages the sync information into discrete updates
* and passes those off to another function, m_syncUpdateCallback.
* \sa m_syncUpdateCallback
*
* \param v A container with the new information sync has received
*/
void
onChronoSyncUpdate(const std::vector<chronosync::MissingDataInfo>& updates);
#endif
/*! \brief Hook function to call whenever PSync detects new data.
*
* This function packages the sync information into discrete updates
* and passes those off to another function, m_syncUpdateCallback.
* \sa m_syncUpdateCallback
*
* \param v A container with the new information sync has received
*/
void
onPSyncUpdate(const std::vector<psync::MissingDataInfo>& updates);
private:
SyncProtocol m_syncProtocol;
SyncUpdateCallback m_syncUpdateCallback;
#ifdef HAVE_CHRONOSYNC
std::shared_ptr<chronosync::Logic> m_chronoSyncLogic;
#endif
std::shared_ptr<psync::FullProducer> m_psyncLogic;
};
} // namespace nlsr
#endif // NLSR_SYNC_PROTOCOL_ADAPTER_HPP