commit more of tiennou's fastpeers patch
This commit is contained in:
parent
76aed9200d
commit
cbaf1b8faa
|
@ -108,9 +108,9 @@ tr_cryptoNew( const uint8_t * torrentHash,
|
||||||
crypto->dh->g = BN_bin2bn( dh_G, sizeof(dh_G), NULL );
|
crypto->dh->g = BN_bin2bn( dh_G, sizeof(dh_G), NULL );
|
||||||
DH_generate_key( crypto->dh );
|
DH_generate_key( crypto->dh );
|
||||||
|
|
||||||
// DH can generate key sizes that are smaller than the size of
|
/* DH can generate key sizes that are smaller than the size of
|
||||||
// P with exponentially decreasing probability, in which case
|
P with exponentially decreasing probability, in which case
|
||||||
// the msb's of myPublicKey need to be zeroed appropriately.
|
the msb's of myPublicKey need to be zeroed appropriately. */
|
||||||
len = DH_size( crypto->dh );
|
len = DH_size( crypto->dh );
|
||||||
offset = KEY_LEN - len;
|
offset = KEY_LEN - len;
|
||||||
assert( len <= KEY_LEN );
|
assert( len <= KEY_LEN );
|
||||||
|
|
|
@ -547,18 +547,21 @@ compareRefillPiece (const void * aIn, const void * bIn)
|
||||||
{
|
{
|
||||||
const struct tr_refill_piece * a = aIn;
|
const struct tr_refill_piece * a = aIn;
|
||||||
const struct tr_refill_piece * b = bIn;
|
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 one piece has a higher priority, it goes first */
|
||||||
if (a->priority != b->priority)
|
if (a->priority != b->priority)
|
||||||
return a->priority > b->priority ? -1 : 1;
|
return a->priority > b->priority ? -1 : 1;
|
||||||
|
|
||||||
/* otherwise if one has fewer peers, it goes first */
|
/* otherwise if one has fewer peers, it goes first */
|
||||||
if (a->peerCount != b->peerCount)
|
if (a->peerCount != b->peerCount)
|
||||||
return a->peerCount < b->peerCount ? -1 : 1;
|
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 */
|
/* otherwise go with our random seed */
|
||||||
return tr_compareUint16( a->random, b->random );
|
return tr_compareUint16( a->random, b->random );
|
||||||
|
@ -614,13 +617,15 @@ getPreferredPieces( Torrent * t,
|
||||||
setme->peerCount = 0;
|
setme->peerCount = 0;
|
||||||
setme->fastAllowed = 0;
|
setme->fastAllowed = 0;
|
||||||
setme->random = tr_rand( UINT16_MAX );
|
setme->random = tr_rand( UINT16_MAX );
|
||||||
/* FIXME */
|
|
||||||
// setme->fastAllowed = tr_bitfieldHas( t->tor->allowedList, i);
|
|
||||||
|
|
||||||
for( k=0; k<peerCount; ++k ) {
|
for( k=0; k<peerCount; ++k ) {
|
||||||
const tr_peer * peer = peers[k];
|
const tr_peer * peer = peers[k];
|
||||||
if( peer->peerIsInterested && !peer->clientIsChoked && tr_bitfieldHas( peer->have, piece ) )
|
if( peer->peerIsInterested && !peer->clientIsChoked && tr_bitfieldHas( peer->have, piece ) )
|
||||||
++setme->peerCount;
|
++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 */
|
/* add some new ones */
|
||||||
nAdd = MAX_CONNECTED_PEERS_PER_TORRENT - peerCount;
|
nAdd = MAX_CONNECTED_PEERS_PER_TORRENT - peerCount;
|
||||||
for( i=0; i<nAdd && i<nCandidates && i<MAX_RECONNECTIONS_PER_PULSE; ++i )
|
for( i=0; i<nAdd && i<nCandidates && i<MAX_RECONNECTIONS_PER_PULSE; ++i )
|
||||||
//for( i=0; i<nCandidates; ++i )
|
|
||||||
{
|
{
|
||||||
tr_peerMgr * mgr = t->manager;
|
tr_peerMgr * mgr = t->manager;
|
||||||
|
|
||||||
|
|
|
@ -1023,7 +1023,6 @@ readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf )
|
||||||
tr_peerIoReadUint32( msgs->io, inbuf, &msgs->blockToUs.offset );
|
tr_peerIoReadUint32( msgs->io, inbuf, &msgs->blockToUs.offset );
|
||||||
msgs->blockToUs.length = msglen - 8;
|
msgs->blockToUs.length = msglen - 8;
|
||||||
assert( EVBUFFER_LENGTH(msgs->inBlock) == 0 );
|
assert( EVBUFFER_LENGTH(msgs->inBlock) == 0 );
|
||||||
//evbuffer_drain( msgs->inBlock, ~0 );
|
|
||||||
msgs->state = msgs->blockToUs.length ? READING_BT_PIECE : AWAITING_BT_LENGTH;
|
msgs->state = msgs->blockToUs.length ? READING_BT_PIECE : AWAITING_BT_LENGTH;
|
||||||
return READ_AGAIN;
|
return READ_AGAIN;
|
||||||
break;
|
break;
|
||||||
|
@ -1723,3 +1722,11 @@ tr_peerMsgsUnsubscribe( tr_peermsgs * peer,
|
||||||
{
|
{
|
||||||
tr_publisherUnsubscribe( peer->publisher, tag );
|
tr_publisherUnsubscribe( peer->publisher, tag );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
tr_peerMsgIsPieceFastAllowed( const tr_peermsgs * peer,
|
||||||
|
uint32_t index )
|
||||||
|
{
|
||||||
|
return tr_bitfieldHas( peer->clientAllowedPieces, index );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,7 @@ tr_publisher_tag tr_peerMsgsSubscribe ( tr_peermsgs * peer,
|
||||||
void tr_peerMsgsUnsubscribe ( tr_peermsgs * peer,
|
void tr_peerMsgsUnsubscribe ( tr_peermsgs * peer,
|
||||||
tr_publisher_tag tag );
|
tr_publisher_tag tag );
|
||||||
|
|
||||||
|
int tr_peerMsgIsPieceFastAllowed( const tr_peermsgs * peer,
|
||||||
|
uint32_t index );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -312,8 +312,6 @@ tr_closeImpl( void * vh )
|
||||||
void
|
void
|
||||||
tr_close( tr_handle * h )
|
tr_close( tr_handle * h )
|
||||||
{
|
{
|
||||||
//assert( tr_torrentCount( h ) == 0 );
|
|
||||||
|
|
||||||
tr_runInEventThread( h, tr_closeImpl, h );
|
tr_runInEventThread( h, tr_closeImpl, h );
|
||||||
while( !h->isClosed )
|
while( !h->isClosed )
|
||||||
tr_wait( 100 );
|
tr_wait( 100 );
|
||||||
|
@ -356,7 +354,6 @@ tr_loadTorrents ( tr_handle * h,
|
||||||
tor = tr_torrentInit( h, path, destination, flags, NULL );
|
tor = tr_torrentInit( h, path, destination, flags, NULL );
|
||||||
if( tor != NULL ) {
|
if( tor != NULL ) {
|
||||||
tr_list_append( &list, tor );
|
tr_list_append( &list, tor );
|
||||||
//fprintf (stderr, "#%d - %s\n", n, tor->info.name );
|
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,7 +204,6 @@ libeventThreadFunc( void * veh )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
eh->base = event_init( );
|
eh->base = event_init( );
|
||||||
//event_set_log_callback( logFunc );
|
|
||||||
evdns_init( );
|
evdns_init( );
|
||||||
timeout_set( &eh->pulse, pumpList, veh );
|
timeout_set( &eh->pulse, pumpList, veh );
|
||||||
timeout_add( &eh->pulse, &eh->pulseInterval );
|
timeout_add( &eh->pulse, &eh->pulseInterval );
|
||||||
|
@ -242,8 +241,6 @@ tr_eventClose( tr_handle * handle )
|
||||||
tr_list_free( &eh->commands, tr_free );
|
tr_list_free( &eh->commands, tr_free );
|
||||||
eh->die = TRUE;
|
eh->die = TRUE;
|
||||||
tr_lockUnlock( eh->lock );
|
tr_lockUnlock( eh->lock );
|
||||||
|
|
||||||
//event_base_loopexit( eh->base, NULL );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue