From c7ed890222939ff9d9a3b575eb83f216ccfebe9e Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Tue, 17 Mar 2009 23:57:20 +0000 Subject: Fix white spaces Introduce loading tracker states with -l Alter tracker state to a human readable form --- trackerlogic.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'trackerlogic.c') diff --git a/trackerlogic.c b/trackerlogic.c index 8ebaa46..1bd8ac7 100644 --- a/trackerlogic.c +++ b/trackerlogic.c @@ -41,6 +41,33 @@ void free_peerlist( ot_peerlist *peer_list ) { free( peer_list ); } +void add_torrent_from_saved_state( ot_hash hash, ot_time base, size_t down_count ) { + int exactmatch; + ot_torrent *torrent; + ot_vector *torrents_list = mutex_bucket_lock_by_hash( hash ); + + if( !accesslist_hashisvalid( hash ) ) + return mutex_bucket_unlock_by_hash( hash, 0 ); + + torrent = vector_find_or_insert( torrents_list, (void*)hash, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch ); + if( !torrent || exactmatch ) + return mutex_bucket_unlock_by_hash( hash, 0 ); + + /* Create a new torrent entry, then */ + memcpy( torrent->hash, hash, sizeof(ot_hash) ); + + if( !( torrent->peer_list = malloc( sizeof (ot_peerlist) ) ) ) { + vector_remove_torrent( torrents_list, torrent ); + return mutex_bucket_unlock_by_hash( hash, 0 ); + } + + byte_zero( torrent->peer_list, sizeof( ot_peerlist ) ); + torrent->peer_list->base = base; + torrent->peer_list->down_count = down_count; + + return mutex_bucket_unlock_by_hash( hash, 1 ); +} + size_t add_peer_to_torrent_and_return_peers( ot_hash hash, ot_peer *peer, PROTO_FLAG proto, size_t amount, char * reply ) { int exactmatch, delta_torrentcount = 0; size_t reply_size; @@ -375,7 +402,7 @@ void trackerlogic_init( ) { void trackerlogic_deinit( void ) { int bucket, delta_torrentcount = 0; size_t j; - + /* Free all torrents... */ for(bucket=0; bucket