40 lines
1.0 KiB
C
40 lines
1.0 KiB
C
#ifndef SELFCHECK_H
|
|
#define SELFCHECK_H
|
|
|
|
#define SELFCHECK_CHALLENGE_LEN 16
|
|
#define SELFCHECK_RECV_TIMEOUT_S 2
|
|
#define SELFCHECK_FAIL_THRESHOLD 3
|
|
#define SELFCHECK_DRIFT_THRESHOLD 10
|
|
#define SELFCHECK_COOLDOWN_S 60
|
|
|
|
/*
|
|
* Init challenge buffer and start UDP socket listener thread.
|
|
* The socket discards any datagram and always
|
|
* responsds with the challenge bytes.
|
|
*
|
|
* Returns 0 on success.
|
|
* Returns -1 on failure.
|
|
*/
|
|
int selfcheck_start_listener(int port);
|
|
|
|
/*
|
|
* Checks if the random challenge bytes are received
|
|
* when sending an empty datagram to the domain and port.
|
|
*
|
|
* Returns 0 if the response matches.
|
|
* Returns -1 on DNS failure, send failure, or timeout.
|
|
* Returns -2 if the response did not match.
|
|
*/
|
|
int selfcheck_domain(const char *domain, int port);
|
|
|
|
/*
|
|
* Same as selfcheck_domain but sends directly to `ip` without DNS.
|
|
*
|
|
* Returns 0 if the response matches.
|
|
* Returns -1 on send failure or timeout.
|
|
* Returns -2 if the response did not match.
|
|
*/
|
|
int selfcheck_ip_str(const char *ip, int port);
|
|
|
|
#endif /* SELFCHECK_H */
|