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;
97 (
const OnReceivedSyncState& onReceivedSyncState,
98 const OnInitialized& onInitialized,
const Name& applicationDataPrefix,
99 const Name& applicationBroadcastPrefix,
int sessionNo,
103 (onReceivedSyncState, onInitialized, applicationDataPrefix,
104 applicationBroadcastPrefix, sessionNo, face, keyChain, certificateName,
107 impl_->initialize(onRegisterFailed);
119 SyncState(
const std::string& dataPrefixUri,
int sessionNo,
int sequenceNo)
120 : dataPrefixUri_(dataPrefixUri), sessionNo_(sessionNo), sequenceNo_(sequenceNo)
147 std::string dataPrefixUri_;
163 return impl_->getProducerSequenceNo(dataPrefix, sessionNo);
183 return impl_->publishNextSequenceNo();
194 return impl_->getSequenceNo();
214 class DigestLogEntry {
217 (
const std::string& digest,
221 getDigest()
const {
return digest_; }
224 getData()
const {
return *data_; }
228 ptr_lib::shared_ptr<google::protobuf::RepeatedPtrField<Sync::SyncState> > data_;
236 class Impl :
public ptr_lib::enable_shared_from_this<Impl> {
244 (
const OnReceivedSyncState& onReceivedSyncState,
245 const OnInitialized& onInitialized,
const Name& applicationDataPrefix,
246 const Name& applicationBroadcastPrefix,
int sessionNo,
247 Face& face, KeyChain& keyChain,
const Name& certificateName,
287 contentCache_.unregisterAll();
314 logFind(
const std::string& digest)
const;
323 (
const ptr_lib::shared_ptr<const Name>& prefix,
324 const ptr_lib::shared_ptr<const Interest>& interest, Face& face,
325 uint64_t registerPrefixId,
326 const ptr_lib::shared_ptr<const InterestFilter>& filter);
331 (
const ptr_lib::shared_ptr<const Interest>& interest,
332 const ptr_lib::shared_ptr<Data>& data);
336 initialTimeOut(
const ptr_lib::shared_ptr<const Interest>& interest);
339 processRecoveryInterest
340 (
const Interest& interest,
const std::string& syncDigest, Face& face);
348 processSyncInterest(
int index,
const std::string& syncDigest, Face& face);
352 sendRecovery(
const std::string& syncDigest);
362 (
const ptr_lib::shared_ptr<const Interest> &interest,
363 const std::string& syncDigest, Face* face);
367 syncTimeout(
const ptr_lib::shared_ptr<const Interest>& interest);
379 (
const ptr_lib::shared_ptr<const Interest>& interest,
380 const ptr_lib::shared_ptr<Data>& data);
384 Name certificateName_;
386 OnReceivedSyncState onReceivedSyncState_;
387 OnInitialized onInitialized_;
388 std::vector<ptr_lib::shared_ptr<DigestLogEntry> > digestLog_;
389 ptr_lib::shared_ptr<DigestTree> digestTree_;
390 std::string applicationDataPrefixUri_;
391 const Name applicationBroadcastPrefix_;
394 MemoryContentCache contentCache_;
398 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-2015 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:161
void shutdown()
Unregister callbacks so that this does not respond to interests anymore.
Definition: chrono-sync2013.hpp:208
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:97
The Face class provides the main methods for NDN communication.
Definition: face.hpp:72
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:181
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:192
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:42
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:129
int getSequenceNo() const
Get the sequence number for this sync state message.
Definition: chrono-sync2013.hpp:144
Copyright (C) 2014-2015 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:64
A SyncState holds the values of a sync state message which is passed to the onReceivedSyncState callb...
Definition: chrono-sync2013.hpp:117
int getSessionNo() const
Get the session number associated with the application data prefix for this sync state message...
Definition: chrono-sync2013.hpp:137