~ubuntu-branches/ubuntu/precise/transmission/precise

« back to all changes in this revision

Viewing changes to libtransmission/session.c

  • Committer: Bazaar Package Importer
  • Author(s): Leo Costela
  • Date: 2009-07-25 20:20:23 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (2.1.19 sid)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20090725202023-9xmfycsfotr430nv
* debian/rules: patch before configure
* debian/patches: add patch to not build libevent, regardless of
  linking (really, really closes: #537868)
* debian/changelog: fix dates

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 * This exemption does not extend to derived works not owned by
8
8
 * the Transmission project.
9
9
 *
10
 
 * $Id: session.c 8698 2009-06-15 03:24:40Z charles $
 
10
 * $Id: session.c 8819 2009-07-17 11:20:30Z livings124 $
11
11
 */
12
12
 
13
13
#include <assert.h>
15
15
#include <string.h> /* memcpy */
16
16
 
17
17
#include <signal.h>
18
 
#include <sys/types.h> /* stat */
19
 
#include <sys/stat.h> /* stat */
 
18
#include <sys/types.h> /* stat(), umask() */
 
19
#include <sys/stat.h> /* stat(), umask() */
20
20
#include <unistd.h> /* stat */
21
21
#include <dirent.h> /* opendir */
22
22
 
23
23
#include <event.h>
24
24
 
25
25
#include "transmission.h"
26
 
#include "session.h"
27
26
#include "bandwidth.h"
28
27
#include "bencode.h"
29
28
#include "blocklist.h"
37
36
#include "platform.h" /* tr_lock */
38
37
#include "port-forwarding.h"
39
38
#include "rpc-server.h"
 
39
#include "session.h"
40
40
#include "stats.h"
41
41
#include "torrent.h"
42
42
#include "tracker.h"
 
43
#include "tr-dht.h"
43
44
#include "trevent.h"
44
45
#include "utils.h"
 
46
#include "verify.h"
45
47
#include "version.h"
46
 
#include "verify.h"
47
48
#include "web.h"
48
 
#include "tr-dht.h"
49
49
 
50
50
#define dbgmsg( ... ) \
51
51
    do { \
364
364
    tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_SOCKET_TOS,          atoi( TR_DEFAULT_PEER_SOCKET_TOS_STR ) );
365
365
    tr_bencDictAddBool( d, TR_PREFS_KEY_PEX_ENABLED,              TRUE );
366
366
    tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING,          TRUE );
367
 
    tr_bencDictAddInt ( d, TR_PREFS_KEY_PREALLOCATION,            TR_PREALLOCATE_FULL );
368
 
    /* tr_bencDictAddInt ( d, TR_PREFS_KEY_PREALLOCATION,            TR_PREALLOCATE_SPARSE ); */
 
367
    tr_bencDictAddInt ( d, TR_PREFS_KEY_PREALLOCATION,            TR_PREALLOCATE_SPARSE );
369
368
    tr_bencDictAddStr ( d, TR_PREFS_KEY_PROXY,                    "" );
370
369
    tr_bencDictAddBool( d, TR_PREFS_KEY_PROXY_AUTH_ENABLED,       FALSE );
371
370
    tr_bencDictAddBool( d, TR_PREFS_KEY_PROXY_ENABLED,            FALSE );
392
391
    tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_DAY,       TR_SCHED_ALL );
393
392
    tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED,                   100 );
394
393
    tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED,           FALSE );
 
394
    tr_bencDictAddInt ( d, TR_PREFS_KEY_UMASK,                    022 );
395
395
    tr_bencDictAddInt ( d, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, 14 );
396
396
    tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV4,        TR_DEFAULT_BIND_ADDRESS_IPV4 );
397
397
    tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV6,        TR_DEFAULT_BIND_ADDRESS_IPV6 );
448
448
    tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_DAY,       tr_sessionGetAltSpeedDay( s ) );
449
449
    tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED,                   tr_sessionGetSpeedLimit( s, TR_UP ) );
450
450
    tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED,           tr_sessionIsSpeedLimited( s, TR_UP ) );
 
451
    tr_bencDictAddInt ( d, TR_PREFS_KEY_UMASK,                    s->umask );
451
452
    tr_bencDictAddInt ( d, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, s->uploadSlotsPerTorrent );
452
453
    tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV4,        tr_ntop_non_ts( &s->public_ipv4->addr ) );
453
454
    tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV6,        tr_ntop_non_ts( &s->public_ipv6->addr ) );
610
611
    signal( SIGPIPE, SIG_IGN );
611
612
#endif
612
613
 
 
614
    /* set the session's file mode creation mask (umask) to session->umask & 0777 */
 
615
    found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_UMASK, &i );
 
616
    assert( found );
 
617
    session->umask = (mode_t)i;
 
618
    umask( session->umask );
 
619
 
613
620
    found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_LIMIT_TORRENT, &i );
614
621
    assert( found );
615
622
    session->peerLimitPerTorrent = i;
837
844
    dbgmsg( "returning session %p; session->tracker is %p", session, session->tracker );
838
845
 
839
846
    if( session->isDHTEnabled )
840
 
        tr_dhtInit(session);
 
847
    {
 
848
#ifdef WITHOUT_DHT
 
849
        tr_inf( "DHT disabled by packager." );
 
850
#else
 
851
        tr_dhtInit( session );
 
852
#endif
 
853
    }
841
854
}
842
855
 
843
856
/***
1020
1033
{
1021
1034
    int isLimited = TRUE;
1022
1035
 
 
1036
    if( !tr_isSession( session ) )
 
1037
        return FALSE;
 
1038
 
1023
1039
    if( tr_sessionUsesAltSpeed( session ) )
1024
1040
        *setme = tr_sessionGetAltSpeed( session, dir );
1025
1041
    else if( tr_sessionIsSpeedLimited( session, dir ) )
1588
1604
}
1589
1605
 
1590
1606
tr_bool
 
1607
tr_sessionAllowsDHT( const tr_session * session UNUSED )
 
1608
{
 
1609
#ifdef WITHOUT_DHT
 
1610
    return 0;
 
1611
#else
 
1612
    return tr_sessionIsDHTEnabled( session );
 
1613
#endif
 
1614
}
 
1615
 
 
1616
tr_bool
1591
1617
tr_sessionIsDHTEnabled( const tr_session * session )
1592
1618
{
1593
1619
    assert( tr_isSession( session ) );