29 #ifdef HAVE_CHRONOSYNC
30 const auto FIXED_SESSION = ndn::name::Component::fromNumber(0);
34 ndn::KeyChain& keyChain,
36 const ndn::Name& syncPrefix,
37 const ndn::Name& userPrefix,
38 ndn::time::milliseconds syncInterestLifetime,
40 : m_syncProtocol(syncProtocol)
41 , m_syncUpdateCallback(std::move(syncUpdateCallback))
43 switch (m_syncProtocol) {
44 #ifdef HAVE_CHRONOSYNC
46 NDN_LOG_DEBUG(
"Using ChronoSync");
47 m_chronoSyncLogic = std::make_shared<chronosync::Logic>(face,
50 [
this] (
auto&&... args) { onChronoSyncUpdate(std::forward<decltype(args)>(args)...); },
51 chronosync::Logic::DEFAULT_NAME,
52 chronosync::Logic::DEFAULT_VALIDATOR,
53 chronosync::Logic::DEFAULT_RESET_TIMER,
54 chronosync::Logic::DEFAULT_CANCEL_RESET_TIMER,
55 chronosync::Logic::DEFAULT_RESET_INTEREST_LIFETIME,
57 chronosync::Logic::DEFAULT_SYNC_REPLY_FRESHNESS,
58 chronosync::Logic::DEFAULT_RECOVERY_INTEREST_LIFETIME,
64 NDN_LOG_DEBUG(
"Using PSync");
65 psync::FullProducer::Options opts;
66 opts.onUpdate = [
this] (
auto&&... args) { onPSyncUpdate(std::forward<decltype(args)>(args)...); };
67 opts.syncInterestLifetime = syncInterestLifetime;
68 m_psyncLogic = std::make_shared<psync::FullProducer>(face, keyChain, syncPrefix, opts);
69 m_psyncLogic->addUserNode(userPrefix);
75 NDN_LOG_DEBUG(
"Using SVS");
76 m_svsCore = std::make_shared<ndn::svs::SVSyncCore>(face,
78 [
this] (
auto&&... args) { onSvsUpdate(std::forward<decltype(args)>(args)...); });
89 switch (m_syncProtocol) {
90 #ifdef HAVE_CHRONOSYNC
92 m_chronoSyncLogic->addUserNode(userPrefix, chronosync::Logic::DEFAULT_NAME, FIXED_SESSION);
97 m_psyncLogic->addUserNode(userPrefix);
112 switch (m_syncProtocol) {
113 #ifdef HAVE_CHRONOSYNC
115 m_chronoSyncLogic->updateSeqNo(seq, userPrefix);
120 m_psyncLogic->publishName(userPrefix, seq);
125 m_svsCore->updateSeqNo(seq, userPrefix);
133 #ifdef HAVE_CHRONOSYNC
135 SyncProtocolAdapter::onChronoSyncUpdate(
const std::vector<chronosync::MissingDataInfo>& updates)
139 for (
const auto& update : updates) {
141 m_syncUpdateCallback(update.session.getPrefix(-1), update.high, 0);
148 SyncProtocolAdapter::onPSyncUpdate(
const std::vector<psync::MissingDataInfo>& updates)
152 for (
const auto& update : updates) {
153 m_syncUpdateCallback(update.prefix, update.highSeq, update.incomingFace);
160 SyncProtocolAdapter::onSvsUpdate(
const std::vector<ndn::svs::MissingDataInfo>& updates)
164 for (
const auto& update : updates) {
165 m_syncUpdateCallback(update.nodeId, update.high, update.incomingFace);
void publishUpdate(const ndn::Name &userPrefix, uint64_t seq)
Publish update to Sync.
SyncProtocolAdapter(ndn::Face &face, ndn::KeyChain &keyChain, SyncProtocol syncProtocol, const ndn::Name &syncPrefix, const ndn::Name &userPrefix, ndn::time::milliseconds syncInterestLifetime, SyncUpdateCallback syncUpdateCallback)
void addUserNode(const ndn::Name &userPrefix)
Add user node to Sync.
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define INIT_LOGGER(name)
#define NLSR_LOG_TRACE(x)
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
std::function< void(const ndn::Name &updateName, uint64_t seqNo, uint64_t incomingFaceId)> SyncUpdateCallback