diff --git a/include/h.h b/include/h.h index d2b39f22d..0c70ba309 100644 --- a/include/h.h +++ b/include/h.h @@ -93,7 +93,7 @@ extern MODVAR ConfigItem_offchans *conf_offchans; extern void completed_connection(int, int, void *); extern void clear_unknown(); extern EVENT(e_unload_module_delayed); -extern EVENT(e_clean_out_throttling_buckets); +extern EVENT(throttling_check_expire); extern void module_loadall(void); extern long set_usermode(char *umode); @@ -964,3 +964,4 @@ extern char *unreal_add_quotes(char *str); extern int unreal_add_quotes_r(char *i, char *o, size_t len); extern void user_account_login(MessageTag *recv_mtags, Client *client); extern void link_generator(void); +extern void update_throttling_timer_settings(void); diff --git a/src/conf.c b/src/conf.c index 2a5cb6d65..e65ebeef2 100644 --- a/src/conf.c +++ b/src/conf.c @@ -2730,25 +2730,7 @@ int config_run() free_iConf(&iConf); memcpy(&iConf, &tempiConf, sizeof(iConf)); memset(&tempiConf, 0, sizeof(tempiConf)); - - { - EventInfo eInfo; - long v; - eInfo.flags = EMOD_EVERY; - if (!THROTTLING_PERIOD) - v = 120000; - else - { - v = THROTTLING_PERIOD/2; - if (v > 5) - v = 5000; /* accuracy, please */ - if (v < 1) - v = 1000; /* duh */ - } - eInfo.every_msec = v; - EventMod(EventFind("bucketcleaning"), &eInfo); - } - + update_throttling_timer_settings(); /* initialize conf_files with defaults if the block isn't set: */ if(!conf_files) diff --git a/src/hash.c b/src/hash.c index 75d1be236..149e2cb79 100644 --- a/src/hash.c +++ b/src/hash.c @@ -886,22 +886,35 @@ int hash_del_watch_list(Client *client) struct MODVAR ThrottlingBucket *ThrottlingHash[THROTTLING_HASH_TABLE_SIZE]; -void init_throttling() +void update_throttling_timer_settings(void) { long v; + EventInfo eInfo; if (!THROTTLING_PERIOD) { - v = 120; + v = 120*1000; } else { - v = THROTTLING_PERIOD/2; - if (v > 5) + v = (THROTTLING_PERIOD*1000)/2; + if (v > 5000) v = 5000; /* run at least every 5s */ - if (v < 1) + if (v < 1000) v = 1000; /* run at max once every 1s */ } - EventAdd(NULL, "bucketcleaning", e_clean_out_throttling_buckets, NULL, v, 0); + + memset(&eInfo, 0, sizeof(eInfo)); + eInfo.flags = EMOD_EVERY; + eInfo.every_msec = v; + EventMod(EventFind("throttling_check_expire"), &eInfo); +} + +void init_throttling() +{ + EventAdd(NULL, "throttling_check_expire", throttling_check_expire, NULL, 123456, 0); + /* Note: the every_ms value (123,456) will be adjusted on boot and rehash + * via the update_throttling_timer_settings() function. + */ } uint64_t hash_throttling(char *ip) @@ -924,7 +937,7 @@ struct ThrottlingBucket *find_throttling_bucket(Client *client) return NULL; } -EVENT(e_clean_out_throttling_buckets) +EVENT(throttling_check_expire) { struct ThrottlingBucket *n, *n_next; int i;