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

This commit is contained in:
Charles Kerr 2009-10-23 03:41:36 +00:00
parent 9575e54a04
commit c85ee09fef
17 changed files with 473 additions and 368 deletions

View File

@ -99,11 +99,27 @@ showUsage( void )
}
static void
gotsig( int sig UNUSED )
got_sigint( int sig UNUSED )
{
closing = TRUE;
}
static void
got_sighup( int sig UNUSED )
{
tr_benc settings;
const char * configDir = tr_sessionGetConfigDir( mySession );
/* reload the settings */
tr_inf( "Reloading settings from \"%s\"", configDir );
tr_bencInitDict( &settings, 0 );
tr_sessionLoadSettings( &settings, configDir, MY_NAME );
tr_sessionSet( mySession, &settings );
/* cleanup */
tr_bencFree( &settings );
}
#if defined(WIN32)
#define USE_NO_DAEMON
#elif !defined(HAVE_DAEMON) || defined(__UCLIBC__)
@ -213,12 +229,9 @@ main( int argc, char ** argv )
const char * configDir = NULL;
dtr_watchdir * watchdir = NULL;
signal( SIGINT, gotsig );
signal( SIGTERM, gotsig );
signal( SIGINT, got_sigint );
#ifndef WIN32
signal( SIGQUIT, gotsig );
signal( SIGPIPE, SIG_IGN );
signal( SIGHUP, SIG_IGN );
signal( SIGHUP, got_sighup );
#endif
/* load settings from defaults + config file */
@ -312,6 +325,7 @@ main( int argc, char ** argv )
/* start the session */
mySession = tr_sessionInit( "daemon", configDir, FALSE, &settings );
tr_sessionSaveSettings( mySession, configDir, &settings );
if( tr_bencDictFindBool( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, &boolVal ) && boolVal )
tr_ninf( MY_NAME, "requiring authentication" );

View File

@ -299,20 +299,15 @@ onRPCChanged( tr_session * session UNUSED,
tr_core_add_torrent( cbdata->core, tr_torrent_new_preexisting( tor ), TRUE );
break;
case TR_RPC_TORRENT_STARTED:
/* this should be automatic */
break;
case TR_RPC_TORRENT_STOPPED:
/* this should be automatic */
break;
case TR_RPC_TORRENT_REMOVING:
tr_core_torrent_destroyed( cbdata->core, tr_torrentId( tor ) );
break;
case TR_RPC_TORRENT_CHANGED:
case TR_RPC_SESSION_CHANGED:
case TR_RPC_TORRENT_CHANGED:
case TR_RPC_TORRENT_MOVED:
case TR_RPC_TORRENT_STARTED:
case TR_RPC_TORRENT_STOPPED:
/* nothing interesting to do here */
break;
}

View File

