mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 20:35:36 +00:00
clamp down on the flood of debug messages.
This commit is contained in:
@@ -138,17 +138,19 @@ enum
|
||||
static void
|
||||
myDebug( const char * file, int line, const tr_handshake * handshake, const char * fmt, ... )
|
||||
{
|
||||
va_list args;
|
||||
const char * addr = tr_peerIoGetAddrStr( handshake->io );
|
||||
struct evbuffer * buf = evbuffer_new( );
|
||||
evbuffer_add_printf( buf, "[%s:%d] %s (%p) ", file, line, addr, handshake );
|
||||
va_start( args, fmt );
|
||||
evbuffer_add_vprintf( buf, fmt, args );
|
||||
va_end( args );
|
||||
|
||||
fprintf( stderr, "%s\n", EVBUFFER_DATA(buf) );
|
||||
|
||||
evbuffer_free( buf );
|
||||
FILE * fp = tr_getLog( );
|
||||
if( fp != NULL )
|
||||
{
|
||||
va_list args;
|
||||
const char * addr = tr_peerIoGetAddrStr( handshake->io );
|
||||
struct evbuffer * buf = evbuffer_new( );
|
||||
evbuffer_add_printf( buf, "[%s:%d] %s (%p) ", file, line, addr, handshake );
|
||||
va_start( args, fmt );
|
||||
evbuffer_add_vprintf( buf, fmt, args );
|
||||
va_end( args );
|
||||
fprintf( stderr, "%s\n", EVBUFFER_DATA(buf) );
|
||||
evbuffer_free( buf );
|
||||
}
|
||||
}
|
||||
|
||||
#define dbgmsg(handshake, fmt...) myDebug(__FILE__, __LINE__, handshake, ##fmt )
|
||||
|
||||
@@ -182,7 +182,6 @@ disconnectPeer( tr_peer * peer )
|
||||
|
||||
if( peer->msgs != NULL )
|
||||
{
|
||||
fprintf( stderr, "PUB unsub peer %p from msgs %p\n", peer, peer->msgs );
|
||||
tr_peerMsgsUnsubscribe( peer->msgs, peer->msgsTag );
|
||||
tr_peerMsgsFree( peer->msgs );
|
||||
peer->msgs = NULL;
|
||||
@@ -634,7 +633,6 @@ myHandshakeDoneCB( tr_handshake * handshake,
|
||||
peer->msgs = tr_peerMsgsNew( t->tor, peer );
|
||||
peer->client = peer_id ? tr_clientForId( peer_id ) : NULL;
|
||||
peer->peerSupportsEncryption = peerSupportsEncryption ? 1 : 0;
|
||||
fprintf( stderr, "PUB sub peer %p to msgs %p\n", peer, peer->msgs );
|
||||
peer->msgsTag = tr_peerMsgsSubscribe( peer->msgs, msgsCallbackFunc, t );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,17 +135,19 @@ struct tr_peermsgs
|
||||
static void
|
||||
myDebug( const char * file, int line, const struct tr_peermsgs * msgs, const char * fmt, ... )
|
||||
{
|
||||
va_list args;
|
||||
const char * addr = tr_peerIoGetAddrStr( msgs->io );
|
||||
struct evbuffer * buf = evbuffer_new( );
|
||||
evbuffer_add_printf( buf, "[%s:%d] %s (%p) ", file, line, addr, msgs );
|
||||
va_start( args, fmt );
|
||||
evbuffer_add_vprintf( buf, fmt, args );
|
||||
va_end( args );
|
||||
|
||||
fprintf( stderr, "%s\n", EVBUFFER_DATA(buf) );
|
||||
|
||||
evbuffer_free( buf );
|
||||
FILE * fp = tr_getLog( );
|
||||
if( fp != NULL )
|
||||
{
|
||||
va_list args;
|
||||
const char * addr = tr_peerIoGetAddrStr( msgs->io );
|
||||
struct evbuffer * buf = evbuffer_new( );
|
||||
evbuffer_add_printf( buf, "[%s:%d] %s (%p) ", file, line, addr, msgs );
|
||||
va_start( args, fmt );
|
||||
evbuffer_add_vprintf( buf, fmt, args );
|
||||
va_end( args );
|
||||
fprintf( fp, "%s\n", EVBUFFER_DATA(buf) );
|
||||
evbuffer_free( buf );
|
||||
}
|
||||
}
|
||||
|
||||
#define dbgmsg(handshake, fmt...) myDebug(__FILE__, __LINE__, handshake, ##fmt )
|
||||
@@ -448,7 +450,6 @@ sendLtepHandshake( tr_peermsgs * msgs )
|
||||
tr_bencInitInt( tr_bencDictAdd( &val, "p" ), port );
|
||||
tr_bencInitStr( tr_bencDictAdd( &val, "v" ), v, 0, 1 );
|
||||
buf = tr_bencSaveMalloc( &val, &len );
|
||||
tr_bencPrint( &val );
|
||||
|
||||
msglen = sizeof(tr_msgid) + sizeof(ltep_msgid) + len;
|
||||
tr_peerIoWriteUint32( msgs->io, outbuf, msglen );
|
||||
|
||||
@@ -265,9 +265,6 @@ tr_trackerScrapeSoon( Tracker * t )
|
||||
t->scrapeTimer = tr_timerNew( t->handle, onTrackerScrapeNow, t, 1000 );
|
||||
}
|
||||
|
||||
static int trackerCount = 0;
|
||||
static int torrentCount = 0;
|
||||
|
||||
static Tracker*
|
||||
tr_trackerGet( const tr_torrent * tor )
|
||||
{
|
||||
@@ -288,7 +285,6 @@ tr_trackerGet( const tr_torrent * tor )
|
||||
tr_dbg( "making a new tracker for \"%s\"", info->primaryAddress );
|
||||
|
||||
t = tr_new0( Tracker, 1 );
|
||||
fprintf( stderr, "TRACKER new tracker %p addr %s; counts are trackers %d torrents %d\n", t, info->primaryAddress, ++trackerCount, torrentCount );
|
||||
t->handle = tor->handle;
|
||||
t->primaryAddress = tr_strdup( info->primaryAddress );
|
||||
t->scrapeIntervalMsec = DEFAULT_SCRAPE_INTERVAL_MSEC;
|
||||
@@ -363,7 +359,6 @@ onTorrentFreeNow( void * vtor )
|
||||
tr_ptrArrayRemoveSorted( t->scrapeQueue, tor, torrentCompare );
|
||||
tr_ptrArrayRemoveSorted( t->scraping, tor, torrentCompare );
|
||||
|
||||
fprintf( stderr, "TRACKER freeing torrent %p name %s; counts are trackers %d torrents %d\n", tor, tor->torrent->info.name, trackerCount, --torrentCount );
|
||||
tr_timerFree( &tor->scrapeTimer );
|
||||
tr_timerFree( &tor->reannounceTimer );
|
||||
tr_publisherFree( &tor->publisher );
|
||||
@@ -378,8 +373,6 @@ fprintf( stderr, "TRACKER freeing torrent %p name %s; counts are trackers %d tor
|
||||
int i;
|
||||
tr_ptrArrayRemoveSorted( getTrackerLookupTable( ), t, trackerCompare );
|
||||
|
||||
fprintf( stderr, "TRACKER freeing tracker %p; counts are trackers %d torrents %d\n", t, --trackerCount, torrentCount );
|
||||
|
||||
if( t->connection != NULL )
|
||||
evhttp_connection_free( t->connection );
|
||||
|
||||
@@ -419,7 +412,6 @@ tr_trackerNew( tr_torrent * torrent )
|
||||
|
||||
/* create a new Torrent and queue it for scraping */
|
||||
tor = tr_new0( Torrent, 1 );
|
||||
fprintf( stderr, "TRACKER new torrent %p name %s; counts are trackers %d torrents %d\n", tor, torrent->info.name, trackerCount, ++torrentCount );
|
||||
tor->publisher = tr_publisherNew( );
|
||||
tor->tracker = t;
|
||||
tor->torrent = torrent;
|
||||
|
||||
@@ -234,8 +234,8 @@ tr_getGlobalSpeedLimit( tr_handle * h,
|
||||
: h->download );
|
||||
}
|
||||
|
||||
|
||||
void tr_torrentRates( tr_handle * h, float * dl, float * ul )
|
||||
void
|
||||
tr_torrentRates( tr_handle * h, float * dl, float * ul )
|
||||
{
|
||||
tr_torrent * tor;
|
||||
|
||||
@@ -253,12 +253,14 @@ void tr_torrentRates( tr_handle * h, float * dl, float * ul )
|
||||
tr_sharedUnlock( h->shared );
|
||||
}
|
||||
|
||||
int tr_torrentCount( tr_handle * h )
|
||||
int
|
||||
tr_torrentCount( tr_handle * h )
|
||||
{
|
||||
return h->torrentCount;
|
||||
}
|
||||
|
||||
void tr_torrentIterate( tr_handle * h, tr_callback_t func, void * d )
|
||||
void
|
||||
tr_torrentIterate( tr_handle * h, tr_callback_t func, void * d )
|
||||
{
|
||||
tr_torrent * tor, * next;
|
||||
|
||||
@@ -273,28 +275,21 @@ static void
|
||||
tr_closeImpl( void * vh )
|
||||
{
|
||||
tr_handle * h = vh;
|
||||
fprintf( stderr, "in tr_closeImpl\n" );
|
||||
tr_peerMgrFree( h->peerMgr );
|
||||
fprintf( stderr, "calling mgr free\n" );
|
||||
|
||||
tr_rcClose( h->upload );
|
||||
tr_rcClose( h->download );
|
||||
|
||||
fprintf( stderr, "calling shared close\n" );
|
||||
tr_sharedClose( h->shared );
|
||||
fprintf( stderr, "calling fd close\n" );
|
||||
tr_fdClose();
|
||||
|
||||
fprintf( stderr, "setting h->closed to TRUE\n" );
|
||||
h->isClosed = TRUE;
|
||||
}
|
||||
void
|
||||
tr_close( tr_handle * h )
|
||||
{
|
||||
fprintf( stderr, "torrentCount is %d\n", h->torrentCount );
|
||||
assert( tr_torrentCount( h ) == 0 );
|
||||
|
||||
fprintf( stderr, "here I am in tr_close...\n" );
|
||||
tr_runInEventThread( h, tr_closeImpl, h );
|
||||
while( !h->isClosed )
|
||||
tr_wait( 200 );
|
||||
@@ -307,6 +302,7 @@ fprintf( stderr, "here I am in tr_close...\n" );
|
||||
|
||||
free( h->tag );
|
||||
free( h );
|
||||
fprintf( stderr, "tr_close() completed.\n" );
|
||||
}
|
||||
|
||||
tr_torrent **
|
||||
|
||||
@@ -211,7 +211,6 @@ libeventThreadFunc( void * veh )
|
||||
eh->h->events = eh;
|
||||
|
||||
event_dispatch( );
|
||||
fprintf( stderr, "w00t!!!!!!!!!!!!!!!!!!!\n" );
|
||||
|
||||
tr_lockFree( eh->lock );
|
||||
event_base_free( eh->base );
|
||||
|
||||
@@ -61,7 +61,31 @@ void tr_msgInit( void )
|
||||
messageLock = tr_lockNew( );
|
||||
}
|
||||
|
||||
void tr_setMessageLevel( int level )
|
||||
FILE*
|
||||
tr_getLog( void )
|
||||
{
|
||||
static int initialized = FALSE;
|
||||
static FILE * file= NULL;
|
||||
|
||||
if( !initialized )
|
||||
{
|
||||
const char * str = getenv( "TR_DEBUG_FD" );
|
||||
int fd;
|
||||
if( str && *str )
|
||||
fd = atoi( str );
|
||||
switch( fd ) {
|
||||
case 1: file = stdout; break;
|
||||
case 2: file = stderr; break;
|
||||
default: file = NULL; break;
|
||||
}
|
||||
initialized = TRUE;
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
void
|
||||
tr_setMessageLevel( int level )
|
||||
{
|
||||
tr_msgInit();
|
||||
tr_lockLock( messageLock );
|
||||
@@ -120,11 +144,14 @@ void tr_msg( int level, char * msg, ... )
|
||||
{
|
||||
va_list args1, args2;
|
||||
tr_msg_list * newmsg;
|
||||
int len1, len2;
|
||||
int len1, len2;
|
||||
FILE * fp;
|
||||
|
||||
assert( NULL != messageLock );
|
||||
tr_lockLock( messageLock );
|
||||
|
||||
fp = tr_getLog( );
|
||||
|
||||
if( !messageLevel )
|
||||
{
|
||||
char * env;
|
||||
@@ -148,6 +175,8 @@ void tr_msg( int level, char * msg, ... )
|
||||
tr_vsprintf( &newmsg->message, &len1, &len2, msg,
|
||||
args1, args2 );
|
||||
va_end( args2 );
|
||||
if( fp != NULL )
|
||||
fprintf( fp, "%s\n", newmsg->message );
|
||||
if( NULL == newmsg->message )
|
||||
{
|
||||
free( newmsg );
|
||||
@@ -161,9 +190,11 @@ void tr_msg( int level, char * msg, ... )
|
||||
}
|
||||
else
|
||||
{
|
||||
vfprintf( stderr, msg, args1 );
|
||||
fputc( '\n', stderr );
|
||||
fflush( stderr );
|
||||
if( fp == NULL )
|
||||
fp = stderr;
|
||||
vfprintf( fp, msg, args1 );
|
||||
fputc( '\n', fp );
|
||||
fflush( fp );
|
||||
}
|
||||
va_end( args1 );
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h> /* for size_t */
|
||||
#include <stdio.h> /* FILE* */
|
||||
|
||||
void tr_msgInit( void );
|
||||
|
||||
@@ -35,6 +36,7 @@ void tr_msgInit( void );
|
||||
#define tr_inf( a... ) tr_msg( TR_MSG_INF, ## a )
|
||||
#define tr_dbg( a... ) tr_msg( TR_MSG_DBG, ## a )
|
||||
void tr_msg ( int level, char * msg, ... );
|
||||
FILE* tr_getLog( void );
|
||||
|
||||
int tr_rand ( int );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user