Nostrduino
Loading...
Searching...
No Matches
Data Structures | Public Member Functions
nostr::NostrPool Class Reference

#include <NostrPool.h>

Public Member Functions

 NostrPool (Transport *transport, int eventStatusTimeoutSeconds=60 *10, const NostrLimits &limits=NostrLimits())
 
 ~NostrPool ()
 
 NostrPool (const NostrPool &)=delete
 
NostrPooloperator= (const NostrPool &)=delete
 
 NostrPool (NostrPool &&)=delete
 
NostrPooloperator= (NostrPool &&)=delete
 
NostrString subscribeMany (std::initializer_list< NostrString > urls, std::initializer_list< std::map< NostrString, std::initializer_list< NostrString > > > filters, NostrEventCallback eventCallback=nullptr, NostrCloseCallback closeCallback=nullptr, NostrEOSECallback eoseCallback=nullptr)
 
NostrString subscribeMany (const std::vector< NostrString > &urls, std::initializer_list< std::map< NostrString, std::initializer_list< NostrString > > > filters, NostrEventCallback eventCallback=nullptr, NostrCloseCallback closeCallback=nullptr, NostrEOSECallback eoseCallback=nullptr)
 
NostrString subscribeMany (std::initializer_list< NostrString > urls, JsonArray filters, NostrEventCallback eventCallback=nullptr, NostrCloseCallback closeCallback=nullptr, NostrEOSECallback eoseCallback=nullptr)
 
NostrString subscribeMany (const std::vector< NostrString > &urls, JsonArray filters, NostrEventCallback eventCallback=nullptr, NostrCloseCallback closeCallback=nullptr, NostrEOSECallback eoseCallback=nullptr)
 
bool publish (std::initializer_list< NostrString > rs, SignedNostrEvent *event, NostrEventStatusCallback statusCallback=nullptr)
 
bool publish (const std::vector< NostrString > &rs, SignedNostrEvent *event, NostrEventStatusCallback statusCallback=nullptr)
 
void loop ()
 
void setVerifyIncomingEvents (bool verify)
 
bool getVerifyIncomingEvents () const
 
void setSeenTracker (NostrSeenCallback callback)
 
void closeSubscription (NostrString subId)
 
const NostrSubscriptiongetSubscription (const NostrString &subId) const
 
bool hasSubscription (const NostrString &subId) const
 
NostrRelayensureRelay (NostrString url)
 
std::vector< NostrStringgetRelays ()
 
void disconnectRelay (NostrString url)
 
void close ()
 
const std::vector< NostrRelay * > * getConnectedRelays () const
 

Detailed Description

The main class for interacting with the Nostr network. Handles subscriptions, relays, and event publishing.

Constructor & Destructor Documentation

◆ NostrPool() [1/3]

nostr::NostrPool::NostrPool ( Transport transport,
int  eventStatusTimeoutSeconds = 60 * 10,
const NostrLimits limits = NostrLimits() 
)
inline

Create a new NostrPool

Parameters
transportA transport object, you can get one for the esp32 platform using nostr::esp32::ESP32Platform::getTransport() , for other platforms you need to implement the Transport interface
eventStatusTimeoutSecondsThe number of seconds to wait for an event status before timing out (optional)

◆ ~NostrPool()

NostrPool::~NostrPool ( )

◆ NostrPool() [2/3]

nostr::NostrPool::NostrPool ( const NostrPool )
delete

◆ NostrPool() [3/3]

nostr::NostrPool::NostrPool ( NostrPool &&  )
delete

Member Function Documentation

◆ close()

void NostrPool::close ( )

Close the pool and disconnect from every relay

◆ closeSubscription()

void NostrPool::closeSubscription ( NostrString  subId)

Close the subscription with the given ID

Parameters
subIdThe subscription ID

◆ disconnectRelay()

void NostrPool::disconnectRelay ( NostrString  url)

Disconnect from the specified relay

Parameters
urlThe relay URL

◆ ensureRelay()

NostrRelay * NostrPool::ensureRelay ( NostrString  url)

Ensure the connection to the specified relay is open

Parameters
urlThe relay URL
Returns
The relay object

◆ getConnectedRelays()

const std::vector< NostrRelay * > * NostrPool::getConnectedRelays ( ) const

