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... | |
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 .
|
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".
| onReceivedSyncState | When 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. |
| onInitialized | This 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. |
| applicationDataPrefix | The 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(). |
| applicationBroadcastPrefix | The broadcast name prefix including the application name. For example, "/ndn/broadcast/ChronoChat-0.3/ndnchat1". This makes a copy of the name. |
| sessionNo | The session number used with the applicationDataPrefix in sync state messages. |
| face | The Face for calling registerPrefix and expressInterest. The Face object must remain valid for the life of this ChronoSync2013 object. |
| keyChain | To sign a data packet containing a sync state message, this calls keyChain.sign(data, certificateName). |
| certificateName | The certificate name of the key to use for signing a data packet containing a sync state message. |
| syncLifetime | The interest lifetime in milliseconds for sending sync interests. |
| onRegisterFailed | If 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. |
|
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.
| prefixes | This clears the vector and adds a copy of each producer prefix and session number. |
|
inline |
Get the current sequence number in the digest tree for the given producer dataPrefix and sessionNo.
| dataPrefix | The producer data prefix as a Name URI string. |
| sessionNo | The producer session number. |
|
inline |
Get the sequence number of the latest data published by this application instance.
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().
| 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. |
|
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.
1.8.6