srvrec.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. SRV record support
  5. ##################################################################### */
  6. /*}}}*/
  7. #ifndef SRVREC_H
  8. #define SRVREC_H
  9. #include <arpa/nameser.h>
  10. #include <vector>
  11. #include <string>
  12. class SrvRec
  13. {
  14. public:
  15. std::string target;
  16. u_int16_t priority;
  17. u_int16_t weight;
  18. u_int16_t port;
  19. // each server is assigned a interval [start, end] in the space of [0, max]
  20. int random_number_range_start;
  21. int random_number_range_end;
  22. int random_number_range_max;
  23. bool operator<(SrvRec const &other) const {
  24. return this->priority < other.priority;
  25. }
  26. bool operator==(SrvRec const &other) const;
  27. SrvRec(std::string const Target, u_int16_t const Priority,
  28. u_int16_t const Weight, u_int16_t const Port) :
  29. target(Target), priority(Priority), weight(Weight), port(Port),
  30. random_number_range_start(0), random_number_range_end(0),
  31. random_number_range_max(0) {}
  32. };
  33. /** \brief Get SRV records from host/port (builds the query string internally)
  34. */
  35. bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result);
  36. /** \brief Get SRV records for query string like: _http._tcp.example.com
  37. */
  38. bool GetSrvRecords(std::string host, int port, std::vector<SrvRec> &Result);
  39. /** \brief Pop a single SRV record from the vector of SrvRec taking
  40. * priority and weight into account
  41. */
  42. SrvRec PopFromSrvRecs(std::vector<SrvRec> &Recs);
  43. #endif