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"
31 namespace google {
namespace protobuf {
template <
typename Element>
class RepeatedPtrField; } }
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;
110 (
const OnReceivedSyncState& onReceivedSyncState,
111 const OnInitialized& onInitialized,
const Name& applicationDataPrefix,
112 const Name& applicationBroadcastPrefix,
int sessionNo,
115 int previousSequenceNumber = -1)
117 (onReceivedSyncState, onInitialized, applicationDataPrefix,
118 applicationBroadcastPrefix, sessionNo, face, keyChain, certificateName,
119 syncLifetime, previousSequenceNumber))
121 impl_->initialize(onRegisterFailed);
134 (
const std::string& dataPrefixUri,
int sessionNo,
int sequenceNo,
135 const Blob& applicationInfo)
136 : dataPrefixUri_(dataPrefixUri), sessionNo_(sessionNo),
137 sequenceNo_(sequenceNo), applicationInfo_(applicationInfo)
172 std::string dataPrefixUri_;
175 Blob applicationInfo_;
185 : dataPrefixUri_(dataPrefixUri), sessionNo_(sessionNo)
205 std::string dataPrefixUri_;
219 impl_->getProducerPrefixes(prefixes);
233 return impl_->getProducerSequenceNo(dataPrefix, sessionNo);
257 return impl_->publishNextSequenceNo(applicationInfo);
268 return impl_->getSequenceNo();
288 class DigestLogEntry {
291 (
const std::string& digest,
295 getDigest()
const {
return digest_; }
298 getData()
const {
return *data_; }
302 ptr_lib::shared_ptr<google::protobuf::RepeatedPtrField<Sync::SyncState> > data_;
310 class Impl :
public ptr_lib::enable_shared_from_this<Impl> {
318 (
const OnReceivedSyncState& onReceivedSyncState,
319 const OnInitialized& onInitialized,
const Name& applicationDataPrefix,
320 const Name& applicationBroadcastPrefix,
int sessionNo,
321 Face& face, KeyChain& keyChain,
const Name& certificateName,
367 contentCache_.unregisterAll();
380 (
const std::string& digest,
const Sync::SyncStateMsg& syncMessage);
394 logFind(
const std::string& digest)
const;
403 (
const ptr_lib::shared_ptr<const Name>& prefix,
404 const ptr_lib::shared_ptr<const Interest>& interest, Face& face,
405 uint64_t registerPrefixId,
406 const ptr_lib::shared_ptr<const InterestFilter>& filter);
411 (
const ptr_lib::shared_ptr<const Interest>& interest,
412 const ptr_lib::shared_ptr<Data>& data);
416 initialTimeOut(
const ptr_lib::shared_ptr<const Interest>& interest);
419 processRecoveryInterest
420 (
const Interest& interest,
const std::string& syncDigest, Face& face);
428 processSyncInterest(
int index,
const std::string& syncDigest, Face& face);
432 sendRecovery(
const std::string& syncDigest);
442 (
const ptr_lib::shared_ptr<const Interest> &interest,
443 const std::string& syncDigest, Face* face);
447 syncTimeout(
const ptr_lib::shared_ptr<const Interest>& interest);
459 (
const ptr_lib::shared_ptr<const Interest>& interest,
460 const ptr_lib::shared_ptr<Data>& data);
464 Name certificateName_;
466 OnReceivedSyncState onReceivedSyncState_;
467 OnInitialized onInitialized_;
468 std::vector<ptr_lib::shared_ptr<DigestLogEntry> > digestLog_;
469 ptr_lib::shared_ptr<DigestTree> digestTree_;
470 std::string applicationDataPrefixUri_;
471 const Name applicationBroadcastPrefix_;
473 int initialPreviousSequenceNo_;
475 MemoryContentCache contentCache_;
479 ptr_lib::shared_ptr<Impl> impl_;
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:114
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:231
const Blob & getApplicationInfo() const
Get the application info which was included when the sender published the next sequence number...
Definition: chrono-sync2013.hpp:169
void shutdown()
Unregister callbacks so that this does not respond to interests anymore.
Definition: chrono-sync2013.hpp:282
The Face class provides the main methods for NDN communication.
Definition: face.hpp:86
Definition: chrono-sync2013.hpp:31
KeyChain is the main class of the security library.
Definition: key-chain.hpp:53
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, int previousSequenceNumber=-1)
Create a new ChronoSync2013 to communicate using the given face.
Definition: chrono-sync2013.hpp:110
int getSequenceNo() const
Get the sequence number of the latest data published by this application instance.
Definition: chrono-sync2013.hpp:266
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
A Blob holds a pointer to an immutable byte array implemented as const std::vector<uint8_t>.
Definition: blob.hpp:42
ChronoSync2013 implements the NDN ChronoSync protocol as described in the 2013 paper "Let's ChronoSy...
Definition: chrono-sync2013.hpp:47
const std::string & getDataPrefix() const
Get the application data prefix.
Definition: chrono-sync2013.hpp:146
int getSequenceNo() const
Get the sequence number for this sync state message.
Definition: chrono-sync2013.hpp:160
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &prefix)> OnRegisterFailed
An OnRegisterFailed function object is used to report when registerPrefix fails.
Definition: face.hpp:71
A PrefixAndSessionNo holds a user's data prefix and session number (used to return a list from getPro...
Definition: chrono-sync2013.hpp:182
const std::string & getDataPrefix() const
Get the application data prefix for this sync state message.
Definition: chrono-sync2013.hpp:194
void getProducerPrefixes(std::vector< PrefixAndSessionNo > &prefixes) const
Get a copy of the current list of producer data prefixes, and the associated session number...
Definition: chrono-sync2013.hpp:217
A SyncState holds the values of a sync state message which is passed to the onReceivedSyncState callb...
Definition: chrono-sync2013.hpp:131
int getSessionNo() const
Get the session number associated with the application data prefix for this sync state message...
Definition: chrono-sync2013.hpp:202
int getSessionNo() const
Get the session number associated with the application data prefix.
Definition: chrono-sync2013.hpp:153
void publishNextSequenceNo(const Blob &applicationInfo=Blob())
Increment the sequence number, create a sync message with the new sequence number and publish a data ...
Definition: chrono-sync2013.hpp:255