Changeset 7533


Ignore:
Timestamp:
Dec 29, 2008, 9:17:48 PM (12 years ago)
Author:
charles
Message:

(trunk libT) use torrent's unique ID as the torrent's lookup key

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/tracker.c

    r7528 r7533  
    9999    char       escaped[SHA_DIGEST_LENGTH * 3 + 1];
    100100    char *     name;
     101    int        torrentId;
    101102
    102103    /* corresponds to the peer_id sent as a tracker request parameter.
     
    175176
    176177static tr_tracker *
    177 findTracker( tr_session *    session,
    178              const uint8_t * hash )
    179 {
    180     tr_torrent * torrent = tr_torrentFindFromHash( session, hash );
     178findTracker( tr_session * session, int torrentId )
     179{
     180    tr_torrent * torrent = tr_torrentFindFromId( session, torrentId );
    181181
    182182    return torrent ? torrent->tracker : NULL;
     
    187187***/
    188188
    189 static const tr_tracker_event emptyEvent = { 0, NULL, NULL, NULL, 0, 0 };
     189static const tr_tracker_event emptyEvent = { 0, NULL, NULL, 0, 0 };
    190190
    191191static void
     
    197197    {
    198198        tr_tracker_event event = emptyEvent;
    199         event.hash = t->hash;
    200199        event.messageType = type;
    201200        event.text = msg;
     
    233232    tr_tracker_event event = emptyEvent;
    234233
    235     event.hash = t->hash;
    236234    event.messageType = TR_TRACKER_PEERS;
    237235    event.allAreSeeds = allAreSeeds;
     
    383381
    384382static void
    385 onStoppedResponse( tr_session *                session,
     383onStoppedResponse( tr_session    * session,
    386384                   long            responseCode UNUSED,
    387385                   const void    * response     UNUSED,
    388386                   size_t          responseLen  UNUSED,
    389                    void *                       torrent_hash )
    390 {
    391     tr_tracker * t = findTracker( session, torrent_hash );
     387                   void          * torrentId )
     388{
     389    tr_tracker * t = findTracker( session, tr_ptr2int( torrentId ) );
    392390    if( t )
    393391    {
     
    403401    dbgmsg( NULL, "got a response to some `stop' message" );
    404402    onReqDone( session );
    405     tr_free( torrent_hash );
    406403}
    407404
     
    411408                   const void * response,
    412409                   size_t       responseLen,
    413                    void *       torrent_hash )
     410                   void       * torrentId )
    414411{
    415412    int retry;
     
    419416
    420417    onReqDone( session );
    421     t = findTracker( session, torrent_hash );
    422     tr_free( torrent_hash );
     418    t = findTracker( session, tr_ptr2int( torrentId ) );
    423419    if( !t ) /* tracker's been closed */
    424420        return;
     
    610606                  const void * response,
    611607                  size_t       responseLen,
    612                   void       * torrent_hash )
     608                  void       * torrentId )
    613609{
    614610    int          success = FALSE;
     
    617613
    618614    onReqDone( session );
    619     t = findTracker( session, torrent_hash );
    620     tr_free( torrent_hash );
     615    t = findTracker( session, tr_ptr2int( torrentId ) );
    621616    if( !t ) /* tracker's been closed... */
    622617        return;
     
    732727struct tr_tracker_request
    733728{
    734     uint8_t             torrent_hash[SHA_DIGEST_LENGTH];
    735729    int                 reqtype; /* TR_REQ_* */
     730    int                 torrentId;
    736731    char *              url;
    737732    tr_web_done_func *  done_func;
     
    813808    req->done_func =  isStopping ? onStoppedResponse : onTrackerResponse;
    814809    req->url = tr_strdup( EVBUFFER_DATA( url ) );
    815     memcpy( req->torrent_hash, tracker->hash, SHA_DIGEST_LENGTH );
     810    req->torrentId = tracker->torrentId;
    816811
    817812    evbuffer_free( url );
     
    836831    req->url = tr_strdup( EVBUFFER_DATA( url ) );
    837832    req->done_func = onScrapeResponse;
    838     memcpy( req->torrent_hash, tracker->hash, SHA_DIGEST_LENGTH );
     833    req->torrentId = tracker->torrentId;
    839834
    840835    evbuffer_free( url );
     
    883878{
    884879    struct tr_tracker_request * req = vreq;
    885     tr_tracker *                t = findTracker( req->session,
    886                                                  req->torrent_hash );
     880    tr_tracker * t = findTracker( req->session, req->torrentId );
    887881
    888882    if( t )
     
    905899    ++req->session->tracker->runningCount;
    906900
    907     tr_webRun( req->session, req->url, NULL, req->done_func,
    908               tr_memdup( req->torrent_hash, SHA_DIGEST_LENGTH ) );
     901    tr_webRun( req->session, req->url, NULL,
     902               req->done_func, tr_int2ptr( req->torrentId ) );
    909903
    910904    freeRequest( req );
     
    10631057    t->lastScrapeResponse       = -1;
    10641058    t->manualAnnounceAllowedAt  = ~(time_t)0;
    1065     t->name = tr_strdup( info->name );
    1066     t->randOffset = tr_cryptoRandInt( 30 );
     1059    t->name                     = tr_strdup( info->name );
     1060    t->torrentId                = torrent->uniqueId;
     1061    t->randOffset               = tr_cryptoRandInt( 30 );
    10671062    memcpy( t->hash, info->hash, SHA_DIGEST_LENGTH );
    10681063    escape( t->escaped, info->hash, SHA_DIGEST_LENGTH );
  • trunk/libtransmission/tracker.h

    r7404 r7533  
    5252    TrackerEventType    messageType;
    5353
    54     /* the torrent's 20-character sha1 hash */
    55     const uint8_t *  hash;
    56 
    5754    /* for TR_TRACKER_WARNING and TR_TRACKER_ERROR */
    5855    const char *  text;
  • trunk/libtransmission/utils.c

    r7529 r7533  
    12851285    return dir==TR_UP || dir==TR_DOWN;
    12861286}
     1287
     1288int
     1289tr_ptr2int( void* v )
     1290{
     1291    return (intptr_t)v;
     1292}
     1293
     1294void*
     1295tr_int2ptr( int i )
     1296{
     1297    return (void*)(intptr_t)i;
     1298}
  • trunk/libtransmission/utils.h

    r7529 r7533  
    402402    && tr_bitfieldHasFast( bitfield, nth ) )
    403403
    404 double tr_getRatio( double numerator,
    405                     double denominator );
     404double tr_getRatio( double numerator, double denominator );
     405
     406
     407int tr_ptr2int( void* );
     408
     409void* tr_int2ptr( int );
    406410
    407411#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.