From c0b00c0bf5b9414f93c76bb6daef9c01e2b49628 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Sun, 22 Jul 2007 00:40:10 +0000 Subject: * fixed "nobody " -> "nobody" fuckup when getpwnam-ing * implemented basic blacklisting: ** the file specified with -b is read and added to a blacklist vector ** if an announce hits a torrent in that blacklist vector, add_peer_to_torrent fails ** sending a SIGHUP to the program forces it to reread the blacklists ** the server returns with a 500, which is not exactly nice but does the job for now ** an adaequat "failure reason:" should be delivered... TODO --- trackerlogic.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'trackerlogic.c') diff --git a/trackerlogic.c b/trackerlogic.c index ebfb1f8..98fcef9 100644 --- a/trackerlogic.c +++ b/trackerlogic.c @@ -22,6 +22,10 @@ /* GLOBAL VARIABLES */ static ot_vector all_torrents[256]; static ot_vector changeset; +#ifdef WANT_BLACKLISTING +static ot_vector blacklist; +#endif + size_t changeset_size = 0; time_t last_clean_time = 0; @@ -155,6 +159,12 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer, int from_changese ot_vector *torrents_list = &all_torrents[*hash[0]], *peer_pool; int base_pool = 0; +#ifdef WANT_BLACKLISTING + binary_search( hash, blacklist.data, blacklist.size, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &exactmatch ); + if( exactmatch ) + return NULL; +#endif + torrent = vector_find_or_insert( torrents_list, (void*)hash, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch ); if( !torrent ) return NULL; @@ -672,3 +682,22 @@ void deinit_logic( void ) { byte_zero( &changeset, sizeof( changeset ) ); changeset_size = 0; } + +#ifdef WANT_BLACKLISTING +void blacklist_reset( void ) { + free( blacklist.data ); + byte_zero( &blacklist, sizeof( blacklist ) ); +} + +int blacklist_addentry( ot_hash *infohash ) { + int em; + void *insert = vector_find_or_insert( &blacklist, infohash, OT_HASH_COMPARE_SIZE, OT_HASH_COMPARE_SIZE, &em ); + + if( !insert ) + return -1; + + memmove( insert, infohash, OT_HASH_COMPARE_SIZE ); + + return 0; +} +#endif -- cgit v1.2.3