From 7c633c259ebc4a863c5076462c5792ecb8b9f617 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 15 Apr 2024 00:39:02 +0200 Subject: clang-format --- trackerlogic.h | 153 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 78 insertions(+), 75 deletions(-) (limited to 'trackerlogic.h') diff --git a/trackerlogic.h b/trackerlogic.h index e43fcdb..022184d 100644 --- a/trackerlogic.h +++ b/trackerlogic.h @@ -6,11 +6,11 @@ #ifndef OT_TRACKERLOGIC_H__ #define OT_TRACKERLOGIC_H__ -#include -#include -#include #include #include +#include +#include +#include #if defined(__linux__) && defined(WANT_ARC4RANDOM) #include @@ -22,73 +22,76 @@ typedef uint8_t ot_hash[20]; typedef time_t ot_time; typedef char ot_ip6[16]; -typedef struct { ot_ip6 address; int bits; } - ot_net; +typedef struct { + ot_ip6 address; + int bits; +} ot_net; /* List of peers should fit in a single UDP packet (around 1200 bytes) */ -#define OT_MAX_PEERS_UDP6 66 -#define OT_MAX_PEERS_UDP4 200 +#define OT_MAX_PEERS_UDP6 66 +#define OT_MAX_PEERS_UDP4 200 -#define OT_IP_SIZE6 16 -#define OT_IP_SIZE4 4 -#define OT_PORT_SIZE 2 -#define OT_FLAG_SIZE 1 -#define OT_TIME_SIZE 1 +#define OT_IP_SIZE6 16 +#define OT_IP_SIZE4 4 +#define OT_PORT_SIZE 2 +#define OT_FLAG_SIZE 1 +#define OT_TIME_SIZE 1 /* Some tracker behaviour tunable */ -#define OT_CLIENT_TIMEOUT 30 +#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_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_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)( nrand48(ws->rand48_state) % OT_CLIENT_REQUEST_VARIATION ) ) +#define OT_CLIENT_REQUEST_INTERVAL_RANDOM \ + (OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION / 2 + (int)(nrand48(ws->rand48_state) % OT_CLIENT_REQUEST_VARIATION)) /* If WANT_MODEST_FULLSCRAPES is on, ip addresses may not fullscrape more frequently than this amount in seconds */ -#define OT_MODEST_PEER_TIMEOUT (60*5) +#define OT_MODEST_PEER_TIMEOUT (60 * 5) /* 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 64 +#define OT_ADMINIP_MAX 64 +#define OT_MAX_THREADS 64 /* Number of minutes after announce before peer is removed */ -#define OT_PEER_TIMEOUT 45 +#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_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 + 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 /* The peer currently in the working */ @@ -174,34 +177,34 @@ struct ot_workstruct { #endif #ifdef WANT_SYNC -#define WANT_SYNC_PARAM( param ) , param +#define WANT_SYNC_PARAM(param) , param #else -#define WANT_SYNC_PARAM( param ) +#define WANT_SYNC_PARAM(param) #endif #ifdef WANT_LOG_NETWORKS #error Live logging networks disabled at the moment. #endif -void trackerlogic_init( void ); -void trackerlogic_deinit( void ); -void exerr( char * message ); +void trackerlogic_init(void); +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 */ -size_t add_peer_to_torrent_and_return_peers( PROTO_FLAG proto, struct ot_workstruct *ws, size_t amount ); -size_t remove_peer_from_torrent( PROTO_FLAG proto, struct ot_workstruct *ws ); -size_t return_tcp_scrape_for_torrent( ot_hash const *hash_list, int amount, char *reply ); -size_t return_udp_scrape_for_torrent( ot_hash const hash, char *reply ); -void add_torrent_from_saved_state( ot_hash const hash, ot_time base, size_t down_count ); +size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstruct *ws, size_t amount); +size_t remove_peer_from_torrent(PROTO_FLAG proto, struct ot_workstruct *ws); +size_t return_tcp_scrape_for_torrent(ot_hash const *hash_list, int amount, char *reply); +size_t return_udp_scrape_for_torrent(ot_hash const hash, char *reply); +void add_torrent_from_saved_state(ot_hash const hash, ot_time base, size_t down_count); #ifdef _DEBUG_RANDOMTORRENTS -void trackerlogic_add_random_torrents(size_t amount); +void trackerlogic_add_random_torrents(size_t amount); #endif /* torrent iterator */ -void iterate_all_torrents( int (*for_each)( ot_torrent* torrent, uintptr_t data ), uintptr_t data ); +void iterate_all_torrents(int (*for_each)(ot_torrent *torrent, uintptr_t data), uintptr_t data); /* Helper, before it moves to its own object */ -void free_peerlist( ot_peerlist *peer_list ); +void free_peerlist(ot_peerlist *peer_list); #endif -- cgit v1.2.3