Changeset 5632


Ignore:
Timestamp:
Apr 17, 2008, 3:48:56 AM (14 years ago)
Author:
charles
Message:

(1) fix choke/unchoke error. (2) if a peer keeps trying to reconnect to us, hang up during the handshake.

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/handshake.c

    r5065 r5632  
    2727#include "handshake.h"
    2828#include "peer-io.h"
     29#include "peer-mgr.h"
    2930#include "torrent.h"
    3031#include "trevent.h"
     
    811812    for( i=0; i<SHA_DIGEST_LENGTH; ++i )
    812813        obfuscatedTorrentHash[i] = req2[i] ^ req3[i];
    813     tor = tr_torrentFindFromObfuscatedHash( handshake->handle, obfuscatedTorrentHash );
    814     if( tor != NULL ) {
     814    if(( tor = tr_torrentFindFromObfuscatedHash( handshake->handle, obfuscatedTorrentHash )))
     815    {
    815816        dbgmsg( handshake, "found the torrent; it's [%s]", tor->info.name );
    816817        tr_peerIoSetTorrentHash( handshake->io, tor->info.hash );
    817     } else {
     818        if( !tr_torrentAllowsPex( tor ) &&
     819            tr_peerMgrPeerIsSeed( handshake->handle->peerMgr,
     820                                  tor->info.hash,
     821                                  tr_peerIoGetAddress( handshake->io, NULL )))
     822        {
     823            dbgmsg( handshake, "a peer has tried to reconnect to us!" );
     824            tr_handshakeDone( handshake, FALSE );
     825            return READ_DONE;
     826        }
     827    }
     828    else
     829    {
    818830        dbgmsg( handshake, "can't find that torrent..." );
    819831        tr_handshakeDone( handshake, FALSE );
  • trunk/libtransmission/peer-mgr.c

    r5587 r5632  
    557557{
    558558    return peer->peerIsInterested && !peer->peerIsChoked;
     559}
     560
     561/***
     562****
     563***/
     564
     565int
     566tr_peerMgrPeerIsSeed( const tr_peerMgr       * mgr,
     567                      const uint8_t          * torrentHash,
     568                      const struct in_addr   * addr )
     569{
     570    int isSeed = FALSE;
     571    const Torrent * t = NULL;
     572    const struct peer_atom * atom = NULL;
     573
     574    t = getExistingTorrent( (tr_peerMgr*)mgr, torrentHash );
     575    if( t )
     576        atom = getExistingAtom( t, addr );
     577    if( atom )
     578        isSeed = ( atom->flags & ADDED_F_SEED_FLAG ) != 0;
     579
     580    return isSeed;
    559581}
    560582
  • trunk/libtransmission/peer-mgr.h

    r4597 r5632  
    4141
    4242void tr_peerMgrFree( tr_peerMgr * manager );
     43
     44int tr_peerMgrPeerIsSeed( const tr_peerMgr      * mgr,
     45                          const uint8_t         * torrentHash,
     46                          const struct in_addr  * addr );
    4347
    4448void tr_peerMgrAddIncoming( tr_peerMgr      * manager,
  • trunk/libtransmission/peer-msgs.c

    r5631 r5632  
    12791279        case BT_BITFIELD: {
    12801280            const int clientIsSeed = tr_torrentIsSeed( msgs->torrent );
     1281            int peerIsSeed;
    12811282            dbgmsg( msgs, "got a bitfield" );
    12821283            msgs->peerSentBitfield = 1;
     
    12841285            updatePeerProgress( msgs );
    12851286            maybeSendFastAllowedSet( msgs );
    1286             tr_peerMsgsSetChoke( msgs, !clientIsSeed || (msgs->info->progress<1.0) );
     1287            peerIsSeed = msgs->info->progress >= 1.0;
     1288            tr_peerMsgsSetChoke( msgs, clientIsSeed && peerIsSeed );
    12871289            fireNeedReq( msgs );
    12881290            break;
Note: See TracChangeset for help on using the changeset viewer.