From 334c6e4bbb97a4c0656e1b07c3e6a565f68eae2b Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Fri, 28 Nov 2008 22:21:10 +0000 Subject: The BIG refactoring [tm]. Too many changes to count them. If it doesn't suite you, revert to last version. --- trackerlogic.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'trackerlogic.h') diff --git a/trackerlogic.h b/trackerlogic.h index 3d7bcb5..c2d071a 100644 --- a/trackerlogic.h +++ b/trackerlogic.h @@ -22,7 +22,7 @@ typedef time_t ot_time; #define OT_CLIENT_REQUEST_VARIATION (60*6) #define OT_TORRENT_TIMEOUT_HOURS 24 -#define OT_TORRENT_TIMEOUT ((60*60*OT_TORRENT_TIMEOUT_HOURS)/OT_POOLS_TIMEOUT) +#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 ) ) @@ -34,15 +34,12 @@ typedef time_t ot_time; #define OT_ADMINIP_MAX 64 #define OT_MAX_THREADS 16 -/* This list points to 9 pools of peers each grouped in five-minute-intervals - thus achieving a timeout of 2700s or 45 minutes - These pools are sorted by its binary content */ -#define OT_POOLS_COUNT 9 -#define OT_POOLS_TIMEOUT (60*5) +#define OT_PEER_TIMEOUT 45 /* From opentracker.c */ -extern time_t g_now; -#define NOW (g_now/OT_POOLS_TIMEOUT) +extern time_t g_now_seconds; +#define g_now_minutes (g_now_seconds/60) + extern uint32_t g_tracker_id; typedef enum { FLAG_TCP, FLAG_UDP, FLAG_MCA } PROTO_FLAG; @@ -57,6 +54,7 @@ static const uint8_t PEER_FLAG_LEECHING = 0x00; #define OT_SETIP( peer, ip ) memmove((peer),(ip),4); #define OT_SETPORT( peer, port ) memmove(((uint8_t*)peer)+4,(port),2); #define OT_FLAG(peer) (((uint8_t*)(peer))[6]) +#define OT_PEERTIME(peer) (((uint8_t*)(peer))[7]) #define OT_PEER_COMPARE_SIZE ((size_t)6) #define OT_HASH_COMPARE_SIZE (sizeof(ot_hash)) @@ -75,18 +73,18 @@ struct ot_peerlist { size_t seed_count; size_t peer_count; size_t down_count; - size_t seed_counts[ OT_POOLS_COUNT ]; - ot_vector peers[ OT_POOLS_COUNT ]; -#ifdef WANT_SYNC_BATCH - ot_vector changeset; -#endif +/* normal peers vector or + pointer to ot_vector[32] buckets if data != NULL and space == 0 +*/ + ot_vector peers; }; +#define OT_PEERLIST_HASBUCKETS(peer_list) ((peer_list) && ((peer_list)->peers.size > (peer_list)->peers.space)) /* Exported functions */ -#if defined( WANT_SYNC_BATCH ) || defined( WANT_SYNC_LIVE ) +#ifdef WANT_SYNC_LIVE #define WANT_SYNC #endif @@ -100,9 +98,11 @@ int trackerlogic_init( const char * const serverdir ); void trackerlogic_deinit( void ); void exerr( char * message ); -ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_SYNC_PARAM( int from_changeset ) ); +/* 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 return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply, PROTO_FLAG proto ); +ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_SYNC_PARAM( int from_sync ) ); size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, PROTO_FLAG proto ); -size_t return_peers_for_torrent( ot_hash *hash, size_t amount, 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 ); -- cgit v1.2.3