1
0
Fork 0
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:
Charles Kerr 2007-07-13 22:22:46 +00:00
parent e6ba612b78
commit f0d97e1a02
12 changed files with 124 additions and 101 deletions

View file

@ -165,7 +165,7 @@ void tr_chokingPulse( tr_choking_t * c )
/* Choke peers who have lost their interest in us */
if( !tr_peerIsInterested( peer ) )
{
if( !tr_peerAmChoking( peer ) )
if( !tr_peerIsChokedByUs( peer ) )
{
tr_peerChoke( peer );
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
peer less than 10 seconds after the time we unchoked him
(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 ) )
{
@ -199,11 +204,6 @@ void tr_chokingPulse( tr_choking_t * c )
if( tr_peerLastChoke( peer ) + 10000 < now )
canChoke[canChokeCount++] = peer;
}
else
{
if( !tr_peerTimesChoked(peer) || tr_peerLastChoke( peer ) + 10000 < now )
canUnchoke[canUnchokeCount++] = peer;
}
}
}

View file

@ -465,11 +465,15 @@ static int OpenFile( int i, const char * folder, const char * name, int write )
}
/* Now try to really open the file */
errno = 0;
file->file = open( path, write ? ( O_RDWR | O_CREAT ) : O_RDONLY, 0666 );
if( file->file < 0 )
{
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;
}

View file

@ -146,10 +146,10 @@ struct tr_peer_s
int advertisedPort; /* listening port we last told peer */
tr_peertree_t sentPeers;
char amChoking;
char amInterested;
char peerChoking;
char peerInterested;
char isChokedByUs;
char isChokingUs;
char isInteresting;
char isInterested;
int optimistic;
int timesChoked;
@ -239,13 +239,13 @@ 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 );
peer = tr_new0( tr_peer_t, 1 );
peertreeInit( &peer->sentPeers );
peer->amChoking = TRUE;
peer->peerChoking = TRUE;
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 );
peer->inRequestMax = peer->inRequestAlloc = 2;
peer->inRequests = tr_new0( tr_request_t, peer->inRequestAlloc );
@ -395,7 +395,7 @@ int tr_peerRead( tr_peer_t * peer )
peer->pos += ret;
if( NULL != tor )
{
if( tr_peerAmInterested( peer ) && !tr_peerIsChoking( peer ) )
if( peer->isInteresting && !peer->isChokingUs )
{
tor->activityDate = date;
}
@ -583,7 +583,7 @@ writeBegin:
date = tr_date();
peer->outDate = date;
if( !tr_peerAmChoking( peer ) )
if( !tr_peerIsChokedByUs( peer ) )
tor->activityDate = date;
/* In case this block is done, you may have messages
@ -594,7 +594,7 @@ writeEnd:
/* Ask for a block whenever possible */
if( !isSeeding
&& !peer->amInterested
&& !peer->isInteresting
&& tor->peerCount > TR_MAX_PEER_COUNT - 2 )
{
/* This peer is no use to us, and it seems there are
@ -603,8 +603,8 @@ writeEnd:
return TR_ERROR;
}
if( peer->amInterested
&& !peer->peerChoking
if( peer->isInteresting
&& !peer->isChokingUs
&& !peer->banned
&& peer->inRequestCount < peer->inRequestMax )
{
@ -656,21 +656,21 @@ int tr_peerIsFrom( const tr_peer_t * peer )
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 )
{
return peer->peerInterested;
return peer->isInterested;
}
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 */
peer_dbg( "banned (%d / %d)", peer->goodPcs, peer->badPcs );
peer->banned = 1;
peer->peerInterested = 0;
peer->banned = TRUE;
peer->isInteresting = FALSE;
peer->isInterested = FALSE;
}
}
tr_bitfieldRem( peer->blamefield, piece );

View file

@ -42,10 +42,10 @@ const uint8_t * tr_peerHash ( const tr_peer_t * );
int tr_peerPulse ( tr_peer_t * );
int tr_peerIsConnected ( 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_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 * );
float tr_peerProgress ( const tr_peer_t * );
int tr_peerPort ( const tr_peer_t * );

View file

