9 std::map <std::string, ACE_INET_Addr> & addresses,
13 : settings_ (settings), id_ (id), context_ (0),
14 addresses_ (addresses),
15 send_monitor_ (send_monitor),
16 receive_monitor_ (receive_monitor),
17 packet_scheduler_ (packet_scheduler)
37 #ifndef _MADARA_NO_KARL_ 39 "TcpTransportReadThread::init:" \
40 " setting rules to %s\n",
45 #endif // _MADARA_NO_KARL_ 50 "TcpTransportReadThread::init:" \
51 " no permanent rules were set");
58 const char * print_prefix,
75 uint64_t bytes_sent = 0;
76 uint64_t packet_size = (uint64_t)result;
84 " fragmenting %" PRIu64
" byte packet (%" PRIu32
" bytes is max fragment size)\n",
90 for (FragmentMap::iterator i = map.begin (); i != map.end (); ++i)
95 for (std::map <std::string, ACE_INET_Addr>::const_iterator addr =
100 ssize_t actual_sent = -1;
108 " Send result was %d of %d byte fragment to %s\n",
109 print_prefix, actual_sent, frag_size, addr->first.c_str ());
114 bytes_sent += actual_sent;
122 " Sent fragments totalling %" PRIu64
" bytes\n",
123 print_prefix, bytes_sent);
129 for (std::map <std::string, ACE_INET_Addr>::const_iterator i =
134 ssize_t actual_sent = -1;
138 " Sent %d packet to %s\n",
139 print_prefix, packet_size, i->first.c_str ());
144 bytes_sent += actual_sent;
151 " Sent %d total bytes via rebroadcast\n",
152 print_prefix, bytes_sent);
157 " Send bandwidth = %" PRIu64
" B/s\n",
175 ACE_Time_Value wait_time (1);
176 ACE_INET_Addr remote;
180 const char * print_prefix =
"TcpTransportReadThread::run";
184 " entering main service loop.\n",
193 " Unable to allocate buffer of size " PRIu32
". Exiting thread.\n",
202 " entering a recv on the socket.\n",
205 ssize_t bytes_read = 0;
209 " received a message header of %" PRIu64
" bytes from %s:%d\n",
212 remote.get_host_addr (), remote.get_port_number ());
218 std::stringstream remote_host;
219 remote_host << remote.get_host_addr ();
221 remote_host << remote.get_port_number ();
225 #ifndef _MADARA_NO_KARL_
229 remote_host.str ().c_str (), header);
233 if (header->
ttl > 0 && rebroadcast_records.size () > 0 &&
237 header->
ttl = std::min (
240 rebroadcast (print_prefix, header, rebroadcast_records);
251 " wait timeout on new messages. Proceeding to next wait\n",
const std::string id_
host:port identifier of this process
uint64_t get_bytes_per_second(void)
Queries the monitor for the current bandwidth utilization per second over the past window...
MADARA_Export void frag(char *source, uint32_t fragment_size, FragmentMap &map)
Breaks a large packet into smaller packets.
madara::knowledge::CompiledExpression on_data_received_
data received rules, defined in Transport settings
BandwidthMonitor & send_monitor_
monitor for sending bandwidth usage
TcpTransportReadThread(const TransportSettings &settings, const std::string &id, std::map< std::string, ACE_INET_Addr > &addresses, BandwidthMonitor &send_monitor, BandwidthMonitor &receive_monitor, PacketScheduler &packet_scheduler)
Constructor.
void rebroadcast(const char *print_prefix, MessageHeader *header, const knowledge::KnowledgeMap &records)
Sends a rebroadcast packet to all peers.
Provides scheduler for dropping packets.
std::vector< std::string > hosts
Host information for transports that require it.
MADARA_Export double sleep(double sleep_time)
Sleeps for a certain amount of time.
Holds basic transport settings.
#define madara_logger_log(logger, level,...)
Fast version of the madara::logger::log method.
madara::utility::ScopedArray< char > buffer_
buffer for sending
T * get_ptr(void)
get the underlying pointer
bool no_receiving
if true, never receive over transport
void run(void)
The main loop internals for the read thread.
void cleanup(void)
Cleanup function called by thread manager.
This class provides a distributed knowledge base to users.
Parses incoming expression strings into a parse tree and generates an expression tree from the parse ...
::std::map< std::string, KnowledgeRecord > KnowledgeMap
bool no_sending
if true, never send over transport
void add(uint64_t size)
Adds a message to the monitor.
std::string on_data_received_logic
logic to be evaluated after every successful update
double slack_time
time to sleep between sends and rebroadcasts
MADARA_Export void delete_fragments(FragmentMap &map)
Deletes fragments within a fragment map and clears the map.
int MADARA_Export process_received_update(const char *buffer, uint32_t bytes_read, const std::string &id, knowledge::ThreadSafeContext &context, const QoSTransportSettings &settings, BandwidthMonitor &send_monitor, BandwidthMonitor &receive_monitor, knowledge::KnowledgeMap &rebroadcast_records, knowledge::CompiledExpression &on_data_received, const char *print_prefix, const char *remote_host, MessageHeader *&header)
Processes a received update, updates monitors, fills rebroadcast records according to settings filter...
BandwidthMonitor & receive_monitor_
monitor for receiving bandwidth usage
uint32_t queue_length
Length of the buffer used to store history of events.
void init(knowledge::KnowledgeBase &knowledge)
Initializes MADARA context-related items.
CompiledExpression compile(const std::string &expression)
Compiles a KaRL expression into an expression tree.
ThreadSafeContext & get_context(void)
Returns the ThreadSafeContext associated with this Knowledge Base.
int MADARA_Export prep_rebroadcast(knowledge::ThreadSafeContext &context, char *buffer, int64_t &buffer_remaining, const QoSTransportSettings &settings, const char *print_prefix, MessageHeader *header, const knowledge::KnowledgeMap &records, PacketScheduler &packet_scheduler)
Preps a buffer for rebroadcasting records to other agents on the network.
Provides monitoring capability of a transport's bandwidth.
Provides functions and classes for the distributed knowledge base.
std::map< uint32_t, const char * > FragmentMap
Map of fragment identifiers to fragments.
std::map< std::string, ACE_INET_Addr > & addresses_
internet addresses of our peers
logger::Logger & get_logger(void) const
Gets the logger used for information printing.
knowledge::ThreadSafeContext * context_
knowledge context
PacketScheduler & packet_scheduler_
scheduler for mimicking target network conditions
uint32_t max_fragment_size
Maximum allowed fragment size for partitioning large messages.
const QoSTransportSettings settings_
Transport settings.
unsigned char get_participant_ttl(void) const
Returns the maximum time to live participation of this transport in rebroadcasting of other agent's m...