commit more of tiennou's fastpeers patch

This commit is contained in:
Charles Kerr 2007-10-10 16:39:12 +00:00
parent 76aed9200d
commit cbaf1b8faa
6 changed files with 26 additions and 20 deletions

View File

@ -108,9 +108,9 @@ tr_cryptoNew( const uint8_t * torrentHash,
crypto->dh->g = BN_bin2bn( dh_G, sizeof(dh_G), NULL );
DH_generate_key( crypto->dh );
// DH can generate key sizes that are smaller than the size of
// P with exponentially decreasing probability, in which case
// the msb's of myPublicKey need to be zeroed appropriately.
/* DH can generate key sizes that are smaller than the size of
P with exponentially decreasing probability, in which case
the msb's of myPublicKey need to be zeroed appropriately. */
len = DH_size( crypto->dh );
offset = KEY_LEN - len;
assert( len <= KEY_LEN );

View File

@ -547,18 +547,21 @@ compareRefillPiece (const void * aIn, const void * bIn)
{
const struct tr_refill_piece * a = aIn;
const struct tr_refill_piece * b = bIn;
/* if one *might be* fastallowed to us, get it first...
* I'm putting it on top so we prioritise those pieces at
* startup, then we'll have them, and we'll be denied access
* to them */
if (a->fastAllowed != b->fastAllowed)
return a->fastAllowed < b->fastAllowed ? -1 : 1;
/* if one piece has a higher priority, it goes first */
if (a->priority != b->priority)
return a->priority > b->priority ? -1 : 1;
/* otherwise if one has fewer peers, it goes first */
if (a->peerCount != b->peerCount)
return a->peerCount < b->peerCount ? -1 : 1;
/* otherwise if one *might be* fastallowed to us */
if (a->fastAllowed != b->fastAllowed)
return a->fastAllowed < b->fastAllowed ? -1 : 1;
/* otherwise go with our random seed */
return tr_compareUint16( a->random, b->random );
@ -614,13 +617,15 @@ getPreferredPieces( Torrent * t,
setme->peerCount = 0;
setme->fastAllowed = 0;
setme->random = tr_rand( UINT16_MAX );
/* FIXME */
// setme->fastAllowed = tr_bitfieldHas( t->tor->allowedList, i);
for( k=0; k<peerCount; ++k ) {
const tr_peer * peer = peers[k];
if( peer->peerIsInterested && !peer->clientIsChoked && tr_bitfieldHas( peer->have, piece ) )
++setme->peerCount;
/* The fast peer extension doesn't force a peer to actually HAVE a fast-allowed piece,
but we're guaranteed to get the same pieces from different peers,
so we'll build a list and pray one actually have this one */
setme->fastAllowed = tr_peerMsgIsPieceFastAllowed( peer->msgs, i);
}
}
@ -1611,7 +1616,6 @@ reconnectPulse( void * vtorrent )
/* add some new ones */
nAdd = MAX_CONNECTED_PEERS_PER_TORRENT - peerCount;
for( i=0; i<nAdd && i<nCandidates && i<MAX_RECONNECTIONS_PER_PULSE; ++i )
//for( i=0; i<nCandidates; ++i )
{
tr_peerMgr * mgr = t->manager;

View File

@ -1023,7 +1023,6 @@ readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf )
tr_peerIoReadUint32( msgs->io, inbuf, &msgs->blockToUs.offset );
msgs->blockToUs.length = msglen - 8;
assert( EVBUFFER_LENGTH(msgs->inBlock) == 0 );
//evbuffer_drain( msgs->inBlock, ~0 );
msgs->state = msgs->blockToUs.length ? READING_BT_PIECE : AWAITING_BT_LENGTH;
return READ_AGAIN;
break;
@ -1723,3 +1722,11 @@ tr_peerMsgsUnsubscribe( tr_peermsgs * peer,
{
tr_publisherUnsubscribe( peer->publisher, tag );
}
int
tr_peerMsgIsPieceFastAllowed( const tr_peermsgs * peer,
uint32_t index )
{
return tr_bitfieldHas( peer->clientAllowedPieces, index );
}

View File

@ -87,6 +87,7 @@ tr_publisher_tag tr_peerMsgsSubscribe ( tr_peermsgs * peer,
void tr_peerMsgsUnsubscribe ( tr_peermsgs * peer,
tr_publisher_tag tag );
int tr_peerMsgIsPieceFastAllowed( const tr_peermsgs * peer,
uint32_t index );
#endif

View File

@ -312,8 +312,6 @@ tr_closeImpl( void * vh )
void
tr_close( tr_handle * h )
{
//assert( tr_torrentCount( h ) == 0 );
tr_runInEventThread( h, tr_closeImpl, h );
while( !h->isClosed )
tr_wait( 100 );
@ -356,7 +354,6 @@ tr_loadTorrents ( tr_handle * h,
tor = tr_torrentInit( h, path, destination, flags, NULL );
if( tor != NULL ) {
tr_list_append( &list, tor );
//fprintf (stderr, "#%d - %s\n", n, tor->info.name );
n++;
}
}

View File

@ -204,7 +204,6 @@ libeventThreadFunc( void * veh )
#endif
eh->base = event_init( );
//event_set_log_callback( logFunc );
evdns_init( );
timeout_set( &eh->pulse, pumpList, veh );
timeout_add( &eh->pulse, &eh->pulseInterval );
@ -242,8 +241,6 @@ tr_eventClose( tr_handle * handle )
tr_list_free( &eh->commands, tr_free );
eh->die = TRUE;
tr_lockUnlock( eh->lock );
//event_base_loopexit( eh->base, NULL );
}
/**