42086827faf627c17963d56f387279b30bd05880
larrym
  Fri Apr 20 12:22:02 2012 -0700
tweak/comment geoIpNode query logic
diff --git src/hg/hgGateway/hgGateway.c src/hg/hgGateway/hgGateway.c
index 18acf5b..d2441c5 100644
--- src/hg/hgGateway/hgGateway.c
+++ src/hg/hgGateway/hgGateway.c
@@ -310,32 +310,34 @@
     char *redirectCookie = findCookieData("redirect");
     char *redirect = cgiOptionalString("redirect");
 
     fprintf(stderr, "GALT redirectCookie=%s redirect=%s\n", 
             redirectCookie, redirect); fflush(stderr); // DEBUG REMOVE
 
     if (redirect == NULL && redirectCookie == NULL)
         {
         int thisNode = sqlUnsigned(thisNodeStr);
         struct sqlConnection *centralConn = hConnectCentral();
         char query[1024];
         char *ipStr = cgiRemoteAddr();
         bits32 ip = 0;
         internetDottedQuadToIp(ipStr, &ip);
 
-        // we assume no overlaps in geoIpNode table, so we can use limit 1 to make query very efficient.
-        safef(query, sizeof query, "select ipStart, ipEnd, node from geoIpNode where %u >= ipStart order by ipStart desc limit 1", ip);
+        // We (sort-of) assume no overlaps in geoIpNode table, so we can use limit 1 to make query very efficient;
+        // we do accomodate a range that is completely contained in another (to accomodate the hgroaming entry for testing);
+        // this is accomplished by "<= ipEnd" in the sql query.
+        safef(query, sizeof query, "select ipStart, ipEnd, node from geoIpNode where %u >= ipStart and %u <= ipEnd order by ipStart desc limit 1", ip, ip);
         char **row;
         struct sqlResult *sr = sqlGetResult(centralConn, query);
         int defaultNode = 1;
         if ((row = sqlNextRow(sr)) != NULL)
             {
             uint ipStart = sqlUnsigned(row[0]);
             uint ipEnd = sqlUnsigned(row[1]);
             if (ipStart <= ip && ipEnd >= ip)
                 {
                 defaultNode = sqlSigned(row[2]);
                 }
             }
         sqlFreeResult(&sr);
 
         fprintf(stderr, "GALT thisNodeStr=%s thisNode=%d ipStr=%s ip=%u defaultNode (for user) %d\n",