Feat: socket thread self check

This commit is contained in:
2026-06-01 20:06:02 +02:00
parent 3570eb02ea
commit f61baf53c8
2 changed files with 179 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
#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 */