1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00

some cleanup... remove some dead/obsolete code

This commit is contained in:
Charles Kerr 2007-10-02 00:05:40 +00:00
parent 1770fa78d6
commit 84ab0092fb
4 changed files with 37 additions and 132 deletions

View file

@ -62,10 +62,16 @@ enum
* with a better idea for managing the connection limits */
MAX_CONNECTED_PEERS_PER_TORRENT = 60,
MAX_RECONNECTIONS_PER_MINUTE = MAX_CONNECTED_PEERS_PER_TORRENT,
MAX_RECONNECTIONS_PER_PULSE = ((MAX_RECONNECTIONS_PER_MINUTE * RECONNECT_PERIOD_MSEC) / (60*1000)),
/* another arbitrary number */
MAX_RECONNECTIONS_PER_MINUTE = 60,
MAX_RECONNECTIONS_PER_PULSE =
((MAX_RECONNECTIONS_PER_MINUTE * RECONNECT_PERIOD_MSEC) / (60*1000)),
/* corresponds to ut_pex's added.f flags */
ADDED_F_ENCRYPTION_FLAG = 1,
/* corresponds to ut_pex's added.f flags */
ADDED_F_SEED_FLAG = 2
};
@ -93,7 +99,6 @@ typedef struct
tr_ptrArray * pool; /* struct peer_atom */
tr_ptrArray * peers; /* tr_peer */
tr_timer * reconnectTimer;
tr_timer * reconnectSoonTimer;
tr_timer * rechokeTimer;
tr_timer * rechokeSoonTimer;
tr_timer * refillTimer;
@ -141,8 +146,7 @@ torrentUnlock( Torrent * torrent )
static int
torrentIsLocked( const Torrent * t )
{
return ( t != NULL )
&& ( tr_globalIsLocked( t->manager->handle ) );
return tr_globalIsLocked( t->manager->handle );
}
/**
@ -359,7 +363,6 @@ freeTorrent( tr_peerMgr * manager, Torrent * t )
memcpy( hash, t->hash, SHA_DIGEST_LENGTH );
tr_timerFree( &t->reconnectTimer );
tr_timerFree( &t->reconnectSoonTimer );
tr_timerFree( &t->rechokeTimer );
tr_timerFree( &t->rechokeSoonTimer );
tr_timerFree( &t->refillTimer );
@ -459,26 +462,6 @@ tr_peerMgrFree( tr_peerMgr * manager )
tr_free( manager );
}
static tr_peer**
getConnectedPeers( Torrent * t, int * setmeCount )
{
int i, peerCount, connectionCount;
tr_peer **peers;
tr_peer **ret;
assert( torrentIsLocked( t ) );
peers = (tr_peer **) tr_ptrArrayPeek( t->peers, &peerCount );
ret = tr_new( tr_peer*, peerCount );
for( i=connectionCount=0; i<peerCount; ++i )
if( peers[i]->msgs != NULL )
ret[connectionCount++] = peers[i];
*setmeCount = connectionCount;
return ret;
}
/***
**** Refill
***/
@ -541,7 +524,7 @@ getPreferredPieces( Torrent * t,
assert( torrentIsLocked( t ) );
peers = getConnectedPeers( t, &peerCount );
peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &peerCount );
for( i=0; i<inf->pieceCount; ++i )
if( isPieceInteresting( tor, i ) )
@ -587,7 +570,6 @@ fprintf (stderr, "new pool: ");
for (i=0; i<15 && i<(int)poolSize; ++i ) fprintf (stderr, "%d, ", (int)pool[i] );
fprintf (stderr, "\n");
#endif
tr_free( peers );
*pieceCount = poolSize;
return pool;
@ -662,7 +644,7 @@ refillPulse( void * vtorrent )
torrentLock( t );
blocks = getPreferredBlocks( t, &blockCount );
peers = getConnectedPeers( t, &peerCount );
peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &peerCount );
/*fprintf( stderr, "REFILL refillPulse for {%s} got %d blocks\n", tor->info.name, (int)blockCount );*/
@ -694,7 +676,6 @@ refillPulse( void * vtorrent )
break;
case TR_ADDREQ_OK:
/*fprintf( stderr, "REFILL peer %p took the request for block %d\n", peers[j]->msgs, block );*/
tr_bitfieldAdd( t->requested, block );
j = peerCount;
break;
@ -707,7 +688,6 @@ refillPulse( void * vtorrent )
}
/* cleanup */
tr_free( peers );
tr_free( blocks );
t->refillTimer = NULL;
@ -724,10 +704,9 @@ broadcastClientHave( Torrent * t, uint32_t index )
assert( torrentIsLocked( t ) );
peers = getConnectedPeers( t, &size );
peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &size );
for( i=0; i<size; ++i )
tr_peerMsgsHave( peers[i]->msgs, index );
tr_free( peers );
}
static void
@ -738,10 +717,9 @@ broadcastGotBlock( Torrent * t, uint32_t index, uint32_t offset, uint32_t length
assert( torrentIsLocked( t ) );
peers = getConnectedPeers( t, &size );
peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &size );
for( i=0; i<size; ++i )
tr_peerMsgsCancel( peers[i]->msgs, index, offset, length );
tr_free( peers );
}
/**
@ -758,30 +736,6 @@ restartReconnectTimer( Torrent * t )
t->reconnectTimer = tr_timerNew( t->manager->handle, reconnectPulse, t, RECONNECT_PERIOD_MSEC );
}
static void
reconnectNow( Torrent * t )
{
reconnectPulse( t );
restartReconnectTimer( t );
}
static int
reconnectSoonCB( void * vt )
{
Torrent * t = vt;
reconnectNow( t );
t->reconnectSoonTimer = NULL;
return FALSE;
}
static void
reconnectSoon( Torrent * t )
{
if( t->reconnectSoonTimer == NULL )
t->reconnectSoonTimer = tr_timerNew( t->manager->handle,
reconnectSoonCB, t, SOON_MSEC );
}
/**
***
**/
@ -859,7 +813,6 @@ msgsCallbackFunc( void * vpeer, void * vevent, void * vt )
case TR_PEERMSG_GOT_ERROR:
peer->doPurge = 1;
reconnectSoon( t );
break;
default:
@ -1011,7 +964,6 @@ tr_peerMgrAddPex( tr_peerMgr * manager,
t = getExistingTorrent( manager, torrentHash );
for( end=pex+pexCount; pex!=end; ++pex )
ensureAtomExists( t, &pex->in_addr, pex->port, pex->flags, from );
reconnectSoon( t );
managerUnlock( manager );
}
@ -1038,7 +990,6 @@ tr_peerMgrAddPeers( tr_peerMgr * manager,
memcpy( &port, walk, 2 ); walk += 2;
ensureAtomExists( t, &addr, port, 0, from );
}
reconnectSoon( t );
managerUnlock( manager );
}
@ -1047,12 +998,6 @@ tr_peerMgrAddPeers( tr_peerMgr * manager,
***
**/
int
tr_peerMgrIsAcceptingConnections( const tr_peerMgr * manager UNUSED )
{
return TRUE; /* manager->connectionCount < MAX_CONNECTED_PEERS; */
}
void
tr_peerMgrSetBlame( tr_peerMgr * manager UNUSED,
const uint8_t * torrentHash UNUSED,
@ -1065,17 +1010,11 @@ tr_peerMgrSetBlame( tr_peerMgr * manager UNUSED,
int
tr_pexCompare( const void * va, const void * vb )
{
const tr_pex * a = (const tr_pex *) va;
const tr_pex * b = (const tr_pex *) vb;
int i = memcmp( &a->in_addr, &b->in_addr, sizeof(struct in_addr) );
if( i ) return i;
if( a->port < b->port ) return -1;
if( a->port > b->port ) return 1;
return 0;
const tr_pex * a = va;
const tr_pex * b = vb;
return memcmp( &a->in_addr, &b->in_addr, sizeof(struct in_addr) );
}
int tr_pexCompare( const void * a, const void * b );
static int
peerPrefersCrypto( const tr_peer * peer )
{
@ -1137,7 +1076,7 @@ tr_peerMgrStartTorrent( tr_peerMgr * manager,
t = getExistingTorrent( manager, torrentHash );
t->isRunning = 1;
restartChokeTimer( t );
reconnectSoon( t );
restartReconnectTimer( t );
managerUnlock( manager );
}
@ -1145,20 +1084,12 @@ tr_peerMgrStartTorrent( tr_peerMgr * manager,
static void
stopTorrent( Torrent * t )
{
int i, size;
tr_peer ** peers;
assert( torrentIsLocked( t ) );
t->isRunning = 0;
tr_timerFree( &t->rechokeTimer );
tr_timerFree( &t->reconnectTimer );
peers = getConnectedPeers( t, &size );
for( i=0; i<size; ++i )
disconnectPeer( peers[i] );
tr_free( peers );
removeAllPeers( t );
}
void
tr_peerMgrStopTorrent( tr_peerMgr * manager,
@ -1382,8 +1313,8 @@ ChokeData;
static int
compareChoke( const void * va, const void * vb )
{
const ChokeData * a = ( const ChokeData * ) va;
const ChokeData * b = ( const ChokeData * ) vb;
const ChokeData * a = va;
const ChokeData * b = vb;
if( a->preferred != b->preferred )
return a->preferred ? -1 : 1;
@ -1417,7 +1348,7 @@ rechokeLeech( Torrent * t )
{
int i, peerCount, size=0, unchoked=0;
const time_t ignorePeersNewerThan = time(NULL) - MIN_CHOKE_PERIOD_SEC;
tr_peer ** peers = getConnectedPeers( t, &peerCount );
tr_peer ** peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &peerCount );
ChokeData * choke = tr_new0( ChokeData, peerCount );
assert( torrentIsLocked( t ) );
@ -1457,7 +1388,6 @@ rechokeLeech( Torrent * t )
/* cleanup */
tr_free( choke );
tr_free( peers );
}
static void
@ -1468,13 +1398,9 @@ rechokeSeed( Torrent * t )
assert( torrentIsLocked( t ) );
peers = getConnectedPeers( t, &size );
/* FIXME */
peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &size );
for( i=0; i<size; ++i )
tr_peerMsgsSetChoke( peers[i]->msgs, FALSE );
tr_free( peers );
}
static int
@ -1541,7 +1467,7 @@ getWeakConnections( Torrent * t, int * setmeSize )
if( peer->doPurge )
isWeak = TRUE;
if( peerIsSeed && clientIsSeed && (now-atom->time >= 30) ) /* pex time */
if( peerIsSeed && clientIsSeed && (now-atom->time >= 20) ) /* pex time */
isWeak = TRUE;
else if( ( now - atom->time ) < LAISSEZ_FAIRE_PERIOD_SECS )
isWeak = FALSE;

View file

@ -36,8 +36,6 @@ tr_peerMgr* tr_peerMgrNew( struct tr_handle * );
void tr_peerMgrFree( tr_peerMgr * manager );
int tr_peerMgrIsAcceptingConnections( const tr_peerMgr * manager );
void tr_peerMgrAddIncoming( tr_peerMgr * manager,
struct in_addr * addr,
uint16_t port,

View file

@ -108,7 +108,6 @@ struct tr_peermsgs
tr_publisher_t * publisher;
struct evbuffer * outMessages; /* buffer of all the non-piece messages */
struct evbuffer * outBlock; /* the block we're currently sending */
struct evbuffer * inBlock; /* the block we're currently receiving */
tr_list * peerAskedFor;
tr_list * clientAskedFor;
@ -1233,22 +1232,6 @@ pulse( void * vmsgs )
if( !canWrite( msgs ) )
{
}
#if 0
else if(( len = EVBUFFER_LENGTH( msgs->outBlock ) ))
{
while ( len && canUpload( msgs ) )
{
const size_t outlen = len; //MIN( len, 2048 );
tr_peerIoWrite( msgs->io, EVBUFFER_DATA(msgs->outBlock), outlen );
evbuffer_drain( msgs->outBlock, outlen );
peerGotBytes( msgs, outlen );
len -= outlen;
msgs->info->clientSentPieceDataAt = now;
msgs->clientSentAnythingAt = now;
dbgmsg( msgs, "wrote %d bytes; %d left in block", (int)outlen, (int)len );
}
}
#endif
else if(( len = EVBUFFER_LENGTH( msgs->outMessages ) ))
{
tr_peerIoWriteBuf( msgs->io, msgs->outMessages );
@ -1258,25 +1241,25 @@ pulse( void * vmsgs )
{
if( canUpload( msgs ) )
{
struct peer_request * req = tr_list_pop_front( &msgs->peerAskedFor );
uint8_t * tmp = tr_new( uint8_t, req->length );
const uint32_t msglen = sizeof(uint8_t) + 2*sizeof(uint32_t) + req->length;
struct peer_request * r = tr_list_pop_front( &msgs->peerAskedFor );
uint8_t * tmp = tr_new( uint8_t, r->length );
const uint32_t msglen = sizeof(uint8_t) + 2*sizeof(uint32_t) + r->length;
struct evbuffer * out = evbuffer_new( );
assert( requestIsValid( msgs, req ) );
assert( requestIsValid( msgs, r ) );
tr_peerIoWriteUint32( msgs->io, out, msglen );
tr_peerIoWriteUint8 ( msgs->io, out, BT_PIECE );
tr_peerIoWriteUint32( msgs->io, out, req->index );
tr_peerIoWriteUint32( msgs->io, out, req->offset );
tr_peerIoWriteUint32( msgs->io, out, r->index );
tr_peerIoWriteUint32( msgs->io, out, r->offset );
tr_peerIoWriteBuf( msgs->io, out );
tr_ioRead( msgs->torrent, req->index, req->offset, req->length, tmp );
tr_peerIoWrite( msgs->io, tmp, req->length );
peerGotBytes( msgs, req->length );
tr_ioRead( msgs->torrent, r->index, r->offset, r->length, tmp );
tr_peerIoWrite( msgs->io, tmp, r->length );
peerGotBytes( msgs, r->length );
dbgmsg( msgs, "putting req into out queue: index %d, offset %d, length %d ... %d blocks left in our queue", (int)req->index, (int)req->offset, (int)req->length, tr_list_size(msgs->peerAskedFor) );
dbgmsg( msgs, "putting req into out queue: index %d, offset %d, length %d ... %d blocks left in our queue", (int)r->index, (int)r->offset, (int)r->length, tr_list_size(msgs->peerAskedFor) );
tr_free( req );
tr_free( r );
tr_free( tmp );
evbuffer_free( out );
}
@ -1290,9 +1273,9 @@ pulse( void * vmsgs )
}
static void
didWrite( struct bufferevent * evin UNUSED, void * vpeer )
didWrite( struct bufferevent * evin UNUSED, void * vmsgs )
{
pulse( (tr_peermsgs *) vpeer );
pulse( vmsgs );
}
static void
@ -1487,7 +1470,6 @@ tr_peerMsgsNew( struct tr_torrent * torrent, struct tr_peer * info )
msgs->pulseTimer = tr_timerNew( msgs->handle, pulse, msgs, PEER_PULSE_INTERVAL );
msgs->pexTimer = tr_timerNew( msgs->handle, pexPulse, msgs, PEX_INTERVAL );
msgs->outMessages = evbuffer_new( );
msgs->outBlock = evbuffer_new( );
msgs->inBlock = evbuffer_new( );
msgs->peerAllowedPieces = NULL;
msgs->clientAllowedPieces = NULL;
@ -1560,7 +1542,6 @@ tr_peerMsgsFree( tr_peermsgs* msgs )
tr_list_free( &msgs->clientAskedFor, tr_free );
tr_list_free( &msgs->peerAskedFor, tr_free );
evbuffer_free( msgs->outMessages );
evbuffer_free( msgs->outBlock );
evbuffer_free( msgs->inBlock );
tr_free( msgs->pex );
msgs->pexCount = 0;

View file

@ -267,7 +267,7 @@ AcceptPeers( tr_shared * s )
uint16_t port;
struct in_addr addr;
if( s->bindSocket < 0 || !tr_peerMgrIsAcceptingConnections( s->h->peerMgr ) )
if( s->bindSocket < 0 )
break;
socket = tr_netAccept( s->bindSocket, &addr, &port );