@ -63,6 +63,8 @@
#include "list.h"
#include "net.h"
#include "platform.h" /* MAX_PATH_LENGTH, TR_PATH_DELIMITER */
#include "session.h"
#include "torrent.h" /* tr_isTorrent() */
#include "utils.h"
#define dbgmsg( ... ) \
@ -91,16 +93,15 @@ struct tr_openfile
uint64_t date;
};
struct tr_fd_s
struct tr_fdInfo
{
int socketCount;
int socketLimit;
int publicSocketLimit;
int openFileLimit;
struct tr_openfile * openFiles;
};
static struct tr_fd_s * gFd = NULL;
/***
****
**** Local Files
@ -277,16 +278,22 @@ tr_close_file( int fd )
* plus the errno values set by tr_mkdirp() and open().
*/
static int
TrOpenFile( int i,
TrOpenFile( tr_session * session,
int i,
const char * filename,
tr_bool doWrite,
tr_preallocation_mode preallocationMode,
uint64_t desiredFileSize )
{
struct tr_openfile * file = &gFd->openFiles[i];
int flags;
struct stat sb;
tr_bool alreadyExisted;
int flags;
struct stat sb;
tr_bool alreadyExisted;
struct tr_openfile * file;
assert( tr_isSession( session ) );
assert( session->fdInfo != NULL );
file = &session->fdInfo->openFiles[i];
/* create subfolders, if any */
if( doWrite )
@ -370,15 +377,21 @@ TrCloseFile( struct tr_openfile * o )
}
int
tr_fdFileGetCached( int torrentId,
tr_file_index_t fileNum,
tr_bool doWrite )
tr_fdFileGetCached( tr_session * session,
int torrentId,
tr_file_index_t fileNum,
tr_bool doWrite )
{
struct tr_openfile * match = NULL;
struct tr_fdInfo * gFd;
assert( tr_isSession( session ) );
assert( session->fdInfo != NULL );
assert( torrentId > 0 );
assert( tr_isBool( doWrite ) );
gFd = session->fdInfo;
/* is it already open? */
{
int i;
@ -410,7 +423,8 @@ tr_fdFileGetCached( int torrentId,
/* returns an fd on success, or a -1 on failure and sets errno */
int
tr_fdFileCheckout( int torrentId,
tr_fdFileCheckout( tr_session * session,
int torrentId,
tr_file_index_t fileNum,
const char * filename,
tr_bool doWrite,
@ -418,12 +432,17 @@ tr_fdFileCheckout( int torrentId,
uint64_t desiredFileSize )
{
int i, winner = -1;
struct tr_fdInfo * gFd;
struct tr_openfile * o;
assert( tr_isSession( session ) );
assert( session->fdInfo != NULL );
assert( torrentId > 0 );
assert( filename && *filename );
assert( tr_isBool( doWrite ) );
gFd = session->fdInfo;
dbgmsg( "looking for file '%s', writable %c", filename, doWrite ? 'y' : 'n' );
/* is it already open? */
@ -487,7 +506,7 @@ tr_fdFileCheckout( int torrentId,
o = &gFd->openFiles[winner];
if( !fileIsOpen( o ) )
{
const int err = TrOpenFile( winner, filename, doWrite,
const int err = TrOpenFile( session, winner, filename, doWrite,
preallocationMode, desiredFileSize );
if( err ) {
errno = err;
@ -508,11 +527,22 @@ tr_fdFileCheckout( int torrentId,
}
void
tr_fdFileClose( const tr_torrent * tor, tr_file_index_t fileNum )
tr_fdFileClose( tr_session * session,
const tr_torrent * tor,
tr_file_index_t fileNum )
{
struct tr_openfile * o;
struct tr_fdInfo * gFd;
const struct tr_openfile * end;
const int torrentId = tr_torrentId( tor );
assert( tr_isSession( session ) );
assert( session->fdInfo != NULL );
assert( tr_isTorrent( tor ) );
assert( fileNum < tor->info.fileCount );
gFd = session->fdInfo;
for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
{
if( torrentId != o->torrentId )
@ -528,11 +558,17 @@ tr_fdFileClose( const tr_torrent * tor, tr_file_index_t fileNum )
}
void
tr_fdTorrentClose( int torrentId )
tr_fdTorrentClose( tr_session * session, int torrentId )
{
struct tr_openfile * o;
struct tr_fdInfo * gFd;
const struct tr_openfile * end;
assert( tr_isSession( session ) );
assert( session->fdInfo != NULL );
gFd = session->fdInfo;
for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
if( fileIsOpen( o ) && ( o->torrentId == torrentId ) )
TrCloseFile( o );
@ -544,18 +580,18 @@ tr_fdTorrentClose( int torrentId )
****
***/
static TR_INLINE int
getSocketMax( struct tr_fd_s * gFd )
{
return gFd->socketLimit;
}
int
tr_fdSocketCreate( int domain, int type )
tr_fdSocketCreate( tr_session * session, int domain, int type )
{
int s = -1;
struct tr_fdInfo * gFd;
if( gFd->socketCount < getSocketMax( gFd ) )
assert( tr_isSession( session ) );
assert( session->fdInfo != NULL );
gFd = session->fdInfo;
if( gFd->socketCount < gFd->socketLimit )
if( ( s = socket( domain, type, 0 ) ) < 0 )
{
if( sockerrno != EAFNOSUPPORT )
@ -567,26 +603,31 @@ tr_fdSocketCreate( int domain, int type )
++gFd->socketCount;
assert( gFd->socketCount >= 0 );
return s;
}
int
tr_fdSocketAccept( int b,
tr_fdSocketAccept( tr_session * session,
int b,
tr_address * addr,
tr_port * port )
{
int s;
unsigned int len;
struct tr_fdInfo * gFd;
struct sockaddr_storage sock;
assert( tr_isSession( session ) );
assert( session->fdInfo != NULL );
assert( addr );
assert( port );
gFd = session->fdInfo;
len = sizeof( struct sockaddr_storage );
s = accept( b, (struct sockaddr *) &sock, &len );
if( ( s >= 0 ) && gFd->socketCount > getSocketMax( gFd ) )
if( ( s >= 0 ) && gFd->socketCount > gFd->socketLimit )
{
EVUTIL_CLOSESOCKET( s );
s = -1;
@ -623,8 +664,15 @@ tr_fdSocketAccept( int b,
}
void
tr_fdSocketClose( int fd )
tr_fdSocketClose( tr_session * session, int fd )
{
struct tr_fdInfo * gFd;
assert( tr_isSession( session ) );
assert( session->fdInfo != NULL );
gFd = session->fdInfo;
if( fd >= 0 )
{
EVUTIL_CLOSESOCKET( fd );
@ -640,59 +688,103 @@ tr_fdSocketClose( int fd )
****
***/
void
tr_fdInit( size_t openFileLimit, size_t socketLimit )
static void
ensureSessionFdInfoExists( tr_session * session )
{
int i;
assert( tr_isSession( session ) );
assert( gFd == NULL );
gFd = tr_new0( struct tr_fd_s, 1 );
gFd->openFiles = tr_new0( struct tr_openfile, openFileLimit );
gFd->openFileLimit = openFileLimit;
#ifdef HAVE_GETRLIMIT
{
struct rlimit rlim;
getrlimit( RLIMIT_NOFILE, &rlim );
rlim.rlim_cur = MIN( rlim.rlim_max,
(rlim_t)( socketLimit + NOFILE_BUFFER ) );
setrlimit( RLIMIT_NOFILE, &rlim );
gFd->socketLimit = rlim.rlim_cur - NOFILE_BUFFER;
tr_dbg( "setrlimit( RLIMIT_NOFILE, %d )", (int)rlim.rlim_cur );
}
#else
gFd->socketLimit = socketLimit;
#endif
tr_dbg( "%zu usable file descriptors", socketLimit );
for( i = 0; i < gFd->openFileLimit; ++i )
gFd->openFiles[i].fd = -1;
if( session->fdInfo == NULL )
session->fdInfo = tr_new0( struct tr_fdInfo, 1 );
}
void
tr_fdClose( void )
tr_fdClose( tr_session * session )
{
struct tr_fdInfo * gFd;
struct tr_openfile * o;
const struct tr_openfile * end;
assert( tr_isSession( session ) );
assert( session->fdInfo != NULL );
gFd = session->fdInfo;
for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
if( fileIsOpen( o ) )
TrCloseFile( o );
tr_free( gFd->openFiles );
tr_free( gFd );
gFd = NULL;
session->fdInfo = NULL;
}
/***
****
***/
void
tr_fdSetFileLimit( tr_session * session, int limit )
{
struct tr_fdInfo * gFd;
ensureSessionFdInfoExists( session );
gFd = session->fdInfo;
if( gFd->openFileLimit != limit )
{
int i;
struct tr_openfile * o;
const struct tr_openfile * end;
/* close any files we've got open */
for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
if( fileIsOpen( o ) )
TrCloseFile( o );
/* rebuild the openFiles array */
tr_free( gFd->openFiles );
gFd->openFiles = tr_new0( struct tr_openfile, limit );
gFd->openFileLimit = limit;
for( i=0; i<gFd->openFileLimit; ++i )
gFd->openFiles[i].fd = -1;
}
}
int
tr_fdGetFileLimit( const tr_session * session )
{
return session && session->fdInfo ? session->fdInfo->openFileLimit : -1;
}
void
tr_fdSetPeerLimit( uint16_t n )
tr_fdSetPeerLimit( tr_session * session, int limit )
{
assert( gFd != NULL && "tr_fdInit() must be called first!" );
gFd->socketLimit = n;
struct tr_fdInfo * gFd;
ensureSessionFdInfoExists( session );
gFd = session->fdInfo;
#ifdef HAVE_GETRLIMIT
{
struct rlimit rlim;
getrlimit( RLIMIT_NOFILE, &rlim );
rlim.rlim_cur = MIN( rlim.rlim_max, (rlim_t)( limit + NOFILE_BUFFER ) );
setrlimit( RLIMIT_NOFILE, &rlim );
gFd->socketLimit = rlim.rlim_cur - NOFILE_BUFFER;
tr_dbg( "setrlimit( RLIMIT_NOFILE, %d )", (int)rlim.rlim_cur );
}
#else
gFd->socketLimit = limit;
#endif
gFd->publicSocketLimit = limit;
tr_dbg( "%d usable file descriptors", limit );
}
uint16_t
tr_fdGetPeerLimit( void )
int
tr_fdGetPeerLimit( const tr_session * session )
{
return gFd ? gFd->socketLimit : -1;
return session && session->fdInfo ? session->fdInfo->publicSocketLimit : -1;
}

View File

@ -34,8 +34,15 @@
* @{
*/
void tr_fdInit( size_t openFileLimit,
size_t globalPeerLimit );
void tr_fdSetFileLimit( tr_session * session, int limit );
int tr_fdGetFileLimit( const tr_session * session );
void tr_fdSetGlobalPeerLimit( tr_session * session, int limit );
/***
****
***/
int tr_open_file_for_scanning( const char * filename );
@ -63,14 +70,16 @@ int64_t tr_lseek( int fd, int64_t offset, int whence );
*
* @see tr_fdFileClose
*/
int tr_fdFileCheckout( int torrentId,
int tr_fdFileCheckout( tr_session * session,
int torrentId,
tr_file_index_t fileNum,
const char * fileName,
tr_bool doWrite,
tr_preallocation_mode preallocationMode,
uint64_t desiredFileSize );
int tr_fdFileGetCached( int torrentId,
int tr_fdFileGetCached( tr_session * session,
int torrentId,
tr_file_index_t fileNum,
tr_bool doWrite );
@ -82,36 +91,39 @@ int tr_fdFileGetCached( int torrentId,
*
* @see tr_fdFileCheckout
*/
void tr_fdFileClose( const tr_torrent * tor, tr_file_index_t fileNo );
void tr_fdFileClose( tr_session * session,
const tr_torrent * tor,
tr_file_index_t fileNo );
/**
* Closes all the files associated with a given torrent id
*/
void tr_fdTorrentClose( int torrentId );
void tr_fdTorrentClose( tr_session * session, int torrentId );
/***********************************************************************
* Sockets
**********************************************************************/
int tr_fdSocketCreate( int domain, int type );
int tr_fdSocketCreate( tr_session * session, int domain, int type );
int tr_fdSocketAccept( int b,
int tr_fdSocketAccept( tr_session * session,
int b,
tr_address * addr,
tr_port * port );
void tr_fdSocketClose( int s );
void tr_fdSocketClose( tr_session * session, int s );
/***********************************************************************
* tr_fdClose
***********************************************************************
* Frees resources allocated by tr_fdInit.
**********************************************************************/
void tr_fdClose( void );
void tr_fdClose( tr_session * session );
void tr_fdSetPeerLimit( uint16_t n );
void tr_fdSetPeerLimit( tr_session * session, int n );
uint16_t tr_fdGetPeerLimit( void );
int tr_fdGetPeerLimit( const tr_session * );
/* @} */

View File

@ -66,7 +66,8 @@ tr_lseek( int fd, int64_t offset, int whence )
/* returns 0 on success, or an errno on failure */
static int
readOrWriteBytes( const tr_torrent * tor,
readOrWriteBytes( tr_session * session,
const tr_torrent * tor,
int ioMode,
tr_file_index_t fileIndex,
uint64_t fileOffset,
@ -89,7 +90,7 @@ readOrWriteBytes( const tr_torrent * tor,
if( !file->length )
return 0;
fd = tr_fdFileGetCached( tr_torrentId( tor ), fileIndex, doWrite );
fd = tr_fdFileGetCached( session, tr_torrentId( tor ), fileIndex, doWrite );
if( fd < 0 )
{
@ -125,7 +126,7 @@ readOrWriteBytes( const tr_torrent * tor,
{
char * filename = tr_buildPath( base, subpath, NULL );
if( ( fd = tr_fdFileCheckout( tor->uniqueId, fileIndex, filename,
if( ( fd = tr_fdFileCheckout( session, tor->uniqueId, fileIndex, filename,
doWrite, preallocationMode, file->length ) ) < 0 )
{
err = errno;
@ -219,7 +220,7 @@ readOrWritePiece( tr_torrent * tor,
const tr_file * file = &info->files[fileIndex];
const uint64_t bytesThisPass = MIN( buflen, file->length - fileOffset );
err = readOrWriteBytes( tor, ioMode, fileIndex, fileOffset, buf, bytesThisPass );
err = readOrWriteBytes( tor->session, tor, ioMode, fileIndex, fileOffset, buf, bytesThisPass );
buf += bytesThisPass;
buflen -= bytesThisPass;
++fileIndex;

View File

@ -303,12 +303,12 @@ tr_netOpenTCP( tr_session * session,
if( isMulticastAddress( addr ) || isIPv6LinkLocalAddress( addr ) )
return -EINVAL;
s = tr_fdSocketCreate( domains[addr->type], SOCK_STREAM );
s = tr_fdSocketCreate( session, domains[addr->type], SOCK_STREAM );
if( s < 0 )
return -1;
if( evutil_make_socket_nonblocking( s ) < 0 ) {
tr_netClose( s );
tr_netClose( session, s );
return -1;
}
@ -339,7 +339,7 @@ tr_netOpenTCP( tr_session * session,
tr_err( _( "Couldn't connect socket %d to %s, port %d (errno %d - %s)" ),
s, tr_ntop_non_ts( addr ), (int)port, tmperrno,
tr_strerror( tmperrno ) );
tr_netClose( s );
tr_netClose( session, s );
s = -tmperrno;
}
@ -436,15 +436,15 @@ tr_net_hasIPv6( tr_port port )
}
int
tr_netAccept( tr_session * session UNUSED,
tr_netAccept( tr_session * session,
int b,
tr_address * addr,
tr_port * port )
{
int fd = tr_fdSocketAccept( b, addr, port );
int fd = tr_fdSocketAccept( session, b, addr, port );
if( fd>=0 && evutil_make_socket_nonblocking(fd)<0 ) {
tr_netClose( fd );
tr_netClose( session, fd );
fd = -1;
}
@ -452,7 +452,7 @@ tr_netAccept( tr_session * session UNUSED,
}
void
tr_netClose( int s )
tr_netClose( tr_session * session, int s )
{
tr_fdSocketClose( s );
tr_fdSocketClose( session, s );
}

View File

@ -114,7 +114,7 @@ int tr_netAccept( tr_session * session,
int tr_netSetTOS( int s,
int tos );
void tr_netClose( int s );
void tr_netClose( tr_session * session, int s );
void tr_netInit( void );

View File

@ -457,7 +457,7 @@ io_dtor( void * vio )
tr_bandwidthDestruct( &io->bandwidth );
evbuffer_free( io->outbuf );
evbuffer_free( io->inbuf );
tr_netClose( io->socket );
tr_netClose( io->session, io->socket );
tr_cryptoFree( io->crypto );
__tr_list_destroy( &io->outbuf_datatypes, trDatatypeFree );
@ -548,15 +548,20 @@ tr_peerIoClear( tr_peerIo * io )
int
tr_peerIoReconnect( tr_peerIo * io )
{
tr_session * session;
assert( tr_isPeerIo( io ) );
assert( !tr_peerIoIsIncoming( io ) );
if( io->socket >= 0 )
tr_netClose( io->socket );
session = tr_peerIoGetSession( io );
io->socket = tr_netOpenTCP( io->session, &io->addr, io->port );
if( io->socket >= 0 )
tr_netClose( session, io->socket );
io->socket = tr_netOpenTCP( session, &io->addr, io->port );
if( io->socket >= 0 )
{
tr_netSetTOS( io->socket, io->session->peerSocketTOS );
tr_netSetTOS( io->socket, session->peerSocketTOS );
return 0;
}

View File

@ -1332,26 +1332,31 @@ tr_peerMgrAddIncoming( tr_peerMgr * manager,
tr_port port,
int socket )
{
tr_session * session;
managerLock( manager );
if( tr_sessionIsAddressBlocked( manager->session, addr ) )
assert( tr_isSession( manager->session ) );
session = manager->session;
if( tr_sessionIsAddressBlocked( session, addr ) )
{
tr_dbg( "Banned IP address \"%s\" tried to connect to us", tr_ntop_non_ts( addr ) );
tr_netClose( socket );
tr_netClose( session, socket );
}
else if( getExistingHandshake( &manager->incomingHandshakes, addr ) )
{
tr_netClose( socket );
tr_netClose( session, socket );
}
else /* we don't have a connetion to them yet... */
{
tr_peerIo * io;
tr_handshake * handshake;
io = tr_peerIoNewIncoming( manager->session, manager->session->bandwidth, addr, port, socket );
io = tr_peerIoNewIncoming( session, session->bandwidth, addr, port, socket );
handshake = tr_handshakeNew( io,
manager->session->encryptionMode,
session->encryptionMode,
myHandshakeDoneCB,
manager );

View File

@ -130,21 +130,23 @@ onTimer( int fd UNUSED, short what UNUSED, void * vshared )
***/
tr_shared *
tr_sharedInit( tr_session * session, tr_bool isEnabled )
tr_sharedInit( tr_session * session )
{
tr_shared * s = tr_new0( tr_shared, 1 );
s->session = session;
s->isEnabled = isEnabled;
s->isEnabled = FALSE;
s->upnpStatus = TR_PORT_UNMAPPED;
s->natpmpStatus = TR_PORT_UNMAPPED;
#if 0
if( isEnabled )
{
s->timer = tr_new0( struct event, 1 );
evtimer_set( s->timer, onTimer, s );
tr_timerAdd( s->timer, 0, 333000 );
}
#endif
return s;
}

View File

@ -29,7 +29,7 @@ struct tr_bindsockets;
typedef struct tr_shared tr_shared;
tr_shared* tr_sharedInit( tr_session*, tr_bool isEnabled );
tr_shared* tr_sharedInit( tr_session* );
void tr_sharedClose( tr_session * );

View File

@ -886,8 +886,7 @@ tr_rpcClose( tr_rpc_server ** ps )
}
tr_rpc_server *
tr_rpcInit( tr_session * session,
tr_benc * settings )
tr_rpcInit( tr_session * session, tr_benc * settings )
{
tr_rpc_server * s;
tr_bool found;
@ -909,11 +908,11 @@ tr_rpcInit( tr_session * session,
found = tr_bencDictFindBool( settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, &boolVal );
assert( found );
s->isWhitelistEnabled = boolVal;
tr_rpcSetWhitelistEnabled( s, boolVal );
found = tr_bencDictFindBool( settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, &boolVal );
assert( found );
s->isPasswordEnabled = boolVal;
tr_rpcSetPasswordEnabled( s, boolVal );
found = tr_bencDictFindStr( settings, TR_PREFS_KEY_RPC_WHITELIST, &str );
assert( found );
@ -921,14 +920,11 @@ tr_rpcInit( tr_session * session,
found = tr_bencDictFindStr( settings, TR_PREFS_KEY_RPC_USERNAME, &str );
assert( found );
s->username = tr_strdup( str );
tr_rpcSetUsername( s, str );
found = tr_bencDictFindStr( settings, TR_PREFS_KEY_RPC_PASSWORD, &str );
assert( found );
if( *str != '{' )
s->password = tr_ssha1( str );
else
s->password = strdup( str );
tr_rpcSetPassword( s, str );
found = tr_bencDictFindStr( settings, TR_PREFS_KEY_RPC_BIND_ADDRESS, &str );
assert( found );

View File

@ -144,7 +144,7 @@ struct tr_bindinfo
static void
close_bindinfo( struct tr_bindinfo * b )
{
if( b->socket >=0 )
if( ( b != NULL ) && ( b->socket >=0 ) )
{
event_del( &b->ev );
EVUTIL_CLOSESOCKET( b->socket );
@ -426,7 +426,7 @@ tr_sessionGetSettings( tr_session * s, struct tr_benc * d )
tr_bencDictAddBool( d, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, tr_sessionIsIncompleteDirEnabled( s ) );
tr_bencDictAddBool( d, TR_PREFS_KEY_LAZY_BITFIELD, s->useLazyBitfield );
tr_bencDictAddInt ( d, TR_PREFS_KEY_MSGLEVEL, tr_getMessageLevel( ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_OPEN_FILE_LIMIT, s->openFileLimit );
tr_bencDictAddInt ( d, TR_PREFS_KEY_OPEN_FILE_LIMIT, tr_fdGetFileLimit( s ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, tr_sessionGetPeerLimit( s ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_LIMIT_TORRENT, s->peerLimitPerTorrent );
tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT, tr_sessionGetPeerPort( s ) );
@ -608,13 +608,13 @@ tr_sessionInit( const char * tag,
assert( session->events != NULL );
/* run the rest in the libtransmission thread */
session->isWaiting = TRUE;
++session->waiting;
data.session = session;
data.configDir = configDir;
data.messageQueuingEnabled = messageQueuingEnabled;
data.clientSettings = clientSettings;
tr_runInEventThread( session, tr_sessionInitImpl, &data );
while( session->isWaiting )
while( session->waiting > 0 )
tr_wait( 100 );
return session;
@ -626,14 +626,7 @@ static void useAltSpeedTime( tr_session * session, tr_bool enabled, tr_bool byUs
static void
tr_sessionInitImpl( void * vdata )
{
int64_t i;
int64_t j;
double d;
tr_bool found;
tr_bool boolVal;
const char * str;
tr_benc settings;
char * filename;
struct init_data * data = vdata;
tr_benc * clientSettings = data->clientSettings;
tr_session * session = data->session;
@ -641,7 +634,8 @@ tr_sessionInitImpl( void * vdata )
assert( tr_amInEventThread( session ) );
assert( tr_bencIsDict( clientSettings ) );
dbgmsg( "tr_sessionInit: the session's top-level bandwidth object is %p", session->bandwidth );
dbgmsg( "tr_sessionInit: the session's top-level bandwidth object is %p",
session->bandwidth );
tr_bencInitDict( &settings, 0 );
tr_sessionGetDefaultSettings( data->configDir, &settings );
@ -652,231 +646,24 @@ tr_sessionInitImpl( void * vdata )
signal( SIGPIPE, SIG_IGN );
#endif
/* set the session's file mode creation mask (umask) to session->umask & 0777 */
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_UMASK, &i );
assert( found );
session->umask = (mode_t)i;
umask( session->umask );
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_LIMIT_TORRENT, &i );
assert( found );
session->peerLimitPerTorrent = i;
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_MSGLEVEL, &i );
assert( found );
tr_setMessageLevel( i );
tr_setMessageQueuing( data->messageQueuingEnabled );
found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_PEX_ENABLED, &boolVal );
assert( found );
session->isPexEnabled = boolVal;
found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_DHT_ENABLED, &boolVal );
assert( found );
session->isDHTEnabled = boolVal;
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ENCRYPTION, &i );
assert( found );
assert( tr_isEncryptionMode( i ) );
session->encryptionMode = i;
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PREALLOCATION, &i );
assert( found );
assert( tr_isPreallocationMode( i ) );
session->preallocationMode = i;
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_SOCKET_TOS, &i );
assert( found );
session->peerSocketTOS = i;
found = tr_bencDictFindStr( &settings, TR_PREFS_KEY_DOWNLOAD_DIR, &str );
assert( found );
session->downloadDir = tr_strdup( str );
found = tr_bencDictFindStr( &settings, TR_PREFS_KEY_INCOMPLETE_DIR, &str );
assert( found );
tr_sessionSetIncompleteDir( session, str );
found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, &boolVal );
assert( found );
tr_sessionSetIncompleteDirEnabled( session, boolVal );
found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_RENAME_PARTIAL_FILES, &boolVal );
assert( found );
tr_sessionSetIncompleteFileNamingEnabled( session, boolVal );
found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_PROXY_ENABLED, &boolVal );
assert( found );
session->isProxyEnabled = boolVal;
found = tr_bencDictFindStr( &settings, TR_PREFS_KEY_PROXY, &str );
assert( found );
session->proxy = tr_strdup( str );
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PROXY_PORT, &i );
assert( found );
session->proxyPort = i;
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PROXY_TYPE, &i );
assert( found );
session->proxyType = i;
found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_PROXY_AUTH_ENABLED, &boolVal );
assert( found );
session->isProxyAuthEnabled = boolVal;
found = tr_bencDictFindStr( &settings, TR_PREFS_KEY_PROXY_USERNAME, &str );
assert( found );
session->proxyUsername = tr_strdup( str );
found = tr_bencDictFindStr( &settings, TR_PREFS_KEY_PROXY_PASSWORD, &str );
assert( found );
session->proxyPassword = tr_strdup( str );
session->so_sndbuf = 1500 * 3; /* 3x MTU for most ethernet/wireless */
session->so_rcvbuf = 8192;
tr_setConfigDir( session, data->configDir );
session->peerMgr = tr_peerMgrNew( session );
found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_LAZY_BITFIELD, &boolVal );
assert( found );
session->useLazyBitfield = boolVal;
/* Initialize rate and file descripts controls */
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_OPEN_FILE_LIMIT, &i );
assert( found );
session->openFileLimit = i;
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, &j );
assert( found );
tr_fdInit( session->openFileLimit, j );
/**
*** random port
**/
found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, &boolVal );
assert( found );
session->isPortRandom = boolVal;
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW, &i );
assert( found );
session->randomPortLow = i;
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH, &i );
assert( found );
session->randomPortHigh = i;
found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_PORT_FORWARDING, &boolVal )
&& tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_PORT, &j );
assert( found );
session->peerPort = session->isPortRandom ? getRandomPort( session ) : j;
/* public addresses */
{
struct tr_bindinfo b;
const char * str;
str = TR_PREFS_KEY_BIND_ADDRESS_IPV4;
tr_bencDictFindStr( &settings, TR_PREFS_KEY_BIND_ADDRESS_IPV4, &str );
if( !tr_pton( str, &b.addr ) || ( b.addr.type != TR_AF_INET ) )
b.addr = tr_inaddr_any;
b.socket = -1;
session->public_ipv4 = tr_memdup( &b, sizeof( struct tr_bindinfo ) );
str = TR_PREFS_KEY_BIND_ADDRESS_IPV6;
tr_bencDictFindStr( &settings, TR_PREFS_KEY_BIND_ADDRESS_IPV6, &str );
if( !tr_pton( str, &b.addr ) || ( b.addr.type != TR_AF_INET6 ) )
b.addr = tr_in6addr_any;
b.socket = -1;
session->public_ipv6 = tr_memdup( &b, sizeof( struct tr_bindinfo ) );
open_incoming_peer_port( session );
}
session->shared = tr_sharedInit( session, boolVal );
/**
**/
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, &i );
assert( found );
session->uploadSlotsPerTorrent = i;
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_USPEED, &i )
&& tr_bencDictFindBool( &settings, TR_PREFS_KEY_USPEED_ENABLED, &boolVal );
assert( found );
tr_sessionSetSpeedLimit( session, TR_UP, i );
tr_sessionLimitSpeed( session, TR_UP, boolVal );
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_DSPEED, &i )
&& tr_bencDictFindBool( &settings, TR_PREFS_KEY_DSPEED_ENABLED, &boolVal );
assert( found );
tr_sessionSetSpeedLimit( session, TR_DOWN, i );
tr_sessionLimitSpeed( session, TR_DOWN, boolVal );
found = tr_bencDictFindReal( &settings, TR_PREFS_KEY_RATIO, &d )
&& tr_bencDictFindBool( &settings, TR_PREFS_KEY_RATIO_ENABLED, &boolVal );
assert( found );
tr_sessionSetRatioLimit( session, d );
tr_sessionSetRatioLimited( session, boolVal );
/**
*** Alternate speed limits
**/
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_UP, &i );
assert( found );
session->altSpeed[TR_UP] = i;
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_DOWN, &i );
assert( found );
session->altSpeed[TR_DOWN] = i;
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, &i );
assert( found );
session->altSpeedTimeBegin = i;
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_TIME_END, &i );
assert( found );
session->altSpeedTimeEnd = i;
found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, &i );
assert( found );
session->altSpeedTimeDay = i;
found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, &boolVal );
assert( found );
useAltSpeedTime( session, boolVal, FALSE );
if( !boolVal )
{
found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_ALT_SPEED_ENABLED, &boolVal );
assert( found );
useAltSpeed( session, boolVal, FALSE );
}
else
useAltSpeed( session, isAltTime( session ), FALSE );
session->shared = tr_sharedInit( session );
/**
*** Blocklist
**/
filename = tr_buildPath( session->configDir, "blocklists", NULL );
tr_mkdirp( filename, 0777 );
tr_free( filename );
found = tr_bencDictFindBool( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, &boolVal );
assert( found );
session->isBlocklistEnabled = boolVal;
loadBlocklists( session );
session->rpcServer = tr_rpcInit( session, &settings );
tr_bencFree( &settings );
{
char * filename = tr_buildPath( session->configDir, "blocklists", NULL );
tr_mkdirp( filename, 0777 );
tr_free( filename );
loadBlocklists( session );
}
assert( tr_isSession( session ) );
@ -895,8 +682,16 @@ tr_sessionInitImpl( void * vdata )
tr_inf( _( "%s %s started" ), TR_NAME, LONG_VERSION_STRING );
tr_statsInit( session );
session->web = tr_webInit( session, &session->public_ipv4->addr );
session->isWaiting = FALSE;
--session->waiting;
///cccc
//initBlocklist
// session->rpcServer = tr_rpcInit( session, settings );
tr_sessionSet( session, &settings );
if( session->isDHTEnabled )
{
@ -906,6 +701,191 @@ tr_sessionInitImpl( void * vdata )
tr_dhtInit( session, &session->public_ipv4->addr );
#endif
}
/* cleanup */
tr_bencFree( &settings );
}
static void
sessionSetImpl( void * vdata )
{
int64_t i;
double d;
tr_bool boolVal;
const char * str;
struct tr_bindinfo b;
struct init_data * data = vdata;
tr_session * session = data->session;
tr_benc * settings = data->clientSettings;
assert( tr_isSession( session ) );
assert( tr_bencIsDict( settings ) );
assert( tr_amInEventThread( session ) );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_UMASK, &i ) ) {
session->umask = (mode_t)i;
umask( session->umask );
}
/* misc features */
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_LAZY_BITFIELD, &boolVal ) )
tr_sessionSetLazyBitfieldEnabled( session, boolVal );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PEER_LIMIT_TORRENT, &i ) )
tr_sessionSetPeerLimitPerTorrent( session, i );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_MSGLEVEL, &i ) )
tr_setMessageLevel( i );
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_PEX_ENABLED, &boolVal ) )
tr_sessionSetPexEnabled( session, boolVal );
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_DHT_ENABLED, &boolVal ) )
tr_sessionSetDHTEnabled( session, boolVal );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ENCRYPTION, &i ) )
tr_sessionSetEncryption( session, i );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PEER_SOCKET_TOS, &i ) )
session->peerSocketTOS = i;
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, &boolVal ) )
tr_blocklistSetEnabled( session, boolVal );
/* files and directories */
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PREALLOCATION, &i ) )
session->preallocationMode = i;
if( tr_bencDictFindStr( settings, TR_PREFS_KEY_DOWNLOAD_DIR, &str ) )
tr_sessionSetDownloadDir( session, str );
if( tr_bencDictFindStr( settings, TR_PREFS_KEY_INCOMPLETE_DIR, &str ) )
tr_sessionSetIncompleteDir( session, str );
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, &boolVal ) )
tr_sessionSetIncompleteDirEnabled( session, boolVal );
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_RENAME_PARTIAL_FILES, &boolVal ) )
tr_sessionSetIncompleteFileNamingEnabled( session, boolVal );
/* proxies */
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_PROXY_ENABLED, &boolVal ) )
tr_sessionSetProxyEnabled( session, boolVal );
if( tr_bencDictFindStr( settings, TR_PREFS_KEY_PROXY, &str ) )
tr_sessionSetProxy( session, str );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PROXY_PORT, &i ) )
tr_sessionSetProxyPort( session, i );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PROXY_TYPE, &i ) )
tr_sessionSetProxyType( session, i );
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_PROXY_AUTH_ENABLED, &boolVal ) )
tr_sessionSetProxyAuthEnabled( session, boolVal );
if( tr_bencDictFindStr( settings, TR_PREFS_KEY_PROXY_USERNAME, &str ) )
tr_sessionSetProxyUsername( session, str );
if( tr_bencDictFindStr( settings, TR_PREFS_KEY_PROXY_PASSWORD, &str ) )
tr_sessionSetProxyPassword( session, str );
/* rpc server */
if( session->rpcServer != NULL ) /* close the old one */
tr_rpcClose( &session->rpcServer );
session->rpcServer = tr_rpcInit( session, settings );
/* public addresses */
free_incoming_peer_port( session );
str = TR_PREFS_KEY_BIND_ADDRESS_IPV4;
tr_bencDictFindStr( settings, TR_PREFS_KEY_BIND_ADDRESS_IPV4, &str );
if( !tr_pton( str, &b.addr ) || ( b.addr.type != TR_AF_INET ) )
b.addr = tr_inaddr_any;
b.socket = -1;
session->public_ipv4 = tr_memdup( &b, sizeof( struct tr_bindinfo ) );
str = TR_PREFS_KEY_BIND_ADDRESS_IPV6;
tr_bencDictFindStr( settings, TR_PREFS_KEY_BIND_ADDRESS_IPV6, &str );
if( !tr_pton( str, &b.addr ) || ( b.addr.type != TR_AF_INET6 ) )
b.addr = tr_in6addr_any;
b.socket = -1;
session->public_ipv6 = tr_memdup( &b, sizeof( struct tr_bindinfo ) );
/* incoming peer port */
if( tr_bencDictFindInt ( settings, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW, &i ) )
session->randomPortLow = i;
if( tr_bencDictFindInt ( settings, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH, &i ) )
session->randomPortHigh = i;
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, &boolVal ) )
tr_sessionSetPeerPortRandomOnStart( session, boolVal );
if( !tr_bencDictFindInt( settings, TR_PREFS_KEY_PEER_PORT, &i ) )
i = session->peerPort;
tr_sessionSetPeerPort( session, boolVal ? getRandomPort( session ) : i );
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_PORT_FORWARDING, &boolVal ) )
tr_sessionSetPortForwardingEnabled( session, boolVal );
/* file and peer socket limits */
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, &i ) )
tr_fdSetPeerLimit( session, i );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_OPEN_FILE_LIMIT, &i ) )
tr_fdSetFileLimit( session, i );
/**
**/
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, &i ) )
session->uploadSlotsPerTorrent = i;
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_USPEED, &i ) )
tr_sessionSetSpeedLimit( session, TR_UP, i );
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_USPEED_ENABLED, &boolVal ) )
tr_sessionLimitSpeed( session, TR_UP, boolVal );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_DSPEED, &i ) )
tr_sessionSetSpeedLimit( session, TR_DOWN, i );
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_DSPEED_ENABLED, &boolVal ) )
tr_sessionLimitSpeed( session, TR_DOWN, boolVal );
if( tr_bencDictFindReal( settings, TR_PREFS_KEY_RATIO, &d ) )
tr_sessionSetRatioLimit( session, d );
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_RATIO_ENABLED, &boolVal ) )
tr_sessionSetRatioLimited( session, boolVal );
/**
*** Alternate speed limits
**/
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_UP, &i ) )
tr_sessionSetAltSpeed( session, TR_UP, i );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_DOWN, &i ) )
tr_sessionSetAltSpeed( session, TR_DOWN, i );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, &i ) )
tr_sessionSetAltSpeedBegin( session, i );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_TIME_END, &i ) )
tr_sessionSetAltSpeedEnd( session, i );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, &i ) )
tr_sessionSetAltSpeedDay( session, i );
if( tr_bencDictFindBool( settings, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, &boolVal ) )
useAltSpeedTime( session, boolVal, FALSE );
if( boolVal )
useAltSpeed( session, isAltTime( session ), FALSE );
else if( tr_bencDictFindBool( settings, TR_PREFS_KEY_ALT_SPEED_ENABLED, &boolVal ) )
useAltSpeed( session, boolVal, FALSE );
fprintf( stderr, "what was passed in: \n%s\n", tr_bencToStr( settings, TR_FMT_JSON, NULL ) );
fprintf( stderr, "-=-=-=-=-=-\n" );
{
tr_benc tmp;
tr_bencInitDict( &tmp, 0 );
tr_sessionGetSettings( session, &tmp );
fprintf( stderr, "and the session's state now: \n%s\n", tr_bencToStr( &tmp, TR_FMT_JSON, NULL ) );
tr_bencFree( &tmp );
}
--session->waiting;
}
void
tr_sessionSet( tr_session * session, struct tr_benc * settings )
{
struct init_data data;
data.session = session;
data.clientSettings = settings;
/* run the rest in the libtransmission thread */
++session->waiting;
tr_runInEventThread( session, sessionSetImpl, &data );
while( session->waiting > 0 )
tr_wait( 100 );
}
/***
@ -1044,14 +1024,16 @@ setPeerPort( void * session )
}
void
tr_sessionSetPeerPort( tr_session * session,
tr_port port )
tr_sessionSetPeerPort( tr_session * session, tr_port port )
{
assert( tr_isSession( session ) );
session->peerPort = port;
if( session->peerPort != port )
{
session->peerPort = port;
tr_runInEventThread( session, setPeerPort, session );
tr_runInEventThread( session, setPeerPort, session );
}
}
tr_port
@ -1468,7 +1450,7 @@ tr_sessionSetPeerLimit( tr_session * session, uint16_t maxGlobalPeers )
{
assert( tr_isSession( session ) );
tr_fdSetPeerLimit( maxGlobalPeers );
tr_fdSetPeerLimit( session, maxGlobalPeers );
}
uint16_t
@ -1476,7 +1458,7 @@ tr_sessionGetPeerLimit( const tr_session * session )
{
assert( tr_isSession( session ) );
return tr_fdGetPeerLimit( );
return tr_fdGetPeerLimit( session );
}
void
@ -1621,7 +1603,7 @@ tr_sessionClose( tr_session * session )
tr_wait( 100 );
}
tr_fdClose( );
tr_fdClose( session );
/* close the libtransmission thread */
tr_eventClose( session );
@ -2149,6 +2131,7 @@ tr_sessionSetProxyEnabled( tr_session * session,
tr_bool isEnabled )
{
assert( tr_isSession( session ) );
assert( tr_isBool( isEnabled ) );
session->isProxyEnabled = isEnabled != 0;
}
@ -2221,6 +2204,7 @@ tr_sessionSetProxyAuthEnabled( tr_session * session,
tr_bool isEnabled )
{
assert( tr_isSession( session ) );
assert( tr_isBool( isEnabled ) );
session->isProxyAuthEnabled = isEnabled != 0;
}

