new ChronoSync2013(onReceivedSyncState, onInitialized, applicationDataPrefix, applicationBroadcastPrefix, sessionNo, face, keyChain, certificateName, syncLifetime, onRegisterFailed)
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 .
Parameters:
Name | Type | Description |
---|---|---|
onReceivedSyncState |
function | 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 |
function | 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 |
Name | 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 |
Name | The broadcast name prefix including the application name. For example, "/ndn/broadcast/ChronoChat-0.3/ndnchat1". This makes a copy of the name. |
sessionNo |
int | The session number used with the applicationDataPrefix in sync state messages. |
face |
Face | The Face for calling registerPrefix and expressInterest. The Face object must remain valid for the life of this ChronoSync2013 object. |
keyChain |
KeyChain | To sign a data packet containing a sync state message, this calls keyChain.sign(data, certificateName). |
certificateName |
Name | The certificate name of the key to use for signing a data packet containing a sync state message. |
syncLifetime |
Milliseconds | The interest lifetime in milliseconds for sending sync interests. |
onRegisterFailed |
function | 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. |
- Source:
Methods
broadcastSyncState(The, The)
Make a data packet with the syncMessage and with name applicationBroadcastPrefix_ + digest.
Sign and send.
Parameters:
Name | Type | Description |
---|---|---|
The |
string | root digest as a hex string for the data packet name. |
The |
SyncStateMsg | syncMessage updates the digest tree state with the given digest. |
- Source:
getSequenceNo() → {int}
Get the sequence number of the latest data published by this application instance.
- Source:
Returns:
the sequence number
- Type
- int
initialTimeOut()
Interest variable not actually in use here
- Source:
judgeRecovery(interest, syncdigest_t, face)
This is called by onInterest after a timeout to check if a recovery is needed.
This method has an interest argument because we use it as the onTimeout for
Face.expressInterest.
Parameters:
Name | Type | Description |
---|---|---|
interest |
Interest | |
syncdigest_t |
string | |
face |
Face |
- Source:
onData(interest, co)
Process sync/recovery data.
Parameters:
Name | Type | Description |
---|---|---|
interest |
Interest | |
co |
Data |
- Source:
onInterest()
Process the sync interest from the applicationBroadcastPrefix. If we can't
satisfy the interest, add it to the pending interest table in
this.contentCache so that a future call to contentCacheAdd may satisfy it.
- Source:
processSyncInst()
Common interest processing, using digest log to find the difference after syncdigest_t
- Source:
Returns:
True if sent a data packet to satisfy the interest.
publishNextSequenceNo()
Increment the sequence number, create a sync message with the new sequence number,
and publish a data packet where the name is applicationBroadcastPrefix + root
digest of current digest tree. Then add the sync message to 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, application should publish the content for the new sequence number.
Get the new sequence number with getSequenceNo().
- Source:
sendRecovery(syncdigest_t)
Send recovery interset.
Parameters:
Name | Type | Description |
---|---|---|
syncdigest_t |
string |
- Source:
shutdown()
Unregister callbacks so that this does not respond to interests anymore.
If you will dispose 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.
- Source:
update(The) → {bool}
Update the digest tree with the messages in content. If the digest tree root is not in
the digest log, also add a log entry with the content.
Parameters:
Name | Type | Description |
---|---|---|
The |
Array.<SyncStates> | sync state messages |
- Source:
Returns:
True if added a digest log entry (because the updated digest tree root
was not in the log), false if didn't add a log entry.
- Type
- bool
(static) 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. Note: this has the same info as the Protobuf class
Sync::SyncState, but we make a separate class so that we don't need the
Protobuf definition in the ChronoSync API.
- Source: