MADARA  3.4.1
madara::transport::UdpRegistryServer Class Reference

UDP-based server that handles a registry of UDP endpoints, which makes it ideal for any NAT-protected agents. More...

#include <UdpRegistryServer.h>

Inheritance diagram for madara::transport::UdpRegistryServer:
madara::transport::UdpTransport madara::transport::BasicASIOTransport madara::transport::Base

Public Types

enum  { ERROR_UDP_NOT_STARTED = -1 }
 
typedef std::vector< std::string > HostsVector
 Used to define a vector of hosts to contact. More...
 

Public Member Functions

 UdpRegistryServer (const std::string &id, madara::knowledge::ThreadSafeContext &context, TransportSettings &config, bool launch_transport)
 Constructor. More...
 
int check_transport (void)
 all subclasses should call this method at the beginning of send_data More...
 
void close () override
 Closes this transport. More...
 
const std::vector< udp::endpoint > & get_udp_endpoints (void)
 
void invalidate_transport (void)
 Invalidates a transport to indicate it is shutting down. More...
 
long prep_send (const knowledge::KnowledgeMap &orig_updates, const char *print_prefix)
 Preps a message for sending. More...
 
long receive_buffer (char *buf, size_t &bytes_read, udp::endpoint &remote)
 Receives a buffer from a remote host. More...
 
int reliability (const int &setting)
 Sets the reliability setting. More...
 
int reliability (void) const
 Accesses reliability setting. More...
 
long send_buffer (const udp::endpoint &target, const char *buf, size_t size)
 Sends a buffer to a host endpoint. More...
 
long send_data (const madara::knowledge::KnowledgeMap &updates) override
 Sends a list of knowledge updates to listeners. More...
 
TransportSettingssettings (void)
 Getter for the transport settings. More...
 
int setup (void) override
 all subclasses should call this method at the end of its setup More...
 
int validate_transport (void)
 Validates a transport to indicate it is not shutting down. More...
 

Public Attributes

knowledge::containers::Integer failed_sends
 failed sends More...
 
knowledge::containers::Integer sent_data
 sent data More...
 
knowledge::containers::Integer sent_data_max
 max data sent More...
 
knowledge::containers::Integer sent_data_min
 min data sent More...
 
knowledge::containers::Integer sent_packets
 sent packets More...
 

Static Public Attributes

static const double default_read_hertz
 
static const int PROFILES = 1
 

Protected Member Functions

virtual bool pre_send_buffer (size_t addr_index)
 
long send_message (const char *buf, size_t size, uint64_t clock)
 
int setup_read_socket () override
 
int setup_read_thread (double hertz, const std::string &name) override
 
virtual int setup_read_threads ()
 
virtual int setup_socket (udp::socket &socket)
 
virtual int setup_sockets ()
 
int setup_write_socket () override
 

Protected Attributes

std::vector< udp::endpoint > addresses_
 holds all multicast addresses we are sending to More...
 
madara::utility::ScopedArray< char > buffer_
 buffer for sending More...
 
madara::knowledge::ThreadSafeContextcontext_
 
knowledge::containers::Map endpoints_
 
utility::EpochEnforcer< utility::Clockenforcer_
 enforces epochs when user specifies a max_send_hertz More...
 
HostsVector hosts
 
const std::string id_
 host:port identifier of this process More...
 
asio::io_service io_service_
 Boost::ASIO IO context. More...
 
volatile bool is_valid_
 
knowledge::KnowledgeBase knowledge_
 knowledge base for threads to use More...
 
uint64_t last_toi_sent_ = 0
 Latest TOI the previous send operation included. More...
 
madara::expression::ExpressionTree on_data_received_
 data received rules, defined in Transport settings More...
 
PacketScheduler packet_scheduler_
 scheduler for dropping packets to simulate network issues More...
 
threads::Threader read_threads_
 threads for reading knowledge updates More...
 
BandwidthMonitor receive_monitor_
 monitor for receiving bandwidth usage More...
 
BandwidthMonitor send_monitor_
 monitor for sending bandwidth usage More...
 
size_t server_count_
 
QoSTransportSettings settings_
 
volatile bool shutting_down_
 
udp::socket socket_ {io_service_}
 underlying socket More...
 

Detailed Description

UDP-based server that handles a registry of UDP endpoints, which makes it ideal for any NAT-protected agents.

Definition at line 24 of file UdpRegistryServer.h.

Member Typedef Documentation

◆ HostsVector

typedef std::vector<std::string> madara::transport::Base::HostsVector
inherited

Used to define a vector of hosts to contact.

Definition at line 51 of file Transport.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
ERROR_UDP_NOT_STARTED 

Definition at line 27 of file UdpRegistryServer.h.

Constructor & Destructor Documentation

◆ UdpRegistryServer()

madara::transport::UdpRegistryServer::UdpRegistryServer ( const std::string &  id,
madara::knowledge::ThreadSafeContext context,
TransportSettings config,
bool  launch_transport 
)

Constructor.

Parameters
idunique identifer - usually a combination of host:port
contextknowledge context
configtransport configuration settings
launch_transportwhether or not to launch this transport

Definition at line 10 of file UdpRegistryServer.cpp.

Member Function Documentation

◆ check_transport()

int madara::transport::Base::check_transport ( void  )
inlineinherited

all subclasses should call this method at the beginning of send_data

Definition at line 17 of file Transport.inl.

◆ close()

void madara::transport::BasicASIOTransport::close ( void  )
overridevirtualinherited

Closes this transport.

Reimplemented from madara::transport::Base.

Definition at line 38 of file BasicASIOTransport.cpp.

◆ get_udp_endpoints()

const std::vector<udp::endpoint>& madara::transport::BasicASIOTransport::get_udp_endpoints ( void  )
inlineinherited

Definition at line 39 of file BasicASIOTransport.h.

◆ invalidate_transport()

void madara::transport::Base::invalidate_transport ( void  )
inlineinherited

Invalidates a transport to indicate it is shutting down.

Definition at line 31 of file Transport.inl.

◆ pre_send_buffer()

virtual bool madara::transport::UdpTransport::pre_send_buffer ( size_t  addr_index)
inlineprotectedvirtualinherited

◆ prep_send()

long madara::transport::Base::prep_send ( const knowledge::KnowledgeMap orig_updates,
const char *  print_prefix 
)
inherited

Preps a message for sending.

Parameters
orig_updatesupdates before send filtering is applied
print_prefixprefix to include before every log message, e.g., "MyTransport::svc"
Returns
-1 Transport is shutting down
-2 Transport is invalid
-3 Unable to allocate send buffer
0 No message to send > 0 size of buffered message

filter the updates according to the filters specified by the user in QoSTransportSettings (if applicable)

size = buffer[0] (unsigned 64 bit) transport id = buffer[8] (8 byte) domain = buffer[16] (32 byte domain name) originator = buffer[48] (64 byte originator host:port) type = buffer[112] (unsigned 32 bit type of message–usually MULTIASSIGN) updates = buffer[116] (unsigned 32 bit number of updates) quality = buffer[120] (unsigned 32 bit quality of message) clock = buffer[124] (unsigned 64 bit clock for this message) ttl = buffer[132] (the new knowledge starts here) knowledge = buffer[133] (the new knowledge starts here)

Definition at line 860 of file Transport.cpp.

◆ receive_buffer()

long madara::transport::UdpTransport::receive_buffer ( char *  buf,
size_t &  bytes_read,
udp::endpoint &  remote 
)
inherited

Receives a buffer from a remote host.

Parameters
bufbuffer to fill with data
bytes_readnumber of bytes read
remoteremote endpoint that sent message
Returns
0 if success, 1 if socket busy, or 2 if unknown error

Definition at line 101 of file UdpTransport.cpp.

◆ reliability() [1/2]

int madara::transport::UdpTransport::reliability ( const int &  setting)
inherited

Sets the reliability setting.

Returns
the changed setting

Definition at line 42 of file UdpTransport.cpp.

◆ reliability() [2/2]

int madara::transport::UdpTransport::reliability ( void  ) const
inherited

Accesses reliability setting.

Returns
whether we are using reliable dissemination or not

Definition at line 37 of file UdpTransport.cpp.

◆ send_buffer()

long madara::transport::UdpTransport::send_buffer ( const udp::endpoint &  target,
const char *  buf,
size_t  size 
)
inherited

Sends a buffer to a host endpoint.

Parameters
bufbuffer to send
sizenumber of bytes to send
targetremote endpoint to send to
Returns
0 if success, 1 if socket busy, or 2 if unknown error

Definition at line 130 of file UdpTransport.cpp.

◆ send_data()

long madara::transport::UdpRegistryServer::send_data ( const madara::knowledge::KnowledgeMap updates)
overridevirtual

Sends a list of knowledge updates to listeners.

Parameters
updateslisting of all updates that must be sent
Returns
result of write operation or -1 if we are shutting down

Implements madara::transport::Base.

Definition at line 32 of file UdpRegistryServer.cpp.

◆ send_message()

long madara::transport::UdpTransport::send_message ( const char *  buf,
size_t  size,
uint64_t  clock 
)
protectedinherited

Definition at line 202 of file UdpTransport.cpp.

◆ settings()

madara::transport::TransportSettings & madara::transport::Base::settings ( void  )
inlineinherited

Getter for the transport settings.

Returns
the current transport settings

Definition at line 40 of file Transport.inl.

◆ setup()

int madara::transport::UdpRegistryServer::setup ( void  )
overridevirtual

all subclasses should call this method at the end of its setup

Reimplemented from madara::transport::BasicASIOTransport.

Definition at line 22 of file UdpRegistryServer.cpp.

◆ setup_read_socket()

int madara::transport::UdpTransport::setup_read_socket ( void  )
overrideprotectedvirtualinherited

Reimplemented from madara::transport::BasicASIOTransport.

Definition at line 58 of file UdpTransport.cpp.

◆ setup_read_thread()

int madara::transport::UdpTransport::setup_read_thread ( double  hertz,
const std::string &  name 
)
overrideprotectedvirtualinherited

Implements madara::transport::BasicASIOTransport.

Definition at line 47 of file UdpTransport.cpp.

◆ setup_read_threads()

int madara::transport::BasicASIOTransport::setup_read_threads ( )
protectedvirtualinherited

Definition at line 233 of file BasicASIOTransport.cpp.

◆ setup_socket()

int madara::transport::BasicASIOTransport::setup_socket ( udp::socket &  socket)
protectedvirtualinherited

Definition at line 134 of file BasicASIOTransport.cpp.

◆ setup_sockets()

int madara::transport::BasicASIOTransport::setup_sockets ( void  )
protectedvirtualinherited

Definition at line 217 of file BasicASIOTransport.cpp.

◆ setup_write_socket()

int madara::transport::UdpTransport::setup_write_socket ( void  )
overrideprotectedvirtualinherited

Reimplemented from madara::transport::BasicASIOTransport.

Definition at line 90 of file UdpTransport.cpp.

◆ validate_transport()

int madara::transport::Base::validate_transport ( void  )
inlineinherited

Validates a transport to indicate it is not shutting down.

Definition at line 6 of file Transport.inl.

Member Data Documentation

◆ addresses_

std::vector<udp::endpoint> madara::transport::BasicASIOTransport::addresses_
protectedinherited

holds all multicast addresses we are sending to

Definition at line 63 of file BasicASIOTransport.h.

◆ buffer_

madara::utility::ScopedArray<char> madara::transport::Base::buffer_
protectedinherited

buffer for sending

Definition at line 153 of file Transport.h.

◆ context_

madara::knowledge::ThreadSafeContext& madara::transport::Base::context_
protectedinherited

Definition at line 135 of file Transport.h.

◆ default_read_hertz

const double madara::transport::BasicASIOTransport::default_read_hertz
staticinherited

Definition at line 37 of file BasicASIOTransport.h.

◆ endpoints_

knowledge::containers::Map madara::transport::UdpRegistryServer::endpoints_
protected

Definition at line 58 of file UdpRegistryServer.h.

◆ enforcer_

utility::EpochEnforcer<utility::Clock> madara::transport::UdpTransport::enforcer_
protectedinherited

enforces epochs when user specifies a max_send_hertz

Definition at line 112 of file UdpTransport.h.

◆ failed_sends

knowledge::containers::Integer madara::transport::UdpTransport::failed_sends
inherited

failed sends

Definition at line 69 of file UdpTransport.h.

◆ hosts

HostsVector madara::transport::Base::hosts
protectedinherited

Definition at line 127 of file Transport.h.

◆ id_

const std::string madara::transport::Base::id_
protectedinherited

host:port identifier of this process

Definition at line 130 of file Transport.h.

◆ io_service_

asio::io_service madara::transport::BasicASIOTransport::io_service_
protectedinherited

Boost::ASIO IO context.

Definition at line 57 of file BasicASIOTransport.h.

◆ is_valid_

volatile bool madara::transport::Base::is_valid_
protectedinherited

Definition at line 125 of file Transport.h.

◆ knowledge_

knowledge::KnowledgeBase madara::transport::BasicASIOTransport::knowledge_
protectedinherited

knowledge base for threads to use

Definition at line 54 of file BasicASIOTransport.h.

◆ last_toi_sent_

uint64_t madara::transport::Base::last_toi_sent_ = 0
protectedinherited

Latest TOI the previous send operation included.

Definition at line 156 of file Transport.h.

◆ on_data_received_

madara::expression::ExpressionTree madara::transport::Base::on_data_received_
protectedinherited

data received rules, defined in Transport settings

Definition at line 139 of file Transport.h.

◆ packet_scheduler_

PacketScheduler madara::transport::Base::packet_scheduler_
protectedinherited

scheduler for dropping packets to simulate network issues

Definition at line 150 of file Transport.h.

◆ PROFILES

const int madara::transport::UdpRegistryServer::PROFILES = 1
static

Definition at line 32 of file UdpRegistryServer.h.

◆ read_threads_

threads::Threader madara::transport::BasicASIOTransport::read_threads_
protectedinherited

threads for reading knowledge updates

Definition at line 60 of file BasicASIOTransport.h.

◆ receive_monitor_

BandwidthMonitor madara::transport::Base::receive_monitor_
protectedinherited

monitor for receiving bandwidth usage

Definition at line 147 of file Transport.h.

◆ send_monitor_

BandwidthMonitor madara::transport::Base::send_monitor_
protectedinherited

monitor for sending bandwidth usage

Definition at line 144 of file Transport.h.

◆ sent_data

knowledge::containers::Integer madara::transport::UdpTransport::sent_data
inherited

sent data

Definition at line 72 of file UdpTransport.h.

◆ sent_data_max

knowledge::containers::Integer madara::transport::UdpTransport::sent_data_max
inherited

max data sent

Definition at line 75 of file UdpTransport.h.

◆ sent_data_min

knowledge::containers::Integer madara::transport::UdpTransport::sent_data_min
inherited

min data sent

Definition at line 78 of file UdpTransport.h.

◆ sent_packets

knowledge::containers::Integer madara::transport::UdpTransport::sent_packets
inherited

sent packets

Definition at line 66 of file UdpTransport.h.

◆ server_count_

size_t madara::transport::UdpRegistryServer::server_count_
protected

Definition at line 56 of file UdpRegistryServer.h.

◆ settings_

QoSTransportSettings madara::transport::Base::settings_
protectedinherited

Definition at line 132 of file Transport.h.

◆ shutting_down_

volatile bool madara::transport::Base::shutting_down_
protectedinherited

Definition at line 126 of file Transport.h.

◆ socket_

udp::socket madara::transport::BasicASIOTransport::socket_ {io_service_}
protectedinherited

underlying socket

Definition at line 66 of file BasicASIOTransport.h.


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