]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/srvrec.h
srv test: do 100 pulls twice and compare list
[apt.git] / apt-pkg / contrib / srvrec.h
index fd71e697f1eff67605d217176a463c55d9686aa9..920b6bb3249a162dfb605b7912f04c8755329e1d 100644 (file)
@@ -3,7 +3,7 @@
 /* ######################################################################
 
    SRV record support
-  
+
    ##################################################################### */
                                                                        /*}}}*/
 #ifndef SRVREC_H
@@ -12,6 +12,7 @@
 #include <arpa/nameser.h>
 #include <vector>
 #include <string>
+#include <tuple>
 
 class SrvRec
 {
@@ -21,9 +22,23 @@ class SrvRec
    u_int16_t weight;
    u_int16_t port;
 
-   bool operator<(SrvRec const &other) const { 
-      return this->priority < other.priority; 
+   // each server is assigned a interval [start, end] in the space of [0, max]
+   int random_number_range_start;
+   int random_number_range_end;
+   int random_number_range_max;
+
+   bool operator<(SrvRec const &other) const {
+      return this->priority < other.priority;
+   }
+   bool operator==(SrvRec const &other) const {
+      return std::tie(target, priority, weight, port) == std::tie(other.target, other.priority, other.weight, other.port);
    }
+
+   SrvRec(std::string const Target, u_int16_t const Priority,
+        u_int16_t const Weight, u_int16_t const Port) :
+      target(Target), priority(Priority), weight(Weight), port(Port),
+      random_number_range_start(0), random_number_range_end(0),
+      random_number_range_max(0) {}
 };
 
 /** \brief Get SRV records from host/port (builds the query string internally) 
@@ -34,4 +49,9 @@ bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result);
  */
 bool GetSrvRecords(std::string host, int port, std::vector<SrvRec> &Result);
 
+/** \brief Pop a single SRV record from the vector of SrvRec taking
+ *         priority and weight into account
+ */
+SrvRec PopFromSrvRecs(std::vector<SrvRec> &Recs);
+
 #endif