All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Classes | Public Types | Public Member Functions | List of all members
ndn::ChronoSync2013 Class Reference

ChronoSync2013 implements the NDN ChronoSync protocol as described in the 2013 paper "Let's ChronoSync: Decentralized Dataset State Synchronization in Named Data Networking". More...

#include <chrono-sync2013.hpp>

Classes

class  PrefixAndSessionNo
 A PrefixAndSessionNo holds a user's data prefix and session number (used to return a list from getProducerPrefixes). More...
 
class  SyncState
 A SyncState holds the values of a sync state message which is passed to the onReceivedSyncState callback which was given to the ChronoSyn2013 constructor. More...
 

Public Types

typedef func_lib::function
< void(const std::vector
< ChronoSync2013::SyncState >
&syncStates, bool isRecovery)> 
OnReceivedSyncState
 
typedef func_lib::function< void()> OnInitialized
 

Public Member Functions

 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. More...
 
void getProducerPrefixes (std::vector< PrefixAndSessionNo > &prefixes) const
 Get a copy of the current list of producer data prefixes, and the associated session number. More...
 
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. More...
 
void publishNextSequenceNo (const Blob &applicationInfo=Blob())
 Increment the sequence number, create a sync message with the new sequence number and publish a data packet where the name is the applicationBroadcastPrefix + the root digest of the current digest tree. More...
 
int getSequenceNo () const
 Get the sequence number of the latest data published by this application instance. More...
 
void shutdown ()
 Unregister callbacks so that this does not respond to interests anymore. More...
 

Detailed Description

ChronoSync2013 implements the NDN ChronoSync protocol as described in the 2013 paper "Let's ChronoSync: Decentralized Dataset State Synchronization in Named Data Networking".

http://named-data.net/publications/chronosync .

Note
The support for ChronoSync is experimental and the API is not finalized. See the API docs for more detail at http://named-data.net/doc/ndn-ccl-api/chrono-sync2013.html .

Constructor & Destructor Documentation

ndn::ChronoSync2013::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 
)
inline

Create a new ChronoSync2013 to communicate using the given face.

Initialize the digest log with a digest of "00" and and empty content. Register the applicationBroadcastPrefix to receive interests for sync state messages and express an interest for the initial root digest "00".

Note
Your application must call processEvents. Since processEvents modifies the internal ChronoSync data structures, your application should make sure that it calls processEvents in the same thread as this constructor (which also modifies the data structures).
Parameters
onReceivedSyncStateWhen ChronoSync receives a sync state message, this calls onReceivedSyncState(syncStates, isRecovery) where syncStates is the list of SyncState messages and isRecovery is true if this is the initial list of SyncState messages or from a recovery interest. (For example, if isRecovery is true, a chat application would not want to re-display all the associated chat messages.) The callback should send interests to fetch the application data for the sequence numbers in the sync state. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
onInitializedThis calls onInitialized() when the first sync data is received (or the interest times out because there are no other publishers yet). NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
applicationDataPrefixThe prefix used by this application instance for application data. For example, "/my/local/prefix/ndnchat4/0K4wChff2v". This is used when sending a sync message for a new sequence number. In the sync message, this uses applicationDataPrefix.toUri().
applicationBroadcastPrefixThe broadcast name prefix including the application name. For example, "/ndn/broadcast/ChronoChat-0.3/ndnchat1". This makes a copy of the name.
sessionNoThe session number used with the applicationDataPrefix in sync state messages.
faceThe Face for calling registerPrefix and expressInterest. The Face object must remain valid for the life of this ChronoSync2013 object.
keyChainTo sign a data packet containing a sync state message, this calls keyChain.sign(data, certificateName).
certificateNameThe certificate name of the key to use for signing a data packet containing a sync state message.
syncLifetimeThe interest lifetime in milliseconds for sending sync interests.
onRegisterFailedIf failed to register the prefix to receive interests for the applicationBroadcastPrefix, this calls onRegisterFailed(applicationBroadcastPrefix). NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
previousSequenceNumber(optional) The previously published sequence number for the same applicationDataPrefix and sessionNo. This can be used by the application to restore the state from a previous use. If omitted, this uses -1 so that the next published sequence number is 0.

Member Function Documentation

void ndn::ChronoSync2013::getProducerPrefixes ( std::vector< PrefixAndSessionNo > &  prefixes) const
inline

Get a copy of the current list of producer data prefixes, and the associated session number.

You can use these in getProducerSequenceNo(). This includes the prefix for this user.

Parameters
prefixesThis clears the vector and adds a copy of each producer prefix and session number.
int ndn::ChronoSync2013::getProducerSequenceNo ( const std::string &  dataPrefix,
int  sessionNo 
) const
inline

Get the current sequence number in the digest tree for the given producer dataPrefix and sessionNo.

Parameters
dataPrefixThe producer data prefix as a Name URI string.
sessionNoThe producer session number.
Returns
The current producer sequence number, or -1 if the producer namePrefix and sessionNo are not in the digest tree.
int ndn::ChronoSync2013::getSequenceNo ( ) const
inline

Get the sequence number of the latest data published by this application instance.

Returns
The sequence number.
void ndn::ChronoSync2013::publishNextSequenceNo ( const Blob applicationInfo = Blob())
inline

Increment the sequence number, create a sync message with the new sequence number and publish a data packet where the name is the applicationBroadcastPrefix + the root digest of the current digest tree.

Then add the sync message to the digest tree and digest log which creates a new root digest. Finally, express an interest for the next sync update with the name applicationBroadcastPrefix + the new root digest. After this, your application should publish the content for the new sequence number. You can get the new sequence number with getSequenceNo().

Note
Your application must call processEvents. Since processEvents modifies the internal ChronoSync data structures, your application should make sure that it calls processEvents in the same thread as publishNextSequenceNo() (which also modifies the data structures).
Parameters
applicationInfo(optional) This appends applicationInfo to the content of the sync messages. This same info is provided to the receiving application in the SyncState state object provided to the onReceivedSyncState callback.
void ndn::ChronoSync2013::shutdown ( )
inline

Unregister callbacks so that this does not respond to interests anymore.

If you will delete this ChronoSync2013 object while your application is still running, you should call shutdown() first. After calling this, you should not call publishNextSequenceNo() again since the behavior will be undefined.

Note
Because this modifies internal ChronoSync data structures, your application should make sure that it calls processEvents in the same thread as shutdown() (which also modifies the data structures).

The documentation for this class was generated from the following file: