088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen#ifndef LOGIN_PROXY_STATE_H
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen#define LOGIN_PROXY_STATE_H
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen
08c183d97d19cf00b517d37614b3ad57b3c11fcfTimo Sirainen#include <sys/time.h>
08c183d97d19cf00b517d37614b3ad57b3c11fcfTimo Sirainen
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainenstruct login_proxy_record {
7dc4bf28c0c4c673a198070edd1ed54e14ae39aeTimo Sirainen struct ip_addr ip;
009217abb57a24a4076092e8e4e165545747839eStephan Bosch in_port_t port;
7dc4bf28c0c4c673a198070edd1ed54e14ae39aeTimo Sirainen
c9d685897f9e7f0d5e27c00d4b03281d6049ccd1Timo Sirainen /* These are used to spread client-visible disconnects over longer
c9d685897f9e7f0d5e27c00d4b03281d6049ccd1Timo Sirainen periods of time to avoid reconnect spikes when a server dies.
c9d685897f9e7f0d5e27c00d4b03281d6049ccd1Timo Sirainen
c9d685897f9e7f0d5e27c00d4b03281d6049ccd1Timo Sirainen If num_disconnects_since_ts=0 when server disconnects us, it's
c9d685897f9e7f0d5e27c00d4b03281d6049ccd1Timo Sirainen increased and disconnect_timestamp is updated. Afterwards it's
c9d685897f9e7f0d5e27c00d4b03281d6049ccd1Timo Sirainen increased for each new disconnection. num_disconnects_since_ts gets
c9d685897f9e7f0d5e27c00d4b03281d6049ccd1Timo Sirainen reset back to zero whenever a) last_success gets updated or b)
c9d685897f9e7f0d5e27c00d4b03281d6049ccd1Timo Sirainen num_delayed_client_disconnects drops to 0. */
c9d685897f9e7f0d5e27c00d4b03281d6049ccd1Timo Sirainen struct timeval disconnect_timestamp;
c9d685897f9e7f0d5e27c00d4b03281d6049ccd1Timo Sirainen unsigned int num_disconnects_since_ts;
c9d685897f9e7f0d5e27c00d4b03281d6049ccd1Timo Sirainen unsigned int num_delayed_client_disconnects;
c9d685897f9e7f0d5e27c00d4b03281d6049ccd1Timo Sirainen
6a438f1cb934e221fc3af4e172d609d19c7aab30Timo Sirainen /* these are tracking connect()s, not necessarily logins: */
6a438f1cb934e221fc3af4e172d609d19c7aab30Timo Sirainen unsigned int num_waiting_connections;
c9d685897f9e7f0d5e27c00d4b03281d6049ccd1Timo Sirainen /* number of connections we're proxying now (post-login) */
c9d685897f9e7f0d5e27c00d4b03281d6049ccd1Timo Sirainen unsigned int num_proxying_connections;
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen struct timeval last_failure;
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen struct timeval last_success;
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen};
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainenstruct login_proxy_state *login_proxy_state_init(const char *notify_path);
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainenvoid login_proxy_state_deinit(struct login_proxy_state **state);
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainenstruct login_proxy_record *
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainenlogin_proxy_state_get(struct login_proxy_state *state,
009217abb57a24a4076092e8e4e165545747839eStephan Bosch const struct ip_addr *ip, in_port_t port);
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainenvoid login_proxy_state_notify(struct login_proxy_state *state,
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainen const char *user);
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainen
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen#endif