Changeset 2339


Ignore:
Timestamp:
Jul 13, 2007, 10:22:46 PM (15 years ago)
Author:
charles
Message:

fix bug that gave the wrong peer count when uploading.

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/choking.c

    r2311 r2339  
    166166            if( !tr_peerIsInterested( peer ) )
    167167            {
    168                 if( !tr_peerAmChoking( peer ) )
     168                if( !tr_peerIsChokedByUs( peer ) )
    169169                {
    170170                    tr_peerChoke( peer );
     
    178178               peer less than 10 seconds after the time we unchoked him
    179179               (or the other way around). */
    180             if( !tr_peerAmChoking( peer ) )
     180            if( tr_peerIsChokedByUs( peer ) )
     181            {
     182                if( !tr_peerTimesChoked(peer) || tr_peerLastChoke( peer ) + 10000 < now )
     183                    canUnchoke[canUnchokeCount++] = peer;
     184            }
     185            else
    181186            {
    182187                if( tr_peerIsOptimistic( peer ) )
     
    200205                    canChoke[canChokeCount++] = peer;
    201206            }
    202             else
    203             {
    204                 if( !tr_peerTimesChoked(peer) || tr_peerLastChoke( peer ) + 10000 < now )
    205                     canUnchoke[canUnchokeCount++] = peer;
    206             }
    207207        }
    208208    }
  • trunk/libtransmission/fdlimit.c

    r2331 r2339  
    466466
    467467    /* Now try to really open the file */
     468    errno = 0;
    468469    file->file = open( path, write ? ( O_RDWR | O_CREAT ) : O_RDONLY, 0666 );
    469470    if( file->file < 0 )
    470471    {
    471472        ret = tr_ioErrorFromErrno();
    472         tr_err( "Could not open %s in %s (%d, %d)", name, folder, write, ret );
     473        if( errno )
     474            tr_err( "Couldn't open %s in %s: %s", name, folder, strerror(errno) );
     475        else
     476            tr_err( "Couldn't open %s in %s", name, folder );
    473477        return ret;
    474478    }
  • trunk/libtransmission/peer.c

    r2328 r2339  
    147147    tr_peertree_t       sentPeers;
    148148
    149     char                amChoking;
    150     char                amInterested;
    151     char                peerChoking;
    152     char                peerInterested;
     149    char                isChokedByUs;
     150    char                isChokingUs;
     151    char                isInteresting;
     152    char                isInterested;
    153153
    154154    int                 optimistic;
     
    239239    assert( 0 <= from && TR_PEER_FROM__MAX > from );
    240240
    241     peer              = tr_new0( tr_peer_t, 1 );
     241    peer                   = tr_new0( tr_peer_t, 1 );
     242    peer->isChokedByUs     = TRUE;
     243    peer->isChokingUs      = TRUE;
     244    peer->date             = tr_date();
     245    peer->keepAlive        = peer->date;
     246    peer->download         = tr_rcInit();
     247    peer->upload           = tr_rcInit();
    242248    peertreeInit( &peer->sentPeers );
    243     peer->amChoking   = TRUE;
    244     peer->peerChoking = TRUE;
    245     peer->date        = tr_date();
    246     peer->keepAlive   = peer->date;
    247     peer->download    = tr_rcInit();
    248     peer->upload      = tr_rcInit();
    249249
    250250    peer->inRequestMax = peer->inRequestAlloc = 2;
     
    396396        if( NULL != tor )
    397397        {
    398             if( tr_peerAmInterested( peer ) && !tr_peerIsChoking( peer ) )
     398            if( peer->isInteresting && !peer->isChokingUs )
    399399            {
    400400                tor->activityDate = date;
     
    584584        peer->outDate     = date;
    585585       
    586         if( !tr_peerAmChoking( peer ) )
     586        if( !tr_peerIsChokedByUs( peer ) )
    587587            tor->activityDate = date;
    588588
     
    595595    /* Ask for a block whenever possible */
    596596    if( !isSeeding
    597         && !peer->amInterested
     597        && !peer->isInteresting
    598598        && tor->peerCount > TR_MAX_PEER_COUNT - 2 )
    599599    {
     
    604604    }
    605605
    606     if(     peer->amInterested
    607         && !peer->peerChoking
     606    if(     peer->isInteresting
     607        && !peer->isChokingUs
    608608        && !peer->banned
    609609        &&  peer->inRequestCount < peer->inRequestMax )
     
    657657}
    658658
    659 int tr_peerAmChoking( const tr_peer_t * peer )
    660 {
    661     return peer->amChoking;
    662 }
    663 int tr_peerAmInterested( const tr_peer_t * peer )
    664 {
    665     return peer->amInterested;
    666 }
    667 int tr_peerIsChoking( const tr_peer_t * peer )
    668 {
    669     return peer->peerChoking;
     659int tr_peerIsChokedByUs( const tr_peer_t * peer )
     660{
     661    return peer->isChokedByUs;
     662}
     663int tr_peerIsInteresting( const tr_peer_t * peer )
     664{
     665    return peer->isInteresting;
     666}
     667int tr_peerIsChokingUs( const tr_peer_t * peer )
     668{
     669    return peer->isChokingUs;
    670670}
    671671int tr_peerIsInterested( const tr_peer_t * peer )
    672672{
    673     return peer->peerInterested;
     673    return peer->isInterested;
    674674}
    675675
     
    777777            /* Full ban */
    778778            peer_dbg( "banned (%d / %d)", peer->goodPcs, peer->badPcs );
    779             peer->banned = 1;
    780             peer->peerInterested = 0;
     779            peer->banned = TRUE;
     780            peer->isInteresting = FALSE;
     781            peer->isInterested = FALSE;
    781782        }
    782783    }
  • trunk/libtransmission/peer.h

    r2231 r2339  
    4343int         tr_peerIsConnected     ( const tr_peer_t * );
    4444int         tr_peerIsFrom          ( const tr_peer_t * );
    45 int         tr_peerAmChoking       ( const tr_peer_t * );
    46 int         tr_peerAmInterested    ( const tr_peer_t * );
    47 int         tr_peerIsChoking       ( const tr_peer_t * );
    4845int         tr_peerTimesChoked     ( const tr_peer_t * );
     46int         tr_peerIsChokingUs     ( const tr_peer_t * );
     47int         tr_peerIsChokedByUs    ( const tr_peer_t * );
     48int         tr_peerIsInteresting   ( const tr_peer_t * );
    4949int         tr_peerIsInterested    ( const tr_peer_t * );
    5050float       tr_peerProgress        ( const tr_peer_t * );
  • trunk/libtransmission/peeraz.h

    r2325 r2339  
    6262#define azmsgCount()    ( (int)(sizeof( az_msgs ) / sizeof( az_msgs[0] ) ) )
    6363
    64 static inline int
     64static int
    6565azmsgIdIndex( int id )
    6666{
     
    8080}
    8181
    82 static inline int
     82static int
    8383azmsgNameIndex( const char * name, int len )
    8484{
     
    273273}
    274274
    275 static inline int
     275static int
    276276parseAZMessageHeader( tr_peer_t * peer, uint8_t * buf, int len,
    277277                      int * msgidret, int * msglenret )
     
    339339}
    340340
    341 static inline int
     341static int
    342342parseAZHandshake( tr_peer_t * peer, uint8_t * buf, int len )
    343343{
     
    454454}
    455455
    456 static inline int
     456static int
    457457parseAZPex( tr_torrent_t * tor, tr_peer_t * peer, uint8_t * buf, int len )
    458458{
  • trunk/libtransmission/peerext.h

    r2325 r2339  
    211211}
    212212
    213 static inline int
     213static int
    214214parseExtendedHandshake( tr_peer_t * peer, uint8_t * buf, int len )
    215215{
     
    277277}
    278278
    279 static inline int
     279static int
    280280parseUTPex( tr_torrent_t * tor, tr_peer_t * peer, uint8_t * buf, int len )
    281281{
  • trunk/libtransmission/peermessages.h

    r2310 r2339  
    116116        int            hdrlen;
    117117
    118         if( peer->amChoking )
     118        if( peer->isChokedByUs ) /* we don't want to send them anything */
    119119            return NULL;
    120120
     
    221221    getMessagePointer( peer, 0, id );
    222222
    223     peer->amChoking = yes;
     223    peer->isChokedByUs = yes;
    224224
    225225    if( !yes )
     
    246246    getMessagePointer( peer, 0, id );
    247247
    248     peer->amInterested = yes;
     248    peer->isInteresting = yes;
    249249
    250250    peer_dbg( "SEND %sinterested", yes ? "" : "un" );
  • trunk/libtransmission/peerparse.h

    r2313 r2339  
    3232 *
    3333 **********************************************************************/
    34 static inline int parseChoke( tr_torrent_t * tor, tr_peer_t * peer,
    35                               int len, int choking )
     34
     35static int parseChoke( tr_torrent_t  * tor,
     36                       tr_peer_t     * peer,
     37                       int             len,
     38                       int             choking )
    3639{
    3740    tr_request_t * r;
     
    4649    peer_dbg( "GET  %schoke", choking ? "" : "un" );
    4750
    48     peer->peerChoking = choking;
     51    peer->isChokingUs = choking;
    4952
    5053    if( choking )
     
    7881 *
    7982 **********************************************************************/
    80 static inline int parseInterested( tr_peer_t * peer, int len,
     83static int parseInterested( tr_peer_t * peer, int len,
    8184                                   int interested )
    8285{
     
    8992    peer_dbg( "GET  %sinterested", interested ? "" : "un" );
    9093
    91     peer->peerInterested = interested;
     94    peer->isInterested = interested;
    9295
    9396    return TR_OK;
     
    99102 *
    100103 **********************************************************************/
    101 static inline int parseHave( tr_torrent_t * tor, tr_peer_t * peer,
     104static int parseHave( tr_torrent_t * tor, tr_peer_t * peer,
    102105                             uint8_t * p, int len )
    103106{
     
    137140}
    138141
    139 static inline int parseBitfield( tr_torrent_t * tor, tr_peer_t * peer,
     142static int parseBitfield( tr_torrent_t * tor, tr_peer_t * peer,
    140143                                 uint8_t * p, int len )
    141144{
     
    192195}
    193196
    194 static inline int parseRequest( tr_torrent_t * tor, tr_peer_t * peer,
     197static int parseRequest( tr_torrent_t * tor, tr_peer_t * peer,
    195198                                uint8_t * p, int len )
    196199{
     
    205208    }
    206209
    207     if( peer->amChoking )
     210    if( peer->isChokedByUs )
    208211    {
    209212        /* Didn't he get it? */
     
    247250}
    248251
    249 static inline void updateRequests( tr_peer_t * peer, int index, int begin )
     252static void updateRequests( tr_peer_t * peer, int index, int begin )
    250253{
    251254    tr_request_t * r;
     
    279282}
    280283
    281 static inline int parsePiece( tr_torrent_t * tor, tr_peer_t * peer,
     284static int parsePiece( tr_torrent_t * tor, tr_peer_t * peer,
    282285                              uint8_t * p, int len )
    283286{
     
    380383}
    381384
    382 static inline int parseCancel( tr_torrent_t * tor, tr_peer_t * peer,
     385static int parseCancel( tr_torrent_t * tor, tr_peer_t * peer,
    383386                               uint8_t * p, int len )
    384387{
     
    425428}
    426429
    427 static inline int parsePort( tr_peer_t * peer, uint8_t * p, int len )
     430static int parsePort( tr_peer_t * peer, uint8_t * p, int len )
    428431{
    429432    in_port_t port;
     
    441444}
    442445
    443 static inline int
     446static int
    444447parseMessageHeader( tr_peer_t * peer, uint8_t * buf, int buflen,
    445448                    int * msgid, int * msglen )
     
    475478}
    476479
    477 static inline int parseMessage( tr_torrent_t * tor, tr_peer_t * peer,
     480static int parseMessage( tr_torrent_t * tor, tr_peer_t * peer,
    478481                                int id, uint8_t * p, int len )
    479482{
     
    540543}
    541544
    542 static inline int parseBufHeader( tr_peer_t * peer )
     545static int parseBufHeader( tr_peer_t * peer )
    543546{
    544547    static uint8_t badproto_http[] =
     
    598601}
    599602
    600 static inline int parseHandshake( tr_torrent_t * tor, tr_peer_t * peer )
     603static int parseHandshake( tr_torrent_t * tor, tr_peer_t * peer )
    601604{
    602605    tr_info_t * inf = &tor->info;
     
    655658}
    656659
    657 static inline int sendInitial( tr_torrent_t * tor, tr_peer_t * peer )
     660static int sendInitial( tr_torrent_t * tor, tr_peer_t * peer )
    658661{
    659662    if( PEER_STATUS_CONNECTED != peer->status )
     
    676679}
    677680
    678 static inline int parseBuf( tr_torrent_t * tor, tr_peer_t * peer )
     681static int parseBuf( tr_torrent_t * tor, tr_peer_t * peer )
    679682{
    680683    int       len, ret, msgid;
  • trunk/libtransmission/peertree.h

    r1579 r2339  
    4141#define peertreeFind(tree, item) RB_FIND(  tr_peertree_s, (tree), (item) )
    4242
    43 static inline int
     43static int
    4444peertreekeycmp( tr_peertree_entry_t * aa, tr_peertree_entry_t * bb )
    4545{
  • trunk/libtransmission/peerutils.h

    r2316 r2339  
    220220    return 0;
    221221}
    222 static void updateInterest( tr_torrent_t * tor, tr_peer_t * peer )
    223 {
    224     int interested = isInteresting( tor, peer );
    225 
    226     if( interested && !peer->amInterested )
    227     {
    228         sendInterest( peer, 1 );
    229     }
    230     if( !interested && peer->amInterested )
    231     {
    232         sendInterest( peer, 0 );
    233     }
     222
     223static void
     224updateInterest( tr_torrent_t * tor, tr_peer_t * peer )
     225{
     226    const int i = !!isInteresting( tor, peer );
     227
     228    if( i != peer->isInteresting )
     229        sendInterest( peer, i );
    234230}
    235231
  • trunk/libtransmission/torrent.c

    r2334 r2339  
    550550    for( i=0; i<tor->peerCount; ++i ) {
    551551        const tr_peer_t * peer = tor->peers[i];
    552             ++s->peersTotal;
     552        ++s->peersTotal;
    553553        if( tr_peerIsConnected( peer ) ) {
    554554            ++s->peersFrom[tr_peerIsFrom(peer)];
    555             if( tr_peerAmInterested( peer ) && !tr_peerIsChoking( peer ) )
     555            if( tr_peerIsInterested( peer ) && !tr_peerIsChokedByUs( peer ) )
    556556                ++s->peersUploading;
    557             if( !tr_peerAmChoking( peer ) )
     557            if( tr_peerIsInteresting( peer ) && !tr_peerIsChokingUs( peer ) )
    558558                ++s->peersDownloading;
    559559        }
     
    631631        struct in_addr * addr;
    632632        int i;
    633         for( i = 0; i < tor->peerCount; i++ )
     633        for( i=0; i<tor->peerCount; ++i )
    634634        {
    635635            peer = tor->peers[i];
     
    642642            }
    643643           
    644             peers[i].client        = tr_peerClient( peer );
    645             peers[i].isConnected   = tr_peerIsConnected( peer );
    646             peers[i].from          = tr_peerIsFrom( peer );
    647             peers[i].progress      = tr_peerProgress( peer );
    648             peers[i].port          = tr_peerPort( peer );
    649            
    650             if( ( peers[i].isDownloading = !tr_peerAmChoking( peer ) ) )
    651             {
    652                 peers[i].uploadToRate = tr_peerUploadRate( peer );
    653             }
    654             if( ( peers[i].isUploading = ( tr_peerAmInterested( peer ) &&
    655                                            !tr_peerIsChoking( peer ) ) ) )
    656             {
    657                 peers[i].downloadFromRate = tr_peerDownloadRate( peer );
    658             }
     644            peers[i].client           =  tr_peerClient( peer );
     645            peers[i].isConnected      =  tr_peerIsConnected( peer );
     646            peers[i].from             =  tr_peerIsFrom( peer );
     647            peers[i].progress         =  tr_peerProgress( peer );
     648            peers[i].port             =  tr_peerPort( peer );
     649            peers[i].isDownloading    = !tr_peerIsChokingUs( peer );
     650            peers[i].uploadToRate     =  tr_peerUploadRate( peer );
     651            peers[i].isUploading      = !tr_peerIsChokedByUs( peer );
     652            peers[i].downloadFromRate =  tr_peerDownloadRate( peer );
    659653        }
    660654    }
  • trunk/mk/lib.mk

    r2325 r2339  
    44include ../mk/common.mk
    55
    6 SRCS = basename.c bencode.c choking.c clients.c completion.c dirname.c \
    7        fastresume.c fdlimit.c http.c inout.c ipcparse.c list.c makemeta.c \
    8        metainfo.c natpmp.c net.c peer.c platform.c ratecontrol.c sha1.c \
    9        shared.c strlcat.c strlcpy.c torrent.c tracker.c transmission.c \
    10        upnp.c utils.c xml.c
     6SRCS = \
     7  basename.c \
     8  bencode.c \
     9  choking.c \
     10  clients.c \
     11  completion.c \
     12  dirname.c \
     13  fastresume.c \
     14  fdlimit.c \
     15  http.c \
     16  inout.c \
     17  ipcparse.c \
     18  list.c \
     19  makemeta.c \
     20  metainfo.c \
     21  natpmp.c \
     22  net.c \
     23  peer.c \
     24  platform.c \
     25  ratecontrol.c \
     26  sha1.c \
     27  shared.c \
     28  strlcat.c \
     29  strlcpy.c \
     30  torrent.c \
     31  tracker.c \
     32  transmission.c \
     33  upnp.c \
     34  utils.c \
     35  xml.c
    1136
    1237OBJS = $(SRCS:%.c=%.o)
Note: See TracChangeset for help on using the changeset viewer.