Balancer input ignores replies of local addresses to prevent loops, load balancer itself updated to not sent self-answers to servers.

This commit is contained in:
Thulinma 2018-07-09 11:23:21 +02:00
parent eeffba15ad
commit 5b059dcf6f
3 changed files with 13 additions and 1 deletions

View file

@ -60,6 +60,12 @@ namespace Mist {
while ((Util::epoch() - startTime < 10) && (balConn || balConn.Received().size())){ while ((Util::epoch() - startTime < 10) && (balConn || balConn.Received().size())){
if (balConn.spool() || balConn.Received().size()){ if (balConn.spool() || balConn.Received().size()){
if (http.Read(balConn.Received().get())){ if (http.Read(balConn.Received().get())){
HTTP::URL newUrl(http.body);
if (Socket::isLocalhost(newUrl.host)){
WARN_MSG("Load balancer returned a local address - ignoring");
startTime = 0;
break;//break out of while loop, ignore return value - it's local.
}
source = http.body; source = http.body;
startTime = 0;//note success startTime = 0;//note success
break;//break out of while loop break;//break out of while loop

View file

@ -93,6 +93,7 @@ private:
public: public:
std::string host; std::string host;
char binHost[16];
unsigned long long availBandwidth; unsigned long long availBandwidth;
JSON::Value geoDetails; JSON::Value geoDetails;
double servLati, servLongi; double servLati, servLongi;
@ -498,6 +499,10 @@ int handleRequest(Socket::Connection &conn){
unsigned int bestScore = 0; unsigned int bestScore = 0;
for (HOSTLOOP){ for (HOSTLOOP){
HOSTCHECK; HOSTCHECK;
if (Socket::matchIPv6Addr(std::string(HOST(i).details->binHost ,16), conn.getBinHost(), 0)){
INFO_MSG("Ignoring same-host entry %s", HOST(i).details->host.data());
continue;
}
unsigned int score = HOST(i).details->source(source); unsigned int score = HOST(i).details->source(source);
if (score > bestScore){ if (score > bestScore){
bestHost = "dtsc://" + HOST(i).details->host; bestHost = "dtsc://" + HOST(i).details->host;
@ -661,6 +666,7 @@ void handleServer(void *hostEntryPointer){
}else{ }else{
if (down){ if (down){
WARN_MSG("Connection established with %s", url.host.c_str()); WARN_MSG("Connection established with %s", url.host.c_str());
memcpy(entry->details->binHost, DL.getSocket().getBinHost().data(), 16);
entry->state = STATE_ONLINE; entry->state = STATE_ONLINE;
down = false; down = false;
} }

View file

@ -13,7 +13,7 @@ int main(int argc, char ** argv){
} }
std::cout << argv[i] << " -> " << u.getUrl() << std::endl; std::cout << argv[i] << " -> " << u.getUrl() << std::endl;
std::cout << "Protocol: " << u.protocol << std::endl; std::cout << "Protocol: " << u.protocol << std::endl;
std::cout << "Host: " << u.host << std::endl; std::cout << "Host: " << u.host << " (Local: " << (Socket::isLocalhost(u.host)?"Yes":"No") << ")" << std::endl;
std::cout << "Port: " << u.getPort() << std::endl; std::cout << "Port: " << u.getPort() << std::endl;
std::cout << "Path: " << u.path << std::endl; std::cout << "Path: " << u.path << std::endl;
std::cout << "Query: " << u.args << std::endl; std::cout << "Query: " << u.args << std::endl;