From 2df09905f5540fee096d48a92cb0c42558498a12 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Fri, 2 Jan 2009 08:57:53 +0000 Subject: * opentracker now drops permissions in correct order and really chroots() if ran as root * lock passing between add_peer_to_torrent and return_peers_for_torrent is now avoided by providing a more general add_peer_to_torrent_and_return_peers function that can be used with NULL parameters to not return any peers (in sync case) * in order to keep a fast overview how many torrents opentracker maintains, every mutex_bucket_unlock operation expects an additional integer parameter that tells ot_mutex.c how many torrents have been added or removed. A function mutex_get_torrent_count has been introduced. --- ot_http.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'ot_http.c') diff --git a/ot_http.c b/ot_http.c index d66fc80..4111d6b 100644 --- a/ot_http.c +++ b/ot_http.c @@ -385,7 +385,6 @@ static ssize_t http_handle_announce( const int64 client_socket, char *data ) { char *c = data; int numwant, tmp, scanon; ot_peer peer; - ot_torrent *torrent; ot_hash *hash = NULL; unsigned short port = htons(6881); ssize_t len; @@ -403,6 +402,10 @@ static ssize_t http_handle_announce( const int64 client_socket, char *data ) { numwant = 50; scanon = 1; +#ifdef _DEBUG_PEERID + g_this_peerid_data = NULL; +#endif + while( scanon ) { switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) { case -2: scanon = 0; break; /* TERMINATOR */ @@ -483,10 +486,11 @@ static ssize_t http_handle_announce( const int64 client_socket, char *data ) { if( OT_PEERFLAG( &peer ) & PEER_FLAG_STOPPED ) len = remove_peer_from_torrent( hash, &peer, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, FLAG_TCP ); - else { - torrent = add_peer_to_torrent( hash, &peer WANT_SYNC_PARAM( 0 ) ); - if( !torrent || !( len = return_peers_for_torrent( torrent, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, FLAG_TCP ) ) ) HTTPERROR_500; - } + else + len = add_peer_to_torrent_and_return_peers(hash, &peer, FLAG_TCP, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf); + + if( !len ) HTTPERROR_500; + stats_issue_event( EVENT_ANNOUNCE, FLAG_TCP, len); return len; } -- cgit v1.2.3