ca3f45c0d7c8ea372d9202eb5160c0f9268c95f2
hiram
Wed Sep 11 10:38:12 2019 -0700
use the correct default delay fraction refs #23217
diff --git src/hg/lib/botDelay.c src/hg/lib/botDelay.c
index a8a44cb..5304629 100644
--- src/hg/lib/botDelay.c
+++ src/hg/lib/botDelay.c
@@ -2,30 +2,33 @@
* for a little bit if IP address looks like it is
* being just too demanding. */
/* Copyright (C) 2014 The Regents of the University of California
* See README in this or parent directory for licensing information. */
#include "common.h"
#include "net.h"
#include "portable.h"
#include "hgConfig.h"
#include "cheapcgi.h"
#include "hui.h"
#include "hCommon.h"
#include "botDelay.h"
+#define defaultDelayFrac 1.0 /* standard penalty for most CGIs */
+#define defaultWarnMs 10000 /* warning at 10 to 20 second delay */
+#define defaultExitMs 20000 /* error 429 Too Many Requests after 20+ second delay */
int botDelayTime(char *host, int port, char *botCheckString)
/* Figure out suggested delay time for ip address in
* milliseconds. */
{
int sd = netMustConnect(host, port);
char buf[256];
netSendString(sd, botCheckString);
netRecieveString(sd, buf);
close(sd);
return atoi(buf);
}
void botDelayMessage(char *ip, int millis)
/* Print out message saying why you are stalled. */
@@ -158,54 +161,54 @@
* in hg.conf. */
{
if (botException())
return;
char *host = cfgOption("bottleneck.host");
char *port = cfgOption("bottleneck.port");
if (host != NULL && port != NULL)
botDelayCgi(host, atoi(port), noWarn, fraction);
}
void hgBotDelay()
/* High level bot delay call - for use with regular webpage output */
{
-hgBotDelayExt(FALSE, 1.0);
+hgBotDelayExt(FALSE, defaultDelayFrac);
}
void hgBotDelayFrac(double fraction)
/* Like hgBotDelay, but imposes a fraction of the standard access penalty */
{
hgBotDelayExt(FALSE, fraction);
}
void hgBotDelayNoWarn()
/* High level bot delay call without warning - for use with non-webpage outputs */
{
-hgBotDelayExt(TRUE, 1.0);
+hgBotDelayExt(TRUE, defaultDelayFrac);
}
void hgBotDelayNoWarnFrac(double fraction)
/* Like hgBotDelayNoWarn, but imposes a fraction of the standard access penalty */
{
hgBotDelayExt(TRUE, fraction);
}
int hgBotDelayTime()
{
-return hgBotDelayTimeFrac(1.0);
+return hgBotDelayTimeFrac(defaultDelayFrac);
}
int hgBotDelayTimeFrac(double fraction)
/* Get suggested delay time from cgi using the standard penalty. */
{
char *ip = getenv("REMOTE_ADDR");
char *host = cfgOption("bottleneck.host");
char *port = cfgOption("bottleneck.port");
int delay = 0;
if (host != NULL && port != NULL && ip != NULL)
{
char *botCheckString = getBotCheckString(ip, fraction);
delay = botDelayTime(host, atoi(port), botCheckString);
freeMem(botCheckString);
@@ -244,45 +247,50 @@
"a web robot is launching queries quickly, and not even waiting for "
"the results of one query to finish before launching another query. "
"We cannot service requests from your IP address under these "
"conditions. (code %d) "
"To use the genome browser functionality from a Unix command line, "
"please read our FAQ on this topic. "
"For further help on how to access our data from a command line, "
"or if "
"you think this delay is being imposed unfairly, please contact genome-www@soe.ucsc.edu."
,hogHost, asctime(localtime(&now)), botDelayMillis);
puts("