基本上我想做以下事情:
string resolveDns(string host){
string rootId = "SOME_ID";
string id = rootId;
string []zones = host.split('.');
for (int i = zones.count() - 1; i >= 0; i--){
id = getZoneId(id, zones[i]);
}
string []ips = getZoneIps(id);
if (ips.count() == 1){
return ips[0];
} else {
return getLeastLoadedIp(ips);
}
}
string getZoneId(string rootId, string zoneName){
return Sql.prepare("SELECT id FROM zones WHERE parent_id=%s AND name=%s", rootId, zoneName);
}
string getZoneIps(string id){
return Sql.prepare("SELECT ip FROM zones WHERE parent_id=%s", id);
}
string getLeastLoadedIp(string []ips){
if (inMem){
int min = INT_MAX;
string ip = null;
for (int i = 0; i < ips->count(); i++){
int count = HashTable.get(queue_length, ips[i]);
if (count < min){
ip = ips[i];
min = count;
}
}
return ip;
} else {
return Sql.prepare("SELECT ip FROM zones WHERE ip IN (%a) ORDER BY queue_length ASC LIMIT 1", ips);
}
}
什么 DNS 服务器允许我这样做?(C 或 C++ 都可以)