]> git.saurik.com Git - apt.git/blame - apt-pkg/contrib/srvrec.h
implement apt-get source msg 'Please use: $vcs' for git
[apt.git] / apt-pkg / contrib / srvrec.h
CommitLineData
f106fecc
MV
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3/* ######################################################################
4
5 SRV record support
cdeb54d4 6
f106fecc
MV
7 ##################################################################### */
8 /*}}}*/
9#ifndef SRVREC_H
10#define SRVREC_H
11
12#include <arpa/nameser.h>
13#include <vector>
14#include <string>
9bfb1136 15#include <tuple>
f106fecc
MV
16
17class SrvRec
18{
19 public:
20 std::string target;
21 u_int16_t priority;
22 u_int16_t weight;
23 u_int16_t port;
24
e5f34ad3
MV
25 // each server is assigned a interval [start, end] in the space of [0, max]
26 int random_number_range_start;
27 int random_number_range_end;
28 int random_number_range_max;
29
76abe9a5
DK
30 bool operator<(SrvRec const &other) const {
31 return this->priority < other.priority;
8194f976 32 }
9bfb1136
DK
33 bool operator==(SrvRec const &other) const {
34 return std::tie(target, priority, weight, port) == std::tie(other.target, other.priority, other.weight, other.port);
35 }
76abe9a5
DK
36
37 SrvRec(std::string const Target, u_int16_t const Priority,
38 u_int16_t const Weight, u_int16_t const Port) :
39 target(Target), priority(Priority), weight(Weight), port(Port),
40 random_number_range_start(0), random_number_range_end(0),
41 random_number_range_max(0) {}
f106fecc
MV
42};
43
a01695e8
MV
44/** \brief Get SRV records from host/port (builds the query string internally)
45 */
f106fecc
MV
46bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result);
47
a01695e8
MV
48/** \brief Get SRV records for query string like: _http._tcp.example.com
49 */
50bool GetSrvRecords(std::string host, int port, std::vector<SrvRec> &Result);
51
c29dbdff
MV
52/** \brief Pop a single SRV record from the vector of SrvRec taking
53 * priority and weight into account
54 */
55SrvRec PopFromSrvRecs(std::vector<SrvRec> &Recs);
56
f106fecc 57#endif