summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/srvrec.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@ubuntu.com>2014-05-23 17:24:17 +0200
committerMichael Vogt <mvo@ubuntu.com>2014-05-23 17:24:17 +0200
commite5f34ad3b043abf033c1626eb8449b75955d6760 (patch)
tree0e23c5eea4aa09b847e65ed348f8a9b63cfe9139 /apt-pkg/contrib/srvrec.cc
parentcc4800145b408de0b4afef88f4489a541024e75a (diff)
WIP start randomizing
Diffstat (limited to 'apt-pkg/contrib/srvrec.cc')
-rw-r--r--apt-pkg/contrib/srvrec.cc31
1 files changed, 29 insertions, 2 deletions
diff --git a/apt-pkg/contrib/srvrec.cc b/apt-pkg/contrib/srvrec.cc
index c473192fc..70247c2ae 100644
--- a/apt-pkg/contrib/srvrec.cc
+++ b/apt-pkg/contrib/srvrec.cc
@@ -105,10 +105,37 @@ bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result)
Result.push_back(rec);
}
- // sort them
+ // implement load balancing as specified in RFC-2782
+
+ // sort them by priority
std::stable_sort(Result.begin(), Result.end());
- // FIXME: implement weight selection as specified in RFC-2782
+ // assign random number ranges
+ int prev_weight = 0;
+ int prev_priority = 0;
+ for(std::vector<SrvRec>::iterator I = Result.begin();
+ I != Result.end(); ++I)
+ {
+ if(prev_priority != I->priority)
+ prev_weight = 0;
+ I->random_number_range_start = prev_weight;
+ I->random_number_range_end = prev_weight + I->weight;
+ prev_weight = I->random_number_range_end;
+ prev_priority = I->priority;
+ }
+
+ // go over the code in reverse order and note the max random range
+ int max = 0;
+ prev_priority = 0;
+ for(std::vector<SrvRec>::iterator I = Result.end();
+ I != Result.begin(); --I)
+ {
+ if(prev_priority != I->priority)
+ max = I->random_number_range_end;
+ I->random_number_range_max = max;
+ }
+
+ // now shuffle
return true;
}