mirror of
https://github.com/transmission/transmission
synced 2025-03-12 07:03:44 +00:00
fix bug that gave the wrong peer count when uploading.
This commit is contained in:
parent
e6ba612b78
commit
f0d97e1a02
12 changed files with 124 additions and 101 deletions
|
@ -165,7 +165,7 @@ void tr_chokingPulse( tr_choking_t * c )
|
||||||
/* Choke peers who have lost their interest in us */
|
/* Choke peers who have lost their interest in us */
|
||||||
if( !tr_peerIsInterested( peer ) )
|
if( !tr_peerIsInterested( peer ) )
|
||||||
{
|
{
|
||||||
if( !tr_peerAmChoking( peer ) )
|
if( !tr_peerIsChokedByUs( peer ) )
|
||||||
{
|
{
|
||||||
tr_peerChoke( peer );
|
tr_peerChoke( peer );
|
||||||
tr_peerSetOptimistic( peer, 0 );
|
tr_peerSetOptimistic( peer, 0 );
|
||||||
|
@ -177,7 +177,12 @@ void tr_chokingPulse( tr_choking_t * c )
|
||||||
those we may unchoke. Whatever happens, we never choke a
|
those we may unchoke. Whatever happens, we never choke a
|
||||||
peer less than 10 seconds after the time we unchoked him
|
peer less than 10 seconds after the time we unchoked him
|
||||||
(or the other way around). */
|
(or the other way around). */
|
||||||
if( !tr_peerAmChoking( peer ) )
|
if( tr_peerIsChokedByUs( peer ) )
|
||||||
|
{
|
||||||
|
if( !tr_peerTimesChoked(peer) || tr_peerLastChoke( peer ) + 10000 < now )
|
||||||
|
canUnchoke[canUnchokeCount++] = peer;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if( tr_peerIsOptimistic( peer ) )
|
if( tr_peerIsOptimistic( peer ) )
|
||||||
{
|
{
|
||||||
|
@ -199,11 +204,6 @@ void tr_chokingPulse( tr_choking_t * c )
|
||||||
if( tr_peerLastChoke( peer ) + 10000 < now )
|
if( tr_peerLastChoke( peer ) + 10000 < now )
|
||||||
canChoke[canChokeCount++] = peer;
|
canChoke[canChokeCount++] = peer;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if( !tr_peerTimesChoked(peer) || tr_peerLastChoke( peer ) + 10000 < now )
|
|
||||||
canUnchoke[canUnchokeCount++] = peer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -465,11 +465,15 @@ static int OpenFile( int i, const char * folder, const char * name, int write )
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now try to really open the file */
|
/* Now try to really open the file */
|
||||||
|
errno = 0;
|
||||||
file->file = open( path, write ? ( O_RDWR | O_CREAT ) : O_RDONLY, 0666 );
|
file->file = open( path, write ? ( O_RDWR | O_CREAT ) : O_RDONLY, 0666 );
|
||||||
if( file->file < 0 )
|
if( file->file < 0 )
|
||||||
{
|
{
|
||||||
ret = tr_ioErrorFromErrno();
|
ret = tr_ioErrorFromErrno();
|
||||||
tr_err( "Could not open %s in %s (%d, %d)", name, folder, write, ret );
|
if( errno )
|
||||||
|
tr_err( "Couldn't open %s in %s: %s", name, folder, strerror(errno) );
|
||||||
|
else
|
||||||
|
tr_err( "Couldn't open %s in %s", name, folder );
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,10 +146,10 @@ struct tr_peer_s
|
||||||
int advertisedPort; /* listening port we last told peer */
|
int advertisedPort; /* listening port we last told peer */
|
||||||
tr_peertree_t sentPeers;
|
tr_peertree_t sentPeers;
|
||||||
|
|
||||||
char amChoking;
|
char isChokedByUs;
|
||||||
char amInterested;
|
char isChokingUs;
|
||||||
char peerChoking;
|
char isInteresting;
|
||||||
char peerInterested;
|
char isInterested;
|
||||||
|
|
||||||
int optimistic;
|
int optimistic;
|
||||||
int timesChoked;
|
int timesChoked;
|
||||||
|
@ -238,14 +238,14 @@ tr_peer_t * tr_peerInit( struct in_addr addr, in_port_t port, int s, int from )
|
||||||
|
|
||||||
assert( 0 <= from && TR_PEER_FROM__MAX > from );
|
assert( 0 <= from && TR_PEER_FROM__MAX > from );
|
||||||
|
|
||||||
peer = tr_new0( tr_peer_t, 1 );
|
peer = tr_new0( tr_peer_t, 1 );
|
||||||
|
peer->isChokedByUs = TRUE;
|
||||||
|
peer->isChokingUs = TRUE;
|
||||||
|
peer->date = tr_date();
|
||||||
|
peer->keepAlive = peer->date;
|
||||||
|
peer->download = tr_rcInit();
|
||||||
|
peer->upload = tr_rcInit();
|
||||||
peertreeInit( &peer->sentPeers );
|
peertreeInit( &peer->sentPeers );
|
||||||
peer->amChoking = TRUE;
|
|
||||||
peer->peerChoking = TRUE;
|
|
||||||
peer->date = tr_date();
|
|
||||||
peer->keepAlive = peer->date;
|
|
||||||
peer->download = tr_rcInit();
|
|
||||||
peer->upload = tr_rcInit();
|
|
||||||
|
|
||||||
peer->inRequestMax = peer->inRequestAlloc = 2;
|
peer->inRequestMax = peer->inRequestAlloc = 2;
|
||||||
peer->inRequests = tr_new0( tr_request_t, peer->inRequestAlloc );
|
peer->inRequests = tr_new0( tr_request_t, peer->inRequestAlloc );
|
||||||
|
@ -395,7 +395,7 @@ int tr_peerRead( tr_peer_t * peer )
|
||||||
peer->pos += ret;
|
peer->pos += ret;
|
||||||
if( NULL != tor )
|
if( NULL != tor )
|
||||||
{
|
{
|
||||||
if( tr_peerAmInterested( peer ) && !tr_peerIsChoking( peer ) )
|
if( peer->isInteresting && !peer->isChokingUs )
|
||||||
{
|
{
|
||||||
tor->activityDate = date;
|
tor->activityDate = date;
|
||||||
}
|
}
|
||||||
|
@ -583,7 +583,7 @@ writeBegin:
|
||||||
date = tr_date();
|
date = tr_date();
|
||||||
peer->outDate = date;
|
peer->outDate = date;
|
||||||
|
|
||||||
if( !tr_peerAmChoking( peer ) )
|
if( !tr_peerIsChokedByUs( peer ) )
|
||||||
tor->activityDate = date;
|
tor->activityDate = date;
|
||||||
|
|
||||||
/* In case this block is done, you may have messages
|
/* In case this block is done, you may have messages
|
||||||
|
@ -594,7 +594,7 @@ writeEnd:
|
||||||
|
|
||||||
/* Ask for a block whenever possible */
|
/* Ask for a block whenever possible */
|
||||||
if( !isSeeding
|
if( !isSeeding
|
||||||
&& !peer->amInterested
|
&& !peer->isInteresting
|
||||||
&& tor->peerCount > TR_MAX_PEER_COUNT - 2 )
|
&& tor->peerCount > TR_MAX_PEER_COUNT - 2 )
|
||||||
{
|
{
|
||||||
/* This peer is no use to us, and it seems there are
|
/* This peer is no use to us, and it seems there are
|
||||||
|
@ -603,8 +603,8 @@ writeEnd:
|
||||||
return TR_ERROR;
|
return TR_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( peer->amInterested
|
if( peer->isInteresting
|
||||||
&& !peer->peerChoking
|
&& !peer->isChokingUs
|
||||||
&& !peer->banned
|
&& !peer->banned
|
||||||
&& peer->inRequestCount < peer->inRequestMax )
|
&& peer->inRequestCount < peer->inRequestMax )
|
||||||
{
|
{
|
||||||
|
@ -656,21 +656,21 @@ int tr_peerIsFrom( const tr_peer_t * peer )
|
||||||
return peer->from;
|
return peer->from;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tr_peerAmChoking( const tr_peer_t * peer )
|
int tr_peerIsChokedByUs( const tr_peer_t * peer )
|
||||||
{
|
{
|
||||||
return peer->amChoking;
|
return peer->isChokedByUs;
|
||||||
}
|
}
|
||||||
int tr_peerAmInterested( const tr_peer_t * peer )
|
int tr_peerIsInteresting( const tr_peer_t * peer )
|
||||||
{
|
{
|
||||||
return peer->amInterested;
|
return peer->isInteresting;
|
||||||
}
|
}
|
||||||
int tr_peerIsChoking( const tr_peer_t * peer )
|
int tr_peerIsChokingUs( const tr_peer_t * peer )
|
||||||
{
|
{
|
||||||
return peer->peerChoking;
|
return peer->isChokingUs;
|
||||||
}
|
}
|
||||||
int tr_peerIsInterested( const tr_peer_t * peer )
|
int tr_peerIsInterested( const tr_peer_t * peer )
|
||||||
{
|
{
|
||||||
return peer->peerInterested;
|
return peer->isInterested;
|
||||||
}
|
}
|
||||||
|
|
||||||
float tr_peerProgress( const tr_peer_t * peer )
|
float tr_peerProgress( const tr_peer_t * peer )
|
||||||
|
@ -776,8 +776,9 @@ void tr_peerBlame( tr_peer_t * peer, int piece, int success )
|
||||||
{
|
{
|
||||||
/* Full ban */
|
/* Full ban */
|
||||||
peer_dbg( "banned (%d / %d)", peer->goodPcs, peer->badPcs );
|
peer_dbg( "banned (%d / %d)", peer->goodPcs, peer->badPcs );
|
||||||
peer->banned = 1;
|
peer->banned = TRUE;
|
||||||
peer->peerInterested = 0;
|
peer->isInteresting = FALSE;
|
||||||
|
peer->isInterested = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tr_bitfieldRem( peer->blamefield, piece );
|
tr_bitfieldRem( peer->blamefield, piece );
|
||||||
|
|
|
@ -42,10 +42,10 @@ const uint8_t * tr_peerHash ( const tr_peer_t * );
|
||||||
int tr_peerPulse ( tr_peer_t * );
|
int tr_peerPulse ( tr_peer_t * );
|
||||||
int tr_peerIsConnected ( const tr_peer_t * );
|
int tr_peerIsConnected ( const tr_peer_t * );
|
||||||
int tr_peerIsFrom ( const tr_peer_t * );
|
int tr_peerIsFrom ( const tr_peer_t * );
|
||||||
int tr_peerAmChoking ( const tr_peer_t * );
|
|
||||||
int tr_peerAmInterested ( const tr_peer_t * );
|
|
||||||
int tr_peerIsChoking ( const tr_peer_t * );
|
|
||||||
int tr_peerTimesChoked ( const tr_peer_t * );
|
int tr_peerTimesChoked ( const tr_peer_t * );
|
||||||
|
int tr_peerIsChokingUs ( const tr_peer_t * );
|
||||||
|
int tr_peerIsChokedByUs ( const tr_peer_t * );
|
||||||
|
int tr_peerIsInteresting ( const tr_peer_t * );
|
||||||
int tr_peerIsInterested ( const tr_peer_t * );
|
int tr_peerIsInterested ( const tr_peer_t * );
|
||||||
float tr_peerProgress ( const tr_peer_t * );
|
float tr_peerProgress ( const tr_peer_t * );
|
||||||
int tr_peerPort ( const tr_peer_t * );
|
int tr_peerPort ( const tr_peer_t * );
|
||||||
|
|
|
@ -61,7 +61,7 @@ az_msgs[] = {
|
||||||
#define azmsgId( idx ) ( az_msgs[(idx)].id )
|
#define azmsgId( idx ) ( az_msgs[(idx)].id )
|
||||||
#define azmsgCount() ( (int)(sizeof( az_msgs ) / sizeof( az_msgs[0] ) ) )
|
#define azmsgCount() ( (int)(sizeof( az_msgs ) / sizeof( az_msgs[0] ) ) )
|
||||||
|
|
||||||
static inline int
|
static int
|
||||||
azmsgIdIndex( int id )
|
azmsgIdIndex( int id )
|
||||||
{
|
{
|
||||||
int ii;
|
int ii;
|
||||||
|
@ -79,7 +79,7 @@ azmsgIdIndex( int id )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static int
|
||||||
azmsgNameIndex( const char * name, int len )
|
azmsgNameIndex( const char * name, int len )
|
||||||
{
|
{
|
||||||
int ii;
|
int ii;
|
||||||
|
@ -272,7 +272,7 @@ sendAZHandshake( tr_torrent_t * tor, tr_peer_t * peer )
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static int
|
||||||
parseAZMessageHeader( tr_peer_t * peer, uint8_t * buf, int len,
|
parseAZMessageHeader( tr_peer_t * peer, uint8_t * buf, int len,
|
||||||
int * msgidret, int * msglenret )
|
int * msgidret, int * msglenret )
|
||||||
{
|
{
|
||||||
|
@ -338,7 +338,7 @@ parseAZMessageHeader( tr_peer_t * peer, uint8_t * buf, int len,
|
||||||
return off;
|
return off;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static int
|
||||||
parseAZHandshake( tr_peer_t * peer, uint8_t * buf, int len )
|
parseAZHandshake( tr_peer_t * peer, uint8_t * buf, int len )
|
||||||
{
|
{
|
||||||
benc_val_t val, * sub, * dict, * subsub;
|
benc_val_t val, * sub, * dict, * subsub;
|
||||||
|
@ -453,7 +453,7 @@ parseAZHandshake( tr_peer_t * peer, uint8_t * buf, int len )
|
||||||
return TR_OK;
|
return TR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static int
|
||||||
parseAZPex( tr_torrent_t * tor, tr_peer_t * peer, uint8_t * buf, int len )
|
parseAZPex( tr_torrent_t * tor, tr_peer_t * peer, uint8_t * buf, int len )
|
||||||
{
|
{
|
||||||
tr_info_t * info = &tor->info;
|
tr_info_t * info = &tor->info;
|
||||||
|
|
|
@ -210,7 +210,7 @@ makeUTPex( tr_torrent_t * tor, tr_peer_t * peer, char ** buf, int * len )
|
||||||
buf, len );
|
buf, len );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static int
|
||||||
parseExtendedHandshake( tr_peer_t * peer, uint8_t * buf, int len )
|
parseExtendedHandshake( tr_peer_t * peer, uint8_t * buf, int len )
|
||||||
{
|
{
|
||||||
benc_val_t val, * sub;
|
benc_val_t val, * sub;
|
||||||
|
@ -276,7 +276,7 @@ parseExtendedHandshake( tr_peer_t * peer, uint8_t * buf, int len )
|
||||||
return TR_OK;
|
return TR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static int
|
||||||
parseUTPex( tr_torrent_t * tor, tr_peer_t * peer, uint8_t * buf, int len )
|
parseUTPex( tr_torrent_t * tor, tr_peer_t * peer, uint8_t * buf, int len )
|
||||||
{
|
{
|
||||||
benc_val_t val, * sub;
|
benc_val_t val, * sub;
|
||||||
|
|
|
@ -115,7 +115,7 @@ blockPending( tr_torrent_t * tor,
|
||||||
tr_request_t * r;
|
tr_request_t * r;
|
||||||
int hdrlen;
|
int hdrlen;
|
||||||
|
|
||||||
if( peer->amChoking )
|
if( peer->isChokedByUs ) /* we don't want to send them anything */
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if( !peer->outRequests ) /* nothing to send */
|
if( !peer->outRequests ) /* nothing to send */
|
||||||
|
@ -220,7 +220,7 @@ static void sendChoke( tr_peer_t * peer, int yes )
|
||||||
id = ( yes ? PEER_MSG_CHOKE : PEER_MSG_UNCHOKE );
|
id = ( yes ? PEER_MSG_CHOKE : PEER_MSG_UNCHOKE );
|
||||||
getMessagePointer( peer, 0, id );
|
getMessagePointer( peer, 0, id );
|
||||||
|
|
||||||
peer->amChoking = yes;
|
peer->isChokedByUs = yes;
|
||||||
|
|
||||||
if( !yes )
|
if( !yes )
|
||||||
{
|
{
|
||||||
|
@ -245,7 +245,7 @@ static void sendInterest( tr_peer_t * peer, int yes )
|
||||||
id = ( yes ? PEER_MSG_INTERESTED : PEER_MSG_UNINTERESTED );
|
id = ( yes ? PEER_MSG_INTERESTED : PEER_MSG_UNINTERESTED );
|
||||||
getMessagePointer( peer, 0, id );
|
getMessagePointer( peer, 0, id );
|
||||||
|
|
||||||
peer->amInterested = yes;
|
peer->isInteresting = yes;
|
||||||
|
|
||||||
peer_dbg( "SEND %sinterested", yes ? "" : "un" );
|
peer_dbg( "SEND %sinterested", yes ? "" : "un" );
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,11 @@
|
||||||
***********************************************************************
|
***********************************************************************
|
||||||
*
|
*
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
static inline int parseChoke( tr_torrent_t * tor, tr_peer_t * peer,
|
|
||||||
int len, int choking )
|
static int parseChoke( tr_torrent_t * tor,
|
||||||
|
tr_peer_t * peer,
|
||||||
|
int len,
|
||||||
|
int choking )
|
||||||
{
|
{
|
||||||
tr_request_t * r;
|
tr_request_t * r;
|
||||||
int i;
|
int i;
|
||||||
|
@ -45,7 +48,7 @@ static inline int parseChoke( tr_torrent_t * tor, tr_peer_t * peer,
|
||||||
|
|
||||||
peer_dbg( "GET %schoke", choking ? "" : "un" );
|
peer_dbg( "GET %schoke", choking ? "" : "un" );
|
||||||
|
|
||||||
peer->peerChoking = choking;
|
peer->isChokingUs = choking;
|
||||||
|
|
||||||
if( choking )
|
if( choking )
|
||||||
{
|
{
|
||||||
|
@ -77,7 +80,7 @@ static inline int parseChoke( tr_torrent_t * tor, tr_peer_t * peer,
|
||||||
***********************************************************************
|
***********************************************************************
|
||||||
*
|
*
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
static inline int parseInterested( tr_peer_t * peer, int len,
|
static int parseInterested( tr_peer_t * peer, int len,
|
||||||
int interested )
|
int interested )
|
||||||
{
|
{
|
||||||
if( len != 0 )
|
if( len != 0 )
|
||||||
|
@ -88,7 +91,7 @@ static inline int parseInterested( tr_peer_t * peer, int len,
|
||||||
|
|
||||||
peer_dbg( "GET %sinterested", interested ? "" : "un" );
|
peer_dbg( "GET %sinterested", interested ? "" : "un" );
|
||||||
|
|
||||||
peer->peerInterested = interested;
|
peer->isInterested = interested;
|
||||||
|
|
||||||
return TR_OK;
|
return TR_OK;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +101,7 @@ static inline int parseInterested( tr_peer_t * peer, int len,
|
||||||
***********************************************************************
|
***********************************************************************
|
||||||
*
|
*
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
static inline int parseHave( tr_torrent_t * tor, tr_peer_t * peer,
|
static int parseHave( tr_torrent_t * tor, tr_peer_t * peer,
|
||||||
uint8_t * p, int len )
|
uint8_t * p, int len )
|
||||||
{
|
{
|
||||||
tr_info_t * inf = &tor->info;
|
tr_info_t * inf = &tor->info;
|
||||||
|
@ -136,7 +139,7 @@ static inline int parseHave( tr_torrent_t * tor, tr_peer_t * peer,
|
||||||
return TR_OK;
|
return TR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int parseBitfield( tr_torrent_t * tor, tr_peer_t * peer,
|
static int parseBitfield( tr_torrent_t * tor, tr_peer_t * peer,
|
||||||
uint8_t * p, int len )
|
uint8_t * p, int len )
|
||||||
{
|
{
|
||||||
tr_info_t * inf = &tor->info;
|
tr_info_t * inf = &tor->info;
|
||||||
|
@ -191,7 +194,7 @@ static inline int parseBitfield( tr_torrent_t * tor, tr_peer_t * peer,
|
||||||
return TR_OK;
|
return TR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int parseRequest( tr_torrent_t * tor, tr_peer_t * peer,
|
static int parseRequest( tr_torrent_t * tor, tr_peer_t * peer,
|
||||||
uint8_t * p, int len )
|
uint8_t * p, int len )
|
||||||
{
|
{
|
||||||
tr_info_t * inf = &tor->info;
|
tr_info_t * inf = &tor->info;
|
||||||
|
@ -204,7 +207,7 @@ static inline int parseRequest( tr_torrent_t * tor, tr_peer_t * peer,
|
||||||
return TR_ERROR_ASSERT;
|
return TR_ERROR_ASSERT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( peer->amChoking )
|
if( peer->isChokedByUs )
|
||||||
{
|
{
|
||||||
/* Didn't he get it? */
|
/* Didn't he get it? */
|
||||||
sendChoke( peer, 1 );
|
sendChoke( peer, 1 );
|
||||||
|
@ -246,7 +249,7 @@ static inline int parseRequest( tr_torrent_t * tor, tr_peer_t * peer,
|
||||||
return TR_OK;
|
return TR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void updateRequests( tr_peer_t * peer, int index, int begin )
|
static void updateRequests( tr_peer_t * peer, int index, int begin )
|
||||||
{
|
{
|
||||||
tr_request_t * r;
|
tr_request_t * r;
|
||||||
int i;
|
int i;
|
||||||
|
@ -278,7 +281,7 @@ static inline void updateRequests( tr_peer_t * peer, int index, int begin )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int parsePiece( tr_torrent_t * tor, tr_peer_t * peer,
|
static int parsePiece( tr_torrent_t * tor, tr_peer_t * peer,
|
||||||
uint8_t * p, int len )
|
uint8_t * p, int len )
|
||||||
{
|
{
|
||||||
tr_info_t * inf = &tor->info;
|
tr_info_t * inf = &tor->info;
|
||||||
|
@ -379,7 +382,7 @@ static int reqCompare( const void * va, const void * vb )
|
||||||
return a->length - b->length;
|
return a->length - b->length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int parseCancel( tr_torrent_t * tor, tr_peer_t * peer,
|
static int parseCancel( tr_torrent_t * tor, tr_peer_t * peer,
|
||||||
uint8_t * p, int len )
|
uint8_t * p, int len )
|
||||||
{
|
{
|
||||||
tr_info_t * inf = &tor->info;
|
tr_info_t * inf = &tor->info;
|
||||||
|
@ -424,7 +427,7 @@ static inline int parseCancel( tr_torrent_t * tor, tr_peer_t * peer,
|
||||||
return TR_OK;
|
return TR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int parsePort( tr_peer_t * peer, uint8_t * p, int len )
|
static int parsePort( tr_peer_t * peer, uint8_t * p, int len )
|
||||||
{
|
{
|
||||||
in_port_t port;
|
in_port_t port;
|
||||||
|
|
||||||
|
@ -440,7 +443,7 @@ static inline int parsePort( tr_peer_t * peer, uint8_t * p, int len )
|
||||||
return TR_OK;
|
return TR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static int
|
||||||
parseMessageHeader( tr_peer_t * peer, uint8_t * buf, int buflen,
|
parseMessageHeader( tr_peer_t * peer, uint8_t * buf, int buflen,
|
||||||
int * msgid, int * msglen )
|
int * msgid, int * msglen )
|
||||||
{
|
{
|
||||||
|
@ -474,7 +477,7 @@ parseMessageHeader( tr_peer_t * peer, uint8_t * buf, int buflen,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int parseMessage( tr_torrent_t * tor, tr_peer_t * peer,
|
static int parseMessage( tr_torrent_t * tor, tr_peer_t * peer,
|
||||||
int id, uint8_t * p, int len )
|
int id, uint8_t * p, int len )
|
||||||
{
|
{
|
||||||
int extid;
|
int extid;
|
||||||
|
@ -539,7 +542,7 @@ static inline int parseMessage( tr_torrent_t * tor, tr_peer_t * peer,
|
||||||
return TR_ERROR;
|
return TR_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int parseBufHeader( tr_peer_t * peer )
|
static int parseBufHeader( tr_peer_t * peer )
|
||||||
{
|
{
|
||||||
static uint8_t badproto_http[] =
|
static uint8_t badproto_http[] =
|
||||||
"HTTP/1.0 400 Nice try...\015\012"
|
"HTTP/1.0 400 Nice try...\015\012"
|
||||||
|
@ -597,7 +600,7 @@ static const uint8_t * parseBufHash( const tr_peer_t * peer )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int parseHandshake( tr_torrent_t * tor, tr_peer_t * peer )
|
static int parseHandshake( tr_torrent_t * tor, tr_peer_t * peer )
|
||||||
{
|
{
|
||||||
tr_info_t * inf = &tor->info;
|
tr_info_t * inf = &tor->info;
|
||||||
int ii;
|
int ii;
|
||||||
|
@ -654,7 +657,7 @@ static inline int parseHandshake( tr_torrent_t * tor, tr_peer_t * peer )
|
||||||
return TR_OK;
|
return TR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int sendInitial( tr_torrent_t * tor, tr_peer_t * peer )
|
static int sendInitial( tr_torrent_t * tor, tr_peer_t * peer )
|
||||||
{
|
{
|
||||||
if( PEER_STATUS_CONNECTED != peer->status )
|
if( PEER_STATUS_CONNECTED != peer->status )
|
||||||
{
|
{
|
||||||
|
@ -675,7 +678,7 @@ static inline int sendInitial( tr_torrent_t * tor, tr_peer_t * peer )
|
||||||
return TR_OK;
|
return TR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int parseBuf( tr_torrent_t * tor, tr_peer_t * peer )
|
static int parseBuf( tr_torrent_t * tor, tr_peer_t * peer )
|
||||||
{
|
{
|
||||||
int len, ret, msgid;
|
int len, ret, msgid;
|
||||||
uint8_t * buf;
|
uint8_t * buf;
|
||||||
|
|
|
@ -40,7 +40,7 @@ tr_peertree_t;
|
||||||
#define peertreeNext(tree, item) RB_NEXT( tr_peertree_s, (tree), (item) )
|
#define peertreeNext(tree, item) RB_NEXT( tr_peertree_s, (tree), (item) )
|
||||||
#define peertreeFind(tree, item) RB_FIND( tr_peertree_s, (tree), (item) )
|
#define peertreeFind(tree, item) RB_FIND( tr_peertree_s, (tree), (item) )
|
||||||
|
|
||||||
static inline int
|
static int
|
||||||
peertreekeycmp( tr_peertree_entry_t * aa, tr_peertree_entry_t * bb )
|
peertreekeycmp( tr_peertree_entry_t * aa, tr_peertree_entry_t * bb )
|
||||||
{
|
{
|
||||||
return memcmp( aa->peer, bb->peer, 6 );
|
return memcmp( aa->peer, bb->peer, 6 );
|
||||||
|
|
|
@ -219,18 +219,14 @@ static int isInteresting( const tr_torrent_t * tor, const tr_peer_t * peer )
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static void updateInterest( tr_torrent_t * tor, tr_peer_t * peer )
|
|
||||||
{
|
|
||||||
int interested = isInteresting( tor, peer );
|
|
||||||
|
|
||||||
if( interested && !peer->amInterested )
|
static void
|
||||||
{
|
updateInterest( tr_torrent_t * tor, tr_peer_t * peer )
|
||||||
sendInterest( peer, 1 );
|
{
|
||||||
}
|
const int i = !!isInteresting( tor, peer );
|
||||||
if( !interested && peer->amInterested )
|
|
||||||
{
|
if( i != peer->isInteresting )
|
||||||
sendInterest( peer, 0 );
|
sendInterest( peer, i );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** utility structure used by getPreferredPieces() and comparePieces() */
|
/** utility structure used by getPreferredPieces() and comparePieces() */
|
||||||
|
|
|
@ -549,12 +549,12 @@ tr_stat_t * tr_torrentStat( tr_torrent_t * tor )
|
||||||
s->peersDownloading = 0;
|
s->peersDownloading = 0;
|
||||||
for( i=0; i<tor->peerCount; ++i ) {
|
for( i=0; i<tor->peerCount; ++i ) {
|
||||||
const tr_peer_t * peer = tor->peers[i];
|
const tr_peer_t * peer = tor->peers[i];
|
||||||
++s->peersTotal;
|
++s->peersTotal;
|
||||||
if( tr_peerIsConnected( peer ) ) {
|
if( tr_peerIsConnected( peer ) ) {
|
||||||
++s->peersFrom[tr_peerIsFrom(peer)];
|
++s->peersFrom[tr_peerIsFrom(peer)];
|
||||||
if( tr_peerAmInterested( peer ) && !tr_peerIsChoking( peer ) )
|
if( tr_peerIsInterested( peer ) && !tr_peerIsChokedByUs( peer ) )
|
||||||
++s->peersUploading;
|
++s->peersUploading;
|
||||||
if( !tr_peerAmChoking( peer ) )
|
if( tr_peerIsInteresting( peer ) && !tr_peerIsChokingUs( peer ) )
|
||||||
++s->peersDownloading;
|
++s->peersDownloading;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -630,7 +630,7 @@ tr_torrentPeers( const tr_torrent_t * tor, int * peerCount )
|
||||||
tr_peer_t * peer;
|
tr_peer_t * peer;
|
||||||
struct in_addr * addr;
|
struct in_addr * addr;
|
||||||
int i;
|
int i;
|
||||||
for( i = 0; i < tor->peerCount; i++ )
|
for( i=0; i<tor->peerCount; ++i )
|
||||||
{
|
{
|
||||||
peer = tor->peers[i];
|
peer = tor->peers[i];
|
||||||
|
|
||||||
|
@ -641,21 +641,15 @@ tr_torrentPeers( const tr_torrent_t * tor, int * peerCount )
|
||||||
sizeof( peers[i].addr ) );
|
sizeof( peers[i].addr ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
peers[i].client = tr_peerClient( peer );
|
peers[i].client = tr_peerClient( peer );
|
||||||
peers[i].isConnected = tr_peerIsConnected( peer );
|
peers[i].isConnected = tr_peerIsConnected( peer );
|
||||||
peers[i].from = tr_peerIsFrom( peer );
|
peers[i].from = tr_peerIsFrom( peer );
|
||||||
peers[i].progress = tr_peerProgress( peer );
|
peers[i].progress = tr_peerProgress( peer );
|
||||||
peers[i].port = tr_peerPort( peer );
|
peers[i].port = tr_peerPort( peer );
|
||||||
|
peers[i].isDownloading = !tr_peerIsChokingUs( peer );
|
||||||
if( ( peers[i].isDownloading = !tr_peerAmChoking( peer ) ) )
|
peers[i].uploadToRate = tr_peerUploadRate( peer );
|
||||||
{
|
peers[i].isUploading = !tr_peerIsChokedByUs( peer );
|
||||||
peers[i].uploadToRate = tr_peerUploadRate( peer );
|
peers[i].downloadFromRate = tr_peerDownloadRate( peer );
|
||||||
}
|
|
||||||
if( ( peers[i].isUploading = ( tr_peerAmInterested( peer ) &&
|
|
||||||
!tr_peerIsChoking( peer ) ) ) )
|
|
||||||
{
|
|
||||||
peers[i].downloadFromRate = tr_peerDownloadRate( peer );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
35
mk/lib.mk
35
mk/lib.mk
|
@ -3,11 +3,36 @@
|
||||||
include ../mk/config.mk
|
include ../mk/config.mk
|
||||||
include ../mk/common.mk
|
include ../mk/common.mk
|
||||||
|
|
||||||
SRCS = basename.c bencode.c choking.c clients.c completion.c dirname.c \
|
SRCS = \
|
||||||
fastresume.c fdlimit.c http.c inout.c ipcparse.c list.c makemeta.c \
|
basename.c \
|
||||||
metainfo.c natpmp.c net.c peer.c platform.c ratecontrol.c sha1.c \
|
bencode.c \
|
||||||
shared.c strlcat.c strlcpy.c torrent.c tracker.c transmission.c \
|
choking.c \
|
||||||
upnp.c utils.c xml.c
|
clients.c \
|
||||||
|
completion.c \
|
||||||
|
dirname.c \
|
||||||
|
fastresume.c \
|
||||||
|
fdlimit.c \
|
||||||
|
http.c \
|
||||||
|
inout.c \
|
||||||
|
ipcparse.c \
|
||||||
|
list.c \
|
||||||
|
makemeta.c \
|
||||||
|
metainfo.c \
|
||||||
|
natpmp.c \
|
||||||
|
net.c \
|
||||||
|
peer.c \
|
||||||
|
platform.c \
|
||||||
|
ratecontrol.c \
|
||||||
|
sha1.c \
|
||||||
|
shared.c \
|
||||||
|
strlcat.c \
|
||||||
|
strlcpy.c \
|
||||||
|
torrent.c \
|
||||||
|
tracker.c \
|
||||||
|
transmission.c \
|
||||||
|
upnp.c \
|
||||||
|
utils.c \
|
||||||
|
xml.c
|
||||||
|
|
||||||
OBJS = $(SRCS:%.c=%.o)
|
OBJS = $(SRCS:%.c=%.o)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue