return ret;
}
- ret->weight=weightVal;
+ ret->setWeight(weightVal);
}
catch(std::exception& e) {
// std::stoi will throw an exception if the string isn't in a value int range
}
if (vars.count("id")) {
- ret->id = boost::lexical_cast<boost::uuids::uuid>(boost::get<string>(vars["id"]));
+ ret->setId(boost::lexical_cast<boost::uuids::uuid>(boost::get<string>(vars["id"])));
}
if(vars.count("checkName")) {
return connected;
}
+void DownstreamState::hash()
+{
+ auto w = weight;
+ hashes.clear();
+ while (w > 0) {
+ std::string uuid = boost::str(boost::format("%s-%d") % id % w);
+ unsigned int wshash = burtleCI((const unsigned char*)uuid.c_str(), uuid.size(), g_hashperturb);
+ hashes.insert(wshash);
+ --w;
+ }
+}
+
+void DownstreamState::setId(const boost::uuids::uuid& newId)
+{
+ id = newId;
+ hash();
+}
+
+void DownstreamState::setWeight(int newWeight)
+{
+ weight = newWeight;
+ hash();
+}
DownstreamState::DownstreamState(const ComboAddress& remote_, const ComboAddress& sourceAddr_, unsigned int sourceItf_, size_t numberOfSockets): remote(remote_), sourceAddr(sourceAddr_), sourceItf(sourceItf_)
{
for (auto& fd : sockets) {
fd = -1;
}
+ hash();
if (!IsAnyAddress(remote)) {
reconnect();
for (const auto& d: servers) {
if (d.second->isUp()) {
- if (d.second->hashes.empty()) {
- // computes server's points
- // @todo check if server's weight can change over time
- auto w = d.second->weight;
- while (w > 0) {
- std::string uuid = boost::str(boost::format("%s-%d") % d.second->id % w);
- unsigned int wshash = burtleCI((const unsigned char*)uuid.c_str(), uuid.size(), g_hashperturb);
- d.second->hashes.insert(wshash);
- --w;
- }
- }
for (const auto& h: d.second->hashes) {
// put server's hashes on the circle
circle.insert(std::make_pair(h, d.second));