Changeset 3116


Ignore:
Timestamp:
Sep 20, 2007, 11:07:36 PM (15 years ago)
Author:
charles
Message:

if we're seeding, disconnect from other seeds (part 1 of 2)

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr-private.h

    r3105 r3116  
    2929    unsigned int  clientIsInterested : 1;
    3030    unsigned int  peerSupportsEncryption : 1;
     31    unsigned int  doDisconnect : 1;
    3132
    3233    struct in_addr in_addr;
  • trunk/libtransmission/peer-mgr.c

    r3105 r3116  
    523523
    524524static void
    525 msgsCallbackFunc( void * source UNUSED, void * vevent, void * vt )
    526 {
     525msgsCallbackFunc( void * vpeer, void * vevent, void * vt )
     526{
     527    tr_peer * peer = vpeer;
    527528    Torrent * t = (Torrent *) vt;
    528529    const tr_peermsgs_event * e = (const tr_peermsgs_event *) vevent;
     
    541542            break;
    542543
     544        case TR_PEERMSG_PEER_PROGRESS: { /* if we're both seeds, then disconnect. */
     545            const int clientIsSeed = tr_cpGetStatus( t->tor->completion ) != TR_CP_INCOMPLETE;
     546            const int peerIsSeed = e->progress >= 1.0;
     547            if( clientIsSeed && peerIsSeed ) {
     548                fprintf( stderr, "DISCONNECTING FROM PEER because both of us are seeds\n" );
     549                peer->doDisconnect = 1;
     550            }
     551            break;
     552        }
     553
    543554        case TR_PEERMSG_CLIENT_BLOCK:
    544555            broadcastGotBlock( t, e->pieceIndex, e->offset, e->length );
     
    546557
    547558        case TR_PEERMSG_GOT_ERROR:
    548             /* FIXME */
     559            peer->doDisconnect = 1;
    549560            break;
    550561
  • trunk/libtransmission/peer-msgs.c

    r3105 r3116  
    155155**/
    156156
    157 static const tr_peermsgs_event blankEvent = { 0, 0, 0, 0 };
    158 
    159 static void
    160 publishEvent( tr_peermsgs * peer, int eventType )
     157static const tr_peermsgs_event blankEvent = { 0, 0, 0, 0, 0.0f };
     158
     159static void
     160publish( tr_peermsgs * msgs, tr_peermsgs_event * e )
     161{
     162    tr_publisherPublish( msgs->publisher, msgs->info, e );
     163}
     164
     165static void
     166fireGotError( tr_peermsgs * msgs )
    161167{
    162168    tr_peermsgs_event e = blankEvent;
    163     e.eventType = eventType;
    164     tr_publisherPublish( peer->publisher, peer, &e );
     169    e.eventType = TR_PEERMSG_GOT_ERROR;
     170    publish( msgs, &e );
    165171}
    166172
     
    170176    tr_peermsgs_event e = blankEvent;
    171177    e.eventType = TR_PEERMSG_NEED_REQ;
    172     tr_publisherPublish( msgs->publisher, msgs, &e );
     178    publish( msgs, &e );
     179}
     180
     181static void
     182firePeerProgress( tr_peermsgs * msgs )
     183{
     184    tr_peermsgs_event e = blankEvent;
     185    e.eventType = TR_PEERMSG_PEER_PROGRESS;
     186    e.progress = msgs->info->progress;
     187    publish( msgs, &e );
    173188}
    174189
     
    179194    e.eventType = TR_PEERMSG_CLIENT_HAVE;
    180195    e.pieceIndex = pieceIndex;
    181     tr_publisherPublish( msgs->publisher, msgs, &e );
    182 }
    183 
    184 static void
    185 fireGotBlock( tr_peermsgs * peer, uint32_t pieceIndex, uint32_t offset, uint32_t length )
     196    publish( msgs, &e );
     197}
     198
     199static void
     200fireGotBlock( tr_peermsgs * msgs, uint32_t pieceIndex, uint32_t offset, uint32_t length )
    186201{
    187202    tr_peermsgs_event e = blankEvent;
     
    190205    e.offset = offset;
    191206    e.length = length;
    192     tr_publisherPublish( peer->publisher, peer, &e );
    193 }
    194 
    195 static void
    196 fireGotError( tr_peermsgs * peer )
    197 {
    198     publishEvent( peer, TR_PEERMSG_GOT_ERROR );
     207    publish( msgs, &e );
    199208}
    200209
     
    648657            dbgmsg( msgs, "after the HAVE message, peer progress is %f", msgs->info->progress );
    649658            updateInterest( msgs );
     659            firePeerProgress( msgs );
    650660            break;
    651661
     
    658668            updateInterest( msgs );
    659669            fireNeedReq( msgs );
    660             /* FIXME: maybe unchoke */
     670            firePeerProgress( msgs );
    661671            break;
    662672
     
    10351045gotError( struct bufferevent * evbuf UNUSED, short what UNUSED, void * vpeer )
    10361046{
    1037     fireGotError( (tr_peermsgs*)vpeer );
     1047    fireGotError( vpeer );
    10381048}
    10391049
  • trunk/libtransmission/peer-msgs.h

    r3105 r3116  
    5959    TR_PEERMSG_CLIENT_HAVE,
    6060    TR_PEERMSG_CLIENT_BLOCK,
     61    TR_PEERMSG_PEER_PROGRESS,
    6162    TR_PEERMSG_GOT_ERROR,
    6263    TR_PEERMSG_NEED_REQ
     
    7071    uint32_t offset;     /* for TR_PEERMSG_GOT_BLOCK */
    7172    uint32_t length;     /* for TR_PEERMSG_GOT_BLOCK */
     73    float progress;      /* for TR_PEERMSG_PEER_PROGRESS */
    7274}
    7375tr_peermsgs_event;
Note: See TracChangeset for help on using the changeset viewer.