@ -61,7 +61,7 @@ az_msgs[] = {
#define azmsgId( idx ) ( az_msgs[(idx)].id )
#define azmsgCount() ( (int)(sizeof( az_msgs ) / sizeof( az_msgs[0] ) ) )
static inline int
static int
azmsgIdIndex( int id )
{
int ii;
@ -79,7 +79,7 @@ azmsgIdIndex( int id )
return 0;
}
static inline int
static int
azmsgNameIndex( const char * name, int len )
{
int ii;
@ -272,7 +272,7 @@ sendAZHandshake( tr_torrent_t * tor, tr_peer_t * peer )
return len;
}
static inline int
static int
parseAZMessageHeader( tr_peer_t * peer, uint8_t * buf, int len,
int * msgidret, int * msglenret )
{
@ -338,7 +338,7 @@ parseAZMessageHeader( tr_peer_t * peer, uint8_t * buf, int len,
return off;
}
static inline int
static int
parseAZHandshake( tr_peer_t * peer, uint8_t * buf, int len )
{
benc_val_t val, * sub, * dict, * subsub;
@ -453,7 +453,7 @@ parseAZHandshake( tr_peer_t * peer, uint8_t * buf, int len )
return TR_OK;
}
static inline int
static int
parseAZPex( tr_torrent_t * tor, tr_peer_t * peer, uint8_t * buf, int len )
{
tr_info_t * info = &tor->info;

View file

@ -210,7 +210,7 @@ makeUTPex( tr_torrent_t * tor, tr_peer_t * peer, char ** buf, int * len )
buf, len );
}
static inline int
static int
parseExtendedHandshake( tr_peer_t * peer, uint8_t * buf, int len )
{
benc_val_t val, * sub;
@ -276,7 +276,7 @@ parseExtendedHandshake( tr_peer_t * peer, uint8_t * buf, int len )
return TR_OK;
}
static inline int
static int
parseUTPex( tr_torrent_t * tor, tr_peer_t * peer, uint8_t * buf, int len )
{
benc_val_t val, * sub;

View file

@ -115,7 +115,7 @@ blockPending( tr_torrent_t * tor,
tr_request_t * r;
int hdrlen;
if( peer->amChoking )
if( peer->isChokedByUs ) /* we don't want to send them anything */
return NULL;
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 );
getMessagePointer( peer, 0, id );
peer->amChoking = yes;
peer->isChokedByUs = yes;
if( !yes )
{
@ -245,7 +245,7 @@ static void sendInterest( tr_peer_t * peer, int yes )
id = ( yes ? PEER_MSG_INTERESTED : PEER_MSG_UNINTERESTED );
getMessagePointer( peer, 0, id );
peer->amInterested = yes;
peer->isInteresting = yes;
peer_dbg( "SEND %sinterested", yes ? "" : "un" );
}

View file

@ -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;
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->peerChoking = choking;
peer->isChokingUs = 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 )
{
if( len != 0 )
@ -88,7 +91,7 @@ static inline int parseInterested( tr_peer_t * peer, int len,
peer_dbg( "GET %sinterested", interested ? "" : "un" );
peer->peerInterested = interested;
peer->isInterested = interested;
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 )
{
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;
}
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 )
{
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;
}
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 )
{
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;
}
if( peer->amChoking )
if( peer->isChokedByUs )
{
/* Didn't he get it? */
sendChoke( peer, 1 );
@ -246,7 +249,7 @@ static inline int parseRequest( tr_torrent_t * tor, tr_peer_t * peer,
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;
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 )
{
tr_info_t * inf = &tor->info;
@ -379,7 +382,7 @@ static int reqCompare( const void * va, const void * vb )
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 )
{
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;
}
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;
@ -440,7 +443,7 @@ static inline int parsePort( tr_peer_t * peer, uint8_t * p, int len )
return TR_OK;
}
static inline int
static int
parseMessageHeader( tr_peer_t * peer, uint8_t * buf, int buflen,
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 extid;
@ -539,7 +542,7 @@ static inline int parseMessage( tr_torrent_t * tor, tr_peer_t * peer,
return TR_ERROR;
}
static inline int parseBufHeader( tr_peer_t * peer )
static int parseBufHeader( tr_peer_t * peer )
{
static uint8_t badproto_http[] =
"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;
int ii;
@ -654,7 +657,7 @@ static inline int parseHandshake( tr_torrent_t * tor, tr_peer_t * peer )
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 )
{
@ -675,7 +678,7 @@ static inline int sendInitial( tr_torrent_t * tor, tr_peer_t * peer )
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;
uint8_t * buf;

View file

@ -40,7 +40,7 @@ tr_peertree_t;
#define peertreeNext(tree, item) RB_NEXT( 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 )
{
return memcmp( aa->peer, bb->peer, 6 );

View file

@ -219,18 +219,14 @@ static int isInteresting( const tr_torrent_t * tor, const tr_peer_t * peer )
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 );
}
if( !interested && peer->amInterested )
{
sendInterest( peer, 0 );
}
const int i = !!isInteresting( tor, peer );
if( i != peer->isInteresting )
sendInterest( peer, i );
}
/** utility structure used by getPreferredPieces() and comparePieces() */

View file

@ -552,9 +552,9 @@ tr_stat_t * tr_torrentStat( tr_torrent_t * tor )
++s->peersTotal;
if( tr_peerIsConnected( peer ) ) {
++s->peersFrom[tr_peerIsFrom(peer)];
if( tr_peerAmInterested( peer ) && !tr_peerIsChoking( peer ) )
if( tr_peerIsInterested( peer ) && !tr_peerIsChokedByUs( peer ) )
++s->peersUploading;
if( !tr_peerAmChoking( peer ) )
if( tr_peerIsInteresting( peer ) && !tr_peerIsChokingUs( peer ) )
++s->peersDownloading;
}
}
@ -630,7 +630,7 @@ tr_torrentPeers( const tr_torrent_t * tor, int * peerCount )
tr_peer_t * peer;
struct in_addr * addr;
int i;
for( i = 0; i < tor->peerCount; i++ )
for( i=0; i<tor->peerCount; ++i )
{
peer = tor->peers[i];
@ -646,18 +646,12 @@ tr_torrentPeers( const tr_torrent_t * tor, int * peerCount )
peers[i].from = tr_peerIsFrom( peer );
peers[i].progress = tr_peerProgress( peer );
peers[i].port = tr_peerPort( peer );
if( ( peers[i].isDownloading = !tr_peerAmChoking( peer ) ) )
{
peers[i].isDownloading = !tr_peerIsChokingUs( peer );
peers[i].uploadToRate = tr_peerUploadRate( peer );
}
if( ( peers[i].isUploading = ( tr_peerAmInterested( peer ) &&
!tr_peerIsChoking( peer ) ) ) )
{
peers[i].isUploading = !tr_peerIsChokedByUs( peer );
peers[i].downloadFromRate = tr_peerDownloadRate( peer );
}
}
}
tr_torrentReaderUnlock( tor );

View file

@ -3,11 +3,36 @@
include ../mk/config.mk
include ../mk/common.mk
SRCS = basename.c bencode.c choking.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
SRCS = \
basename.c \
bencode.c \
choking.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)