View File

@ -39,6 +39,7 @@ struct tr_address;
struct tr_announcer;
struct tr_bandwidth;
struct tr_bindsockets;
struct tr_fdInfo;
struct tr_session
{
@ -49,7 +50,6 @@ struct tr_session
tr_bool isProxyEnabled;
tr_bool isProxyAuthEnabled;
tr_bool isClosed;
tr_bool isWaiting;
tr_bool useLazyBitfield;
tr_bool isIncompleteFileNamingEnabled;
tr_bool isRatioLimited;
@ -57,6 +57,7 @@ struct tr_session
tr_benc removedTorrents;
int waiting;
int umask;
int speedLimit[2];
@ -74,6 +75,7 @@ struct tr_session
tr_altSpeedFunc * altCallback;
void * altCallbackUserData;
struct tr_fdInfo * fdInfo;
int magicNumber;
@ -84,7 +86,6 @@ struct tr_session
struct tr_event_handle * events;
uint16_t peerLimitPerTorrent;
uint16_t openFileLimit;
int uploadSlotsPerTorrent;
@ -131,12 +132,6 @@ struct tr_session
struct event * altTimer;
struct event * saveTimer;
/* the size of the output buffer for peer connections */
int so_sndbuf;
/* the size of the input buffer for peer connections */
int so_rcvbuf;
/* monitors the "global pool" speeds */
struct tr_bandwidth * bandwidth;

View File

@ -1450,7 +1450,7 @@ stopTorrent( void * vtor )
tr_peerMgrStopTorrent( tor );
tr_announcerTorrentStopped( tor );
tr_fdTorrentClose( tor->uniqueId );
tr_fdTorrentClose( tor->session, tor->uniqueId );
if( !tor->isDeleting )
tr_torrentSave( tor );
@ -1618,7 +1618,7 @@ tr_torrentRecheckCompleteness( tr_torrent * tor )
tor->completeness = completeness;
tor->needsSeedRatioCheck = TRUE;
tr_fdTorrentClose( tor->uniqueId );
tr_fdTorrentClose( tor->session, tor->uniqueId );
/* if the torrent is a seed now,
* and the files used to be in the incompleteDir,
@ -2342,7 +2342,7 @@ tr_torrentDeleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc )
fileFunc = remove;
/* close all the files because we're about to delete them */
tr_fdTorrentClose( tor->uniqueId );
tr_fdTorrentClose( tor->session, tor->uniqueId );
if( tor->info.fileCount > 1 )
deleteLocalData( tor, fileFunc );
@ -2532,7 +2532,7 @@ tr_torrentFileCompleted( tr_torrent * tor, tr_file_index_t fileNum )
const char * base;
/* close the file so that we can reopen in read-only mode as needed */
tr_fdFileClose( tor, fileNum );
tr_fdFileClose( tor->session, tor, fileNum );
/* if the torrent's filename on disk isn't the same as the one in the metadata,
* then it's been modified to denote that it was a partial file.

View File

@ -303,6 +303,9 @@ tr_session * tr_sessionInit( const char * tag,
tr_bool messageQueueingEnabled,
struct tr_benc * settings );
void tr_sessionSet( tr_session * session,
struct tr_benc * settings );
/** @brief End a libtransmission session
@see tr_sessionInit() */
void tr_sessionClose( tr_session * );

View File

@ -13,6 +13,7 @@
#ifndef TR_HTTP_H
#define TR_HTTP_H
struct tr_address;
typedef struct tr_web tr_web;
tr_web* tr_webInit( tr_session * session,