The peer top-up loop re-announced to trackers only at the full advertised interval (~30 min), so a torrent that dropped to a handful of peers would sit there for up to half an hour with only the 5-minute DHT refresh to help — looking like the re-announce system was dead. Now, when fewer than LOW_PEER_THRESHOLD (10) peers are connected, the next tracker announce is scheduled at the tracker's min_interval floor (never below 60s) instead of the full interval, so a thin swarm actually tries to recover. Once peers recover the full interval is used again. Capture the tracker's min_interval (was being dropped) to stay announce-compliant. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
54 lines
2.1 KiB
C
54 lines
2.1 KiB
C
/* 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 */
|