psync::Consumer Class Reference

Consumer logic to subscribe to producer's data. More...

#include <PSync/consumer.hpp>

Classes

struct  Options
 Constructor options. More...
 

Public Member Functions

 Consumer (const ndn::Name &syncPrefix, ndn::Face &face, const ReceiveHelloCallback &onReceiveHelloData, const UpdateCallback &onUpdate, unsigned int count, double falsePositive=0.001, ndn::time::milliseconds helloInterestLifetime=HELLO_INTEREST_LIFETIME, ndn::time::milliseconds syncInterestLifetime=SYNC_INTEREST_LIFETIME)
 
 Consumer (ndn::Face &face, const ndn::Name &syncPrefix, const Options &opts)
 Constructor. More...
 
bool addSubscription (const ndn::Name &prefix, uint64_t seqNo, bool callSyncDataCb=true)
 Add prefix to subscription list. More...
 
std::optional< uint64_t > getSeqNo (const ndn::Name &prefix) const
 
std::set< ndn::Name > getSubscriptionList () const
 
bool isSubscribed (const ndn::Name &prefix) const
 
bool removeSubscription (const ndn::Name &prefix)
 Remove prefix from subscription list. More...
 
void sendHelloInterest ()
 send hello interest /<sync-prefix>/hello/ More...
 
void sendSyncInterest ()
 send sync interest /<sync-prefix>/sync/<BF>/<producers-IBF> More...
 
void stop ()
 Stop segment fetcher to stop the sync and free resources. More...
 

Detailed Description

Consumer logic to subscribe to producer's data.

Application needs to call sendHelloInterest to get the subscription list in psync::ReceiveHelloCallback. It can then add the desired names using addSubscription. Finally application will call sendSyncInterest. If the application adds something later to the subscription list then it may call sendSyncInterest again for sending the next sync interest with updated IBF immediately to reduce any delay in sync data. Whenever there is new data UpdateCallback will be called to notify the application.

If consumer wakes up after a long time to sync, producer may not decode the differences with its old IBF successfully and send an application nack. Upon receiving the nack, consumer will send a hello again and inform the application via psync::ReceiveHelloCallback and psync::UpdateCallback.

Currently, fetching of the data needs to be handled by the application.

Definition at line 55 of file consumer.hpp.

Constructor & Destructor Documentation

◆ Consumer() [1/2]

psync::Consumer::Consumer ( ndn::Face &  face,
const ndn::Name &  syncPrefix,
const Options opts 
)

Constructor.

Parameters
faceApplication face.
syncPrefixPrefix to send hello and sync Interests to producer.
optsOptions.

Definition at line 30 of file consumer.cpp.

◆ Consumer() [2/2]

psync::Consumer::Consumer ( const ndn::Name &  syncPrefix,
ndn::Face &  face,
const ReceiveHelloCallback onReceiveHelloData,
const UpdateCallback onUpdate,
unsigned int  count,
double  falsePositive = 0.001,
ndn::time::milliseconds  helloInterestLifetime = HELLO_INTEREST_LIFETIME,
ndn::time::milliseconds  syncInterestLifetime = SYNC_INTEREST_LIFETIME 
)

Definition at line 47 of file consumer.cpp.

Member Function Documentation

◆ addSubscription()

bool psync::Consumer::addSubscription ( const ndn::Name &  prefix,
uint64_t  seqNo,
bool  callSyncDataCb = true 
)

Add prefix to subscription list.

Parameters
prefixprefix to be added to the list
seqNothe latest sequence number for the prefix received in HelloData callback
callSyncDataCbtrue by default to let app know that a new sequence number is available. Usually sequence number is zero in hello data, but when it is not Consumer can notify the app. Since the app is aware of the latest sequence number by ReceiveHelloCallback, app may choose to not let Consumer call UpdateCallback by setting this to false.
Returns
true if prefix is added, false if it is already present

Definition at line 62 of file consumer.cpp.

◆ getSeqNo()

std::optional<uint64_t> psync::Consumer::getSeqNo ( const ndn::Name &  prefix) const
inline

Definition at line 149 of file consumer.hpp.

◆ getSubscriptionList()

std::set<ndn::Name> psync::Consumer::getSubscriptionList ( ) const
inline

Definition at line 137 of file consumer.hpp.

◆ isSubscribed()

bool psync::Consumer::isSubscribed ( const ndn::Name &  prefix) const
inline

Definition at line 143 of file consumer.hpp.

◆ removeSubscription()

bool psync::Consumer::removeSubscription ( const ndn::Name &  prefix)

Remove prefix from subscription list.

Parameters
prefixprefix to be removed from the list
Returns
true if prefix is removed, false if it is not present

Definition at line 82 of file consumer.cpp.

◆ sendHelloInterest()

void psync::Consumer::sendHelloInterest ( )

send hello interest /<sync-prefix>/hello/

Should be called by the application whenever it wants to send a hello

Definition at line 119 of file consumer.cpp.

◆ sendSyncInterest()

void psync::Consumer::sendSyncInterest ( )

send sync interest /<sync-prefix>/sync/<BF>/<producers-IBF>

Should be called after subscription list is set or updated

Definition at line 193 of file consumer.cpp.

◆ stop()

void psync::Consumer::stop ( )

Stop segment fetcher to stop the sync and free resources.

Definition at line 102 of file consumer.cpp.