Changeset 9387


Ignore:
Timestamp:
Oct 23, 2009, 3:41:36 AM (12 years ago)
Author:
charles
Message:

(trunk) trunk's just been too stable lately. #2119: reload settings.json on SIGHUP

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/daemon.c

    r8903 r9387  
    100100
    101101static void
    102 gotsig( int sig UNUSED )
     102got_sigint( int sig UNUSED )
    103103{
    104104    closing = TRUE;
     105}
     106
     107static void
     108got_sighup( int sig UNUSED )
     109{
     110    tr_benc settings;
     111    const char * configDir = tr_sessionGetConfigDir( mySession );
     112
     113    /* reload the settings */
     114    tr_inf( "Reloading settings from \"%s\"", configDir );
     115    tr_bencInitDict( &settings, 0 );
     116    tr_sessionLoadSettings( &settings, configDir, MY_NAME );
     117    tr_sessionSet( mySession, &settings );
     118
     119    /* cleanup */
     120    tr_bencFree( &settings );
    105121}
    106122
     
    214230    dtr_watchdir * watchdir = NULL;
    215231
    216     signal( SIGINT, gotsig );
    217     signal( SIGTERM, gotsig );
     232    signal( SIGINT, got_sigint );
    218233#ifndef WIN32
    219     signal( SIGQUIT, gotsig );
    220     signal( SIGPIPE, SIG_IGN );
    221     signal( SIGHUP, SIG_IGN );
     234    signal( SIGHUP, got_sighup );
    222235#endif
    223236
     
    313326    /* start the session */
    314327    mySession = tr_sessionInit( "daemon", configDir, FALSE, &settings );
     328    tr_sessionSaveSettings( mySession, configDir, &settings );
    315329
    316330    if( tr_bencDictFindBool( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, &boolVal ) && boolVal )
  • trunk/gtk/main.c

    r9346 r9387  
    300300            break;
    301301
    302         case TR_RPC_TORRENT_STARTED:
    303             /* this should be automatic */
    304             break;
    305 
    306         case TR_RPC_TORRENT_STOPPED:
    307             /* this should be automatic */
    308             break;
    309 
    310302        case TR_RPC_TORRENT_REMOVING:
    311303            tr_core_torrent_destroyed( cbdata->core, tr_torrentId( tor ) );
    312304            break;
    313305
     306        case TR_RPC_SESSION_CHANGED:
    314307        case TR_RPC_TORRENT_CHANGED:
    315         case TR_RPC_SESSION_CHANGED:
     308        case TR_RPC_TORRENT_MOVED:
     309        case TR_RPC_TORRENT_STARTED:
     310        case TR_RPC_TORRENT_STOPPED:
    316311            /* nothing interesting to do here */
    317312            break;
  • trunk/libtransmission/fdlimit.c

    r9346 r9387  
    6464#include "net.h"
    6565#include "platform.h" /* MAX_PATH_LENGTH, TR_PATH_DELIMITER */
     66#include "session.h"
     67#include "torrent.h" /* tr_isTorrent() */
    6668#include "utils.h"
    6769
     
    9294};
    9395
    94 struct tr_fd_s
     96struct tr_fdInfo
    9597{
    9698    int                   socketCount;
    9799    int                   socketLimit;
     100    int                   publicSocketLimit;
    98101    int                   openFileLimit;
    99102    struct tr_openfile  * openFiles;
    100103};
    101 
    102 static struct tr_fd_s * gFd = NULL;
    103104
    104105/***
     
    278279 */
    279280static int
    280 TrOpenFile( int                      i,
     281TrOpenFile( tr_session             * session,
     282            int                      i,
    281283            const char             * filename,
    282284            tr_bool                  doWrite,
     
    284286            uint64_t                 desiredFileSize )
    285287{
    286     struct tr_openfile * file = &gFd->openFiles[i];
    287     int                  flags;
    288     struct stat          sb;
    289     tr_bool              alreadyExisted;
     288    int flags;
     289    struct stat sb;
     290    tr_bool alreadyExisted;
     291    struct tr_openfile * file;
     292
     293    assert( tr_isSession( session ) );
     294    assert( session->fdInfo != NULL );
     295
     296    file = &session->fdInfo->openFiles[i];
    290297
    291298    /* create subfolders, if any */
     
    371378
    372379int
    373 tr_fdFileGetCached( int              torrentId,
    374                     tr_file_index_t  fileNum,
    375                     tr_bool          doWrite )
     380tr_fdFileGetCached( tr_session       * session,
     381                    int                torrentId,
     382                    tr_file_index_t    fileNum,
     383                    tr_bool            doWrite )
    376384{
    377385    struct tr_openfile * match = NULL;
    378 
     386    struct tr_fdInfo * gFd;
     387
     388    assert( tr_isSession( session ) );
     389    assert( session->fdInfo != NULL );
    379390    assert( torrentId > 0 );
    380391    assert( tr_isBool( doWrite ) );
     392
     393    gFd = session->fdInfo;
    381394
    382395    /* is it already open? */
     
    411424/* returns an fd on success, or a -1 on failure and sets errno */
    412425int
    413 tr_fdFileCheckout( int                      torrentId,
     426tr_fdFileCheckout( tr_session             * session,
     427                   int                      torrentId,
    414428                   tr_file_index_t          fileNum,
    415429                   const char             * filename,
     
    419433{
    420434    int i, winner = -1;
     435    struct tr_fdInfo * gFd;
    421436    struct tr_openfile * o;
    422437
     438    assert( tr_isSession( session ) );
     439    assert( session->fdInfo != NULL );
    423440    assert( torrentId > 0 );
    424441    assert( filename && *filename );
    425442    assert( tr_isBool( doWrite ) );
     443
     444    gFd = session->fdInfo;
    426445
    427446    dbgmsg( "looking for file '%s', writable %c", filename, doWrite ? 'y' : 'n' );
     
    488507    if( !fileIsOpen( o ) )
    489508    {
    490         const int err = TrOpenFile( winner, filename, doWrite,
     509        const int err = TrOpenFile( session, winner, filename, doWrite,
    491510                                    preallocationMode, desiredFileSize );
    492511        if( err ) {
     
    509528
    510529void
    511 tr_fdFileClose( const tr_torrent * tor, tr_file_index_t fileNum )
     530tr_fdFileClose( tr_session        * session,
     531                const tr_torrent  * tor,
     532                tr_file_index_t     fileNum )
    512533{
    513534    struct tr_openfile * o;
     535    struct tr_fdInfo * gFd;
    514536    const struct tr_openfile * end;
    515537    const int torrentId = tr_torrentId( tor );
     538
     539    assert( tr_isSession( session ) );
     540    assert( session->fdInfo != NULL );
     541    assert( tr_isTorrent( tor ) );
     542    assert( fileNum < tor->info.fileCount );
     543
     544    gFd = session->fdInfo;
     545
    516546    for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
    517547    {
     
    529559
    530560void
    531 tr_fdTorrentClose( int torrentId )
     561tr_fdTorrentClose( tr_session * session, int torrentId )
    532562{
    533563    struct tr_openfile * o;
     564    struct tr_fdInfo * gFd;
    534565    const struct tr_openfile * end;
     566
     567    assert( tr_isSession( session ) );
     568    assert( session->fdInfo != NULL );
     569
     570    gFd = session->fdInfo;
    535571
    536572    for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
     
    545581***/
    546582
    547 static TR_INLINE int
    548 getSocketMax( struct tr_fd_s * gFd )
    549 {
    550     return gFd->socketLimit;
    551 }
    552 
    553583int
    554 tr_fdSocketCreate( int domain, int type )
     584tr_fdSocketCreate( tr_session * session, int domain, int type )
    555585{
    556586    int s = -1;
    557 
    558     if( gFd->socketCount < getSocketMax( gFd ) )
     587    struct tr_fdInfo * gFd;
     588
     589    assert( tr_isSession( session ) );
     590    assert( session->fdInfo != NULL );
     591
     592    gFd = session->fdInfo;
     593
     594    if( gFd->socketCount < gFd->socketLimit )
    559595        if( ( s = socket( domain, type, 0 ) ) < 0 )
    560596        {
     
    568604
    569605    assert( gFd->socketCount >= 0 );
    570 
    571606    return s;
    572607}
    573608
    574609int
    575 tr_fdSocketAccept( int           b,
     610tr_fdSocketAccept( tr_session  * session,
     611                   int           b,
    576612                   tr_address  * addr,
    577613                   tr_port     * port )
     
    579615    int s;
    580616    unsigned int len;
     617    struct tr_fdInfo * gFd;
    581618    struct sockaddr_storage sock;
    582619
     620    assert( tr_isSession( session ) );
     621    assert( session->fdInfo != NULL );
    583622    assert( addr );
    584623    assert( port );
    585624
     625    gFd = session->fdInfo;
     626
    586627    len = sizeof( struct sockaddr_storage );
    587628    s = accept( b, (struct sockaddr *) &sock, &len );
    588629
    589     if( ( s >= 0 ) && gFd->socketCount > getSocketMax( gFd ) )
     630    if( ( s >= 0 ) && gFd->socketCount > gFd->socketLimit )
    590631    {
    591632        EVUTIL_CLOSESOCKET( s );
     
    624665
    625666void
    626 tr_fdSocketClose( int fd )
    627 {
     667tr_fdSocketClose( tr_session * session, int fd )
     668{
     669    struct tr_fdInfo * gFd;
     670
     671    assert( tr_isSession( session ) );
     672    assert( session->fdInfo != NULL );
     673
     674    gFd = session->fdInfo;
     675
    628676    if( fd >= 0 )
    629677    {
     
    641689***/
    642690
     691static void
     692ensureSessionFdInfoExists( tr_session * session )
     693{
     694    assert( tr_isSession( session ) );
     695
     696    if( session->fdInfo == NULL )
     697        session->fdInfo = tr_new0( struct tr_fdInfo, 1 );
     698}
     699
    643700void
    644 tr_fdInit( size_t openFileLimit, size_t socketLimit )
    645 {
    646     int i;
    647 
    648     assert( gFd == NULL );
    649     gFd = tr_new0( struct tr_fd_s, 1 );
    650     gFd->openFiles = tr_new0( struct tr_openfile, openFileLimit );
    651     gFd->openFileLimit = openFileLimit;
     701tr_fdClose( tr_session * session )
     702{
     703    struct tr_fdInfo * gFd;
     704    struct tr_openfile * o;
     705    const struct tr_openfile * end;
     706
     707    assert( tr_isSession( session ) );
     708    assert( session->fdInfo != NULL );
     709
     710    gFd = session->fdInfo;
     711
     712    for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
     713        if( fileIsOpen( o ) )
     714            TrCloseFile( o );
     715
     716    tr_free( gFd->openFiles );
     717    tr_free( gFd );
     718    session->fdInfo = NULL;
     719}
     720
     721/***
     722****
     723***/
     724
     725void
     726tr_fdSetFileLimit( tr_session * session, int limit )
     727{
     728    struct tr_fdInfo * gFd;
     729
     730    ensureSessionFdInfoExists( session );
     731
     732    gFd = session->fdInfo;
     733
     734    if( gFd->openFileLimit != limit )
     735    {
     736        int i;
     737        struct tr_openfile * o;
     738        const struct tr_openfile * end;
     739
     740        /* close any files we've got open  */
     741        for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
     742            if( fileIsOpen( o ) )
     743                TrCloseFile( o );
     744
     745        /* rebuild the openFiles array */
     746        tr_free( gFd->openFiles );
     747        gFd->openFiles = tr_new0( struct tr_openfile, limit );
     748        gFd->openFileLimit = limit;
     749        for( i=0; i<gFd->openFileLimit; ++i )
     750            gFd->openFiles[i].fd = -1;
     751    }
     752}
     753
     754int
     755tr_fdGetFileLimit( const tr_session * session )
     756{
     757    return session && session->fdInfo ? session->fdInfo->openFileLimit : -1;
     758}
     759
     760void
     761tr_fdSetPeerLimit( tr_session * session, int limit )
     762{
     763    struct tr_fdInfo * gFd;
     764
     765    ensureSessionFdInfoExists( session );
     766
     767    gFd = session->fdInfo;
    652768
    653769#ifdef HAVE_GETRLIMIT
     
    655771        struct rlimit rlim;
    656772        getrlimit( RLIMIT_NOFILE, &rlim );
    657         rlim.rlim_cur = MIN( rlim.rlim_max,
    658                             (rlim_t)( socketLimit + NOFILE_BUFFER ) );
     773        rlim.rlim_cur = MIN( rlim.rlim_max, (rlim_t)( limit + NOFILE_BUFFER ) );
    659774        setrlimit( RLIMIT_NOFILE, &rlim );
    660775        gFd->socketLimit = rlim.rlim_cur - NOFILE_BUFFER;
     
    662777    }
    663778#else
    664     gFd->socketLimit = socketLimit;
    665 #endif
    666     tr_dbg( "%zu usable file descriptors", socketLimit );
    667 
    668     for( i = 0; i < gFd->openFileLimit; ++i )
    669         gFd->openFiles[i].fd = -1;
    670 }
    671 
    672 void
    673 tr_fdClose( void )
    674 {
    675     struct tr_openfile * o;
    676     const struct tr_openfile * end;
    677 
    678     for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
    679         if( fileIsOpen( o ) )
    680             TrCloseFile( o );
    681 
    682     tr_free( gFd->openFiles );
    683     tr_free( gFd );
    684     gFd = NULL;
    685 }
    686 
    687 void
    688 tr_fdSetPeerLimit( uint16_t n )
    689 {
    690     assert( gFd != NULL && "tr_fdInit() must be called first!" );
    691     gFd->socketLimit = n;
    692 }
    693 
    694 uint16_t
    695 tr_fdGetPeerLimit( void )
    696 {
    697     return gFd ? gFd->socketLimit : -1;
    698 }
     779    gFd->socketLimit = limit;
     780#endif
     781    gFd->publicSocketLimit = limit;
     782
     783    tr_dbg( "%d usable file descriptors", limit );
     784}
     785
     786int
     787tr_fdGetPeerLimit( const tr_session * session )
     788{
     789    return session && session->fdInfo ? session->fdInfo->publicSocketLimit : -1;
     790}
  • trunk/libtransmission/fdlimit.h

    r9346 r9387  
    3535 */
    3636
    37 void tr_fdInit( size_t openFileLimit,
    38                 size_t globalPeerLimit );
     37void tr_fdSetFileLimit( tr_session * session, int limit );
     38
     39int tr_fdGetFileLimit( const tr_session * session );
     40
     41void tr_fdSetGlobalPeerLimit( tr_session * session, int limit );
     42
     43/***
     44****
     45***/
    3946
    4047int tr_open_file_for_scanning( const char * filename );
     
    6471 * @see tr_fdFileClose
    6572 */
    66 int  tr_fdFileCheckout( int                      torrentId,
     73int  tr_fdFileCheckout( tr_session             * session,
     74                        int                      torrentId,
    6775                        tr_file_index_t          fileNum,
    6876                        const char             * fileName,
     
    7179                        uint64_t                 desiredFileSize );
    7280
    73 int tr_fdFileGetCached( int                      torrentId,
     81int tr_fdFileGetCached( tr_session             * session,
     82                        int                      torrentId,
    7483                        tr_file_index_t          fileNum,
    7584                        tr_bool                  doWrite );
     
    8392 * @see tr_fdFileCheckout
    8493 */
    85 void     tr_fdFileClose( const tr_torrent * tor, tr_file_index_t fileNo );
     94void tr_fdFileClose( tr_session        * session,
     95                     const tr_torrent  * tor,
     96                     tr_file_index_t     fileNo );
    8697
    8798
     
    89100 * Closes all the files associated with a given torrent id
    90101 */
    91 void tr_fdTorrentClose( int torrentId );
     102void tr_fdTorrentClose( tr_session * session, int torrentId );
    92103
    93104
     
    95106 * Sockets
    96107 **********************************************************************/
    97 int      tr_fdSocketCreate( int domain, int type );
     108int      tr_fdSocketCreate( tr_session * session, int domain, int type );
    98109
    99 int      tr_fdSocketAccept( int           b,
     110int      tr_fdSocketAccept( tr_session  * session,
     111                            int           b,
    100112                            tr_address  * addr,
    101113                            tr_port     * port );
    102114
    103 void     tr_fdSocketClose( int s );
     115void     tr_fdSocketClose( tr_session * session, int s );
    104116
    105117/***********************************************************************
     
    108120 * Frees resources allocated by tr_fdInit.
    109121 **********************************************************************/
    110 void     tr_fdClose( void );
     122void     tr_fdClose( tr_session * session );
    111123
    112124
    113 void     tr_fdSetPeerLimit( uint16_t n );
     125void     tr_fdSetPeerLimit( tr_session * session, int n );
    114126
    115 uint16_t tr_fdGetPeerLimit( void );
     127int      tr_fdGetPeerLimit( const tr_session * );
    116128
    117129/* @} */
  • trunk/libtransmission/inout.c

    r9346 r9387  
    6767/* returns 0 on success, or an errno on failure */
    6868static int
    69 readOrWriteBytes( const tr_torrent * tor,
     69readOrWriteBytes( tr_session       * session,
     70                  const tr_torrent * tor,
    7071                  int                ioMode,
    7172                  tr_file_index_t    fileIndex,
     
    9091        return 0;
    9192
    92     fd = tr_fdFileGetCached( tr_torrentId( tor ), fileIndex, doWrite );
     93    fd = tr_fdFileGetCached( session, tr_torrentId( tor ), fileIndex, doWrite );
    9394
    9495    if( fd < 0 )
     
    126127            char * filename = tr_buildPath( base, subpath, NULL );
    127128
    128             if( ( fd = tr_fdFileCheckout( tor->uniqueId, fileIndex, filename,
     129            if( ( fd = tr_fdFileCheckout( session, tor->uniqueId, fileIndex, filename,
    129130                                          doWrite, preallocationMode, file->length ) ) < 0 )
    130131            {
     
    220221        const uint64_t bytesThisPass = MIN( buflen, file->length - fileOffset );
    221222
    222         err = readOrWriteBytes( tor, ioMode, fileIndex, fileOffset, buf, bytesThisPass );
     223        err = readOrWriteBytes( tor->session, tor, ioMode, fileIndex, fileOffset, buf, bytesThisPass );
    223224        buf += bytesThisPass;
    224225        buflen -= bytesThisPass;
  • trunk/libtransmission/net.c

    r8889 r9387  
    304304        return -EINVAL;
    305305
    306     s = tr_fdSocketCreate( domains[addr->type], SOCK_STREAM );
     306    s = tr_fdSocketCreate( session, domains[addr->type], SOCK_STREAM );
    307307    if( s < 0 )
    308308        return -1;
    309309
    310310    if( evutil_make_socket_nonblocking( s ) < 0 ) {
    311         tr_netClose( s );
     311        tr_netClose( session, s );
    312312        return -1;
    313313    }
     
    340340                    s, tr_ntop_non_ts( addr ), (int)port, tmperrno,
    341341                    tr_strerror( tmperrno ) );
    342         tr_netClose( s );
     342        tr_netClose( session, s );
    343343        s = -tmperrno;
    344344    }
     
    437437
    438438int
    439 tr_netAccept( tr_session  * session UNUSED,
     439tr_netAccept( tr_session  * session,
    440440              int           b,
    441441              tr_address  * addr,
    442442              tr_port     * port )
    443443{
    444     int fd = tr_fdSocketAccept( b, addr, port );
     444    int fd = tr_fdSocketAccept( session, b, addr, port );
    445445
    446446    if( fd>=0 && evutil_make_socket_nonblocking(fd)<0 ) {
    447         tr_netClose( fd );
     447        tr_netClose( session, fd );
    448448        fd = -1;
    449449    }
     
    453453
    454454void
    455 tr_netClose( int s )
    456 {
    457     tr_fdSocketClose( s );
    458 }
     455tr_netClose( tr_session * session, int s )
     456{
     457    tr_fdSocketClose( session, s );
     458}
  • trunk/libtransmission/net.h

    r8398 r9387  
    115115                   int tos );
    116116
    117 void tr_netClose( int s );
     117void tr_netClose( tr_session * session, int s );
    118118
    119119void tr_netInit( void );
  • trunk/libtransmission/peer-io.c

    r9273 r9387  
    458458    evbuffer_free( io->outbuf );
    459459    evbuffer_free( io->inbuf );
    460     tr_netClose( io->socket );
     460    tr_netClose( io->session, io->socket );
    461461    tr_cryptoFree( io->crypto );
    462462    __tr_list_destroy( &io->outbuf_datatypes, trDatatypeFree );
     
    549549tr_peerIoReconnect( tr_peerIo * io )
    550550{
     551    tr_session * session;
     552
     553    assert( tr_isPeerIo( io ) );
    551554    assert( !tr_peerIoIsIncoming( io ) );
    552555
     556    session = tr_peerIoGetSession( io );
     557
    553558    if( io->socket >= 0 )
    554         tr_netClose( io->socket );
    555 
    556     io->socket = tr_netOpenTCP( io->session, &io->addr, io->port );
     559        tr_netClose( session, io->socket );
     560
     561    io->socket = tr_netOpenTCP( session, &io->addr, io->port );
    557562    if( io->socket >= 0 )
    558563    {
    559         tr_netSetTOS( io->socket, io->session->peerSocketTOS );
     564        tr_netSetTOS( io->socket, session->peerSocketTOS );
    560565        return 0;
    561566    }
  • trunk/libtransmission/peer-mgr.c

    r9383 r9387  
    13331333                       int          socket )
    13341334{
     1335    tr_session * session;
     1336
    13351337    managerLock( manager );
    13361338
    1337     if( tr_sessionIsAddressBlocked( manager->session, addr ) )
     1339    assert( tr_isSession( manager->session ) );
     1340    session = manager->session;
     1341
     1342    if( tr_sessionIsAddressBlocked( session, addr ) )
    13381343    {
    13391344        tr_dbg( "Banned IP address \"%s\" tried to connect to us", tr_ntop_non_ts( addr ) );
    1340         tr_netClose( socket );
     1345        tr_netClose( session, socket );
    13411346    }
    13421347    else if( getExistingHandshake( &manager->incomingHandshakes, addr ) )
    13431348    {
    1344         tr_netClose( socket );
     1349        tr_netClose( session, socket );
    13451350    }
    13461351    else /* we don't have a connetion to them yet... */
     
    13491354        tr_handshake * handshake;
    13501355
    1351         io = tr_peerIoNewIncoming( manager->session, manager->session->bandwidth, addr, port, socket );
     1356        io = tr_peerIoNewIncoming( session, session->bandwidth, addr, port, socket );
    13521357
    13531358        handshake = tr_handshakeNew( io,
    1354                                      manager->session->encryptionMode,
     1359                                     session->encryptionMode,
    13551360                                     myHandshakeDoneCB,
    13561361                                     manager );
  • trunk/libtransmission/port-forwarding.c

    r8767 r9387  
    131131
    132132tr_shared *
    133 tr_sharedInit( tr_session  * session, tr_bool isEnabled )
     133tr_sharedInit( tr_session  * session )
    134134{
    135135    tr_shared * s = tr_new0( tr_shared, 1 );
    136136
    137137    s->session      = session;
    138     s->isEnabled    = isEnabled;
     138    s->isEnabled    = FALSE;
    139139    s->upnpStatus   = TR_PORT_UNMAPPED;
    140140    s->natpmpStatus = TR_PORT_UNMAPPED;
    141141
     142#if 0
    142143    if( isEnabled )
    143144    {
     
    146147        tr_timerAdd( s->timer, 0, 333000 );
    147148    }
     149#endif
    148150
    149151    return s;
  • trunk/libtransmission/port-forwarding.h

    r8903 r9387  
    3030typedef struct tr_shared tr_shared;
    3131
    32 tr_shared* tr_sharedInit( tr_session*, tr_bool isEnabled );
     32tr_shared* tr_sharedInit( tr_session* );
    3333
    3434void       tr_sharedClose( tr_session * );
  • trunk/libtransmission/rpc-server.c

    r8911 r9387  
    887887
    888888tr_rpc_server *
    889 tr_rpcInit( tr_session  * session,
    890             tr_benc * settings )
     889tr_rpcInit( tr_session  * session, tr_benc * settings )
    891890{
    892891    tr_rpc_server * s;
     
    910909    found = tr_bencDictFindBool( settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, &boolVal );
    911910    assert( found );
    912     s->isWhitelistEnabled = boolVal;
     911    tr_rpcSetWhitelistEnabled( s, boolVal );
    913912
    914913    found = tr_bencDictFindBool( settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, &boolVal );
    915914    assert( found );
    916     s->isPasswordEnabled = boolVal;
     915    tr_rpcSetPasswordEnabled( s, boolVal );
    917916
    918917    found = tr_bencDictFindStr( settings, TR_PREFS_KEY_RPC_WHITELIST, &str );
     
    922921    found = tr_bencDictFindStr( settings, TR_PREFS_KEY_RPC_USERNAME, &str );
    923922    assert( found );
    924     s->username = tr_strdup( str );
     923    tr_rpcSetUsername( s, str );
    925924
    926925    found = tr_bencDictFindStr( settings, TR_PREFS_KEY_RPC_PASSWORD, &str );
    927926    assert( found );
    928     if( *str != '{' )
    929         s->password = tr_ssha1( str );
    930     else
    931         s->password = strdup( str );
     927    tr_rpcSetPassword( s, str );
    932928
    933929    found = tr_bencDictFindStr( settings, TR_PREFS_KEY_RPC_BIND_ADDRESS, &str );
  • trunk/libtransmission/session.c

    r9380 r9387  
    145145close_bindinfo( struct tr_bindinfo * b )
    146146{
    147     if( b->socket >=0 )
     147    if( ( b != NULL ) && ( b->socket >=0 ) )
    148148    {
    149149        event_del( &b->ev );
     
    427427    tr_bencDictAddBool( d, TR_PREFS_KEY_LAZY_BITFIELD,            s->useLazyBitfield );
    428428    tr_bencDictAddInt ( d, TR_PREFS_KEY_MSGLEVEL,                 tr_getMessageLevel( ) );
    429     tr_bencDictAddInt ( d, TR_PREFS_KEY_OPEN_FILE_LIMIT,          s->openFileLimit );
     429    tr_bencDictAddInt ( d, TR_PREFS_KEY_OPEN_FILE_LIMIT,          tr_fdGetFileLimit( s ) );
    430430    tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_LIMIT_GLOBAL,        tr_sessionGetPeerLimit( s ) );
    431431    tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_LIMIT_TORRENT,       s->peerLimitPerTorrent );
     
    609609
    610610    /* run the rest in the libtransmission thread */
    611     session->isWaiting = TRUE;
     611    ++session->waiting;
    612612    data.session = session;
    613613    data.configDir = configDir;
     
    615615    data.clientSettings = clientSettings;
    616616    tr_runInEventThread( session, tr_sessionInitImpl, &data );
    617     while( session->isWaiting )
     617    while( session->waiting > 0 )
    618618        tr_wait( 100 );
    619619
     
    627627tr_sessionInitImpl( void * vdata )
    628628{
    629     int64_t i;
    630     int64_t j;
    631     double  d;
    632     tr_bool found;
    633     tr_bool boolVal;
    634     const char * str;
    635629    tr_benc settings;
    636     char * filename;
    637630    struct init_data * data = vdata;
    638631    tr_benc * clientSettings = data->clientSettings;
     
    642635    assert( tr_bencIsDict( clientSettings ) );
    643636
    644     dbgmsg( "tr_sessionInit: the session's top-level bandwidth object is %p", session->bandwidth );
     637    dbgmsg( "tr_sessionInit: the session's top-level bandwidth object is %p",
     638            session->bandwidth );
    645639
    646640    tr_bencInitDict( &settings, 0 );
     
    653647#endif
    654648
    655     /* set the session's file mode creation mask (umask) to session->umask & 0777 */
    656     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_UMASK, &i );
    657     assert( found );
    658     session->umask = (mode_t)i;
    659     umask( session->umask );
    660 
    661     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_LIMIT_TORRENT, &i );
    662     assert( found );
    663     session->peerLimitPerTorrent = i;
    664 
    665     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_MSGLEVEL, &i );
    666     assert( found );
    667     tr_setMessageLevel( i );
    668649    tr_setMessageQueuing( data->messageQueuingEnabled );
    669650
    670 
    671     found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_PEX_ENABLED, &boolVal );
    672     assert( found );
    673     session->isPexEnabled = boolVal;
    674 
    675     found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_DHT_ENABLED, &boolVal );
    676     assert( found );
    677     session->isDHTEnabled = boolVal;
    678 
    679     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ENCRYPTION, &i );
    680     assert( found );
    681     assert( tr_isEncryptionMode( i ) );
    682     session->encryptionMode = i;
    683 
    684     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PREALLOCATION, &i );
    685     assert( found );
    686     assert( tr_isPreallocationMode( i ) );
    687     session->preallocationMode = i;
    688 
    689     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_SOCKET_TOS, &i );
    690     assert( found );
    691     session->peerSocketTOS = i;
    692 
    693     found = tr_bencDictFindStr( &settings, TR_PREFS_KEY_DOWNLOAD_DIR, &str );
    694     assert( found );
    695     session->downloadDir = tr_strdup( str );
    696 
    697     found = tr_bencDictFindStr( &settings, TR_PREFS_KEY_INCOMPLETE_DIR, &str );
    698     assert( found );
    699     tr_sessionSetIncompleteDir( session, str );
    700 
    701     found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, &boolVal );
    702     assert( found );
    703     tr_sessionSetIncompleteDirEnabled( session, boolVal );
    704 
    705     found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_RENAME_PARTIAL_FILES, &boolVal );
    706     assert( found );
    707     tr_sessionSetIncompleteFileNamingEnabled( session, boolVal );
    708 
    709     found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_PROXY_ENABLED, &boolVal );
    710     assert( found );
    711     session->isProxyEnabled = boolVal;
    712 
    713     found = tr_bencDictFindStr( &settings, TR_PREFS_KEY_PROXY, &str );
    714     assert( found );
    715     session->proxy = tr_strdup( str );
    716 
    717     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PROXY_PORT, &i );
    718     assert( found );
    719     session->proxyPort = i;
    720 
    721     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PROXY_TYPE, &i );
    722     assert( found );
    723     session->proxyType = i;
    724 
    725     found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_PROXY_AUTH_ENABLED, &boolVal );
    726     assert( found );
    727     session->isProxyAuthEnabled = boolVal;
    728 
    729     found = tr_bencDictFindStr( &settings, TR_PREFS_KEY_PROXY_USERNAME, &str );
    730     assert( found );
    731     session->proxyUsername = tr_strdup( str );
    732 
    733     found = tr_bencDictFindStr( &settings, TR_PREFS_KEY_PROXY_PASSWORD, &str );
    734     assert( found );
    735     session->proxyPassword = tr_strdup( str );
    736 
    737     session->so_sndbuf = 1500 * 3; /* 3x MTU for most ethernet/wireless */
    738     session->so_rcvbuf = 8192;
    739 
    740651    tr_setConfigDir( session, data->configDir );
    741652
    742653    session->peerMgr = tr_peerMgrNew( session );
    743654
    744     found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_LAZY_BITFIELD, &boolVal );
    745     assert( found );
    746     session->useLazyBitfield = boolVal;
    747 
    748     /* Initialize rate and file descripts controls */
    749 
    750     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_OPEN_FILE_LIMIT, &i );
    751     assert( found );
    752     session->openFileLimit = i;
    753     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, &j );
    754     assert( found );
    755     tr_fdInit( session->openFileLimit, j );
    756 
    757     /**
    758     *** random port
    759     **/
    760 
    761     found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, &boolVal );
    762     assert( found );
    763     session->isPortRandom = boolVal;
    764 
    765     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW, &i );
    766     assert( found );
    767     session->randomPortLow = i;
    768 
    769     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH, &i );
    770     assert( found );
    771     session->randomPortHigh = i;
    772 
    773     found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_PORT_FORWARDING, &boolVal )
    774          && tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_PORT, &j );
    775     assert( found );
    776     session->peerPort = session->isPortRandom ? getRandomPort( session ) : j;
    777 
    778     /* public addresses */
    779 
    780     {
    781         struct tr_bindinfo b;
    782         const char * str;
    783 
    784         str = TR_PREFS_KEY_BIND_ADDRESS_IPV4;
    785         tr_bencDictFindStr( &settings, TR_PREFS_KEY_BIND_ADDRESS_IPV4, &str );
    786         if( !tr_pton( str, &b.addr ) || ( b.addr.type != TR_AF_INET ) )
    787             b.addr = tr_inaddr_any;
    788         b.socket = -1;
    789         session->public_ipv4 = tr_memdup( &b, sizeof( struct tr_bindinfo ) );
    790 
    791         str = TR_PREFS_KEY_BIND_ADDRESS_IPV6;
    792         tr_bencDictFindStr( &settings, TR_PREFS_KEY_BIND_ADDRESS_IPV6, &str );
    793         if( !tr_pton( str, &b.addr ) || ( b.addr.type != TR_AF_INET6 ) )
    794             b.addr = tr_in6addr_any;
    795         b.socket = -1;
    796         session->public_ipv6 = tr_memdup( &b, sizeof( struct tr_bindinfo ) );
    797 
    798         open_incoming_peer_port( session );
    799     }
    800 
    801     session->shared = tr_sharedInit( session, boolVal );
    802 
    803     /**
    804     **/
    805 
    806     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, &i );
    807     assert( found );
    808     session->uploadSlotsPerTorrent = i;
    809 
    810     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_USPEED, &i )
    811          && tr_bencDictFindBool( &settings, TR_PREFS_KEY_USPEED_ENABLED, &boolVal );
    812     assert( found );
    813     tr_sessionSetSpeedLimit( session, TR_UP, i );
    814     tr_sessionLimitSpeed( session, TR_UP, boolVal );
    815 
    816     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_DSPEED, &i )
    817          && tr_bencDictFindBool( &settings, TR_PREFS_KEY_DSPEED_ENABLED, &boolVal );
    818     assert( found );
    819     tr_sessionSetSpeedLimit( session, TR_DOWN, i );
    820     tr_sessionLimitSpeed( session, TR_DOWN, boolVal );
    821 
    822     found = tr_bencDictFindReal( &settings, TR_PREFS_KEY_RATIO, &d )
    823          && tr_bencDictFindBool( &settings, TR_PREFS_KEY_RATIO_ENABLED, &boolVal );
    824     assert( found );
    825     tr_sessionSetRatioLimit( session, d );
    826     tr_sessionSetRatioLimited( session, boolVal );
    827 
    828     /**
    829     ***  Alternate speed limits
    830     **/
    831 
    832     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_UP, &i );
    833     assert( found );
    834     session->altSpeed[TR_UP] = i;
    835 
    836     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_DOWN, &i );
    837     assert( found );
    838     session->altSpeed[TR_DOWN] = i;
    839 
    840     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, &i );
    841     assert( found );
    842     session->altSpeedTimeBegin = i;
    843 
    844     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_TIME_END, &i );
    845     assert( found );
    846     session->altSpeedTimeEnd = i;
    847 
    848     found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, &i );
    849     assert( found );
    850     session->altSpeedTimeDay = i;
    851 
    852     found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, &boolVal );
    853     assert( found );
    854     useAltSpeedTime( session, boolVal, FALSE );
    855 
    856     if( !boolVal )
    857     {
    858         found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_ALT_SPEED_ENABLED, &boolVal );
    859         assert( found );
    860         useAltSpeed( session, boolVal, FALSE );
    861     }
    862     else
    863         useAltSpeed( session, isAltTime( session ), FALSE );
     655    session->shared = tr_sharedInit( session );
    864656
    865657    /**
     
    867659    **/
    868660
    869     filename = tr_buildPath( session->configDir, "blocklists", NULL );
    870     tr_mkdirp( filename, 0777 );
    871     tr_free( filename );
    872     found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, &boolVal );
    873     assert( found );
    874     session->isBlocklistEnabled = boolVal;
    875     loadBlocklists( session );
    876 
    877     session->rpcServer = tr_rpcInit( session, &settings );
    878 
    879     tr_bencFree( &settings );
     661    {
     662        char * filename = tr_buildPath( session->configDir, "blocklists", NULL );
     663        tr_mkdirp( filename, 0777 );
     664        tr_free( filename );
     665        loadBlocklists( session );
     666    }
    880667
    881668    assert( tr_isSession( session ) );
     
    896683
    897684    tr_statsInit( session );
     685
    898686    session->web = tr_webInit( session, &session->public_ipv4->addr );
    899     session->isWaiting = FALSE;
     687    --session->waiting;
     688
     689///cccc
     690//initBlocklist       
     691//    session->rpcServer = tr_rpcInit( session, settings );
     692
     693
     694    tr_sessionSet( session, &settings );
    900695
    901696    if( session->isDHTEnabled )
     
    907702#endif
    908703    }
     704
     705    /* cleanup */
     706    tr_bencFree( &settings );
     707}
     708
     709static void
     710sessionSetImpl( void * vdata )
     711{
     712    int64_t i;
     713    double  d;
     714    tr_bool boolVal;
     715    const char * str;
     716    struct tr_bindinfo b;
     717    struct init_data * data = vdata;
     718    tr_session * session = data->session;
     719    tr_benc * settings = data->clientSettings;
     720
     721    assert( tr_isSession( session ) );
     722    assert( tr_bencIsDict( settings ) );
     723    assert( tr_amInEventThread( session ) );
     724
     725    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_UMASK, &i ) ) {
     726        session->umask = (mode_t)i;
     727        umask( session->umask );
     728    }
     729
     730    /* misc features */
     731    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_LAZY_BITFIELD, &boolVal ) )
     732        tr_sessionSetLazyBitfieldEnabled( session, boolVal );
     733    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PEER_LIMIT_TORRENT, &i ) )
     734        tr_sessionSetPeerLimitPerTorrent( session, i );
     735    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_MSGLEVEL, &i ) )
     736        tr_setMessageLevel( i );
     737    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_PEX_ENABLED, &boolVal ) )
     738        tr_sessionSetPexEnabled( session, boolVal );
     739    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_DHT_ENABLED, &boolVal ) )
     740        tr_sessionSetDHTEnabled( session, boolVal );
     741    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ENCRYPTION, &i ) )
     742        tr_sessionSetEncryption( session, i );
     743    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PEER_SOCKET_TOS, &i ) )
     744        session->peerSocketTOS = i;
     745    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, &boolVal ) )
     746        tr_blocklistSetEnabled( session, boolVal );
     747
     748    /* files and directories */
     749    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PREALLOCATION, &i ) )
     750        session->preallocationMode = i;
     751    if( tr_bencDictFindStr( settings, TR_PREFS_KEY_DOWNLOAD_DIR, &str ) )
     752        tr_sessionSetDownloadDir( session, str );
     753    if( tr_bencDictFindStr( settings, TR_PREFS_KEY_INCOMPLETE_DIR, &str ) )
     754        tr_sessionSetIncompleteDir( session, str );
     755    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, &boolVal ) )
     756        tr_sessionSetIncompleteDirEnabled( session, boolVal );
     757    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_RENAME_PARTIAL_FILES, &boolVal ) )
     758        tr_sessionSetIncompleteFileNamingEnabled( session, boolVal );
     759
     760    /* proxies */
     761    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_PROXY_ENABLED, &boolVal ) )
     762        tr_sessionSetProxyEnabled( session, boolVal );
     763    if( tr_bencDictFindStr( settings, TR_PREFS_KEY_PROXY, &str ) )
     764        tr_sessionSetProxy( session, str );
     765    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PROXY_PORT, &i ) )
     766        tr_sessionSetProxyPort( session, i );
     767    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PROXY_TYPE, &i ) )
     768        tr_sessionSetProxyType( session, i );
     769    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_PROXY_AUTH_ENABLED, &boolVal ) )
     770        tr_sessionSetProxyAuthEnabled( session, boolVal );
     771    if( tr_bencDictFindStr( settings, TR_PREFS_KEY_PROXY_USERNAME, &str ) )
     772        tr_sessionSetProxyUsername( session, str );
     773    if( tr_bencDictFindStr( settings, TR_PREFS_KEY_PROXY_PASSWORD, &str ) )
     774        tr_sessionSetProxyPassword( session, str );
     775
     776    /* rpc server */
     777    if( session->rpcServer != NULL ) /* close the old one */
     778        tr_rpcClose( &session->rpcServer );
     779    session->rpcServer = tr_rpcInit( session, settings );
     780
     781    /* public addresses */
     782
     783    free_incoming_peer_port( session );
     784
     785    str = TR_PREFS_KEY_BIND_ADDRESS_IPV4;
     786    tr_bencDictFindStr( settings, TR_PREFS_KEY_BIND_ADDRESS_IPV4, &str );
     787    if( !tr_pton( str, &b.addr ) || ( b.addr.type != TR_AF_INET ) )
     788        b.addr = tr_inaddr_any;
     789    b.socket = -1;
     790    session->public_ipv4 = tr_memdup( &b, sizeof( struct tr_bindinfo ) );
     791
     792    str = TR_PREFS_KEY_BIND_ADDRESS_IPV6;
     793    tr_bencDictFindStr( settings, TR_PREFS_KEY_BIND_ADDRESS_IPV6, &str );
     794    if( !tr_pton( str, &b.addr ) || ( b.addr.type != TR_AF_INET6 ) )
     795        b.addr = tr_in6addr_any;
     796    b.socket = -1;
     797    session->public_ipv6 = tr_memdup( &b, sizeof( struct tr_bindinfo ) );
     798
     799    /* incoming peer port */
     800    if( tr_bencDictFindInt ( settings, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW, &i ) )
     801        session->randomPortLow = i;
     802    if( tr_bencDictFindInt ( settings, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH, &i ) )
     803        session->randomPortHigh = i;
     804    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, &boolVal ) )
     805        tr_sessionSetPeerPortRandomOnStart( session, boolVal );
     806    if( !tr_bencDictFindInt( settings, TR_PREFS_KEY_PEER_PORT, &i ) )
     807        i = session->peerPort;
     808    tr_sessionSetPeerPort( session, boolVal ? getRandomPort( session ) : i );
     809    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_PORT_FORWARDING, &boolVal ) )
     810        tr_sessionSetPortForwardingEnabled( session, boolVal );
     811
     812    /* file and peer socket limits */
     813    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, &i ) )
     814        tr_fdSetPeerLimit( session, i );
     815    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_OPEN_FILE_LIMIT, &i ) )
     816        tr_fdSetFileLimit( session, i );
     817
     818    /**
     819    **/
     820
     821    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, &i ) )
     822        session->uploadSlotsPerTorrent = i;
     823
     824    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_USPEED, &i ) )
     825        tr_sessionSetSpeedLimit( session, TR_UP, i );
     826    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_USPEED_ENABLED, &boolVal ) )
     827        tr_sessionLimitSpeed( session, TR_UP, boolVal );
     828
     829    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_DSPEED, &i ) )
     830        tr_sessionSetSpeedLimit( session, TR_DOWN, i );
     831    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_DSPEED_ENABLED, &boolVal ) )
     832        tr_sessionLimitSpeed( session, TR_DOWN, boolVal );
     833
     834    if( tr_bencDictFindReal( settings, TR_PREFS_KEY_RATIO, &d ) )
     835        tr_sessionSetRatioLimit( session, d );
     836    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_RATIO_ENABLED, &boolVal ) )
     837        tr_sessionSetRatioLimited( session, boolVal );
     838
     839    /**
     840    ***  Alternate speed limits
     841    **/
     842
     843    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_UP, &i ) )
     844        tr_sessionSetAltSpeed( session, TR_UP, i );
     845    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_DOWN, &i ) )
     846        tr_sessionSetAltSpeed( session, TR_DOWN, i );
     847    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, &i ) )
     848        tr_sessionSetAltSpeedBegin( session, i );
     849    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_TIME_END, &i ) )
     850        tr_sessionSetAltSpeedEnd( session, i );
     851    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, &i ) )
     852        tr_sessionSetAltSpeedDay( session, i );
     853    if( tr_bencDictFindBool( settings, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, &boolVal ) )
     854        useAltSpeedTime( session, boolVal, FALSE );
     855    if( boolVal )
     856        useAltSpeed( session, isAltTime( session ), FALSE );
     857    else if( tr_bencDictFindBool( settings, TR_PREFS_KEY_ALT_SPEED_ENABLED, &boolVal ) )
     858        useAltSpeed( session, boolVal, FALSE );
     859
     860
     861
     862    fprintf( stderr, "what was passed in: \n%s\n", tr_bencToStr( settings, TR_FMT_JSON, NULL ) );
     863
     864    fprintf( stderr, "-=-=-=-=-=-\n" );
     865
     866    {
     867    tr_benc tmp;
     868    tr_bencInitDict( &tmp, 0 );
     869    tr_sessionGetSettings( session, &tmp );
     870    fprintf( stderr, "and the session's state now: \n%s\n", tr_bencToStr( &tmp, TR_FMT_JSON, NULL ) );
     871    tr_bencFree( &tmp );
     872    }
     873
     874    --session->waiting;
     875}
     876
     877void
     878tr_sessionSet( tr_session * session, struct tr_benc  * settings )
     879{
     880    struct init_data data;
     881    data.session = session;
     882    data.clientSettings = settings;
     883
     884    /* run the rest in the libtransmission thread */
     885    ++session->waiting;
     886    tr_runInEventThread( session, sessionSetImpl, &data );
     887    while( session->waiting > 0 )
     888        tr_wait( 100 );
    909889}
    910890
     
    10451025
    10461026void
    1047 tr_sessionSetPeerPort( tr_session * session,
    1048                        tr_port      port )
    1049 {
    1050     assert( tr_isSession( session ) );
    1051 
    1052     session->peerPort = port;
    1053 
    1054     tr_runInEventThread( session, setPeerPort, session );
     1027tr_sessionSetPeerPort( tr_session * session, tr_port port )
     1028{
     1029    assert( tr_isSession( session ) );
     1030
     1031    if( session->peerPort != port )
     1032    {
     1033        session->peerPort = port;
     1034
     1035        tr_runInEventThread( session, setPeerPort, session );
     1036    }
    10551037}
    10561038
     
    14691451    assert( tr_isSession( session ) );
    14701452
    1471     tr_fdSetPeerLimit( maxGlobalPeers );
     1453    tr_fdSetPeerLimit( session, maxGlobalPeers );
    14721454}
    14731455
     
    14771459    assert( tr_isSession( session ) );
    14781460
    1479     return tr_fdGetPeerLimit( );
     1461    return tr_fdGetPeerLimit( session );
    14801462}
    14811463
     
    16221604    }
    16231605
    1624     tr_fdClose( );
     1606    tr_fdClose( session );
    16251607
    16261608    /* close the libtransmission thread */
     
    21502132{
    21512133    assert( tr_isSession( session ) );
     2134    assert( tr_isBool( isEnabled ) );
    21522135
    21532136    session->isProxyEnabled = isEnabled != 0;
     
    22222205{
    22232206    assert( tr_isSession( session ) );
     2207    assert( tr_isBool( isEnabled ) );
    22242208
    22252209    session->isProxyAuthEnabled = isEnabled != 0;
  • trunk/libtransmission/session.h

    r9337 r9387  
    4040struct tr_bandwidth;
    4141struct tr_bindsockets;
     42struct tr_fdInfo;
    4243
    4344struct tr_session
     
    5051    tr_bool                      isProxyAuthEnabled;
    5152    tr_bool                      isClosed;
    52     tr_bool                      isWaiting;
    5353    tr_bool                      useLazyBitfield;
    5454    tr_bool                      isIncompleteFileNamingEnabled;
     
    5858    tr_benc                      removedTorrents;
    5959
     60    int                          waiting;
    6061    int                          umask;
    6162
     
    7576    void                       * altCallbackUserData;
    7677
     78    struct tr_fdInfo           * fdInfo;
    7779
    7880    int                          magicNumber;
     
    8587
    8688    uint16_t                     peerLimitPerTorrent;
    87     uint16_t                     openFileLimit;
    8889
    8990    int                          uploadSlotsPerTorrent;
     
    131132    struct event               * altTimer;
    132133    struct event               * saveTimer;
    133 
    134     /* the size of the output buffer for peer connections */
    135     int so_sndbuf;
    136 
    137     /* the size of the input buffer for peer connections */
    138     int so_rcvbuf;
    139134
    140135    /* monitors the "global pool" speeds */
  • trunk/libtransmission/torrent.c

    r9351 r9387  
    14511451    tr_announcerTorrentStopped( tor );
    14521452
    1453     tr_fdTorrentClose( tor->uniqueId );
     1453    tr_fdTorrentClose( tor->session, tor->uniqueId );
    14541454
    14551455    if( !tor->isDeleting )
     
    16191619        tor->completeness = completeness;
    16201620        tor->needsSeedRatioCheck = TRUE;
    1621         tr_fdTorrentClose( tor->uniqueId );
     1621        tr_fdTorrentClose( tor->session, tor->uniqueId );
    16221622
    16231623        /* if the torrent is a seed now,
     
    23432343
    23442344    /* close all the files because we're about to delete them */
    2345     tr_fdTorrentClose( tor->uniqueId );
     2345    tr_fdTorrentClose( tor->session, tor->uniqueId );
    23462346
    23472347    if( tor->info.fileCount > 1 )
     
    25332533
    25342534    /* close the file so that we can reopen in read-only mode as needed */
    2535     tr_fdFileClose( tor, fileNum );
     2535    tr_fdFileClose( tor->session, tor, fileNum );
    25362536
    25372537    /* if the torrent's filename on disk isn't the same as the one in the metadata,
  • trunk/libtransmission/transmission.h

    r9344 r9387  
    304304                             struct tr_benc * settings );
    305305
     306void tr_sessionSet( tr_session      * session,
     307                    struct tr_benc  * settings );
     308
    306309/** @brief End a libtransmission session
    307310    @see tr_sessionInit() */
  • trunk/libtransmission/web.h

    r9383 r9387  
    1414#define TR_HTTP_H
    1515
     16struct tr_address;
    1617typedef struct tr_web tr_web;
    1718
Note: See TracChangeset for help on using the changeset viewer.