e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen#ifndef AUTH_PENALTY_H
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen#define AUTH_PENALTY_H
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainenstruct auth_request;
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen#define AUTH_PENALTY_INIT_SECS 2
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen#define AUTH_PENALTY_MAX_SECS 15
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen/* timeout specifies how long it takes for penalty to be irrelevant. */
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen#define AUTH_PENALTY_TIMEOUT \
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen (AUTH_PENALTY_INIT_SECS + 4 + 8 + AUTH_PENALTY_MAX_SECS)
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen#define AUTH_PENALTY_MAX_PENALTY 4
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen/* If lookup failed, penalty and last_update are both zero */
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainentypedef void auth_penalty_callback_t(unsigned int penalty,
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen struct auth_request *request);
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainenstruct auth_penalty *auth_penalty_init(const char *path);
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainenvoid auth_penalty_deinit(struct auth_penalty **penalty);
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainenunsigned int auth_penalty_to_secs(unsigned int penalty);
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainenvoid auth_penalty_lookup(struct auth_penalty *penalty,
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen struct auth_request *auth_request,
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen auth_penalty_callback_t *callback);
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainenvoid auth_penalty_update(struct auth_penalty *penalty,
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen struct auth_request *auth_request, unsigned int value);
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainen#endif