MADARA  3.2.3
QoSTransportSettings.cpp
Go to the documentation of this file.
6 
7 namespace logger = madara::logger;
10 
12  : TransportSettings (), rebroadcast_ttl_ (0),
13  participant_rebroadcast_ttl_ (0),
14  trusted_peers_ (), banned_peers_ (),
15  packet_drop_rate_ (0.0), packet_drop_burst_ (1),
16  max_send_bandwidth_ (-1), max_total_bandwidth_ (-1),
17  deadline_ (-1)
18 {
19 
20 }
21 
23  const QoSTransportSettings & settings)
24  : TransportSettings (settings),
27  trusted_peers_ (settings.trusted_peers_),
28  banned_peers_ (settings.banned_peers_),
31  send_filters_ (settings.send_filters_),
38  deadline_ (settings.deadline_)
39 {
40 }
41 
43  const TransportSettings & settings)
44  : TransportSettings (settings),
45  rebroadcast_ttl_ (0),
47  trusted_peers_ (),
48  banned_peers_ (),
49  packet_drop_rate_ (0.0),
51  deadline_ (-1)
52 {
53  const QoSTransportSettings * rhs = dynamic_cast <const QoSTransportSettings *> (
54  &settings);
55  if (rhs)
56  {
70  deadline_ = rhs->deadline_;
71  }
72  else
73  {
74  TransportSettings * lhs = dynamic_cast <TransportSettings *> (this);
75  *lhs = settings;
76  }
77 }
78 
80 {
81  // need to clean up functors
82 }
83 
84 void
86  const QoSTransportSettings & rhs)
87 {
88  if (this != &rhs)
89  {
90  TransportSettings * lhs_base = (TransportSettings *)this;
91  TransportSettings * rhs_base = (TransportSettings *)&rhs;
92 
93  *lhs_base = *rhs_base;
94 
108  deadline_ = rhs.deadline_;
109  }
110 }
111 
112 void
114  const TransportSettings & rhs)
115 {
116  if (this != &rhs)
117  {
118  rebroadcast_ttl_ = 0;
120  trusted_peers_.clear ();
121  banned_peers_.clear ();
125  packet_drop_rate_ = 0.0;
127  packet_drop_burst_ = 1;
128  max_send_bandwidth_ = -1;
130  deadline_ = -1;
131 
132  TransportSettings * lhs_base = (TransportSettings *)this;
133  TransportSettings * rhs_base = (TransportSettings *)&rhs;
134 
135  *lhs_base = *rhs_base;
136  }
137 }
138 
139 void
141 {
142  rebroadcast_ttl_ = ttl;
143 }
144 
145 unsigned char
147 {
148  return rebroadcast_ttl_;
149 }
150 
151 void
153  unsigned char ttl)
154 {
156 }
157 
158 unsigned char
160 {
162 }
163 
164 void
166  const std::string & peer)
167 {
168  banned_peers_.erase (peer);
169  trusted_peers_[peer] = 1;
170 }
171 
172 void
174  const std::string & peer)
175 {
176  trusted_peers_.erase (peer);
177  banned_peers_[peer] = 1;
178 }
179 
180 bool
182  const std::string & peer)
183 {
184  bool condition = false;
185  if (trusted_peers_.find (peer) != trusted_peers_.end ())
186  {
187  trusted_peers_.erase (peer);
188  condition = true;
189  }
190  return condition;
191 }
192 
193 bool
195  const std::string & peer)
196 {
197  bool condition = false;
198  if (banned_peers_.find (peer) != banned_peers_.end ())
199  {
200  banned_peers_.erase (peer);
201  condition = true;
202  }
203  return condition;
204 }
205 
206 bool
208  const std::string & peer) const
209 {
210  bool condition = false;
211 
219  if (trusted_peers_.size () == 0)
220  {
221  if (banned_peers_.find (peer) == banned_peers_.end ())
222  condition = true;
223  }
224  else
225  {
226  condition = (trusted_peers_.find (peer) != trusted_peers_.end ());
227  }
228 
229  return condition;
230 }
231 
232 
233 void
237 {
238  send_filters_.add (types, function);
239 }
240 
241 void
243  filters::RecordFilter * functor)
244 {
245  send_filters_.add (types, functor);
246 }
247 
248 void
250  void (*function) (
253 {
254  send_filters_.add (function);
255 }
256 
257 void
259  filters::AggregateFilter * functor)
260 {
261  send_filters_.add (functor);
262 }
263 
264 void
266 filters::AggregateFilter * functor)
267 {
268  receive_filters_.add (functor);
269 }
270 
271 void
273 filters::BufferFilter * functor)
274 {
275  buffer_filters_.push_back (functor);
276 }
277 
278 void
282 {
283  receive_filters_.add (types, function);
284 }
285 
286 void
288  filters::RecordFilter * functor)
289 {
290  receive_filters_.add (types, functor);
291 }
292 
293 void
295  void (*function) (
298 {
299  receive_filters_.add (function);
300 }
301 
302 void
306 {
307  rebroadcast_filters_.add (types, function);
308 }
309 
310 void
312  filters::RecordFilter * functor)
313 {
314  rebroadcast_filters_.add (types, functor);
315 }
316 
317 void
319  void (*function) (
322 {
323  rebroadcast_filters_.add (function);
324 }
325 
326 void
328  filters::AggregateFilter * functor)
329 {
330  rebroadcast_filters_.add (functor);
331 }
332 
333 #ifdef _MADARA_JAVA_
334 
335 void
337  uint32_t types, jobject & object)
338 {
340  logger::global_logger.get (),
342  "QoSTransportSettings::add: "
343  "Adding Java record filter to receive queue\n");
344 
345  receive_filters_.add (types, object);
346 }
347 
348 void
350  uint32_t types, jobject & object)
351 {
352  send_filters_.add (types, object);
353 }
354 
355 void
357  uint32_t types, jobject & object)
358 {
359  rebroadcast_filters_.add (types, object);
360 }
361 
362 
363 void
365  jobject & object)
366 {
367  receive_filters_.add (object);
368 }
369 
370 void
372  jobject & object)
373 {
374  send_filters_.add (object);
375 }
376 
377 void
379  jobject & object)
380 {
381  rebroadcast_filters_.add (object);
382 }
383 
384 #endif
385 
386 #ifdef _MADARA_PYTHON_CALLBACKS_
387 
388 void
390  uint32_t types, boost::python::object & object)
391 {
392  receive_filters_.add (types, object);
393 }
394 
395 void
397  uint32_t types, boost::python::object & object)
398 {
399  send_filters_.add (types, object);
400 }
401 
402 void
404  uint32_t types, boost::python::object & object)
405 {
406  rebroadcast_filters_.add (types, object);
407 }
408 
409 
410 void
412  boost::python::object & object)
413 {
414  receive_filters_.add (object);
415 }
416 
417 void
419  boost::python::object & object)
420 {
421  send_filters_.add (object);
422 }
423 
424 void
426  boost::python::object & object)
427 {
428  rebroadcast_filters_.add (object);
429 }
430 
431 
432 #endif
433 
434 void
437 {
438  send_filters_.attach (context);
439  receive_filters_.attach (context);
440  rebroadcast_filters_.attach (context);
441 }
442 
443 void
445 {
446  send_filters_.clear (types);
447 }
448 
449 void
451  ()
452 {
454 }
455 
456 void
458 {
459  receive_filters_.clear (types);
460 }
461 
462 void
464  ()
465 {
467 }
468 
469 void
471 {
472  rebroadcast_filters_.clear (types);
473 }
474 
475 
476 void
478 {
479  buffer_filters_.clear ();
480 }
481 
482 void
484  ()
485 {
487 }
488 
489 
493  const std::string & name,
494  transport::TransportContext & context) const
495 {
496  return send_filters_.filter (input, name, context);
497 }
498 
499 void
501  knowledge::KnowledgeMap & records,
502  const TransportContext & transport_context) const
503 {
504  send_filters_.filter (records, transport_context);
505 }
506 
507 
508 int
510  unsigned char * source, int size, int max_size) const
511 {
512  // encode from front to back
513  for (filters::BufferFilters::const_iterator i = buffer_filters_.begin ();
514  i != buffer_filters_.end (); ++i)
515  {
516  size = (*i)->encode (source, size, max_size);
517  }
518 
519  return size;
520 }
521 
522 
523 int
525  unsigned char * source, int size, int max_size) const
526 {
527  // decode from back to front
528  for (filters::BufferFilters::const_reverse_iterator i = buffer_filters_.rbegin ();
529  i != buffer_filters_.rend (); ++i)
530  {
531  size = (*i)->decode (source, size, max_size);
532  }
533 
534  return size;
535 }
536 
537 
541  const std::string & name,
542  transport::TransportContext & context) const
543 {
544  return receive_filters_.filter (input, name, context);
545 }
546 
547 void
549  knowledge::KnowledgeMap & records,
550  const transport::TransportContext & transport_context) const
551 {
552  receive_filters_.filter (records, transport_context);
553 }
554 
558  const std::string & name,
559  transport::TransportContext & context) const
560 {
561  return rebroadcast_filters_.filter (input, name, context);
562 }
563 
564 void
566  knowledge::KnowledgeMap & records,
567  const transport::TransportContext & transport_context) const
568 {
569  rebroadcast_filters_.filter (records, transport_context);
570 }
571 
572 void
574  void) const
575 {
577 }
578 
579 void
581  void) const
582 {
584 }
585 
586 void
588  void) const
589 {
591 }
592 
593 
594 
595 size_t
597  void) const
598 {
600 }
601 
602 size_t
604  void) const
605 {
607 }
608 
609 size_t
611  void) const
612 {
614 }
615 
616 size_t
618  void) const
619 {
621 }
622 
623 
624 size_t
626  void) const
627 {
629 }
630 
631 size_t
633  void) const
634 {
636 }
637 
638 size_t
640 void) const
641 {
642  return buffer_filters_.size ();
643 }
644 
645 void
647  double drop_rate,
648  int drop_type,
649  uint64_t drop_burst)
650 {
651  packet_drop_rate_ = drop_rate;
652  packet_drop_type_ = drop_type;
653  packet_drop_burst_ = drop_burst;
654 }
655 
656 double
658 {
659  return packet_drop_rate_;
660 }
661 
662 int
664 {
665  return packet_drop_type_;
666 }
667 
668 uint64_t
670 {
671  return packet_drop_burst_;
672 }
673 
674 void
676  int64_t send_bandwidth)
677 {
678  max_send_bandwidth_ = send_bandwidth;
679 }
680 
681 int64_t
683  void) const
684 {
685  return max_send_bandwidth_;
686 }
687 
688 void
690  int64_t total_bandwidth)
691 {
692  max_total_bandwidth_ = total_bandwidth;
693 }
694 
695 int64_t
697  void) const
698 {
699  return max_total_bandwidth_;
700 }
701 
702 void
704 {
705  deadline_ = deadline;
706 }
707 
708 double
710 {
711  return deadline_;
712 }
713 
714 void
716  const std::string & prefix)
717 {
718  TransportSettings::load (filename, prefix);
719 
721  knowledge.load_context (filename);
722 
723  containers::Map trusted_peers (prefix + ".trusted_peers", knowledge);
724  containers::Map banned_peers (prefix + ".banned_peers", knowledge);
725 
726  rebroadcast_ttl_ = (unsigned char)knowledge.get (
727  prefix + ".rebroadcast_ttl").to_integer ();
728  participant_rebroadcast_ttl_ = (unsigned char)knowledge.get (
729  prefix + ".participant_rebroadcast_ttl").to_integer ();
730 
731  std::vector <std::string> trusted_keys, banned_keys;
732 
733  trusted_peers.keys (trusted_keys);
734  banned_peers.keys (banned_keys);
735 
736  for (size_t i = 0; i < trusted_keys.size (); ++i)
737  {
738  trusted_peers_[trusted_keys[i]] = 1;
739  }
740 
741  for (size_t i = 0; i < banned_keys.size (); ++i)
742  {
743  banned_peers_[banned_keys[i]] = 1;
744  }
745 
746  packet_drop_rate_ = knowledge.get (
747  prefix + ".packet_drop_rate").to_double ();
748  packet_drop_type_ = (int)knowledge.get (
749  prefix + ".packet_drop_type").to_integer ();
750  packet_drop_burst_ = (uint64_t)knowledge.get (
751  prefix + ".packet_drop_burst").to_integer ();
752 
753  max_send_bandwidth_ = (int64_t)knowledge.get (
754  prefix + ".max_send_bandwidth").to_integer ();
755  max_total_bandwidth_ = (int64_t)knowledge.get (
756  prefix + ".max_total_bandwidth").to_integer ();
757 
758  deadline_ = knowledge.get (
759  prefix + ".deadline").to_double ();
760 }
761 
762 void
764  const std::string & prefix)
765 {
766  TransportSettings::load_text (filename, prefix);
767 
769  knowledge.evaluate (madara::utility::file_to_string (filename));
770 
771  containers::Map trusted_peers (prefix + ".trusted_peers", knowledge);
772  containers::Map banned_peers (prefix + ".banned_peers", knowledge);
773 
774  rebroadcast_ttl_ = (unsigned char)knowledge.get (
775  prefix + ".rebroadcast_ttl").to_integer ();
776  participant_rebroadcast_ttl_ = (unsigned char)knowledge.get (
777  prefix + ".participant_rebroadcast_ttl").to_integer ();
778 
779  std::vector <std::string> trusted_keys, banned_keys;
780 
781  trusted_peers.keys (trusted_keys);
782  banned_peers.keys (banned_keys);
783 
784  for (size_t i = 0; i < trusted_keys.size (); ++i)
785  {
786  trusted_peers_[trusted_keys[i]] = 1;
787  }
788 
789  for (size_t i = 0; i < banned_keys.size (); ++i)
790  {
791  banned_peers_[banned_keys[i]] = 1;
792  }
793 
794  packet_drop_rate_ = knowledge.get (
795  prefix + ".packet_drop_rate").to_double ();
796  packet_drop_type_ = (int)knowledge.get (
797  prefix + ".packet_drop_type").to_integer ();
798  packet_drop_burst_ = (uint64_t)knowledge.get (
799  prefix + ".packet_drop_burst").to_integer ();
800 
801  max_send_bandwidth_ = (int64_t)knowledge.get (
802  prefix + ".max_send_bandwidth").to_integer ();
803  max_total_bandwidth_ = (int64_t)knowledge.get (
804  prefix + ".max_total_bandwidth").to_integer ();
805 
806  deadline_ = knowledge.get (
807  prefix + ".deadline").to_double ();
808 }
809 
810 void
812  const std::string & filename,
813  const std::string & prefix) const
814 {
815  // Save the underlying base settings first
816  TransportSettings::save (filename, prefix);
817 
818  // then load the savings
820  knowledge.load_context (filename);
821 
822  containers::Map trusted_peers (prefix + ".trusted_peers", knowledge);
823  containers::Map banned_peers (prefix + ".banned_peers", knowledge);
824 
825  knowledge.set (prefix + ".rebroadcast_ttl", Integer (rebroadcast_ttl_));
826  knowledge.set (prefix + ".participant_rebroadcast_ttl",
828 
829  for (std::map <std::string, int>::const_iterator i = trusted_peers_.begin ();
830  i != trusted_peers_.end (); ++i)
831  {
832  trusted_peers.set (i->first, Integer (1));
833  }
834 
835  for (std::map <std::string, int>::const_iterator i = banned_peers_.begin ();
836  i != banned_peers_.end (); ++i)
837  {
838  banned_peers.set (i->first, Integer (1));
839  }
840 
841  knowledge.set (prefix + ".packet_drop_rate", packet_drop_rate_);
842  knowledge.set (prefix + ".packet_drop_type", Integer (packet_drop_type_));
843  knowledge.set (prefix + ".packet_drop_burst", Integer (packet_drop_burst_));
844 
845  knowledge.set (prefix + ".max_send_bandwidth",
847  knowledge.set (prefix + ".max_total_bandwidth",
849  knowledge.set (prefix + ".deadline", deadline_);
850 
851  knowledge.save_context (filename);
852 }
853 
854 
855 void
857  const std::string & filename,
858  const std::string & prefix) const
859 {
860  // Save the underlying base settings first
861  TransportSettings::save_text (filename, prefix);
862 
863  // then load the savings
865  knowledge.evaluate (madara::utility::file_to_string (filename));
866 
867  containers::Map trusted_peers (prefix + ".trusted_peers", knowledge);
868  containers::Map banned_peers (prefix + ".banned_peers", knowledge);
869 
870  knowledge.set (prefix + ".rebroadcast_ttl", Integer (rebroadcast_ttl_));
871  knowledge.set (prefix + ".participant_rebroadcast_ttl",
873 
874  for (std::map <std::string, int>::const_iterator i = trusted_peers_.begin ();
875  i != trusted_peers_.end (); ++i)
876  {
877  trusted_peers.set (i->first, Integer (1));
878  }
879 
880  for (std::map <std::string, int>::const_iterator i = banned_peers_.begin ();
881  i != banned_peers_.end (); ++i)
882  {
883  banned_peers.set (i->first, Integer (1));
884  }
885 
886  knowledge.set (prefix + ".packet_drop_rate", packet_drop_rate_);
887  knowledge.set (prefix + ".packet_drop_type", Integer (packet_drop_type_));
888  knowledge.set (prefix + ".packet_drop_burst", Integer (packet_drop_burst_));
889 
890  knowledge.set (prefix + ".max_send_bandwidth",
892  knowledge.set (prefix + ".max_total_bandwidth",
894  knowledge.set (prefix + ".deadline", deadline_);
895 
896  knowledge.save_as_karl (filename);
897 }
898 
This class encapsulates an entry in a KnowledgeBase.
virtual void load_text(const std::string &filename, const std::string &prefix="transport")
Loads the settings from a text file.
bool is_trusted(const std::string &peer) const
Checks if a peer is trusted.
knowledge::KnowledgeRecord filter(const knowledge::KnowledgeRecord &input, const std::string &name, transport::TransportContext &context) const
Filters an input according to its filter chain.
void add_trusted_peer(const std::string &peer)
Adds a trusted peer.
virtual void load(const std::string &filename, const std::string &prefix="transport")
Loads the settings from a binary file.
void clear_receive_filters(uint32_t types)
Clears the list of filters for the specified types.
int filter_decode(unsigned char *source, int size, int max_size) const
Calls decode on the the buffer filter chain.
int64_t save_context(const std::string &filename) const
Saves the context to a file.
void clear(uint32_t types)
Clears the list of filters for the specified types.
size_t get_number_of_receive_filtered_types(void) const
Returns the number of types that are filtered after received.
void add_send_filter(uint32_t types, knowledge::KnowledgeRecord(*function)(knowledge::FunctionArguments &, knowledge::Variables &))
Adds a filter that will be applied to certain types before sending.
void clear_aggregate_filters(void)
Clears the aggregate filters.
void attach(knowledge::ThreadSafeContext *context)
Attaches a context to the various filtering systems.
void clear_receive_aggregate_filters(void)
Clears the list of receive time aggregate filters.
void print_num_filters(void) const
Prints the number of filters chained for each type.
void clear_send_aggregate_filters(void)
Clears the list of send time aggregate filters.
double to_double(void) const
converts the value to a float/double.
Abstract base class for implementing aggregate record filters via a functor interface.
void keys(std::vector< std::string > &curkeys) const
Returns the keys within the map.
Definition: Map.cpp:516
int get_drop_type(void) const
Returns the policy type for packet drops.
void add_rebroadcast_filter(uint32_t types, knowledge::KnowledgeRecord(*function)(knowledge::FunctionArguments &, knowledge::Variables &))
Adds a filter that will be applied to certain types after receiving and before rebroadcasting (if TTL...
int64_t get_send_bandwidth_limit(void) const
Returns the limit for sending on this transport in bytes per second.
knowledge::KnowledgeRecord filter_receive(const madara::knowledge::KnowledgeRecord &input, const std::string &name, transport::TransportContext &context) const
Filters an input according to the receive filter chain.
void attach(ThreadSafeContext *context)
Attaches a context.
void clear_rebroadcast_filters(uint32_t types)
Clears the list of filters for the specified types.
This class stores variables and their values for use by any entity needing state information in a thr...
void operator=(const QoSTransportSettings &settings)
Assignment operator.
MADARA_EXPORT utility::Refcounter< logger::Logger > global_logger
unsigned char get_rebroadcast_ttl(void) const
Gets the time to live for rebroadcasting (number of rebroadcasts per message).
bool remove_trusted_peer(const std::string &peer)
Removes a trusted peer, if it exists in the list.
Abstract base class for implementing individual record filters via a functor interface.
Definition: RecordFilter.h:33
Provides knowledge logging services to files and terminals.
Definition: GlobalLogger.h:11
Holds basic transport settings.
void add_filter(filters::BufferFilter *filter)
Adds a buffer filter to the chain.
knowledge::KnowledgeRecordFilters send_filters_
A container for filters applied before sending from this host.
std::vector< KnowledgeRecord > FunctionArguments
double get_deadline(void) const
Returns the latency deadline in seconds.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Retrieves a knowledge value.
Provides context about the transport.
unsigned char rebroadcast_ttl_
number of rebroadcasts for receivers to ultimately do.
virtual void load_text(const std::string &filename, const std::string &prefix="transport")
Loads the settings from a text file.
virtual void save(const std::string &filename, const std::string &prefix="transport") const
Saves the settings from a binary file.
Provides container classes for fast knowledge base access and mutation.
Definition: Barrier.h:27
size_t get_number_of_send_aggregate_filters(void) const
Returns the number of aggregate filters applied before sending @ return the number of aggregate filte...
void set_deadline(double deadline)
Sets the packet deadline in seconds.
void add_receive_filter(uint32_t types, knowledge::KnowledgeRecord(*function)(knowledge::FunctionArguments &, knowledge::Variables &))
Adds a filter that will be applied to certain types after receiving and before applying to the local ...
unsigned char participant_rebroadcast_ttl_
This field is meant to limit the number of rebroadcasts that this transport will participate in...
bool remove_banned_peer(const std::string &peer)
Removes a trusted peer, if it exists in the list.
int set(const std::string &key, madara::knowledge::KnowledgeRecord::Integer value=madara::knowledge::KnowledgeRecord::MODIFIED)
Sets a location within the map to the specified value.
Definition: Map.cpp:605
virtual void save_text(const std::string &filename, const std::string &prefix="transport") const
Saves the settings from a text file.
static struct madara::knowledge::tags::string_t string
void clear_rebroadcast_aggregate_filters(void)
Clears the list of rebroadcast time aggregate filters.
void print_num_filters_send(void) const
Prints the number of filters chained for each type to the send filter.
void set_total_bandwidth_limit(int64_t bandwidth)
Sets a bandwidth limit for receiving and sending over the transport.
knowledge::KnowledgeRecord filter_rebroadcast(const madara::knowledge::KnowledgeRecord &input, const std::string &name, transport::TransportContext &context) const
Filters an input according to the rebroadcast filter chain.
size_t get_number_of_buffer_filters(void) const
Returns the number of buffer filters.
uint64_t get_drop_burst(void) const
Returns the bursts of packet drops.
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:32
void print_num_filters_receive(void) const
Prints the number of filters chained for each type to the receive filter.
This class stores a map of strings to KaRL variables.
Definition: Map.h:32
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
madara::knowledge::KnowledgeRecord::Integer Integer
void set_rebroadcast_ttl(unsigned char ttl)
Sets the time to live for our packets.
::std::map< std::string, KnowledgeRecord > KnowledgeMap
std::string file_to_string(const std::string &filename)
Reads a file into a string.
Definition: Utility.cpp:347
int64_t save_as_karl(const std::string &filename) const
Saves the context to a file as karl assignments, rather than binary.
size_t get_number_of_receive_aggregate_filters(void) const
Returns the number of aggregate filters applied after receiving @ return the number of aggregate filt...
size_t get_number_of_filtered_types(void) const
Returns the number of types that have filters.
double deadline_
Deadline for packets at which packets drop.
void clear_buffer_filters(void)
Clears the list of buffer filters.
Integer to_integer(void) const
converts the value to an integer.
filters::BufferFilters buffer_filters_
buffer filters have an encode and decode method
size_t get_number_of_aggregate_filters(void) const
Returns the number of aggregate update filters.
void print_num_filters_rebroadcast(void) const
Prints the number of filters chained for each type to the rebroadcast filter.
int64_t max_send_bandwidth_
Maximum send bandwidth usage per second before packets drop.
void add_banned_peer(const std::string &peer)
Adds a banned peer.
Container for quality-of-service settings.
int filter_encode(unsigned char *source, int size, int max_size) const
Calls encode on the the buffer filter chain.
std::map< std::string, int > trusted_peers_
A container of all trusted peers.
void set_send_bandwidth_limit(int64_t bandwidth)
Sets a bandwidth limit for sending on this transport in bytes per sec.
int64_t get_total_bandwidth_limit(void) const
Returns the total limit for this transport in bytes per second.
std::map< std::string, int > banned_peers_
A container of all banned peers.
int set(const VariableReference &variable, const std::string &value, const EvalSettings &settings=EvalSettings(false, false, true, false, false))
Atomically sets the value of a variable to a string.
Provides functions and classes for the distributed knowledge base.
knowledge::KnowledgeRecord filter_send(const madara::knowledge::KnowledgeRecord &input, const std::string &name, transport::TransportContext &context) const
Filters an input according to send&#39;s filter chain.
void clear_send_filters(uint32_t types)
Clears the list of filters for the specified types.
size_t get_number_of_send_filtered_types(void) const
Returns the number of types that are filtered before send.
double packet_drop_rate_
Rate for dropping packets.
int64_t max_total_bandwidth_
Maximum bandwidth usage for the transport (receive/send) before drop.
madara::knowledge::KnowledgeRecord evaluate(const std::string &expression, const EvalSettings &settings=EvalSettings())
Evaluates an expression.
virtual void save_text(const std::string &filename, const std::string &prefix="transport") const
Saves the settings from a text file.
virtual void load(const std::string &filename, const std::string &prefix="transport")
Loads the settings from a binary file.
int64_t load_context(const std::string &filename, bool use_id=true, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(true, true, true, false))
Loads the context from a file.
uint64_t packet_drop_burst_
Burst of packet drops.
double get_drop_rate(void) const
Returns the percentage of dropped packets to enforce on sends.
Abstract base class for implementing buffer filters via a functor interface.
Definition: BufferFilter.h:26
void add(uint32_t types, knowledge::KnowledgeRecord(*function)(FunctionArguments &, Variables &))
Adds a filter to the list of types.
void enable_participant_ttl(unsigned char maximum_ttl=255)
Enables rebroadcast support up to a certain time to live for other agent&#39;s messages.
void update_drop_rate(double drop_rate, int drop_type=PACKET_DROP_DETERMINISTIC, uint64_t drop_burst=1)
Updates a packet drop rate, type, and burst.
size_t get_number_of_rebroadcast_filtered_types(void) const
Returns the number of types that are filtered before rebroadcast.
size_t get_number_of_rebroadcast_aggregate_filters(void) const
Returns the number of aggregate filters applied before rebroadcasting @ return the number of aggregat...
Provides an interface for external functions into the MADARA KaRL variable settings.
knowledge::KnowledgeRecordFilters receive_filters_
A container for receive filters.
knowledge::KnowledgeRecordFilters rebroadcast_filters_
A container for rebroadcast filters.
virtual void save(const std::string &filename, const std::string &prefix="transport") const
Saves the settings from a binary file.
unsigned char get_participant_ttl(void) const
Returns the maximum time to live participation of this transport in rebroadcasting of other agent&#39;s m...