7263b5feefa2d3e068f9cb580b04e1d55d1fd8d2 jcasper Wed May 7 18:25:12 2025 -0700 Updating python version of botDelay check to match new C version, refs #35584 diff --git src/hg/pyLib/hgLib3.py src/hg/pyLib/hgLib3.py index 76900bbb49a..043992f3c87 100644 --- src/hg/pyLib/hgLib3.py +++ src/hg/pyLib/hgLib3.py @@ -469,30 +469,40 @@ return None def getCookieUser(): " port of lib/botDelay.c:getCookieUser: get hguid cookie value " user = None centralCookie = cfgOption("central.cookie", default="hguid") if centralCookie: user = findCookieData(centralCookie) return user def getBotCheckString(ip, fraction): " port of lib/botDelay.c:getBotCheckString: compose user.ip fraction for bot check " user = getCookieUser() + useNew = cfgOptionBoolean("newBotDelay") + if (useNew): + hgsid = cgiString("hgsid") + if user: + botCheckString = "uid%s %f" % (user, fraction) + elif hgsid: + botCheckString = "sid%s %f" % (hgsid, fraction) + else: + botCheckString = "%s %f" % (ip, fraction) + else: if user: botCheckString = "%s.%s %f" % (user, ip, fraction) else: botCheckString = "%s %f" % (ip, fraction) return botCheckString def hgBotDelay(fraction=1.0, useBytes=None): """ Implement bottleneck delay, get bottleneck server from hg.conf. This behaves similar to the function src/hg/lib/botDelay.c:hgBotDelay It does not use the hgsid, currently it always uses the IP address. Using the hgsid makes little sense. It is more lenient than the C version. If useBytes is set, use only the first x bytes of the IP address. This helps block bots that all use similar IP addresses, at the risk of blocking