/* This software was written by Dirk Engling It is considered beerware. Prost. Skol. Cheers or whatever. $id$ */ #ifndef __OT_TRACKERLOGIC_H__ #define __OT_TRACKERLOGIC_H__ #include #include #include #include typedef uint8_t ot_hash[20]; typedef time_t ot_time; typedef char ot_ip6[16]; #ifdef WANT_V6 #define OT_IP_SIZE 16 #define PEERS6 "6" #else #define OT_IP_SIZE 4 #define PEERS6 "" #endif /* Some tracker behaviour tunable */ #define OT_CLIENT_TIMEOUT 30 #define OT_CLIENT_TIMEOUT_CHECKINTERVAL 10 #define OT_CLIENT_TIMEOUT_SEND (60*15) #define OT_CLIENT_REQUEST_INTERVAL (60*30) #define OT_CLIENT_REQUEST_VARIATION (60*6) #define OT_TORRENT_TIMEOUT_HOURS 24 #define OT_TORRENT_TIMEOUT (60*OT_TORRENT_TIMEOUT_HOURS) #define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( random( ) % OT_CLIENT_REQUEST_VARIATION ) ) /* If peers come back before 10 minutes, don't live sync them */ #define OT_CLIENT_SYNC_RENEW_BOUNDARY 10 /* Number of tracker admin ip addresses allowed */ #define OT_ADMINIP_MAX 64 #define OT_MAX_THREADS 16 #define OT_PEER_TIMEOUT 45 /* We maintain a list of 1024 pointers to sorted list of ot_torrent structs Sort key is, of course, its hash */ #define OT_BUCKET_COUNT_BITS 10 #define OT_BUCKET_COUNT (1<peers.size > (peer_list)->peers.space)) struct ot_workstruct { /* Thread specific, static */ char *inbuf; #define G_INBUF_SIZE 8192 char *outbuf; #define G_OUTBUF_SIZE 8192 #ifdef _DEBUG_HTTPERROR char *debugbuf; #define G_DEBUGBUF_SIZE 8192 #endif /* HTTP specific, non static */ char *request; ssize_t request_size; char *reply; ssize_t reply_size; }; /* Exported functions */ #ifdef WANT_SYNC_LIVE #define WANT_SYNC #endif #ifdef WANT_SYNC #define WANT_SYNC_PARAM( param ) , param #else #define WANT_SYNC_PARAM( param ) #endif #if defined WANT_V6 && defined WANT_LOG_NETWORKS #undef WANT_LOG_NETWORKS #endif void trackerlogic_init( ); void trackerlogic_deinit( void ); void exerr( char * message ); /* add_peer_to_torrent does only release the torrent bucket if from_sync is set, otherwise it is released in return_peers_for_torrent */ #define add_peer_to_torrent(hash,peer,proto) add_peer_to_torrent_and_return_peers(hash,peer,proto,0,NULL) size_t add_peer_to_torrent_and_return_peers( ot_hash hash, ot_peer *peer, PROTO_FLAG proto, size_t amount, char * reply ); size_t remove_peer_from_torrent( ot_hash hash, ot_peer *peer, char *reply, PROTO_FLAG proto ); size_t return_tcp_scrape_for_torrent( ot_hash *hash, int amount, char *reply ); size_t return_udp_scrape_for_torrent( ot_hash hash, char *reply ); /* Helper, before it moves to its own object */ void free_peerlist( ot_peerlist *peer_list ); #endif