diff --git a/src/input/input_balancer.cpp b/src/input/input_balancer.cpp index e2ef81e1..5c8cc38e 100644 --- a/src/input/input_balancer.cpp +++ b/src/input/input_balancer.cpp @@ -60,6 +60,12 @@ namespace Mist { while ((Util::epoch() - startTime < 10) && (balConn || balConn.Received().size())){ if (balConn.spool() || balConn.Received().size()){ 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; startTime = 0;//note success break;//break out of while loop diff --git a/src/utils/util_load.cpp b/src/utils/util_load.cpp index d71b0986..b3688cbd 100644 --- a/src/utils/util_load.cpp +++ b/src/utils/util_load.cpp @@ -93,6 +93,7 @@ private: public: std::string host; + char binHost[16]; unsigned long long availBandwidth; JSON::Value geoDetails; double servLati, servLongi; @@ -498,6 +499,10 @@ int handleRequest(Socket::Connection &conn){ unsigned int bestScore = 0; for (HOSTLOOP){ 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); if (score > bestScore){ bestHost = "dtsc://" + HOST(i).details->host; @@ -661,6 +666,7 @@ void handleServer(void *hostEntryPointer){ }else{ if (down){ WARN_MSG("Connection established with %s", url.host.c_str()); + memcpy(entry->details->binHost, DL.getSocket().getBinHost().data(), 16); entry->state = STATE_ONLINE; down = false; } diff --git a/test/url.cpp b/test/url.cpp index 04a5ff6c..0cccb7a7 100644 --- a/test/url.cpp +++ b/test/url.cpp @@ -13,7 +13,7 @@ int main(int argc, char ** argv){ } std::cout << argv[i] << " -> " << u.getUrl() << 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 << "Path: " << u.path << std::endl; std::cout << "Query: " << u.args << std::endl;