23 #ifndef NDN_CHRONO_SYNC_HPP
24 #define NDN_CHRONO_SYNC_HPP
27 #include "../face.hpp"
28 #include "../security/key-chain.hpp"
29 #include "../util/memory-content-cache.hpp"
32 namespace Sync {
class SyncStateMsg; }
33 namespace Sync {
class SyncState; }
50 typedef func_lib::function<void
51 (
const std::vector<ChronoSync2013::SyncState>& syncStates,
bool isRecovery)>
54 typedef func_lib::function<void()> OnInitialized;
106 (
const OnReceivedSyncState& onReceivedSyncState,
107 const OnInitialized& onInitialized,
const Name& applicationDataPrefix,
108 const Name& applicationBroadcastPrefix,
int sessionNo,
112 (onReceivedSyncState, onInitialized, applicationDataPrefix,
113 applicationBroadcastPrefix, sessionNo, face, keyChain, certificateName,
116 impl_->initialize(onRegisterFailed);
128 SyncState(
const std::string& dataPrefixUri,
int sessionNo,
int sequenceNo)
129 : dataPrefixUri_(dataPrefixUri), sessionNo_(sessionNo), sequenceNo_(sequenceNo)
156 std::string dataPrefixUri_;
172 return impl_->getProducerSequenceNo(dataPrefix, sessionNo);
192 return impl_->publishNextSequenceNo();
203 return impl_->getSequenceNo();
223 class DigestLogEntry {
226 (
const std::string& digest,
230 getDigest()
const {
return digest_; }
233 getData()
const {
return *data_; }
237 ptr_lib::shared_ptr<google::protobuf::RepeatedPtrField<Sync::SyncState> > data_;
245 class Impl :
public ptr_lib::enable_shared_from_this<Impl> {
253 (
const OnReceivedSyncState& onReceivedSyncState,
254 const OnInitialized& onInitialized,
const Name& applicationDataPrefix,
255 const Name& applicationBroadcastPrefix,
int sessionNo,
256 Face& face, KeyChain& keyChain,
const Name& certificateName,
296 contentCache_.unregisterAll();
323 logFind(
const std::string& digest)
const;
332 (
const ptr_lib::shared_ptr<const Name>& prefix,
333 const ptr_lib::shared_ptr<const Interest>& interest, Face& face,
334 uint64_t registerPrefixId,
335 const ptr_lib::shared_ptr<const InterestFilter>& filter);
340 (
const ptr_lib::shared_ptr<const Interest>& interest,
341 const ptr_lib::shared_ptr<Data>& data);
345 initialTimeOut(
const ptr_lib::shared_ptr<const Interest>& interest);
348 processRecoveryInterest
349 (
const Interest& interest,
const std::string& syncDigest, Face& face);
357 processSyncInterest(
int index,
const std::string& syncDigest, Face& face);
361 sendRecovery(
const std::string& syncDigest);
371 (
const ptr_lib::shared_ptr<const Interest> &interest,
372 const std::string& syncDigest, Face* face);
376 syncTimeout(
const ptr_lib::shared_ptr<const Interest>& interest);
388 (
const ptr_lib::shared_ptr<const Interest>& interest,
389 const ptr_lib::shared_ptr<Data>& data);
393 Name certificateName_;
395 OnReceivedSyncState onReceivedSyncState_;
396 OnInitialized onInitialized_;
397 std::vector<ptr_lib::shared_ptr<DigestLogEntry> > digestLog_;
398 ptr_lib::shared_ptr<DigestTree> digestTree_;
399 std::string applicationDataPrefixUri_;
400 const Name applicationBroadcastPrefix_;
403 MemoryContentCache contentCache_;
407 ptr_lib::shared_ptr<Impl> impl_;
Definition: sync-state.pb.h:290
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:111
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
int getProducerSequenceNo(const std::string &dataPrefix, int sessionNo) const
Get the current sequence number in the digest tree for the given producer dataPrefix and sessionNo...
Definition: chrono-sync2013.hpp:170
void shutdown()
Unregister callbacks so that this does not respond to interests anymore.
Definition: chrono-sync2013.hpp:217
ChronoSync2013(const OnReceivedSyncState &onReceivedSyncState, const OnInitialized &onInitialized, const Name &applicationDataPrefix, const Name &applicationBroadcastPrefix, int sessionNo, Face &face, KeyChain &keyChain, const Name &certificateName, Milliseconds syncLifetime, const OnRegisterFailed &onRegisterFailed)
Create a new ChronoSync2013 to communicate using the given face.
Definition: chrono-sync2013.hpp:106
The Face class provides the main methods for NDN communication.
Definition: face.hpp:86
Definition: chrono-sync2013.hpp:32
void publishNextSequenceNo()
Increment the sequence number, create a sync message with the new sequence number and publish a data ...
Definition: chrono-sync2013.hpp:190
Definition: chrono-sync2013.hpp:31
KeyChain is the main class of the security library.
Definition: key-chain.hpp:45
int getSequenceNo() const
Get the sequence number of the latest data published by this application instance.
Definition: chrono-sync2013.hpp:201
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
ChronoSync2013 implements the NDN ChronoSync protocol as described in the 2013 paper "Let's ChronoSyn...
Definition: chrono-sync2013.hpp:47
const std::string & getDataPrefix() const
Get the application data prefix for this sync state message.
Definition: chrono-sync2013.hpp:138
int getSequenceNo() const
Get the sequence number for this sync state message.
Definition: chrono-sync2013.hpp:153
Copyright (C) 2014-2016 Regents of the University of California.
Definition: channel-status.pb.h:315
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &)> OnRegisterFailed
An OnRegisterFailed function object is used to report when registerPrefix fails.
Definition: face.hpp:72
A SyncState holds the values of a sync state message which is passed to the onReceivedSyncState callb...
Definition: chrono-sync2013.hpp:126
int getSessionNo() const
Get the session number associated with the application data prefix for this sync state message...
Definition: chrono-sync2013.hpp:146