Changeset 3076


Ignore:
Timestamp:
Sep 15, 2007, 8:36:46 PM (16 years ago)
Author:
charles
Message:
  • better pex handling. we now support uTorrent's added.f flags for the first time ever...
  • fix bugs in tr_set_compare
  • if the torrent has `pexDisabled' set, don't give or recieve pex messages.
Location:
branches/encryption/libtransmission
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/encryption/libtransmission/handshake.c

    r3065 r3076  
    7979struct tr_handshake
    8080{
     81    unsigned int peerSupportsEncryption : 1;
    8182    tr_peerIo * io;
    8283    tr_crypto * crypto;
     
    451452
    452453    fprintf( stderr, "got a %s handshake\n", (isEncrypted ? "encrypted" : "plaintext") );
     454    handshake->peerSupportsEncryption = isEncrypted;
    453455    tr_peerIoSetEncryption( handshake->io, isEncrypted
    454456        ? PEER_ENCRYPTION_RC4
     
    657659        EVBUFFER_DATA(inbuf)[3] );
    658660    isEncrypted = pstrlen != 19;
     661    handshake->peerSupportsEncryption = isEncrypted;
    659662    tr_peerIoSetEncryption( handshake->io, isEncrypted
    660663        ? PEER_ENCRYPTION_RC4
     
    798801        ? handshake->peer_id
    799802        : NULL;
    800 fprintf( stderr, "handshake %p: firing done.  connected==%d\n", handshake, isConnected );
    801     (*handshake->doneCB)(handshake, handshake->io, isConnected, peer_id, handshake->doneUserData);
     803    (*handshake->doneCB)( handshake,
     804                          handshake->io,
     805                          isConnected,
     806                          peer_id,
     807                          handshake->peerSupportsEncryption,
     808                          handshake->doneUserData );
    802809    tr_handshakeFree( handshake );
    803810}
  • branches/encryption/libtransmission/handshake.h

    r3061 r3076  
    2929                                int                   isConnected,
    3030                                const uint8_t       * peerId,
     31                                int                   peerSupportsEncryption,
    3132                                void                * userData );
    3233
  • branches/encryption/libtransmission/internal.h

    r3072 r3076  
    149149    uint64_t                   startDate;
    150150    uint64_t                   stopDate;
    151     char                       ioLoaded;
    152151
    153152    uint64_t                   downloadedCur;
  • branches/encryption/libtransmission/peer-mgr-private.h

    r3070 r3076  
    2424typedef struct tr_peer
    2525{
    26     unsigned int  pexEnabled : 1;
    2726    unsigned int  peerIsChoked : 1;
    2827    unsigned int  peerIsInterested : 1;
    2928    unsigned int  clientIsChoked : 1;
    3029    unsigned int  clientIsInterested : 1;
     30    unsigned int  peerSupportsEncryption : 1;
    3131
    3232    struct in_addr in_addr;
    3333    uint16_t port;
    3434    struct tr_peerIo * io;
    35     int from;
     35    uint8_t from;
    3636
    3737    struct tr_bitfield * banned;
     
    4747    struct tr_peermsgs * msgs;
    4848    tr_publisher_tag msgsTag;
    49 
    50     struct tr_pex * lastPex;
    51     int lastPexCount;
    5249}
    5350tr_peer;
  • branches/encryption/libtransmission/peer-mgr.c

    r3072 r3076  
    520520                   int               isConnected,
    521521                   const uint8_t   * peer_id,
     522                   int               peerSupportsEncryption,
    522523                   void            * vmanager )
    523524{
     
    531532
    532533    assert( io != NULL );
     534    assert( isConnected==0 || isConnected==1 );
     535    assert( peerSupportsEncryption==0 || peerSupportsEncryption==1 );
    533536
    534537    ours = tr_ptrArrayRemoveSorted( manager->handshakes,
     
    581584            peer->msgs = tr_peerMsgsNew( t->tor, peer );
    582585            peer->client = peer_id ? tr_clientForId( peer_id ) : NULL;
     586            peer->peerSupportsEncryption = peerSupportsEncryption ? 1 : 0;
    583587            fprintf( stderr, "PUB sub peer %p to msgs %p\n", peer, peer->msgs );
    584588            peer->msgsTag = tr_peerMsgsSubscribe( peer->msgs, msgsCallbackFunc, t );
     
    723727    for( i=0; i<peerCount; ++i, ++walk )
    724728    {
    725         walk->in_addr = peers[i]->in_addr;
    726         walk->port = peers[i]->port;
    727         walk->flags = '\0'; /* FIXME */
     729        const tr_peer * peer = peers[i];
     730
     731        walk->in_addr = peer->in_addr;
     732
     733        walk->port = peer->port;
     734
     735        walk->flags = 0;
     736        if( peer->peerSupportsEncryption ) walk->flags |= 1;
     737        if( peer->progress >= 1.0 )        walk->flags |= 2;
    728738    }
    729739
     
    909919}
    910920
    911 void
    912 tr_peerMgrDisablePex( tr_peerMgr    * manager,
    913                       const uint8_t * torrentHash,
    914                       int             disable)
    915 {
    916     Torrent * t = getExistingTorrent( manager, torrentHash );
    917     tr_torrent * tor = t->tor;
    918 
    919     if( ( tor->pexDisabled != disable ) && ! ( TR_FLAG_PRIVATE & tor->info.flags ) )
    920     {
    921         int i, size;
    922         tr_peer ** peers = (tr_peer **) tr_ptrArrayPeek( t->peers, &size );
    923         for( i=0; i<size; ++i )
    924             peers[i]->pexEnabled = disable ? 0 : 1;
    925 
    926         tor->pexDisabled = disable;
    927     }
    928 }
    929 
    930921/**
    931922***
  • branches/encryption/libtransmission/peer-mgr.h

    r2989 r3076  
    8080                               const uint8_t  * torrentHash );
    8181
    82 void tr_peerMgrDisablePex( tr_peerMgr    * manager,
    83                            const uint8_t * torrentHash,
    84                            int             disable );
    85 
    8682void tr_peerMgrTorrentAvailability( const tr_peerMgr * manager,
    8783                                    const uint8_t    * torrentHash,
  • branches/encryption/libtransmission/peer-msgs.c

    r3070 r3076  
    3939**/
    4040
    41 #define MINUTES_TO_MSEC(N) ((N) * 60 * 1000)
    42 
    43 /* pex attempts are made this frequently */
    44 #define PEX_INTERVAL (MINUTES_TO_MSEC(1))
    45 
    46 #define PEER_PULSE_INTERVAL_MSEC 50
     41#define PEX_INTERVAL (60 * 1000)
     42
     43#define PEER_PULSE_INTERVAL (50)
    4744
    4845enum
     
    9188struct tr_peermsgs
    9289{
    93     uint8_t state;
    94 
    9590    tr_peer * info;
    9691
     
    110105    tr_timer * pexTimer;
    111106
    112     unsigned int  notListening        : 1;
     107    unsigned int notListening    : 1;
     108    unsigned int peerSupportsPex : 1;
    113109
    114110    struct peer_request blockToUs; /* the block currntly being sent to us */
    115 
    116     uint32_t incomingMessageLength;
    117111
    118112    time_t gotKeepAliveTime;
    119113    time_t clientSentPexAt;
    120114
     115    uint8_t state;
     116
    121117    uint8_t ut_pex_id;
    122118    uint16_t listeningPort;
    123119
    124120    uint16_t pexCount;
     121
     122    uint32_t incomingMessageLength;
     123
    125124    tr_pex * pex;
    126125};
     
    269268    assert( msgs != NULL );
    270269    assert( msgs->info != NULL );
    271 
    272     if( msgs->info->peerIsChoked != !!choke )
     270    assert( choke==0 || choke==1 );
     271
     272    if( msgs->info->peerIsChoked != choke )
    273273    {
    274274        const uint32_t len = sizeof(uint8_t);
     
    411411        sub = tr_bencDictFind( sub, "ut_pex" );
    412412        if( tr_bencIsInt( sub ) ) {
     413            peer->peerSupportsPex = 1;
    413414            peer->ut_pex_id = (uint8_t) sub->val.i;
    414415            fprintf( stderr, "peer->ut_pex is %d\n", (int)peer->ut_pex_id );
     
    416417    }
    417418
     419#if 0
    418420    /* get peer's client name */
    419421    sub = tr_bencDictFind( &val, "v" );
     
    427429        fprintf( stderr, "peer->client is now [%s]\n", peer->info->client );
    428430    }
     431#endif
    429432
    430433    /* get peer's listening port */
     
    440443
    441444static void
    442 parseUtPex( tr_peermsgs * peer, int msglen, struct evbuffer * inbuf )
     445parseUtPex( tr_peermsgs * msgs, int msglen, struct evbuffer * inbuf )
    443446{
    444447    benc_val_t val, * sub;
    445448    uint8_t * tmp;
    446449
    447     if( !peer->info->pexEnabled ) /* no sharing! */
     450    if( msgs->torrent->pexDisabled ) /* no sharing! */
    448451        return;
    449452
     
    461464        const int n = sub->val.s.i / 6 ;
    462465        fprintf( stderr, "got %d peers from uT pex\n", n );
    463         tr_peerMgrAddPeers( peer->handle->peerMgr,
    464                             peer->torrent->info.hash,
     466        tr_peerMgrAddPeers( msgs->handle->peerMgr,
     467                            msgs->torrent->info.hash,
    465468                            TR_PEER_FROM_PEX,
    466469                            (uint8_t*)sub->val.s.s, n );
    467470    }
    468471
    469     fireGotPex( peer );
     472    fireGotPex( msgs );
    470473
    471474    tr_bencFree( &val );
     
    492495    {
    493496        fprintf( stderr, "got ut pex\n" );
    494         msgs->info->pexEnabled = 1;
     497        msgs->peerSupportsPex = 1;
    495498        parseUtPex( msgs, msglen, inbuf );
    496         //sendPex( msgs );
    497499    }
    498500    else
     
    980982PexDiffs;
    981983
    982 static void pexAddedCb( void * vpex, void * userData )
     984static void
     985pexAddedCb( void * vpex, void * userData )
    983986{
    984987    PexDiffs * diffs = (PexDiffs *) userData;
     
    992995}
    993996
    994 static void pexRemovedCb( void * vpex, void * userData )
     997static void
     998pexRemovedCb( void * vpex, void * userData )
    995999{
    9961000    PexDiffs * diffs = (PexDiffs *) userData;
     
    10031007}
    10041008
    1005 static void pexElementCb( void * vpex, void * userData )
     1009static void
     1010pexElementCb( void * vpex, void * userData )
    10061011{
    10071012    PexDiffs * diffs = (PexDiffs *) userData;
     
    10171022sendPex( tr_peermsgs * msgs )
    10181023{
    1019     if( msgs->info->pexEnabled )
     1024    if( msgs->peerSupportsPex && !msgs->torrent->pexDisabled )
    10201025    {
    10211026        int i;
     
    10661071        flags = tr_bencDictAdd( &val, "added.f" );
    10671072        tmp = walk = tr_new( uint8_t, diffs.addedCount );
    1068         for( i=0; i<diffs.addedCount; ++i )
     1073        for( i=0; i<diffs.addedCount; ++i ) {
     1074            fprintf( stderr, "PEX -->> -->> flag is %d\n", (int)diffs.added[i].flags );
    10691075            *walk++ = diffs.added[i].flags;
     1076        }
    10701077        assert( ( walk - tmp ) == diffs.addedCount );
    10711078        tr_bencInitStr( flags, tmp, walk-tmp, FALSE );
     
    11291136    peer->info->peerIsInterested = 0;
    11301137    peer->info->have = tr_bitfieldNew( torrent->info.pieceCount );
    1131     peer->pulseTimer = tr_timerNew( peer->handle, pulse, peer, PEER_PULSE_INTERVAL_MSEC );
     1138    peer->pulseTimer = tr_timerNew( peer->handle, pulse, peer, PEER_PULSE_INTERVAL );
    11321139    peer->pexTimer = tr_timerNew( peer->handle, pexPulse, peer, PEX_INTERVAL );
    11331140    peer->outMessages = evbuffer_new( );
  • branches/encryption/libtransmission/torrent.c

    r3072 r3076  
    677677}
    678678
    679 /***********************************************************************
    680  * torrentReallyStop
    681  ***********************************************************************
    682  * Joins the download thread and frees/closes everything related to it.
    683  **********************************************************************/
    684 
    685 void tr_torrentDisablePex( tr_torrent * tor, int disable )
    686 {
    687     tr_torrentLock( tor );
    688 
    689     if( ! ( TR_FLAG_PRIVATE & tor->info.flags ) )
    690     {
    691         if( tor->pexDisabled != disable )
    692         {
    693             tor->pexDisabled = disable;
    694             tr_peerMgrDisablePex( tor->handle->peerMgr,
    695                                   tor->info.hash,
    696                                   tor->pexDisabled );
    697         }
    698     }
    699 
    700     tr_torrentUnlock( tor );
     679
     680void
     681tr_torrentDisablePex( tr_torrent * tor, int disable )
     682{
     683    assert( tor != NULL );
     684    assert( disable==0 || disable==1 );
     685    //assert( tor->runStatus != TR_RUN_RUNNING );
     686
     687    /* pex is ALWAYS disabled for private torrents */
     688    if( tor->info.flags & TR_FLAG_PRIVATE )
     689        disable = TRUE;
     690
     691    tor->pexDisabled = disable;
    701692}
    702693
  • branches/encryption/libtransmission/utils.c

    r3049 r3076  
    200200                void * userData )
    201201{
    202     size_t ai, bi;
    203202    const uint8_t * a = (const uint8_t *) va;
    204203    const uint8_t * b = (const uint8_t *) vb;
    205 
    206     for( ai=bi=0; ai<aCount && bi<bCount; )
    207     {
    208         if( ai==aCount )
     204    const uint8_t * aend = a + elementSize*aCount;
     205    const uint8_t * bend = b + elementSize*bCount;
     206
     207    while( a!=aend || b!=bend )
     208    {
     209        if( a==aend )
    209210        {
    210211            (*in_b_cb)( (void*)b, userData );
    211212            b += elementSize;
    212213        }
    213         else if ( bi==bCount )
     214        else if ( b==bend )
    214215        {
    215216            (*in_a_cb)( (void*)a, userData );
Note: See TracChangeset for help on using the changeset viewer.