a1708067edcd7dbca14b244587c416afaf041114 jcasper Mon Apr 10 16:47:31 2017 -0700 DAS server can now contact a bottleneck server to moderate usage, refs #19193 diff --git src/hg/das/das.c src/hg/das/das.c index d84ba0a..8d0d138 100644 --- src/hg/das/das.c +++ src/hg/das/das.c @@ -8,31 +8,31 @@ /* Copyright (C) 2013 The Regents of the University of California * See README in this or parent directory for licensing information. */ #include "common.h" #include "linefile.h" #include "hash.h" #include "cheapcgi.h" #include "htmshell.h" #include "psl.h" #include "jksql.h" #include "hdb.h" #include "chromInfo.h" #include "bed.h" #include "genePred.h" #include "trackTable.h" - +#include "botDelay.h" /* Including the count in the types response can be very slow for large * regions and is optional. Inclusion of count if controlled by this compile- * time option. */ #define TYPES_RETURN_COUNT 0 static char *version = "1.00"; static char *database = NULL; /* DAS response codes */ #define DAS_OK 200 #define DAS_BAD_COMMAND 400 #define DAS_BAD_DATA_SOURCE 401 #define DAS_BAD_COMMAND_ARGS 402 @@ -63,47 +63,54 @@ dasHead(code, FALSE); if (code != DAS_OK) exit(-1); printf("<?xml version=\"1.0\" standalone=\"no\"?>\n"); } static char dasStrand(char strand) /* convert a strand to a valid DAS strand (+,-,0) */ { if ((strand == '+') || (strand == '-')) return strand; else return '0'; } -void blockHog(char *hogHost, char *hogAddr) -/* Compare host/addr to those of an abusive client that we want to block. */ -{ -char *rhost = getenv("REMOTE_HOST"); -char *raddr = getenv("REMOTE_ADDR"); -if ((rhost != NULL && sameWord(rhost, hogHost)) || - (raddr != NULL && sameWord(raddr, hogAddr))) + +void sendHogMessage(char *hogHost) { dasHead(DAS_OK, TRUE); printf("Your host, %s, has been sending too many requests lately and is " "unfairly loading our site, impacting performance for other users. " "Please contact genome@cse.ucsc.edu to ask that your site " "be reenabled. Also, please consider downloading sequence and/or " "annotations in bulk -- see http://genome.ucsc.edu/downloads.html.", hogHost); exit(0); } + + +void blockHog(char *hogHost, char *hogAddr) +/* Compare host/addr to those of an abusive client that we want to block. */ +{ +char *rhost = getenv("REMOTE_HOST"); +char *raddr = getenv("REMOTE_ADDR"); +if ((rhost != NULL && sameWord(rhost, hogHost)) || + (raddr != NULL && sameWord(raddr, hogAddr))) + { + sendHogMessage(hogHost); + } } static void dasHelp(char *s) /* Put up some hopefully helpful information. */ { dasHead(DAS_OK, TRUE); puts(s); exit(0); } static void dasAbout() /* Print a little info when they just hit cgi-bin/das. */ { dasHead(DAS_OK, TRUE); dasHelp("UCSC DAS Server.\n" @@ -1077,18 +1084,26 @@ int main(int argc, char *argv[]) /* Process command line. */ { char *path = getenv("PATH_INFO"); cgiSpoof(&argc, argv); if (cgiVarExists("verbose")) verboseSetLevel(cgiInt("verbose")); if (argc == 2) path = argv[1]; /* Temporary measure to shut down abusive clients */ #if 0 blockHog("pix39.systemsbiology.net", "198.107.152.39"); #endif + +int delay = hgBotDelayTimeFrac(0.03); +if (delay > 2000) + { + char *hogHost = getenv("REMOTE_ADDR"); + sendHogMessage(hogHost); + } +sleep1000(delay); das(path); return 0; }