/* tracker.h — HTTP and UDP tracker announce client. * * The wire codec (query building, bencode/UDP packet encode+decode) lives in the * sibling `torrent-tracker` library; the implementation here (src/discovery) * owns only the socket glue. HTTPS/TLS is deferred to a later transport backend; * the built-ins are plaintext HTTP and UDP. */ #ifndef NAUT_TRACKER_H #define NAUT_TRACKER_H #include "naut/common.h" /* IPv4 compact peer (BEP-23). IPv6 (BEP-7) is a later addition. */ typedef struct { uint8_t ip[4]; uint16_t port; } naut_peer_addr; typedef enum { NAUT_TEV_NONE = 0, NAUT_TEV_COMPLETED = 1, NAUT_TEV_STARTED = 2, NAUT_TEV_STOPPED = 3 } naut_tracker_event; /* values match BEP-15 UDP event codes */ typedef struct { uint8_t info_hash[20]; uint8_t peer_id[20]; uint16_t port; uint64_t uploaded, downloaded, left; naut_tracker_event event; int32_t numwant; /* -1 for default */ uint32_t key; } naut_announce_req; typedef struct { int32_t interval; int32_t min_interval; /* tracker's floor, 0 if not advertised */ int32_t seeders, leechers; /* -1 if absent */ naut_peer_addr *peers; size_t num_peers; char *failure; /* tracker "failure reason", or NULL */ } naut_tracker_response; void naut_tracker_response_free(naut_tracker_response *r); /* Build the full announce GET URL (base?...params) with percent-encoded binary * info_hash/peer_id. Returns bytes written (excl NUL) or 0 on overflow. */ size_t naut_tracker_http_url(const char *base, const naut_announce_req *req, char *out, size_t outsz); /* --- live fetch helpers (blocking) --- */ /* HTTP GET the announce URL; fills out. Only http:// (no TLS yet). */ naut_err naut_tracker_announce_http(const char *url, naut_tracker_response *out); /* Full UDP connect+announce handshake against host:port. */ naut_err naut_tracker_announce_udp(const char *host, uint16_t port, const naut_announce_req *req, naut_tracker_response *out); #endif /* NAUT_TRACKER_H */