Changeset 1161


Ignore:
Timestamp:
Dec 6, 2006, 9:09:56 PM (15 years ago)
Author:
livings124
Message:

use array of pointers for the addresses

Location:
branches/multitracker/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/multitracker/libtransmission/metainfo.c

    r1160 r1161  
    8787    benc_val_t   meta, * beInfo, * list, * val, * sublist;
    8888    char       * address, * announce;
    89     int          i, j, k, tiers, inTier, port, random;
     89    int          i, j, k, tiersSet, tiers, inTier, port, random;
    9090    struct stat sb;
    91     tr_announce_list_item_t * announceItem, * lastAnnounceItem;
     91    tr_announce_list_item_t * announceItem, * prevAnnounceItem, * nextAnnounceItem;
    9292
    9393    assert( NULL == path || NULL == savedHash );
     
    195195    announce = calloc( sizeof( char ), MAX_PATH_LENGTH );
    196196   
     197    tiersSet = 0;
    197198    if( ( val = tr_bencDictFind( &meta, "announce-list" ) ) )
    198199    {
    199200        list = val->val.l.vals;
    200201       
    201         inf->trackerAnnounceList = calloc( sizeof( tr_announce_list_item_t ), val->val.l.count );
     202        inf->trackerAnnounceList = calloc( sizeof( int ), val->val.l.count );
     203        tiersSet = 1;
    202204       
    203205        tiers = 0;
     
    214216                }
    215217               
    216                 if( inTier == 0 )
     218                /* Shuffle order of sublist */
     219                random = tr_rand( inTier+1 );
     220               
     221                announceItem = calloc( sizeof( tr_announce_list_item_t ), 1 );
     222                prevAnnounceItem = 0;
     223                nextAnnounceItem = inf->trackerAnnounceList[tiers];
     224                for( k = 0; k < random; k++ )
    217225                {
    218                     announceItem = & inf->trackerAnnounceList[tiers];
     226                    prevAnnounceItem = nextAnnounceItem;
     227                    nextAnnounceItem = nextAnnounceItem->nextItem;
     228                }
     229               
     230                announceItem->nextItem = nextAnnounceItem;
     231                if( prevAnnounceItem )
     232                {
     233                    prevAnnounceItem->nextItem = announceItem;
    219234                }
    220235                else
    221236                {
    222                     announceItem = calloc( sizeof( tr_announce_list_item_t ), 1 );
    223                    
    224                     /* Shuffle order of tier addresses */
    225                     random = tr_rand( inTier + 1 );
    226                     if( random == 0 )
    227                     {
    228                         *announceItem = inf->trackerAnnounceList[tiers];
    229                         inf->trackerAnnounceList[tiers].nextItem = announceItem;
    230                         announceItem = & inf->trackerAnnounceList[tiers];
    231                     }
    232                     else
    233                     {
    234                         lastAnnounceItem = & inf->trackerAnnounceList[tiers];
    235                         for( k = 0; k < random - 1; k++ )
    236                         {
    237                             lastAnnounceItem = lastAnnounceItem->nextItem;
    238                         }
    239                        
    240                         announceItem->nextItem = lastAnnounceItem->nextItem;
    241                         lastAnnounceItem->nextItem = announceItem;
    242                     }
     237                    inf->trackerAnnounceList[tiers] = announceItem;
    243238                }
    244239               
     240                /* Set values */
    245241                snprintf( announceItem->address, 256, "%s", address );
    246242                announceItem->port = port;
     
    251247           
    252248            /* Only use tier if there are useable addresses */
    253             if (inTier)
     249            if( inTier > 0 )
    254250            {
    255251                tiers++;
     
    264260    {
    265261        tr_err( "list %d:", i );
    266         for (announceItem = & inf->trackerAnnounceList[i]; announceItem != NULL; announceItem = announceItem->nextItem)
     262        for (announceItem = inf->trackerAnnounceList[i]; announceItem != NULL; announceItem = announceItem->nextItem)
    267263        {
    268264            tr_err( "%s:%d%s", announceItem->address, announceItem->port, announceItem->announce );
     
    293289        }
    294290       
    295         if ( !inf->trackerAnnounceList )
    296             inf->trackerAnnounceList = calloc( sizeof( tr_announce_list_item_t ), 1 );
     291        if ( !tiersSet )
     292            inf->trackerAnnounceList = calloc( sizeof( int ), 1 );
     293        announceItem = calloc( sizeof( tr_announce_list_item_t ), 1 );
    297294       
    298295        inf->trackerAnnounceTiers = 1;
    299         snprintf( inf->trackerAnnounceList[0].address, 256, "%s", address );
    300         inf->trackerAnnounceList[0].port = port;
    301         snprintf( inf->trackerAnnounceList[0].announce, MAX_PATH_LENGTH, "%s", announce );
    302     }
    303    
    304     tr_setTorrentAnnounce( inf, &inf->trackerAnnounceList[0] );
     296        snprintf( inf->trackerAnnounceList[0]->address, 256, "%s", address );
     297        inf->trackerAnnounceList[0]->port = port;
     298        snprintf( inf->trackerAnnounceList[0]->announce, MAX_PATH_LENGTH, "%s", announce );
     299    }
     300   
     301    tr_setTorrentAnnounce( inf, inf->trackerAnnounceList[0] );
    305302   
    306303    free( address );
  • branches/multitracker/libtransmission/tracker.c

    r1160 r1161  
    123123   
    124124    /* If there are no more trackers don't try to change the announce */
    125     announceItem = &inf->trackerAnnounceList[tc->announceTier];
     125    announceItem = inf->trackerAnnounceList[tc->announceTier];
    126126    for( i = 0; i <= tc->announceTierLast; i++ )
    127127    {
     
    244244    const char   * data;
    245245    int            len, i;
    246     tr_announce_list_item_t * announceItem, * prevAnnounceItem, * tempAnnounceItem;
     246    tr_announce_list_item_t * announceItem, * prevAnnounceItem;
    247247
    248248    if( ( NULL == tc->http ) && shouldConnect( tc ) )
     
    252252            tr_err( "Tracker: %s failed to connect, trying next", inf->trackerAddress );
    253253           
    254             announceItem = &inf->trackerAnnounceList[tc->announceTier];
     254            announceItem = inf->trackerAnnounceList[tc->announceTier];
    255255            for( i = 0; i <= tc->announceTierLast; i++ )
    256256            {
     
    265265                /* Move address to front of tier in announce list */
    266266                prevAnnounceItem->nextItem = announceItem->nextItem;
    267                
    268                 tempAnnounceItem = calloc( sizeof( tr_announce_list_item_t ), 1 );
    269                 *tempAnnounceItem = inf->trackerAnnounceList[tc->announceTier];
    270                 inf->trackerAnnounceList[tc->announceTier] = *announceItem;
    271                 inf->trackerAnnounceList[tc->announceTier].nextItem = tempAnnounceItem;
    272                
    273                 free( announceItem );
     267                announceItem->nextItem = inf->trackerAnnounceList[tc->announceTier];
     268                inf->trackerAnnounceList[tc->announceTier] = announceItem;
    274269            }
    275270            else
     
    279274            }
    280275           
    281             setAnnounce( tc, &inf->trackerAnnounceList[tc->announceTier] );
     276            setAnnounce( tc, inf->trackerAnnounceList[tc->announceTier] );
    282277            tc->shouldChangeAnnounce = 0;
    283278        }
     
    286281            if( tc->announceTier != 0 )
    287282            {
    288                 setAnnounce( tc, inf->trackerAnnounceList );
     283                setAnnounce( tc, inf->trackerAnnounceList[0] );
    289284                tc->announceTier = 0;
    290285            }
  • branches/multitracker/libtransmission/transmission.h

    r1160 r1161  
    329329    int                 trackerCanScrape;
    330330   
    331     tr_announce_list_item_t  * trackerAnnounceList;
     331    tr_announce_list_item_t  ** trackerAnnounceList;
    332332    int                 trackerAnnounceTiers;
    333333   
Note: See TracChangeset for help on using the changeset viewer.