Changeset 7722
- Timestamp:
- Jan 16, 2009, 5:31:10 PM (12 years ago)
- Location:
- branches/1.5x
- Files:
-
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.5x/configure.ac
r7681 r7722 50 50 AC_C_INLINE 51 51 if test "x$GCC" = "xyes" ; then 52 CFLAGS="-std=gnu99 -ggdb3 -Wall -Wextra -Wredundant-decls -Wpointer-arith -Wformat-security -W -Wmissing-declarations -Wdeclaration-after-statement -Wcast-align -Win line -Winit-self -Wundef -Wnested-externs -Wmissing-format-attribute"52 CFLAGS="-std=gnu99 -ggdb3 -Wall -Wextra -Wredundant-decls -Wpointer-arith -Wformat-security -W -Wmissing-declarations -Wdeclaration-after-statement -Wcast-align -Winit-self -Wundef -Wnested-externs -Wmissing-format-attribute" 53 53 CXXFLAGS="-Wall -Wformat-security -W" 54 54 fi -
branches/1.5x/gtk/conf.h
r7664 r7722 23 23 *****************************************************************************/ 24 24 25 struct tr_benc;26 27 /**28 ***29 **/30 31 25 #ifndef TG_CONF_H 32 26 #define TG_CONF_H 27 28 #include <inttypes.h> 29 #include <libtransmission/transmission.h> 33 30 34 31 int64_t pref_int_get ( const char * key ); -
branches/1.5x/gtk/details.c
r7664 r7722 12 12 13 13 #include <errno.h> 14 #include <math.h> /* ceil() */ 14 15 #include <stddef.h> 15 16 #include <stdio.h> … … 1011 1012 char buf[128]; 1012 1013 const tr_stat * stat = tr_torrent_stat( a->gtor ); 1014 const tr_info * info = tr_torrent_info( a->gtor ); 1013 1015 const double complete = stat->percentComplete * 100.0; 1014 1016 const double done = stat->percentDone * 100.0; 1017 const double verifiedPieceCount = (double)stat->haveValid / info->pieceSize; 1015 1018 1016 1019 pch = tr_torrent_status_str( a->gtor ); … … 1035 1038 sizeof( sizeStr2 ) ); 1036 1039 /* %1$s is total size of what we've saved to disk 1037 %2$s is how much of it's passed the checksum test */ 1038 g_snprintf( buf, sizeof( buf ), _( 1039 "%1$s (%2$s verified)" ), sizeStr, sizeStr2 ); 1040 %2$s is how much of it's passed the checksum test 1041 %3$s is how many pieces are verified */ 1042 g_snprintf( buf, sizeof( buf ), _( "%1$s (%2$s verified in %3$d pieces)" ), 1043 sizeStr, sizeStr2, (int)ceil(verifiedPieceCount) ); 1040 1044 gtk_label_set_text( GTK_LABEL( a->have_lb ), buf ); 1041 1045 -
branches/1.5x/gtk/main.c
r7664 r7722 238 238 239 239 { 240 tr_torrent * tor = NULL;241 240 tr_session * session = tr_core_session( data->core ); 242 int activeCount = 0; 243 while(( tor = tr_torrentNext( session, tor ))) 244 if( TR_STATUS_IS_ACTIVE( tr_torrentGetActivity( tor ))) 245 ++activeCount; 241 int activeCount = tr_sessionGetActiveTorrentCount( session ); 246 242 action_sensitize( "pause-all-torrents", activeCount != 0 ); 247 243 } -
branches/1.5x/gtk/notify.c
r7664 r7722 16 16 #endif 17 17 #include <glib/gi18n.h> 18 #include "conf.h" 18 19 #include "notify.h" 20 #include "tr-prefs.h" 19 21 #include "util.h" 20 22 … … 61 63 tr_notify_send( TrTorrent *tor ) 62 64 { 63 const tr_info * info = tr_torrent_info( tor ); 64 NotifyNotification * n = notify_notification_new( _( 65 "Torrent Complete" ), 66 info->name, 67 "transmission", NULL ); 65 if( pref_flag_get( PREF_KEY_SHOW_DESKTOP_NOTIFICATION ) ) 66 { 67 const tr_info * info = tr_torrent_info( tor ); 68 NotifyNotification * n; 68 69 69 if( info->fileCount == 1 ) 70 notify_notification_add_action( n, "file", _( "Open File" ), 71 NOTIFY_ACTION_CALLBACK( 72 notifyCallback ), tor, NULL ); 73 notify_notification_add_action( n, "folder", _( "Open Folder" ), 74 NOTIFY_ACTION_CALLBACK( 75 notifyCallback ), tor, NULL ); 76 notify_notification_show( n, NULL ); 70 n = notify_notification_new( _( "Torrent Complete" ), 71 info->name, 72 "transmission", NULL ); 73 74 if( info->fileCount == 1 ) 75 notify_notification_add_action( 76 n, "file", _( "Open File" ), 77 NOTIFY_ACTION_CALLBACK( notifyCallback ), tor, 78 NULL ); 79 80 notify_notification_add_action( 81 n, "folder", _( "Open Folder" ), 82 NOTIFY_ACTION_CALLBACK( notifyCallback ), tor, NULL ); 83 84 notify_notification_show( n, NULL ); 85 } 77 86 } 78 87 -
branches/1.5x/gtk/tr-core.c
r7664 r7722 1208 1208 /* always allow hibernation when all the torrents are paused */ 1209 1209 if( inhibit ) { 1210 gboolean active = FALSE; 1211 tr_session * session = tr_core_session( core ); 1212 tr_torrent * tor = NULL; 1213 while(( tor = tr_torrentNext( session, tor ))) 1214 if(( active = ( tr_torrentGetActivity( tor ) != TR_STATUS_STOPPED ))) 1215 break; 1216 if( !active ) 1210 tr_session * session = tr_core_session( core ); 1211 1212 if( tr_sessionGetActiveTorrentCount( session ) == 0 ) 1217 1213 inhibit = FALSE; 1218 1214 } -
branches/1.5x/gtk/tr-prefs.c
r7664 r7722 40 40 cf_check_older_configs( ); 41 41 42 #if HAVE_GIO42 #ifdef HAVE_GIO 43 43 str = NULL; 44 44 if( !str ) str = g_get_user_special_dir( G_USER_DIRECTORY_DESKTOP ); … … 57 57 pref_flag_set_default ( PREF_KEY_STATUSBAR, TRUE ); 58 58 pref_flag_set_default ( PREF_KEY_SHOW_TRAY_ICON, FALSE ); 59 pref_flag_set_default ( PREF_KEY_SHOW_DESKTOP_NOTIFICATION, TRUE ); 59 60 pref_string_set_default ( PREF_KEY_STATUSBAR_STATS, "total-ratio" ); 60 61 … … 349 350 s = _( "Show _icon in the desktop Notification Area" ); 350 351 w = new_check_button( s, PREF_KEY_SHOW_TRAY_ICON, core ); 352 hig_workarea_add_wide_control( t, &row, w ); 353 354 s = _( "Show desktop _notifications" ); 355 w = new_check_button( s, PREF_KEY_SHOW_DESKTOP_NOTIFICATION, core ); 351 356 hig_workarea_add_wide_control( t, &row, w ); 352 357 -
branches/1.5x/gtk/tr-prefs.h
r7664 r7722 33 33 #define PREF_KEY_DIR_WATCH_ENABLED "watch-dir-enabled" 34 34 #define PREF_KEY_SHOW_TRAY_ICON "show-notification-area-icon" 35 #define PREF_KEY_SHOW_DESKTOP_NOTIFICATION "show-desktop-notification" 35 36 #define PREF_KEY_START "start-added-torrents" 36 37 #define PREF_KEY_TRASH_ORIGINAL "trash-original-torrent-files" -
branches/1.5x/libtransmission/completion.c
r7664 r7722 316 316 return cp->completeBlocks[piece] == tr_torPieceCountBlocks( cp->tor, piece ); 317 317 } 318 319 tr_bool 320 tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t fileIndex ) 321 { 322 tr_block_index_t block; 323 324 const tr_torrent * tor = cp->tor; 325 const tr_file * file = &tor->info.files[fileIndex]; 326 const tr_block_index_t firstBlock = file->offset / tor->blockSize; 327 const tr_block_index_t lastBlock = ( file->offset + file->length - 1 ) / tor->blockSize; 328 329 assert( tr_torBlockPiece( tor, firstBlock ) == file->firstPiece ); 330 assert( tr_torBlockPiece( tor, lastBlock ) == file->lastPiece ); 331 332 for( block=firstBlock; block<=lastBlock; ++block ) 333 if( !tr_cpBlockIsComplete( cp, block ) ) 334 return FALSE; 335 336 return TRUE; 337 } -
branches/1.5x/libtransmission/completion.h
r7664 r7722 129 129 tr_piece_index_t piece ); 130 130 131 tr_bool tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t ); 132 131 133 /** 132 134 *** Blocks 133 135 **/ 134 136 135 static TR_INLINE inttr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block ) {137 static TR_INLINE tr_bool tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block ) { 136 138 return tr_bitfieldHas( &cp->blockBitfield, block ); 137 139 } -
branches/1.5x/libtransmission/fastresume.c
r7664 r7722 416 416 tr_pex pex; 417 417 readBytes( &pex, &buf, sizeof( tr_pex ) ); 418 tr_peerMgrAddPex( tor->session->peerMgr, tor->info.hash, 419 TR_PEER_FROM_CACHE, 420 &pex ); 418 tr_peerMgrAddPex( tor, TR_PEER_FROM_CACHE, &pex ); 421 419 } 422 420 -
branches/1.5x/libtransmission/fdlimit.c
r7664 r7722 109 109 #endif 110 110 111 static int 112 preallocateFile( const char * filename, uint64_t length ) 113 { 114 int success = 0; 111 static tr_bool 112 preallocateFileSparse( int fd, uint64_t length ) 113 { 114 const char zero = '\0'; 115 116 if( length == 0 ) 117 return TRUE; 118 119 if( lseek( fd, length-1, SEEK_SET ) == -1 ) 120 return FALSE; 121 if( write( fd, &zero, 1 ) == -1 ) 122 return FALSE; 123 if( ftruncate( fd, length ) == -1 ) 124 return FALSE; 125 126 return TRUE; 127 } 128 129 static tr_bool 130 preallocateFileFull( const char * filename, uint64_t length ) 131 { 132 tr_bool success = 0; 115 133 116 134 #ifdef WIN32 … … 171 189 */ 172 190 static int 173 TrOpenFile( int i,174 const char * folder,175 const char * torrentFile,176 intdoWrite,177 int doPreallocate,178 uint64_t desiredFileSize )191 TrOpenFile( int i, 192 const char * folder, 193 const char * torrentFile, 194 tr_bool doWrite, 195 tr_preallocation_mode preallocationMode, 196 uint64_t desiredFileSize ) 179 197 { 180 198 struct tr_openfile * file = &gFd->openFiles[i]; … … 203 221 alreadyExisted = !stat( filename, &sb ) && S_ISREG( sb.st_mode ); 204 222 205 if( doWrite && !alreadyExisted && doPreallocate)206 if( preallocateFile ( filename, desiredFileSize ) )223 if( doWrite && !alreadyExisted && ( preallocationMode == TR_PREALLOCATE_FULL ) ) 224 if( preallocateFileFull( filename, desiredFileSize ) ) 207 225 tr_inf( _( "Preallocated file \"%s\"" ), filename ); 208 226 … … 225 243 } 226 244 245 if( doWrite && !alreadyExisted && ( preallocationMode == TR_PREALLOCATE_SPARSE ) ) 246 preallocateFileSparse( file->fd, desiredFileSize ); 247 227 248 tr_free( filename ); 228 249 return 0; … … 257 278 /* returns an fd on success, or a -1 on failure and sets errno */ 258 279 int 259 tr_fdFileCheckout( const char * folder,260 const char * torrentFile,261 intdoWrite,262 int doPreallocate,263 uint64_t desiredFileSize )280 tr_fdFileCheckout( const char * folder, 281 const char * torrentFile, 282 tr_bool doWrite, 283 tr_preallocation_mode preallocationMode, 284 uint64_t desiredFileSize ) 264 285 { 265 286 int i, winner = -1; … … 359 380 if( !fileIsOpen( o ) ) 360 381 { 361 const int err = TrOpenFile( winner, folder, torrentFile, doWrite, doPreallocate, desiredFileSize );382 const int err = TrOpenFile( winner, folder, torrentFile, doWrite, preallocationMode, desiredFileSize ); 362 383 if( err ) { 363 384 tr_lockUnlock( gFd->lock ); -
branches/1.5x/libtransmission/fdlimit.h
r7664 r7722 27 27 #endif 28 28 29 #include "transmission.h" 29 30 #include "net.h" 30 31 … … 51 52 * @see tr_fdFileClose 52 53 */ 53 int tr_fdFileCheckout( const char * folder,54 const char * torrentFile,55 intdoWrite,56 int doPreallocate,57 uint64_t desiredFileSize );54 int tr_fdFileCheckout( const char * folder, 55 const char * torrentFile, 56 tr_bool doWrite, 57 tr_preallocation_mode preallocationMode, 58 uint64_t desiredFileSize ); 58 59 59 60 /** -
branches/1.5x/libtransmission/handshake.c
r7664 r7722 847 847 { 848 848 const tr_bool clientIsSeed = tr_torrentIsSeed( tor ); 849 const tr_bool peerIsSeed = tr_peerMgrPeerIsSeed( handshake->session->peerMgr, 850 tor->info.hash, 851 tr_peerIoGetAddress( handshake->io, NULL ) ); 849 const tr_bool peerIsSeed = tr_peerMgrPeerIsSeed( tor, tr_peerIoGetAddress( handshake->io, NULL ) ); 852 850 dbgmsg( handshake, "got INCOMING connection's encrypted handshake for torrent [%s]", 853 851 tor->info.name ); -
branches/1.5x/libtransmission/inout.c
r7664 r7722 72 72 const tr_info * info = &tor->info; 73 73 const tr_file * file = &info->files[fileIndex]; 74 tr_preallocation_mode preallocationMode; 74 75 75 76 typedef size_t ( *iofunc )( int, void *, size_t ); … … 94 95 return 0; 95 96 97 if( ( file->dnd ) || ( ioMode != TR_IO_WRITE ) ) 98 preallocationMode = TR_PREALLOCATE_NONE; 99 else 100 preallocationMode = tor->session->preallocationMode; 101 96 102 if( ( ioMode == TR_IO_READ ) && !fileExists ) /* does file exist? */ 97 103 err = errno; 98 else if( ( fd = tr_fdFileCheckout ( tor->downloadDir, file->name, ioMode == TR_IO_WRITE, !file->dnd, file->length ) ) < 0 )104 else if( ( fd = tr_fdFileCheckout ( tor->downloadDir, file->name, ioMode == TR_IO_WRITE, preallocationMode, file->length ) ) < 0 ) 99 105 err = errno; 100 106 else if( tr_lseek( fd, (int64_t)fileOffset, SEEK_SET ) == -1 ) -
branches/1.5x/libtransmission/net.c
r7669 r7722 129 129 } 130 130 131 void 132 tr_suspectAddress( const tr_address * a UNUSED, const char * source UNUSED ) 133 { 134 /* this is overkill for a production environment, 135 * but useful in the nightly builds, so only compile it into the nightlies */ 136 #ifdef TR_UNSTABLE 137 /* be really aggressive in what we report */ 138 if( a->type == TR_AF_INET && !( ntohl( a->addr.addr4.s_addr ) & 0xff000000 ) ) 139 tr_err( "Funny looking address %s from %s", tr_ntop_non_ts( a ), source ); 140 /* /16s taken from ipv6 rib on 21 dec, 2008 */ 141 /* this is really, really ugly. expedience over quality */ 142 if( a->type == TR_AF_INET6 ) 143 { 144 uint16_t slash16; 145 uint16_t valid[] = { 0x339, 0x2002, 0x2003, 0x2400, 0x2401, 0x2402, 146 0x2403, 0x2404, 0x2405, 0x2406, 0x2407, 0x2600, 0x2607, 0x2610, 147 0x2620, 0x2800, 0x2801, 0x2a00, 0x2a01, 0x0a02, 0x2001, 0x0000 }; 148 uint16_t *p; 149 tr_bool good = FALSE; 150 p = valid; 151 memcpy( &slash16, &a->addr, 2 ); 152 slash16 = ntohs( slash16 ); 153 while( *p ) 154 { 155 if( slash16 == *p ) 156 good = TRUE; 157 p++; 158 } 159 if( !good && !IN6_IS_ADDR_V4MAPPED( &a->addr.addr6 ) ) 160 tr_err( "Funny looking address %s from %s", tr_ntop_non_ts( a ), source ); 161 } 162 #endif 163 } 164 131 165 const char * 132 166 tr_ntop( const tr_address * src, char * dst, int size ) -
branches/1.5x/libtransmission/net.h
r7669 r7722 89 89 void tr_normalizeV4Mapped( tr_address * const addr ); 90 90 91 void tr_suspectAddress( const tr_address * a, const char * source ); 92 91 93 static TR_INLINE tr_bool tr_isAddress( const tr_address * a ) { return ( a != NULL ) && ( a->type==TR_AF_INET || a->type==TR_AF_INET6 ); } 92 94 -
branches/1.5x/libtransmission/peer-mgr.c
r7669 r7722 1 1 2 /* 2 3 * This file Copyright (C) 2007-2009 Charles Kerr <charles@transmissionbt.com> … … 27 28 #include "completion.h" 28 29 #include "crypto.h" 30 #include "fdlimit.h" 29 31 #include "handshake.h" 30 32 #include "inout.h" /* tr_ioTestPiece */ … … 32 34 #include "peer-io.h" 33 35 #include "peer-mgr.h" 34 #include "peer-mgr-private.h"35 36 #include "peer-msgs.h" 36 37 #include "ptrarray.h" … … 116 117 }; 117 118 118 typedef struct 119 typedef struct tr_torrent_peers 119 120 { 120 121 tr_bool isRunning; … … 139 140 { 140 141 tr_session * session; 141 tr_ptrArray torrents; /* Torrent */142 142 tr_ptrArray incomingHandshakes; /* tr_handshake */ 143 143 tr_timer * bandwidthTimer; … … 235 235 **/ 236 236 237 static int238 torrentCompare( const void * va,239 const void * vb )240 {241 const Torrent * a = va;242 const Torrent * b = vb;243 244 return memcmp( a->hash, b->hash, SHA_DIGEST_LENGTH );245 }246 247 static int248 torrentCompareToHash( const void * va,249 const void * vb )250 {251 const Torrent * a = va;252 const uint8_t * b_hash = vb;253 254 return memcmp( a->hash, b_hash, SHA_DIGEST_LENGTH );255 }256 257 237 static Torrent* 258 238 getExistingTorrent( tr_peerMgr * manager, 259 239 const uint8_t * hash ) 260 240 { 261 return (Torrent*) tr_ptrArrayFindSorted( &manager->torrents,262 hash, 263 torrentCompareToHash );241 tr_torrent * tor = tr_torrentFindFromHash( manager->session, hash ); 242 243 return tor == NULL ? NULL : tor->torrentPeers; 264 244 } 265 245 … … 454 434 455 435 m->session = session; 456 m->torrents = TR_PTR_ARRAY_INIT;457 436 m->incomingHandshakes = TR_PTR_ARRAY_INIT; 458 437 m->bandwidthTimer = tr_timerNew( session, bandwidthPulse, m, BANDWIDTH_PERIOD_MSEC ); … … 474 453 tr_ptrArrayDestruct( &manager->incomingHandshakes, NULL ); 475 454 476 /* free the torrents. */477 tr_ptrArrayDestruct( &manager->torrents, torrentDestructor );478 479 455 managerUnlock( manager ); 480 456 tr_free( manager ); … … 498 474 499 475 tr_bool 500 tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr, 501 const uint8_t * torrentHash, 476 tr_peerMgrPeerIsSeed( const tr_torrent * tor, 502 477 const tr_address * addr ) 503 478 { 504 479 tr_bool isSeed = FALSE; 505 const Torrent * t = NULL; 506 const struct peer_atom * atom = NULL; 507 508 t = getExistingTorrent( (tr_peerMgr*)mgr, torrentHash ); 509 if( t ) 510 atom = getExistingAtom( t, addr ); 480 const Torrent * t = tor->torrentPeers; 481 const struct peer_atom * atom = getExistingAtom( t, addr ); 482 511 483 if( atom ) 512 484 isSeed = ( atom->flags & ADDED_F_SEED_FLAG ) != 0; … … 1063 1035 case TR_PEER_CLIENT_GOT_BLOCK: 1064 1036 { 1065 tr_torrent * 1037 tr_torrent * tor = t->tor; 1066 1038 1067 1039 tr_block_index_t block = _tr_block( tor, e->pieceIndex, e->offset ); … … 1085 1057 tr_torrentSetHasPiece( tor, p, ok ); 1086 1058 tr_torrentSetPieceChecked( tor, p, TRUE ); 1087 tr_peerMgrSetBlame( tor ->session->peerMgr, tor->info.hash, p, ok );1059 tr_peerMgrSetBlame( tor, p, ok ); 1088 1060 1089 1061 if( !ok ) 1062 { 1090 1063 gotBadPiece( t, p ); 1064 } 1091 1065 else 1092 1066 { 1093 1067 int i; 1094 int peerCount = tr_ptrArraySize( &t->peers ); 1095 tr_peer ** peers = (tr_peer**) tr_ptrArrayBase( &t->peers ); 1068 int peerCount; 1069 tr_peer ** peers; 1070 tr_file_index_t fileIndex; 1071 1072 peerCount = tr_ptrArraySize( &t->peers ); 1073 peers = (tr_peer**) tr_ptrArrayBase( &t->peers ); 1096 1074 for( i=0; i<peerCount; ++i ) 1097 1075 tr_peerMsgsHave( peers[i]->msgs, p ); 1076 1077 for( fileIndex=0; fileIndex<tor->info.fileCount; ++fileIndex ) 1078 { 1079 const tr_file * file = &tor->info.files[fileIndex]; 1080 if( ( file->firstPiece <= p ) && ( p <= file->lastPiece ) && tr_cpFileIsComplete( &tor->completion, fileIndex ) ) 1081 { 1082 char * path = tr_buildPath( tor->downloadDir, file->name, NULL ); 1083 tordbg( t, "closing recently-completed file \"%s\"", path ); 1084 tr_fdFileClose( path ); 1085 tr_free( path ); 1086 } 1087 } 1098 1088 } 1099 1089 … … 1316 1306 1317 1307 void 1318 tr_peerMgrAddPex( tr_peerMgr * manager, 1319 const uint8_t * torrentHash, 1308 tr_peerMgrAddPex( tr_torrent * tor, 1320 1309 uint8_t from, 1321 1310 const tr_pex * pex ) … … 1323 1312 if( tr_isPex( pex ) ) /* safeguard against corrupt data */ 1324 1313 { 1325 Torrent * t; 1326 managerLock( manager ); 1327 1328 t = getExistingTorrent( manager, torrentHash ); 1314 Torrent * t = tor->torrentPeers; 1315 managerLock( t->manager ); 1316 1329 1317 if( !tr_sessionIsAddressBlocked( t->manager->session, &pex->addr ) ) 1330 1318 ensureAtomExists( t, &pex->addr, pex->port, pex->flags, from ); 1331 1319 1332 managerUnlock( manager );1320 managerUnlock( t->manager ); 1333 1321 } 1334 1322 } … … 1397 1385 for( i = 0 ; i < n ; i++ ) { 1398 1386 memcpy( &pex[i].addr, walk, sizeof( tr_address ) ); 1387 tr_suspectAddress( &pex[i].addr, "tracker" ); 1399 1388 memcpy( &pex[i].port, walk + sizeof( tr_address ), 2 ); 1400 1389 pex[i].flags = 0x00; … … 1411 1400 1412 1401 void 1413 tr_peerMgrSetBlame( tr_peerMgr * manager, 1414 const uint8_t * torrentHash, 1402 tr_peerMgrSetBlame( tr_torrent * tor, 1415 1403 tr_piece_index_t pieceIndex, 1416 1404 int success ) … … 1419 1407 { 1420 1408 int peerCount, i; 1421 Torrent * t = getExistingTorrent( manager, torrentHash );1409 Torrent * t = tor->torrentPeers; 1422 1410 tr_peer ** peers; 1423 1411 … … 1471 1459 1472 1460 int 1473 tr_peerMgrGetPeers( tr_peerMgr * manager, 1474 const uint8_t * torrentHash, 1461 tr_peerMgrGetPeers( tr_torrent * tor, 1475 1462 tr_pex ** setme_pex, 1476 1463 uint8_t af) 1477 1464 { 1478 1465 int peersReturning = 0; 1479 const Torrent * t; 1480 1481 managerLock( manager ); 1482 1483 t = getExistingTorrent( manager, torrentHash ); 1484 if( t == NULL ) 1485 { 1486 *setme_pex = NULL; 1487 } 1488 else 1466 const Torrent * t = tor->torrentPeers; 1467 1468 managerLock( t->manager ); 1469 1489 1470 { 1490 1471 int i; … … 1521 1502 } 1522 1503 1523 managerUnlock( manager );1504 managerUnlock( t->manager ); 1524 1505 return peersReturning; 1525 1506 } … … 1530 1511 1531 1512 void 1532 tr_peerMgrStartTorrent( tr_peerMgr * manager, 1533 const uint8_t * torrentHash ) 1534 { 1535 Torrent * t; 1536 1537 managerLock( manager ); 1538 1539 t = getExistingTorrent( manager, torrentHash ); 1513 tr_peerMgrStartTorrent( tr_torrent * tor ) 1514 { 1515 Torrent * t = tor->torrentPeers; 1516 1517 managerLock( t->manager ); 1540 1518 1541 1519 assert( t ); … … 1563 1541 } 1564 1542 1565 managerUnlock( manager );1543 managerUnlock( t->manager ); 1566 1544 } 1567 1545 … … 1586 1564 1587 1565 void 1588 tr_peerMgrStopTorrent( tr_peerMgr * manager, 1589 const uint8_t * torrentHash ) 1590 { 1591 managerLock( manager ); 1592 1593 stopTorrent( getExistingTorrent( manager, torrentHash ) ); 1594 1595 managerUnlock( manager ); 1566 tr_peerMgrStopTorrent( tr_torrent * tor ) 1567 { 1568 Torrent * t = tor->torrentPeers; 1569 1570 managerLock( t->manager ); 1571 1572 stopTorrent( t ); 1573 1574 managerUnlock( t->manager ); 1596 1575 } 1597 1576 … … 1600 1579 tr_torrent * tor ) 1601 1580 { 1602 Torrent * t;1603 1604 1581 managerLock( manager ); 1605 1582 1606 1583 assert( tor ); 1607 assert( getExistingTorrent( manager, tor->info.hash ) == NULL ); 1608 1609 t = torrentConstructor( manager, tor ); 1610 tr_ptrArrayInsertSorted( &manager->torrents, t, torrentCompare ); 1584 assert( tor->torrentPeers == NULL ); 1585 1586 tor->torrentPeers = torrentConstructor( manager, tor ); 1611 1587 1612 1588 managerUnlock( manager ); … … 1614 1590 1615 1591 void 1616 tr_peerMgrRemoveTorrent( tr_peerMgr * manager, 1617 const uint8_t * torrentHash ) 1618 { 1619 Torrent * t; 1620 1621 managerLock( manager ); 1622 1623 t = getExistingTorrent( manager, torrentHash ); 1624 assert( t ); 1625 stopTorrent( t ); 1626 tr_ptrArrayRemoveSorted( &manager->torrents, t, torrentCompare ); 1627 torrentDestructor( t ); 1628 1629 managerUnlock( manager ); 1592 tr_peerMgrRemoveTorrent( tr_torrent * tor ) 1593 { 1594 tr_torrentLock( tor ); 1595 1596 stopTorrent( tor->torrentPeers ); 1597 torrentDestructor( tor->torrentPeers ); 1598 1599 tr_torrentUnlock( tor ); 1630 1600 } 1631 1601 1632 1602 void 1633 tr_peerMgrTorrentAvailability( const tr_peerMgr * manager, 1634 const uint8_t * torrentHash, 1635 int8_t * tab, 1603 tr_peerMgrTorrentAvailability( const tr_torrent * tor, 1604 int8_t * tab, 1636 1605 unsigned int tabCount ) 1637 1606 { 1638 1607 tr_piece_index_t i; 1639 1608 const Torrent * t; 1640 const tr_torrent * tor;1641 1609 float interval; 1642 1610 tr_bool isSeed; 1643 1611 int peerCount; 1644 1612 const tr_peer ** peers; 1645 managerLock( manager );1646 1647 t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );1613 tr_torrentLock( tor ); 1614 1615 t = tor->torrentPeers; 1648 1616 tor = t->tor; 1649 1617 interval = tor->info.pieceCount / (float)tabCount; … … 1668 1636 } 1669 1637 1670 managerUnlock( manager );1638 tr_torrentUnlock( tor ); 1671 1639 } 1672 1640 1673 1641 /* Returns the pieces that are available from peers */ 1674 1642 tr_bitfield* 1675 tr_peerMgrGetAvailable( const tr_peerMgr * manager, 1676 const uint8_t * torrentHash ) 1643 tr_peerMgrGetAvailable( const tr_torrent * tor ) 1677 1644 { 1678 1645 int i; 1679 1646 int peerCount; 1680 Torrent * t ;1647 Torrent * t = tor->torrentPeers; 1681 1648 const tr_peer ** peers; 1682 1649 tr_bitfield * pieces; 1683 managerLock( manager ); 1684 1685 t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); 1650 managerLock( t->manager ); 1651 1686 1652 pieces = tr_bitfieldNew( t->tor->info.pieceCount ); 1687 1653 peerCount = tr_ptrArraySize( &t->peers ); … … 1690 1656 tr_bitfieldOr( pieces, peers[i]->have ); 1691 1657 1692 managerUnlock( manager );1658 managerUnlock( t->manager ); 1693 1659 return pieces; 1694 1660 } 1695 1661 1696 int1697 tr_peerMgrHasConnections( const tr_peerMgr * manager,1698 const uint8_t * torrentHash )1699 {1700 int ret;1701 const Torrent * t;1702 managerLock( manager );1703 1704 t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );1705 ret = t && ( !tr_ptrArrayEmpty( &t->peers ) || !tr_ptrArrayEmpty( &t->webseeds ) );1706 1707 managerUnlock( manager );1708 return ret;1709 }1710 1711 1662 void 1712 tr_peerMgrTorrentStats( const tr_peerMgr * manager, 1713 const uint8_t * torrentHash, 1663 tr_peerMgrTorrentStats( tr_torrent * tor, 1714 1664 int * setmePeersKnown, 1715 1665 int * setmePeersConnected, … … 1721 1671 { 1722 1672 int i, size; 1723 const Torrent * t ;1673 const Torrent * t = tor->torrentPeers; 1724 1674 const tr_peer ** peers; 1725 1675 const tr_webseed ** webseeds; 1726 1676 1727 managerLock( manager ); 1728 1729 t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); 1677 managerLock( t->manager ); 1678 1730 1679 peers = (const tr_peer **) tr_ptrArrayBase( &t->peers ); 1731 1680 size = tr_ptrArraySize( &t->peers ); … … 1769 1718 ++*setmeWebseedsSendingToUs; 1770 1719 1771 managerUnlock( manager );1720 managerUnlock( t->manager ); 1772 1721 } 1773 1722 1774 1723 float* 1775 tr_peerMgrWebSpeeds( const tr_peerMgr * manager, 1776 const uint8_t * torrentHash ) 1777 { 1778 const Torrent * t; 1724 tr_peerMgrWebSpeeds( const tr_torrent * tor ) 1725 { 1726 const Torrent * t = tor->torrentPeers; 1779 1727 const tr_webseed ** webseeds; 1780 1728 int i; … … 1783 1731 uint64_t now; 1784 1732 1785 assert( manager ); 1786 managerLock( manager ); 1787 1788 t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); 1733 assert( t->manager ); 1734 managerLock( t->manager ); 1735 1789 1736 webseeds = (const tr_webseed**) tr_ptrArrayBase( &t->webseeds ); 1790 1737 webseedCount = tr_ptrArraySize( &t->webseeds ); 1791 assert( webseedCount == t ->tor->info.webseedCount );1738 assert( webseedCount == tor->info.webseedCount ); 1792 1739 ret = tr_new0( float, webseedCount ); 1793 1740 now = tr_date( ); … … 1797 1744 ret[i] = -1.0; 1798 1745 1799 managerUnlock( manager );1746 managerUnlock( t->manager ); 1800 1747 return ret; 1801 1748 } … … 1809 1756 1810 1757 struct tr_peer_stat * 1811 tr_peerMgrPeerStats( const tr_peerMgr * manager, 1812 const uint8_t * torrentHash, 1758 tr_peerMgrPeerStats( const tr_torrent * tor, 1813 1759 int * setmeCount ) 1814 1760 { 1815 1761 int i, size; 1816 const Torrent * t ;1762 const Torrent * t = tor->torrentPeers; 1817 1763 const tr_peer ** peers; 1818 1764 tr_peer_stat * ret; 1819 1765 uint64_t now; 1820 1766 1821 assert( manager ); 1822 managerLock( manager ); 1823 1824 t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash ); 1767 assert( t->manager ); 1768 managerLock( t->manager ); 1769 1825 1770 size = tr_ptrArraySize( &t->peers ); 1826 1771 peers = (const tr_peer**) tr_ptrArrayBase( &t->peers ); … … 1872 1817 *setmeCount = size; 1873 1818 1874 managerUnlock( manager );1819 managerUnlock( t->manager ); 1875 1820 return ret; 1876 1821 } … … 2352 2297 pumpAllPeers( tr_peerMgr * mgr ) 2353 2298 { 2354 const int torrentCount = tr_ptrArraySize( &mgr->torrents ); 2355 int i, j; 2356 2357 for( i=0; i<torrentCount; ++i ) 2358 { 2359 Torrent * t = tr_ptrArrayNth( &mgr->torrents, i ); 2299 tr_torrent * tor = NULL; 2300 2301 while(( tor = tr_torrentNext( mgr->session, tor ))) 2302 { 2303 int j; 2304 Torrent * t = tor->torrentPeers; 2305 2360 2306 for( j=0; j<tr_ptrArraySize( &t->peers ); ++j ) 2361 2307 { -
branches/1.5x/libtransmission/peer-mgr.h
r7664 r7722 25 25 26 26 #include "net.h" 27 #include "publish.h" /* tr_publisher_tag */ 27 28 28 29 struct tr_peer_stat; … … 47 48 tr_pex; 48 49 50 51 struct tr_bandwidth; 52 struct tr_bitfield; 53 struct tr_peerIo; 54 struct tr_peermsgs; 55 56 enum 57 { 58 ENCRYPTION_PREFERENCE_UNKNOWN, 59 ENCRYPTION_PREFERENCE_YES, 60 ENCRYPTION_PREFERENCE_NO 61 }; 62 63 /** 64 * State information about a connected peer. 65 * 66 * @see struct peer_atom 67 * @see tr_peermsgs 68 */ 69 typedef struct tr_peer 70 { 71 tr_bool peerIsChoked; 72 tr_bool peerIsInterested; 73 tr_bool clientIsChoked; 74 tr_bool clientIsInterested; 75 tr_bool doPurge; 76 77 /* number of bad pieces they've contributed to */ 78 uint8_t strikes; 79 80 uint8_t encryption_preference; 81 tr_port port; 82 tr_address addr; 83 struct tr_peerIo * io; 84 85 struct tr_bitfield * blame; 86 struct tr_bitfield * have; 87 88 /** how complete the peer's copy of the torrent is. [0.0...1.0] */ 89 float progress; 90 91 /* the client name from the `v' string in LTEP's handshake dictionary */ 92 char * client; 93 94 time_t chokeChangedAt; 95 96 struct tr_peermsgs * msgs; 97 tr_publisher_tag msgsTag; 98 } 99 tr_peer; 100 101 49 102 int tr_pexCompare( const void * a, const void * b ); 50 103 … … 53 106 void tr_peerMgrFree( tr_peerMgr * manager ); 54 107 55 tr_bool tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr, 56 const uint8_t * torrentHash, 57 const tr_address * addr ); 108 tr_bool tr_peerMgrPeerIsSeed( const tr_torrent * tor, 109 const tr_address * addr ); 58 110 59 111 void tr_peerMgrAddIncoming( tr_peerMgr * manager, … … 78 130 size_t * setme_pex_count ); 79 131 80 void tr_peerMgrAddPex( tr_peerMgr * manager, 81 const uint8_t * torrentHash, 132 void tr_peerMgrAddPex( tr_torrent * tor, 82 133 uint8_t from, 83 134 const tr_pex * pex ); 84 135 85 void tr_peerMgrSetBlame( tr_peerMgr * manager, 86 const uint8_t * torrentHash, 136 void tr_peerMgrSetBlame( tr_torrent * tor, 87 137 tr_piece_index_t pieceIndex, 88 138 int success ); 89 139 90 int tr_peerMgrGetPeers( tr_peerMgr * manager, 91 const uint8_t * torrentHash, 140 int tr_peerMgrGetPeers( tr_torrent * tor, 92 141 tr_pex ** setme_pex, 93 142 uint8_t af); 94 143 95 void tr_peerMgrStartTorrent( tr_peerMgr * manager, 96 const uint8_t * torrentHash ); 144 void tr_peerMgrStartTorrent( tr_torrent * tor ); 97 145 98 void tr_peerMgrStopTorrent( tr_peerMgr * manager, 99 const uint8_t * torrentHash ); 146 void tr_peerMgrStopTorrent( tr_torrent * tor ); 100 147 101 148 void tr_peerMgrAddTorrent( tr_peerMgr * manager, 102 149 struct tr_torrent * tor ); 103 150 104 void tr_peerMgrRemoveTorrent( tr_peerMgr * manager, 105 const uint8_t * torrentHash ); 151 void tr_peerMgrRemoveTorrent( tr_torrent * tor ); 106 152 107 void tr_peerMgrTorrentAvailability( const tr_peerMgr * manager, 108 const uint8_t * torrentHash, 153 void tr_peerMgrTorrentAvailability( const tr_torrent * tor, 109 154 int8_t * tab, 110 155 unsigned int tabCount ); 111 156 112 struct tr_bitfield* tr_peerMgrGetAvailable( const tr_peerMgr * manager, 113 const uint8_t * torrentHash ); 157 struct tr_bitfield* tr_peerMgrGetAvailable( const tr_torrent * tor ); 114 158 115 int tr_peerMgrHasConnections( const tr_peerMgr * manager, 116 const uint8_t * torrentHash ); 117 118 void tr_peerMgrTorrentStats( const tr_peerMgr * manager, 119 const uint8_t * torrentHash, 159 void tr_peerMgrTorrentStats( tr_torrent * tor, 120 160 int * setmePeersKnown, 121 161 int * setmePeersConnected, … … 126 166 int * setmePeersFrom ); /* TR_PEER_FROM__MAX */ 127 167 128 struct tr_peer_stat* tr_peerMgrPeerStats( const tr_peerMgr * manager, 129 const uint8_t * torrentHash, 130 int * setmeCount ); 168 struct tr_peer_stat* tr_peerMgrPeerStats( const tr_torrent * tor, 169 int * setmeCount ); 131 170 132 float* tr_peerMgrWebSpeeds( const tr_peerMgr * manager, 133 const uint8_t * torrentHash ); 171 float* tr_peerMgrWebSpeeds( const tr_torrent * tor ); 134 172 135 173 174 double tr_peerGetPieceSpeed( const tr_peer * peer, 175 uint64_t now, 176 tr_direction direction ); 177 136 178 #endif -
branches/1.5x/libtransmission/peer-msgs.c
r7669 r7722 31 31 #include "peer-io.h" 32 32 #include "peer-mgr.h" 33 #include "peer-mgr-private.h"34 33 #include "peer-msgs.h" 35 34 #include "platform.h" /* MAX_STACK_ARRAY_SIZE */ … … 1048 1047 uint8_t * tmp = tr_new( uint8_t, msglen ); 1049 1048 tr_benc val; 1050 consttr_torrent * tor = msgs->torrent;1049 tr_torrent * tor = msgs->torrent; 1051 1050 const uint8_t * added; 1052 1051 size_t added_len; … … 1068 1067 &n ); 1069 1068 for( i = 0; i < n; ++i ) 1070 tr_peerMgrAddPex( msgs->session->peerMgr, tor->info.hash, 1071 TR_PEER_FROM_PEX, pex + i ); 1069 tr_peerMgrAddPex( tor, TR_PEER_FROM_PEX, pex + i ); 1072 1070 tr_free( pex ); 1073 1071 } … … 1084 1082 &n ); 1085 1083 for( i = 0; i < n; ++i ) 1086 tr_peerMgrAddPex( msgs->session->peerMgr, tor->info.hash, 1087 TR_PEER_FROM_PEX, pex + i ); 1084 tr_peerMgrAddPex( tor, TR_PEER_FROM_PEX, pex + i ); 1088 1085 tr_free( pex ); 1089 1086 } … … 1624 1621 1625 1622 default: 1623 ret = READ_ERR; 1626 1624 assert( 0 ); 1627 1625 } … … 1915 1913 tr_pex * newPex = NULL; 1916 1914 tr_pex * newPex6 = NULL; 1917 const int newCount = tr_peerMgrGetPeers( msgs->session->peerMgr, 1918 msgs->torrent->info.hash, 1919 &newPex, TR_AF_INET ); 1920 const int newCount6 = tr_peerMgrGetPeers( msgs->session->peerMgr, 1921 msgs->torrent->info.hash, 1922 &newPex6, TR_AF_INET6 ); 1915 const int newCount = tr_peerMgrGetPeers( msgs->torrent, &newPex, TR_AF_INET ); 1916 const int newCount6 = tr_peerMgrGetPeers( msgs->torrent, &newPex6, TR_AF_INET6 ); 1923 1917 1924 1918 /* build the diffs */ … … 1981 1975 for( i = 0; i < diffs.addedCount; ++i ) 1982 1976 { 1977 tr_suspectAddress( &diffs.added[i].addr, "pex" ); 1983 1978 memcpy( walk, &diffs.added[i].addr.addr, 4 ); walk += 4; 1984 1979 memcpy( walk, &diffs.added[i].port, 2 ); walk += 2; … … 2011 2006 for( i = 0; i < diffs6.addedCount; ++i ) 2012 2007 { 2008 tr_suspectAddress( &diffs6.added[i].addr, "pex6" ); 2013 2009 memcpy( walk, &diffs6.added[i].addr.addr.addr6.s6_addr, 16 ); 2014 2010 walk += 16; -
branches/1.5x/libtransmission/port-forwarding.c
r7664 r7722 166 166 incomingPeersPulse( tr_shared * s ) 167 167 { 168 int allPaused; 169 tr_torrent * tor; 168 tr_bool allPaused; 170 169 171 170 if( s->shouldChange ) … … 177 176 } 178 177 179 /* see if any torrents aren't paused */ 180 allPaused = 1; 181 tor = NULL; 182 while( ( tor = tr_torrentNext( s->session, tor ) ) ) 183 { 184 if( TR_STATUS_IS_ACTIVE( tr_torrentGetActivity( tor ) ) ) 185 { 186 allPaused = 0; 187 break; 188 } 189 } 178 allPaused = tr_sessionGetActiveTorrentCount( s->session ) == 0; 190 179 191 180 /* if we have any running torrents, check for new incoming peer connections */ -
branches/1.5x/libtransmission/resume.c
r7684 r7722 69 69 { 70 70 tr_pex * pex = NULL; 71 int count = tr_peerMgrGetPeers( tor->session->peerMgr, 72 tor->info.hash, &pex, TR_AF_INET ); 71 int count = tr_peerMgrGetPeers( (tr_torrent*) tor, &pex, TR_AF_INET ); 73 72 74 73 if( count > 0 ) … … 78 77 pex = NULL; 79 78 80 count = tr_peerMgrGetPeers( tor->session->peerMgr, tor->info.hash, &pex, 81 TR_AF_INET6 ); 79 count = tr_peerMgrGetPeers( (tr_torrent*) tor, &pex, TR_AF_INET6 ); 82 80 if( count > 0 ) 83 81 tr_bencDictAddRaw( dict, KEY_PEERS6, pex, sizeof( tr_pex ) * count ); … … 102 100 tr_pex pex; 103 101 memcpy( &pex, str + ( i * sizeof( tr_pex ) ), sizeof( tr_pex ) ); 104 tr_peerMgrAddPex( tor->session->peerMgr, 105 tor->info.hash, TR_PEER_FROM_CACHE, &pex ); 102 tr_peerMgrAddPex( tor, TR_PEER_FROM_CACHE, &pex ); 106 103 } 107 104 tr_tordbg( tor, "Loaded %d IPv4 peers from resume file", count ); … … 117 114 tr_pex pex; 118 115 memcpy( &pex, str + ( i * sizeof( tr_pex ) ), sizeof( tr_pex ) ); 119 tr_peerMgrAddPex( tor->session->peerMgr, 120 tor->info.hash, TR_PEER_FROM_CACHE, &pex ); 116 tr_peerMgrAddPex( tor, TR_PEER_FROM_CACHE, &pex ); 121 117 } 122 118 tr_tordbg( tor, "Loaded %d IPv6 peers from resume file", count ); -
branches/1.5x/libtransmission/rpc-server.c
r7664 r7722 709 709 tr_rpc_server * 710 710 tr_rpcInit( tr_session * session, 711 tr_bool isEnabled, 712 tr_port port, 713 tr_bool isWhitelistEnabled, 714 const char * whitelist, 715 tr_bool isPasswordEnabled, 716 const char * username, 717 const char * password ) 711 tr_benc * settings ) 718 712 { 719 713 tr_rpc_server * s; 714 tr_bool found; 715 int64_t i; 716 const char *str; 720 717 721 718 s = tr_new0( tr_rpc_server, 1 ); 722 719 s->session = session; 723 s->port = port; 724 s->username = tr_strdup( username ); 725 s->password = tr_strdup( password ); 726 s->isWhitelistEnabled = isWhitelistEnabled; 727 s->isPasswordEnabled = isPasswordEnabled; 728 s->isEnabled = isEnabled != 0; 729 tr_rpcSetWhitelist( s, whitelist ? whitelist : "127.0.0.1" ); 720 721 found = tr_bencDictFindInt( settings, TR_PREFS_KEY_RPC_ENABLED, &i ); 722 assert( found ); 723 s->isEnabled = i != 0; 724 725 found = tr_bencDictFindInt( settings, TR_PREFS_KEY_RPC_PORT, &i ); 726 assert( found ); 727 s->port = i; 728 729 found = tr_bencDictFindInt( settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, &i ); 730 assert( found ); 731 s->isWhitelistEnabled = i != 0; 732 733 found = tr_bencDictFindInt( settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, &i ); 734 assert( found ); 735 s->isPasswordEnabled = i != 0; 736 737 found = tr_bencDictFindStr( settings, TR_PREFS_KEY_RPC_WHITELIST, &str ); 738 assert( found ); 739 tr_rpcSetWhitelist( s, str ? str : "127.0.0.1" ); 740 741 found = tr_bencDictFindStr( settings, TR_PREFS_KEY_RPC_USERNAME, &str ); 742 assert( found ); 743 s->username = tr_strdup( str ); 744 745 found = tr_bencDictFindStr( settings, TR_PREFS_KEY_RPC_PASSWORD, &str ); 746 assert( found ); 747 s->password = tr_strdup( str ); 730 748 731 749 #ifdef HAVE_ZLIB … … 736 754 #endif 737 755 738 if( isEnabled ) 756 if( s->isEnabled ) 757 { 758 tr_ninf( MY_NAME, _( "Serving RPC and Web requests on port %d" ), (int) s->port ); 739 759 tr_runInEventThread( session, startServer, s ); 740 760 741 if( isEnabled ) 742 { 743 tr_ninf( MY_NAME, _( "Serving RPC and Web requests on port %d" ), (int)port ); 744 745 if( isWhitelistEnabled ) 761 if( s->isWhitelistEnabled ) 746 762 tr_ninf( MY_NAME, _( "Whitelist enabled" ) ); 747 763 748 if( isPasswordEnabled )764 if( s->isPasswordEnabled ) 749 765 tr_ninf( MY_NAME, _( "Password required" ) ); 750 766 } -
branches/1.5x/libtransmission/rpc-server.h
r7664 r7722 21 21 22 22 tr_rpc_server * tr_rpcInit( tr_session * session, 23 tr_bool isEnabled, 24 tr_port port, 25 tr_bool isWhitelistEnabled, 26 const char * whitelist, 27 tr_bool isPasswordEnabled, 28 const char * username, 29 const char * password ); 23 tr_benc * settings ); 30 24 31 25 void tr_rpcClose( tr_rpc_server ** freeme ); -
branches/1.5x/libtransmission/rpcimpl.c
r7714 r7722 688 688 tr_benc * args_out ) 689 689 { 690 tr_benc * d; 691 tr_torrent * tor; 692 int running; 693 int total; 694 695 tor = NULL; 696 total = running = 0; 690 int running = 0; 691 int total = 0; 692 tr_torrent * tor = NULL; 693 697 694 while(( tor = tr_torrentNext( session, tor ))) { 698 695 ++total; … … 701 698 } 702 699 703 d = tr_bencDictAddDict( args_out, "session-stats", 5 ); 704 tr_bencDictAddInt( d, "activeTorrentCount", running ); 705 tr_bencDictAddInt( d, "downloadSpeed", (int)( tr_sessionGetPieceSpeed( session, TR_DOWN ) * 1024 ) ); 706 tr_bencDictAddInt( d, "pausedTorrentCount", total - running ); 707 tr_bencDictAddInt( d, "torrentCount", total ); 708 tr_bencDictAddInt( d, "uploadSpeed", (int)( tr_sessionGetPieceSpeed( session, TR_UP ) * 1024 ) ); 700 tr_bencDictAddInt( args_out, "activeTorrentCount", running ); 701 tr_bencDictAddInt( args_out, "downloadSpeed", (int)( tr_sessionGetPieceSpeed( session, TR_DOWN ) * 1024 ) ); 702 tr_bencDictAddInt( args_out, "pausedTorrentCount", total - running ); 703 tr_bencDictAddInt( args_out, "torrentCount", total ); 704 tr_bencDictAddInt( args_out, "uploadSpeed", (int)( tr_sessionGetPieceSpeed( session, TR_UP ) * 1024 ) ); 709 705 return NULL; 710 706 } -
branches/1.5x/libtransmission/session.c
r7664 r7722 238 238 tr_bencDictAddInt( d, TR_PREFS_KEY_PEX_ENABLED, TRUE ); 239 239 tr_bencDictAddInt( d, TR_PREFS_KEY_PORT_FORWARDING, TRUE ); 240 tr_bencDictAddInt( d, TR_PREFS_KEY_PREALLOCATION, TR_PREALLOCATE_SPARSE ); 240 241 tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY, "" ); 241 242 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_AUTH_ENABLED, FALSE ); … … 283 284 tr_bencDictAddInt( d, TR_PREFS_KEY_PEX_ENABLED, s->isPexEnabled ); 284 285 tr_bencDictAddInt( d, TR_PREFS_KEY_PORT_FORWARDING, tr_sessionIsPortForwardingEnabled( s ) ); 286 tr_bencDictAddInt( d, TR_PREFS_KEY_PREALLOCATION, s->preallocationMode ); 285 287 tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY, s->proxy ); 286 288 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_AUTH_ENABLED, s->isProxyAuthEnabled ); … … 370 372 tr_session * session; 371 373 char * filename; 372 int64_t rpc_enabled, whitelist_enabled, rpc_auth_enabled, rpc_port;373 const char * whitelist = NULL, *rpc_passwd = NULL, *rpc_username = NULL;374 374 375 375 assert( tr_bencIsDict( clientSettings ) ); … … 406 406 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ENCRYPTION, &i ); 407 407 assert( found ); 408 assert( tr_isEncryptionMode( i ) ); 408 409 session->encryptionMode = i; 410 411 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PREALLOCATION, &i ); 412 assert( found ); 413 assert( tr_isPreallocationMode( i ) ); 414 session->preallocationMode = i; 409 415 410 416 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_SOCKET_TOS, &i ); … … 528 534 529 535 session->web = tr_webInit( session ); 530 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_RPC_ENABLED, &rpc_enabled ) 531 && tr_bencDictFindInt( &settings, TR_PREFS_KEY_RPC_PORT, &rpc_port ) 532 && tr_bencDictFindInt( &settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, &whitelist_enabled ) 533 && tr_bencDictFindInt( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, &rpc_auth_enabled ) 534 && tr_bencDictFindStr( &settings, TR_PREFS_KEY_RPC_WHITELIST, &whitelist ) 535 && tr_bencDictFindStr( &settings, TR_PREFS_KEY_RPC_USERNAME, &rpc_username ) 536 && tr_bencDictFindStr( &settings, TR_PREFS_KEY_RPC_PASSWORD, &rpc_passwd ); 537 assert( found ); 538 session->rpcServer = tr_rpcInit( session, rpc_enabled, rpc_port, whitelist_enabled, whitelist, 539 rpc_auth_enabled, rpc_username, rpc_passwd ); 536 session->rpcServer = tr_rpcInit( session, &settings ); 540 537 541 538 metainfoLookupRescan( session ); … … 1411 1408 } 1412 1409 1410 int 1411 tr_sessionGetActiveTorrentCount( tr_session * session ) 1412 { 1413 int ret = 0; 1414 tr_torrent * tor = NULL; 1415 1416 while(( tor = tr_torrentNext( session, tor ))) 1417 if( tr_torrentGetActivity( tor ) != TR_STATUS_STOPPED ) 1418 ++ret; 1419 1420 return ret; 1421 } -
branches/1.5x/libtransmission/session.h
r7664 r7722 71 71 72 72 tr_encryption_mode encryptionMode; 73 74 tr_preallocation_mode preallocationMode; 73 75 74 76 struct tr_event_handle * events; -
branches/1.5x/libtransmission/torrent.c
r7688 r7722 206 206 if( event->allAreSeeds ) 207 207 pex[i].flags |= ADDED_F_SEED_FLAG; 208 tr_peerMgrAddPex( tor->session->peerMgr, tor->info.hash, 209 TR_PEER_FROM_TRACKER, pex + i ); 208 tr_peerMgrAddPex( tor, TR_PEER_FROM_TRACKER, pex + i ); 210 209 } 211 210 … … 745 744 &s->downloaders ); 746 745 747 tr_peerMgrTorrentStats( tor->session->peerMgr, 748 tor->info.hash, 746 tr_peerMgrTorrentStats( tor, 749 747 &s->peersKnown, 750 748 &s->peersConnected, … … 800 798 { 801 799 tr_piece_index_t i; 802 tr_bitfield * peerPieces = tr_peerMgrGetAvailable( 803 tor->session->peerMgr, 804 tor->info. 805 hash ); 800 tr_bitfield * peerPieces = tr_peerMgrGetAvailable( tor ); 806 801 s->desiredAvailable = 0; 807 802 for( i = 0; i < tor->info.pieceCount; ++i ) … … 920 915 tr_torrentWebSpeeds( const tr_torrent * tor ) 921 916 { 922 return tor ? tr_peerMgrWebSpeeds( tor->session->peerMgr, tor->info.hash ) 923 : NULL; 917 return tor ? tr_peerMgrWebSpeeds( tor ) : NULL; 924 918 } 925 919 … … 931 925 932 926 if( tor ) 933 ret = tr_peerMgrPeerStats( tor->session->peerMgr, 934 tor->info.hash, peerCount ); 927 ret = tr_peerMgrPeerStats( tor, peerCount ); 935 928 936 929 return ret; … … 949 942 int size ) 950 943 { 951 tr_peerMgrTorrentAvailability( tor->session->peerMgr, 952 tor->info.hash, 953 tab, size ); 944 tr_peerMgrTorrentAvailability( tor, tab, size ); 954 945 } 955 946 … … 1013 1004 tr_globalLock( session ); 1014 1005 1015 tr_peerMgrRemoveTorrent( session->peerMgr, tor->info.hash);1006 tr_peerMgrRemoveTorrent( tor ); 1016 1007 1017 1008 tr_cpDestruct( &tor->completion ); … … 1066 1057 tor->startDate = time( NULL ); 1067 1058 tr_trackerStart( tor->tracker ); 1068 tr_peerMgrStartTorrent( tor ->session->peerMgr, tor->info.hash);1059 tr_peerMgrStartTorrent( tor ); 1069 1060 1070 1061 tr_globalUnlock( tor->session ); … … 1155 1146 1156 1147 tr_verifyRemove( tor ); 1157 tr_peerMgrStopTorrent( tor ->session->peerMgr, tor->info.hash);1148 tr_peerMgrStopTorrent( tor ); 1158 1149 tr_trackerStop( tor->tracker ); 1159 1150 -
branches/1.5x/libtransmission/torrent.h
r7664 r7722 25 25 struct tr_bandwidth; 26 26 struct tr_ratecontrol; 27 struct tr_torrent_peers; 27 28 28 29 /** … … 111 112 time_t* tr_torrentGetMTimes( const tr_torrent * tor, 112 113 size_t * setmeCount ); 114 115 tr_torrent* tr_torrentNext( tr_session * session, 116 tr_torrent * current ); 117 113 118 114 119 typedef enum … … 194 199 195 200 struct tr_bandwidth * bandwidth; 201 202 struct tr_torrent_peers * torrentPeers; 196 203 }; 197 204 -
branches/1.5x/libtransmission/tracker.c
r7719 r7722 260 260 memcpy( &addr.addr.addr4, compactWalk, 4 ); 261 261 memcpy( &port, compactWalk + 4, 2 ); 262 tr_suspectAddress( &addr, "compact" ); 262 263 263 264 memcpy( walk, &addr, sizeof( addr ) ); … … 292 293 memcpy( &port, compactWalk + 16, 2 ); 293 294 compactWalk += 18; 295 tr_suspectAddress( &addr, "compact6" ); 294 296 295 297 memcpy( walk, &addr, sizeof( addr ) ); … … 367 369 368 370 memcpy( walk, &addr, sizeof( tr_address ) ); 371 tr_suspectAddress( &addr, "old tracker" ); 369 372 port = htons( itmp ); 370 373 memcpy( walk + sizeof( tr_address ), &port, 2 ); … … 933 936 934 937 /* upkeep: queue periodic rescrape / reannounce */ 935 for( tor = session->torrentList; tor; tor = tor->next ) 938 tor = NULL; 939 while(( tor = tr_torrentNext( session, tor ))) 936 940 { 937 941 tr_tracker * t = tor->tracker; … … 962 966 if( ( session->tracker ) 963 967 && ( session->tracker->runningCount < 1 ) 964 && ( session->torrentList == NULL) )968 && ( tr_sessionCountTorrents( session ) == 0 ) ) 965 969 { 966 970 tr_trackerSessionClose( session ); -
branches/1.5x/libtransmission/transmission.h
r7664 r7722 107 107 typedef enum 108 108 { 109 TR_PREALLOCATE_NONE = 0, 110 TR_PREALLOCATE_SPARSE = 1, 111 TR_PREALLOCATE_FULL = 2 112 } 113 tr_preallocation_mode; 114 115 static TR_INLINE tr_bool tr_isPreallocationMode( tr_preallocation_mode m ) 116 { 117 return ( m == TR_PREALLOCATE_NONE ) 118 || ( m == TR_PREALLOCATE_SPARSE ) 119 || ( m == TR_PREALLOCATE_FULL ); 120 } 121 122 typedef enum 123 { 109 124 TR_PROXY_HTTP, 110 125 TR_PROXY_SOCKS4, … … 120 135 } 121 136 tr_encryption_mode; 137 138 static TR_INLINE tr_bool tr_isEncryptionMode( tr_encryption_mode m ) 139 { 140 return ( m == TR_CLEAR_PREFERRED ) 141 || ( m == TR_ENCRYPTION_PREFERRED ) 142 || ( m == TR_ENCRYPTION_REQUIRED ); 143 } 144 122 145 123 146 #define TR_DEFAULT_OPEN_FILE_LIMIT_STR "32" … … 147 170 #define TR_PREFS_KEY_PORT_FORWARDING "port-forwarding-enabled" 148 171 #define TR_PREFS_KEY_PROXY_AUTH_ENABLED "proxy-auth-enabled" 172 #define TR_PREFS_KEY_PREALLOCATION "preallocation" 149 173 #define TR_PREFS_KEY_PROXY_ENABLED "proxy-enabled" 150 174 #define TR_PREFS_KEY_PROXY_PASSWORD "proxy-auth-password" … … 564 588 int * setmeCount ); 565 589 590 int tr_sessionGetActiveTorrentCount( tr_session * session ); 591 566 592 /** @} */ 567 593 … … 817 843 */ 818 844 void tr_torrentDeleteLocalData( tr_torrent * torrent, tr_fileFunc fileFunc ); 819 820 /**821 * @brief Iterate through the torrents.822 *823 * Pass in a NULL pointer to get the first torrent.824 */825 tr_torrent* tr_torrentNext( tr_session * session,826 tr_torrent * current );827 828 845 829 846 uint64_t tr_torrentGetBytesLeftToAllocate( const tr_torrent * torrent ); -
branches/1.5x/libtransmission/web.c
r7664 r7722 129 129 curl_easy_setopt( easy, CURLOPT_CONNECTTIMEOUT, 120L ); 130 130 curl_easy_setopt( easy, CURLOPT_FOLLOWLOCATION, 1L ); 131 curl_easy_setopt( easy, CURLOPT_FORBID_REUSE, 1L ); 131 132 curl_easy_setopt( easy, CURLOPT_NOSIGNAL, 1L ); 132 133 curl_easy_setopt( easy, CURLOPT_PRIVATE, task );
Note: See TracChangeset
for help on using the changeset viewer.