Changeset 8477


Ignore:
Timestamp:
May 22, 2009, 4:03:12 AM (14 years ago)
Author:
charles
Message:

(1.6x libT) backport r8465, which defers building the hash-to-torrent-filename lookup table until someone asks for it

Location:
branches/1.6x/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/1.6x/libtransmission/metainfo.c

    r8122 r8477  
    7575}
    7676
     77/* this is for really old versions of T and will probably be removed someday */
    7778void
    7879tr_metainfoMigrate( tr_session * session,
  • branches/1.6x/libtransmission/session.c

    r8457 r8477  
    5151            tr_deepLog( __FILE__, __LINE__, NULL, __VA_ARGS__ ); \
    5252    } while( 0 )
     53
     54struct tr_metainfo_lookup
     55{
     56    char    hashString[2 * SHA_DIGEST_LENGTH + 1];
     57    char *  filename;
     58};
    5359
    5460static tr_port
     
    446452}
    447453
    448 static void metainfoLookupRescan( tr_session * );
    449454static void tr_sessionInitImpl( void * );
    450455static void onAltTimer( int, short, void* );
     
    757762    tr_statsInit( session );
    758763    session->web = tr_webInit( session );
    759     metainfoLookupRescan( session );
    760764    session->isWaiting = FALSE;
    761765    dbgmsg( "returning session %p; session->tracker is %p", session, session->tracker );
     
    16861690
    16871691    return strcmp( a, b->hashString );
    1688 }
    1689 
    1690 const char*
    1691 tr_sessionFindTorrentFile( const tr_session * session,
    1692                            const char       * hashStr )
    1693 {
    1694     struct tr_metainfo_lookup * l = bsearch( hashStr,
    1695                                              session->metainfoLookup,
    1696                                              session->metainfoLookupCount,
    1697                                              sizeof( struct tr_metainfo_lookup ),
    1698                                              compareHashStringToLookupEntry );
    1699 
    1700     return l ? l->filename : NULL;
    17011692}
    17021693
     
    17591750}
    17601751
     1752static struct tr_metainfo_lookup *
     1753metainfoLookup( const tr_session * session, const char * hashString )
     1754{
     1755    /* because only the mac client uses metainfoLookup, and because building
     1756     * the lookup is expensive, we hold off on building it until the client
     1757     * actually asks to look up a hash... */
     1758    if( !session->metainfoLookupCount )
     1759        metainfoLookupRescan( (tr_session*)session );
     1760
     1761    return bsearch( hashString,
     1762                    session->metainfoLookup,
     1763                    session->metainfoLookupCount,
     1764                    sizeof( struct tr_metainfo_lookup ),
     1765                    compareHashStringToLookupEntry );
     1766}
     1767
     1768const char*
     1769tr_sessionFindTorrentFile( const tr_session  * session,
     1770                           const char        * hashString )
     1771{
     1772    const struct tr_metainfo_lookup * l = metainfoLookup( session, hashString );
     1773
     1774    return l ? l->filename : NULL;
     1775}
     1776
    17611777void
    17621778tr_sessionSetTorrentFile( tr_session * session,
     
    17641780                          const char * filename )
    17651781{
    1766     struct tr_metainfo_lookup * l = bsearch( hashString,
    1767                                              session->metainfoLookup,
    1768                                              session->metainfoLookupCount,
    1769                                              sizeof( struct tr_metainfo_lookup ),
    1770                                              compareHashStringToLookupEntry );
    1771 
     1782    struct tr_metainfo_lookup * l;
     1783
     1784    /* since we walk session->configDir/torrents/ to build the lookup table,
     1785     * and tr_sessionSetTorrentFile() is just to tell us there's a new file
     1786     * in that same directory, we don't need to do anything here if the
     1787     * lookup table hasn't been built yet */
     1788    if( session->metainfoLookup == NULL )
     1789        return;
     1790
     1791    l = metainfoLookup( session, hashString );
    17721792    if( l )
    17731793    {
     
    19431963    return tr_rpcGetBindAddress( session->rpcServer );
    19441964}
    1945 
    1946 /***
    1947 ****
    1948 ***/
    1949 
    1950 tr_bool
    1951 tr_sessionIsProxyEnabled( const tr_session * session )
    1952 {
    1953     assert( tr_isSession( session ) );
    1954 
    1955     return session->isProxyEnabled;
    1956 }
    1957 
    1958 void
    19591965tr_sessionSetProxyEnabled( tr_session * session,
    19601966                           tr_bool      isEnabled )
  • branches/1.6x/libtransmission/session.h

    r8243 r8477  
    4848const uint8_t* tr_getPeerId( void );
    4949
    50 struct tr_metainfo_lookup
    51 {
    52     char    hashString[2 * SHA_DIGEST_LENGTH + 1];
    53     char *  filename;
    54 };
    55 
    5650struct tr_address;
    5751struct tr_bandwidth;
     52struct tr_metainfo_lookup;
    5853
    5954struct tr_session
Note: See TracChangeset for help on using the changeset viewer.