Back to Site
Loading...
Searching...
No Matches
librats::PubSub Class Referencefinal

#include <pubsub.h>

Inheritance diagram for librats::PubSub:
[legend]
Collaboration diagram for librats::PubSub:
[legend]

Classes

struct  Config
 GossipSub tuning. More...

Public Types

using Handler = std::function<void(const PeerId& from, const std::string& topic, ByteView data)>
using Validator = std::function<ValidationResult(const PeerId& from, const std::string& topic, ByteView data)>

Public Member Functions

 PubSub ()
 PubSub (Config config)
 ~PubSub () override
void subscribe (const std::string &topic, Handler handler)
 Subscribe to a topic and deliver matching messages to handler.
void unsubscribe (const std::string &topic)
void publish (const std::string &topic, ByteView data)
 Publish data on topic: along the mesh if we are subscribed, else via fanout.
bool is_subscribed (const std::string &topic) const
std::vector< std::string > subscribed_topics () const
std::vector< PeerId > peers_for_topic (const std::string &topic) const
 known subscribers
std::vector< PeerId > mesh_peers (const std::string &topic) const
 our mesh for topic
void set_validator (const std::string &topic, Validator validator)
 Gate inbound messages for a topic; topic == "" installs a global validator used when no per-topic validator is registered.
void attach (NodeContext &ctx) override
void start () override
 launch the heartbeat thread
void stop () override
 stop and join it
Public Member Functions inherited from librats::Subsystem
virtual ~Subsystem ()=default

Detailed Description

Definition at line 59 of file pubsub.h.

Member Typedef Documentation

◆ Handler

using librats::PubSub::Handler = std::function<void(const PeerId& from, const std::string& topic, ByteView data)>

Definition at line 61 of file pubsub.h.

◆ Validator

using librats::PubSub::Validator = std::function<ValidationResult(const PeerId& from, const std::string& topic, ByteView data)>

Definition at line 62 of file pubsub.h.

Constructor & Destructor Documentation

◆ PubSub() [1/2]

librats::PubSub::PubSub ( )

◆ PubSub() [2/2]

librats::PubSub::PubSub ( Config config)
explicit

◆ ~PubSub()

librats::PubSub::~PubSub ( )
override

Member Function Documentation

◆ attach()

void librats::PubSub::attach ( NodeContext & ctx)
overridevirtual

Implements librats::Subsystem.

◆ is_subscribed()

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

◆ mesh_peers()

std::vector< PeerId > librats::PubSub::mesh_peers ( const std::string & topic) const

our mesh for topic

◆ peers_for_topic()

std::vector< PeerId > librats::PubSub::peers_for_topic ( const std::string & topic) const

known subscribers

◆ publish()

void librats::PubSub::publish ( const std::string & topic,
ByteView data )

Publish data on topic: along the mesh if we are subscribed, else via fanout.

◆ set_validator()

void librats::PubSub::set_validator ( const std::string & topic,
Validator validator )

Gate inbound messages for a topic; topic == "" installs a global validator used when no per-topic validator is registered.

◆ start()

void librats::PubSub::start ( )
overridevirtual

launch the heartbeat thread

Implements librats::Subsystem.

◆ stop()

void librats::PubSub::stop ( )
overridevirtual

stop and join it

Implements librats::Subsystem.

◆ subscribe()

void librats::PubSub::subscribe ( const std::string & topic,
Handler handler )

Subscribe to a topic and deliver matching messages to handler.

◆ subscribed_topics()

std::vector< std::string > librats::PubSub::subscribed_topics ( ) const

◆ unsubscribe()

void librats::PubSub::unsubscribe ( const std::string & topic)

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