mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-06-30 19:06:37 +02:00
Add some temporary safety mechanism if too many HTTP(S) requests in progress.
Will allow tweaking in config later. This is separate from rate-limit btw, which also still needs to be done.
This commit is contained in:
@@ -1392,6 +1392,7 @@ extern void url_start_async(const char *url, HttpMethod http_method, const char
|
||||
extern void url_init(void);
|
||||
extern void url_cancel_handle_by_callback_data(void *ptr);
|
||||
extern EVENT(url_socket_timeout);
|
||||
extern int downloads_in_progress(void);
|
||||
/* end of url stuff */
|
||||
extern char *collapse(char *pattern);
|
||||
extern void clear_scache_hash_table(void);
|
||||
|
||||
@@ -320,6 +320,17 @@ int _spamreport(Client *client, const char *ip, NameValuePrioList *details, cons
|
||||
char *url = NULL;
|
||||
char *body = NULL;
|
||||
NameValuePrioList *headers = NULL;
|
||||
int num;
|
||||
|
||||
num = downloads_in_progress();
|
||||
if (num > 100)
|
||||
{
|
||||
// TODO: throttle this error
|
||||
unreal_log(ULOG_WARNING, "spamreport", "SPAMREPORT_TOO_MANY_CONCURRENT_REQUESTS", NULL,
|
||||
"Already $num_requests HTTP(S) requests in progress, new spamreport requests ignored.",
|
||||
log_data_integer("num_requests", num));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!spamreport_block)
|
||||
{
|
||||
|
||||
@@ -453,3 +453,16 @@ char *urlencode(const char *s, char *wbuf, int wlen)
|
||||
strlcpy(wbuf, ret, wlen);
|
||||
return wbuf;
|
||||
}
|
||||
|
||||
int downloads_in_progress(void)
|
||||
{
|
||||
Download *d;
|
||||
int count = 0;
|
||||
|
||||
/* Bit stupid to do it this slow way, can't we maintain a counter? Needs to be accurate though */
|
||||
|
||||
for (d = downloads; d; d = d->next);
|
||||
count++;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -1226,3 +1226,16 @@ char *urlencode(const char *s, char *wbuf, int wlen)
|
||||
|
||||
return wbuf;
|
||||
}
|
||||
|
||||
int downloads_in_progress(void)
|
||||
{
|
||||
Download *d;
|
||||
int count = 0;
|
||||
|
||||
/* Bit stupid to do it this slow way, can't we maintain a counter? Needs to be accurate though */
|
||||
|
||||
for (d = downloads; d; d = d->next);
|
||||
count++;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user