Get all relays that the pool is connected to

Returns
A list of relays

◆ getRelays()

std::vector< NostrString > NostrPool::getRelays ( )

Get all relays that the pool is connected to

Returns
A list of relay URLs
Deprecated:
Use getConnectedRelays() instead

◆ getSubscription()

const NostrSubscription * NostrPool::getSubscription ( const NostrString subId) const

Get a subscription by ID, or nullptr if it does not exist

◆ getVerifyIncomingEvents()

bool nostr::NostrPool::getVerifyIncomingEvents ( ) const
inline

Return whether incoming subscription events are verified.

◆ hasSubscription()

bool NostrPool::hasSubscription ( const NostrString subId) const

Check whether a subscription with the given ID exists

◆ loop()

void NostrPool::loop ( )

Tick the NostrPool. This should be called in the main loop of your sketch

◆ operator=() [1/2]

NostrPool & nostr::NostrPool::operator= ( const NostrPool )
delete

◆ operator=() [2/2]

NostrPool & nostr::NostrPool::operator= ( NostrPool &&  )
delete

◆ publish() [1/2]

bool NostrPool::publish ( const std::vector< NostrString > &  rs,
SignedNostrEvent event,
NostrEventStatusCallback  statusCallback = nullptr 
)

◆ publish() [2/2]

bool NostrPool::publish ( std::initializer_list< NostrString rs,
SignedNostrEvent event,
NostrEventStatusCallback  statusCallback = nullptr 
)

Publish a signed event to one or more relays. The pool will automatically start listening to the specified relays after publishing.

Parameters
rsThe relays to publish to
eventThe event to publish
statusCallbackA callback to be called when the event status is known (optional)

◆ setSeenTracker()

void NostrPool::setSeenTracker ( NostrSeenCallback  callback)

Set the event tracking callback. Return true when an event has already been seen and should be discarded. A null callback restores the default behavior, which keeps no tracking state and returns false for every event.

Calls to the callback are serialized by the pool.

◆ setVerifyIncomingEvents()

void nostr::NostrPool::setVerifyIncomingEvents ( bool  verify)
inline

Enable or disable cryptographic verification of subscription events. Disabled by default for backwards compatibility.

◆ subscribeMany() [1/4]

NostrString NostrPool::subscribeMany ( const std::vector< NostrString > &  urls,
JsonArray  filters,
NostrEventCallback  eventCallback = nullptr,
NostrCloseCallback  closeCallback = nullptr,
NostrEOSECallback  eoseCallback = nullptr 
)

◆ subscribeMany() [2/4]

NostrString NostrPool::subscribeMany ( const std::vector< NostrString > &  urls,
std::initializer_list< std::map< NostrString, std::initializer_list< NostrString > > >  filters,
NostrEventCallback  eventCallback = nullptr,
NostrCloseCallback  closeCallback = nullptr,
NostrEOSECallback  eoseCallback = nullptr 
)

◆ subscribeMany() [3/4]

NostrString NostrPool::subscribeMany ( std::initializer_list< NostrString urls,
JsonArray  filters,
NostrEventCallback  eventCallback = nullptr,
NostrCloseCallback  closeCallback = nullptr,
NostrEOSECallback  eoseCallback = nullptr 
)

Subscribe to events from one or more relays

Parameters
urlsThe relays to subscribe to
filtersA json array of filters for each relay
eventCallbackA callback to be called when an event is received (optional)
closeCallbackA callback to be called when the subscription is closed (optional)
eoseCallbackA callback to be called when the stored events are exhausted (optional)
Returns
The subscription ID

◆ subscribeMany() [4/4]

NostrString NostrPool::subscribeMany ( std::initializer_list< NostrString urls,
std::initializer_list< std::map< NostrString, std::initializer_list< NostrString > > >  filters,
NostrEventCallback  eventCallback = nullptr,
NostrCloseCallback  closeCallback = nullptr,
NostrEOSECallback  eoseCallback = nullptr 
)

Subscribe to events from one or more relays

Parameters
urlsThe relays to subscribe to
filtersA list of filters for each relay
eventCallbackA callback to be called when an event is received (optional)
closeCallbackA callback to be called when the subscription is closed (optional)
eoseCallbackA callback to be called when the stored events are exhausted (optional)
Returns
The subscription ID

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