Back to Site
Loading...
Searching...
No Matches
librats::GossipSub Class Reference

Main GossipSub implementation class. More...

#include <gossipsub.h>

Public Member Functions

 GossipSub (RatsClient &rats_client, const GossipSubConfig &config=GossipSubConfig())
 Constructor.
 
 ~GossipSub ()
 Destructor.
 
bool start ()
 Start the GossipSub service.
 
void stop ()
 Stop the GossipSub service.
 
bool is_running () const
 Check if GossipSub is running.
 
bool subscribe (const std::string &topic)
 Subscribe to a topic.
 
bool unsubscribe (const std::string &topic)
 Unsubscribe from a topic.
 
bool is_subscribed (const std::string &topic) const
 Check if subscribed to a topic.
 
std::vector< std::string > get_subscribed_topics () const
 Get list of subscribed topics.
 
bool publish (const std::string &topic, const std::string &message)
 Publish a message to a topic.
 
bool publish (const std::string &topic, const nlohmann::json &message)
 Publish a JSON message to a topic.
 
void set_message_validator (const std::string &topic, MessageValidator validator)
 Set message validator for a topic.
 
void set_message_handler (const std::string &topic, MessageHandler handler)
 Set message handler for a topic.
 
void set_peer_joined_handler (const std::string &topic, PeerJoinedHandler handler)
 Set peer joined handler for a topic.
 
void set_peer_left_handler (const std::string &topic, PeerLeftHandler handler)
 Set peer left handler for a topic.
 
std::vector< std::string > get_topic_peers (const std::string &topic) const
 Get peers subscribed to a topic.
 
std::vector< std::string > get_mesh_peers (const std::string &topic) const
 Get mesh peers for a topic.
 
double get_peer_score (const std::string &peer_id) const
 Get peer score.
 
nlohmann::json get_statistics () const
 Get GossipSub statistics.
 
nlohmann::json get_cache_statistics () const
 Get message cache statistics.
 

Friends

class RatsClient
 

Detailed Description

Main GossipSub implementation class.

Definition at line 167 of file gossipsub.h.

Constructor & Destructor Documentation

◆ GossipSub()

librats::GossipSub::GossipSub ( RatsClient rats_client,
const GossipSubConfig config = GossipSubConfig() 
)
explicit

Constructor.

Parameters
rats_clientReference to the RatsClient instance
configGossipSub configuration

◆ ~GossipSub()

librats::GossipSub::~GossipSub ( )

Destructor.

Member Function Documentation

◆ get_cache_statistics()

nlohmann::json librats::GossipSub::get_cache_statistics ( ) const

Get message cache statistics.

Returns
JSON object with cache statistics

◆ get_mesh_peers()

std::vector< std::string > librats::GossipSub::get_mesh_peers ( const std::string &  topic) const

Get mesh peers for a topic.

Parameters
topicTopic name
Returns
Vector of peer IDs in the mesh

◆ get_peer_score()

double librats::GossipSub::get_peer_score ( const std::string &  peer_id) const

Get peer score.

Parameters
peer_idPeer ID
Returns
Peer score

◆ get_statistics()

nlohmann::json librats::GossipSub::get_statistics ( ) const

Get GossipSub statistics.

Returns
JSON object with statistics

◆ get_subscribed_topics()

std::vector< std::string > librats::GossipSub::get_subscribed_topics ( ) const

Get list of subscribed topics.

Returns
Vector of topic names

◆ get_topic_peers()

std::vector< std::string > librats::GossipSub::get_topic_peers ( const std::string &  topic) const

Get peers subscribed to a topic.

Parameters
topicTopic name
Returns
Vector of peer IDs

◆ is_running()

bool librats::GossipSub::is_running ( ) const

Check if GossipSub is running.

Returns
true if running

◆ is_subscribed()

bool librats::GossipSub::is_subscribed ( const std::string &  topic) const

Check if subscribed to a topic.

Parameters
topicTopic name to check
Returns
true if subscribed

◆ publish() [1/2]

bool librats::GossipSub::publish ( const std::string &  topic,
const nlohmann::json &  message 
)

Publish a JSON message to a topic.

Parameters
topicTopic to publish to
messageJSON message content
Returns
true if published successfully

◆ publish() [2/2]

bool librats::GossipSub::publish ( const std::string &  topic,
const std::string &  message 
)

Publish a message to a topic.

Parameters
topicTopic to publish to
messageMessage content
Returns
true if published successfully

◆ set_message_handler()

void librats::GossipSub::set_message_handler ( const std::string &  topic,
MessageHandler  handler 
)

Set message handler for a topic.

Parameters
topicTopic name
handlerMessage handler function

◆ set_message_validator()

void librats::GossipSub::set_message_validator ( const std::string &  topic,
MessageValidator  validator 
)

Set message validator for a topic.

Parameters
topicTopic name (empty for all topics)
validatorValidation function

◆ set_peer_joined_handler()

void librats::GossipSub::set_peer_joined_handler ( const std::string &  topic,
PeerJoinedHandler  handler 
)

Set peer joined handler for a topic.

Parameters
topicTopic name
handlerPeer joined handler function

◆ set_peer_left_handler()

void librats::GossipSub::set_peer_left_handler ( const std::string &  topic,
PeerLeftHandler  handler 
)

Set peer left handler for a topic.

Parameters
topicTopic name
handlerPeer left handler function

◆ start()

bool librats::GossipSub::start ( )

Start the GossipSub service.

Returns
true if started successfully

◆ stop()

void librats::GossipSub::stop ( )

Stop the GossipSub service.

◆ subscribe()

bool librats::GossipSub::subscribe ( const std::string &  topic)

Subscribe to a topic.

Parameters
topicTopic name to subscribe to
Returns
true if subscription successful

◆ unsubscribe()

bool librats::GossipSub::unsubscribe ( const std::string &  topic)

Unsubscribe from a topic.

Parameters
topicTopic name to unsubscribe from
Returns
true if unsubscription successful

Friends And Related Symbol Documentation

◆ RatsClient

friend class RatsClient
friend

Definition at line 168 of file gossipsub.h.


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