Ignore:
Timestamp:
Apr 19, 2008, 3:07:59 PM (14 years ago)
Author:
charles
Message:

#890: be smarter about noticing seeds from tracker & pex

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/tracker.c

    r5626 r5647  
    222222***/
    223223
    224 static const tr_tracker_event emptyEvent = { 0, NULL, NULL, NULL, 0 };
     224static const tr_tracker_event emptyEvent = { 0, NULL, NULL, NULL, 0, 0 };
    225225
    226226static void
     
    257257
    258258static void
    259 publishNewPeers( tr_tracker * t, int count, uint8_t * peers )
     259publishNewPeers( tr_tracker * t, int allAreSeeds, void * compact, int compactLen )
    260260{
    261261    tr_tracker_event event = emptyEvent;
    262262    event.hash = t->hash;
    263263    event.messageType = TR_TRACKER_PEERS;
    264     event.peerCount = count;
    265     event.peerCompact = peers;
    266     tr_ndbg( t->name, "Torrent got %d new peers", count );
    267     if( count )
     264    event.allAreSeeds = allAreSeeds;
     265    event.compact = compact;
     266    event.compactLen = compactLen;
     267    if( compactLen )
    268268        tr_publisherPublish( t->publisher, t, &event );
    269269}
     
    361361/* Convert to compact form */
    362362static uint8_t *
    363 parseOldPeers( tr_benc * bePeers, int * setmePeerCount )
     363parseOldPeers( tr_benc * bePeers, size_t * byteCount )
    364364{
    365365    int i;
     
    394394    }
    395395
    396     *setmePeerCount = peerCount;
     396    *byteCount = peerCount * 6;
    397397    return compact;
    398398}
     
    433433        {
    434434            tr_benc * tmp;
     435            int incomplete = -1;
    435436
    436437            if(( tmp = tr_bencDictFind( &benc, "failure reason" ))) {
     
    461462
    462463            if(( tmp = tr_bencDictFind( &benc, "incomplete" )))
    463                 t->leecherCount = tmp->val.i;
     464                t->leecherCount = incomplete = tmp->val.i;
    464465
    465466            if(( tmp = tr_bencDictFind( &benc, "peers" )))
    466467            {
    467                 int peerCount = 0;
    468                 uint8_t * peerCompact = NULL;
    469 
    470                 if( tmp->type == TYPE_LIST ) /* original protocol */
     468                const int allAreSeeds = incomplete == 0;
     469
     470                if( tmp->type == TYPE_STR ) /* "compact" extension */
    471471                {
    472                     if( tmp->val.l.count > 0 )
    473                         peerCompact = parseOldPeers( tmp, &peerCount );
     472                    publishNewPeers( t, allAreSeeds, tmp->val.s.s, tmp->val.s.i );
    474473                }
    475                 else if( tmp->type == TYPE_STR ) /* "compact" extension */
     474                else if( tmp->type == TYPE_LIST ) /* original protocol */
    476475                {
    477                     if( tmp->val.s.i >= 6 )
    478                     {
    479                         peerCount = tmp->val.s.i / 6;
    480                         peerCompact = tr_new( uint8_t, tmp->val.s.i );
    481                         memcpy( peerCompact, tmp->val.s.s, tmp->val.s.i );
    482                     }
     476                    size_t byteCount = 0;
     477                    uint8_t * compact = parseOldPeers( tmp, &byteCount );
     478                    publishNewPeers( t, allAreSeeds, compact, byteCount );
     479                    tr_free( compact );
    483480                }
    484 
    485                 publishNewPeers( t, peerCount, peerCompact );
    486                 tr_free( peerCompact );
    487481            }
    488482        }
Note: See TracChangeset for help on using the changeset viewer.