From 48f67314b6922ffc66c3f089363bd48b72adf755 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Thu, 15 Oct 2009 19:52:17 +0000 Subject: Should not report sync scrape packets in stderr --- proxy.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'proxy.c') diff --git a/proxy.c b/proxy.c index 4977b5c..d5cbab6 100644 --- a/proxy.c +++ b/proxy.c @@ -59,7 +59,7 @@ int g_self_pipe[2]; /* So after each bucket wait 1 / OT_BUCKET_COUNT intervals */ #define OT_SYNC_SLEEP ( ( ( OT_SYNC_INTERVAL_MINUTES ) * 60 * 1000000 ) / ( OT_BUCKET_COUNT ) ) -enum { OT_SYNC_PEER }; +enum { OT_SYNC_PEER = 0xbeef }; enum { FLAG_SERVERSOCKET = 1 }; /* For incoming packets */ @@ -195,8 +195,8 @@ void free_peerlist( ot_peerlist *peer_list ) { static void livesync_handle_peersync( ssize_t datalen ) { int off = sizeof( g_tracker_id ) + sizeof( uint32_t ); - /* Now basic sanity checks have been done on the live sync packet - We might add more testing and logging. */ + fprintf( stderr, "." ); + while( off + (ssize_t)sizeof( ot_hash ) + (ssize_t)sizeof( ot_peer ) <= datalen ) { ot_peer *peer = (ot_peer*)(g_inbuffer + off + sizeof(ot_hash)); ot_hash *hash = (ot_hash*)(g_inbuffer + off); @@ -227,6 +227,7 @@ enum { }; #define PROXYPEER_NEEDSCONNECT(flag) ((flag)==FLAG_OUTGOING) +#define PROXYPEER_ISCONNECTED(flag) (((flag)&FLAG_MASK)==FLAG_CONNECTED) #define PROXYPEER_SETDISCONNECTED(flag) (flag)=(((flag)&FLAG_OUTGOING)|FLAG_DISCONNECTED) #define PROXYPEER_SETCONNECTING(flag) (flag)=(((flag)&FLAG_OUTGOING)|FLAG_CONNECTING) #define PROXYPEER_SETWAITTRACKERID(flag) (flag)=(((flag)&FLAG_OUTGOING)|FLAG_WAITTRACKERID) @@ -439,16 +440,13 @@ static void handle_write( int64 peersocket ) { case FLAG_CONNECTED: switch( iob_send( peersocket, &peer->outdata ) ) { case 0: /* all data sent */ - fprintf( stderr, "EMPTY\n" ); io_dontwantwrite( peersocket ); break; case -3: /* an error occured */ - fprintf( stderr, "ERROR\n" ); io_close( peersocket ); reset_info_block( peer ); break; default: /* Normal operation or eagain */ - fprintf( stderr, "EGAIN\n" ); break; } break; @@ -594,7 +592,9 @@ static void * streamsync_worker( void * args ) { ot_vector *torrents_list = mutex_bucket_lock( bucket ); size_t tor_offset, count_def = 0, count_one = 0, count_two = 0, count_peers = 0; size_t mem, mem_a = 0, mem_b = 0; - uint8_t *ptr, *ptr_a, *ptr_b, *ptr_c; + uint8_t *ptr = 0, *ptr_a, *ptr_b, *ptr_c; + + if( !torrents_list->size ) goto unlock_continue; /* For each torrent in this bucket.. */ for( tor_offset=0; tor_offsetsize; ++tor_offset ) { @@ -614,6 +614,8 @@ static void * streamsync_worker( void * args ) { mem = 3 * ( 4 + 1 + 1 + 2 ) + ( count_one + count_two ) * 19 + count_def * 20 + ( count_one + 2 * count_two + count_peers ) * 7; + fprintf( stderr, "Mem: %d\n", mem ); + ptr = ptr_a = ptr_b = ptr_c = malloc( mem ); if( !ptr ) goto unlock_continue; @@ -697,11 +699,14 @@ unlock_continue: mem = ptr_c - ptr; for( i=0; i