Fix white spaces

Introduce loading tracker states with -l
Alter tracker state to a human readable form
dynamic-accesslists
erdgeist 16 years ago
parent a58bce83ad
commit c7ed890222

@ -394,6 +394,42 @@ int parse_configfile( char * config_filename ) {
return bound;
}
void load_state(const char * const state_filename ) {
FILE * state_filehandle;
char inbuf[512];
ot_hash infohash;
unsigned long long base, downcount;
int consumed;
state_filehandle = fopen( state_filename, "r" );
if( state_filehandle == NULL ) {
fprintf( stderr, "Warning: Can't open config file: %s.", state_filename );
return;
}
/* We do ignore anything that is not of the form "^[:xdigit:]:\d+:\d+" */
while( fgets( inbuf, sizeof(inbuf), state_filehandle ) ) {
int i;
for( i=0; i<(int)sizeof(ot_hash); ++i ) {
int eger = 16 * scan_fromhex( inbuf[ 2*i ] ) + scan_fromhex( inbuf[ 1 + 2*i ] );
if( eger < 0 )
continue;
infohash[i] = eger;
}
if( i != (int)sizeof(ot_hash) ) continue;
i *= 2;
if( inbuf[ i++ ] != ':' || !( consumed = scan_ulonglong( inbuf+i, &base ) ) ) continue;
i += consumed;
if( inbuf[ i++ ] != ':' || !( consumed = scan_ulonglong( inbuf+i, &downcount ) ) ) continue;
add_torrent_from_saved_state( infohash, base, downcount );
}
fclose( state_filehandle );
}
int drop_privileges (const char * const serverdir) {
struct passwd *pws = NULL;
@ -448,7 +484,7 @@ int main( int argc, char **argv ) {
#endif
while( scanon ) {
switch( getopt( argc, argv, ":i:p:A:P:d:r:s:f:v"
switch( getopt( argc, argv, ":i:p:A:P:d:r:s:f:l:v"
#ifdef WANT_ACCESSLIST_BLACK
"b:"
#elif defined( WANT_ACCESSLIST_WHITE )
@ -477,6 +513,7 @@ while( scanon ) {
#endif
case 'd': set_config_option( &g_serverdir, optarg ); break;
case 'r': set_config_option( &g_redirecturl, optarg ); break;
case 'l': load_state( optarg ); break;
case 'A':
if( !scan_ip6( optarg, tmpip )) { usage( argv[0] ); exit( 1 ); }
accesslist_blessip( tmpip, 0xffff ); /* Allow everything for now */

@ -184,10 +184,8 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas
r += sprintf( r, ":%zd:%zd\n", peer_list->seed_count, peer_list->peer_count-peer_list->seed_count );
break;
case TASK_FULLSCRAPE_TRACKERSTATE:
memcpy( r, *hash, sizeof(ot_hash) ); r += sizeof(ot_hash);
uint64_pack_big( r, (uint64_t)peer_list->down_count );
uint64_pack_big( r + 8, (uint64_t)peer_list->base );
r += 16;
to_hex( r, *hash ); r+= 2 * sizeof(ot_hash);
r += sprintf( r, ":%zd:%zd\n", peer_list->base, peer_list->down_count );
break;
}

@ -412,6 +412,9 @@ static ssize_t http_handle_announce( const int64 sock, struct ot_workstruct *ws,
}
}
/* XXX DEBUG */
stats_issue_event( EVENT_ACCEPT, FLAG_TCP, (uintptr_t)ws->reply );
/* Scanned whole query string */
if( !hash )
return ws->reply_size = sprintf( ws->reply, "d14:failure reason80:Your client forgot to send your torrent's info_hash. Please upgrade your client.e" );

@ -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;

@ -147,6 +147,7 @@ size_t add_peer_to_torrent_and_return_peers( ot_hash hash, ot_peer *peer, PROTO
size_t remove_peer_from_torrent( ot_hash hash, ot_peer *peer, 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 );
void add_torrent_from_saved_state( ot_hash hash, ot_time base, size_t down_count );
/* torrent iterator */
void iterate_all_torrents( int (*for_each)( ot_torrent* torrent, uintptr_t data ), uintptr_t data );

Loading…
Cancel
Save