mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 09:39:08 +01:00
(trunk libT) #2632 "Add streaming capability to libtransmission (but not the Transmission GUI clients)" -- implemented
This commit is contained in:
@@ -11,10 +11,8 @@
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <string.h> /* memcpy, memcmp, strstr */
|
||||
#include <stdlib.h> /* qsort */
|
||||
#include <limits.h> /* INT_MAX */
|
||||
|
||||
#include <event.h>
|
||||
|
||||
@@ -154,7 +152,7 @@ struct block_request
|
||||
struct weighted_piece
|
||||
{
|
||||
tr_piece_index_t index;
|
||||
int16_t salt;
|
||||
tr_piece_index_t salt;
|
||||
int16_t requestCount;
|
||||
};
|
||||
|
||||
@@ -778,7 +776,11 @@ comparePieceByWeight( const void * va, const void * vb )
|
||||
if( ia < ib ) return 1;
|
||||
|
||||
/* tertiary key: random */
|
||||
return a->salt - b->salt;
|
||||
if( a->salt < b->salt ) return -1;
|
||||
if( a->salt > b->salt ) return 1;
|
||||
|
||||
/* okay, they're equal */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -857,6 +859,7 @@ pieceListRebuild( Torrent * t )
|
||||
tr_piece_index_t poolCount = 0;
|
||||
const tr_torrent * tor = t->tor;
|
||||
const tr_info * inf = tr_torrentInfo( tor );
|
||||
const tr_bool isStreaming = tr_torrentIsStreaming( tor );
|
||||
struct weighted_piece * pieces;
|
||||
int pieceCount;
|
||||
|
||||
@@ -872,7 +875,8 @@ pieceListRebuild( Torrent * t )
|
||||
struct weighted_piece * piece = pieces + i;
|
||||
piece->index = pool[i];
|
||||
piece->requestCount = 0;
|
||||
piece->salt = tr_cryptoWeakRandInt( 255 );
|
||||
piece->salt = isStreaming ? piece->index
|
||||
: (tr_piece_index_t)tr_cryptoWeakRandInt( 4096 );
|
||||
}
|
||||
|
||||
/* if we already had a list of pieces, merge it into
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#define KEY_SPEEDLIMIT_OLD "speed-limit"
|
||||
#define KEY_SPEEDLIMIT_UP "speed-limit-up"
|
||||
#define KEY_SPEEDLIMIT_DOWN "speed-limit-down"
|
||||
#define KEY_STREAMING "streaming"
|
||||
#define KEY_RATIOLIMIT "ratio-limit"
|
||||
#define KEY_UPLOADED "uploaded"
|
||||
|
||||
@@ -503,7 +504,7 @@ tr_torrentSaveResume( const tr_torrent * tor )
|
||||
|
||||
tr_tordbg( tor, "Saving .resume file for \"%s\"", tr_torrentName( tor ) );
|
||||
|
||||
tr_bencInitDict( &top, 33 ); /* arbitrary "big enough" number */
|
||||
tr_bencInitDict( &top, 34 ); /* arbitrary "big enough" number */
|
||||
tr_bencDictAddInt( &top, KEY_ACTIVITY_DATE, tor->activityDate );
|
||||
tr_bencDictAddInt( &top, KEY_ADDED_DATE, tor->addedDate );
|
||||
tr_bencDictAddInt( &top, KEY_CORRUPT, tor->corruptPrev + tor->corruptCur );
|
||||
@@ -516,6 +517,7 @@ tr_torrentSaveResume( const tr_torrent * tor )
|
||||
tr_bencDictAddInt( &top, KEY_MAX_PEERS, tor->maxConnectedPeers );
|
||||
tr_bencDictAddInt( &top, KEY_BANDWIDTH_PRIORITY, tr_torrentGetPriority( tor ) );
|
||||
tr_bencDictAddBool( &top, KEY_PAUSED, !tor->isRunning );
|
||||
tr_bencDictAddBool( &top, KEY_STREAMING, tr_torrentIsStreaming( tor ) );
|
||||
savePeers( &top, tor );
|
||||
saveFilePriorities( &top, tor );
|
||||
saveDND( &top, tor );
|
||||
@@ -609,6 +611,13 @@ loadFromFile( tr_torrent * tor,
|
||||
fieldsLoaded |= TR_FR_RUN;
|
||||
}
|
||||
|
||||
if( ( fieldsToLoad & TR_FR_STREAMING )
|
||||
&& tr_bencDictFindBool( &top, KEY_STREAMING, &boolVal ) )
|
||||
{
|
||||
tor->isStreaming = boolVal;
|
||||
fieldsLoaded |= TR_FR_STREAMING;
|
||||
}
|
||||
|
||||
if( ( fieldsToLoad & TR_FR_ADDED_DATE )
|
||||
&& tr_bencDictFindInt( &top, KEY_ADDED_DATE, &i ) )
|
||||
{
|
||||
|
||||
@@ -35,7 +35,8 @@ enum
|
||||
TR_FR_ADDED_DATE = ( 1 << 13 ),
|
||||
TR_FR_DONE_DATE = ( 1 << 14 ),
|
||||
TR_FR_ACTIVITY_DATE = ( 1 << 15 ),
|
||||
TR_FR_RATIOLIMIT = ( 1 << 16 )
|
||||
TR_FR_RATIOLIMIT = ( 1 << 16 ),
|
||||
TR_FR_STREAMING = ( 1 << 17 )
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1890,6 +1890,28 @@ tr_torrentSetPriority( tr_torrent * tor, tr_priority_t priority )
|
||||
****
|
||||
***/
|
||||
|
||||
tr_bool
|
||||
tr_torrentIsStreaming( const tr_torrent * tor )
|
||||
{
|
||||
assert( tr_isTorrent( tor ) );
|
||||
assert( tr_isBool( tor->isStreaming ) );
|
||||
|
||||
return tor->isStreaming;
|
||||
}
|
||||
|
||||
void
|
||||
tr_torrentSetStreaming( tr_torrent * tor, tr_bool isStreaming )
|
||||
{
|
||||
assert( tr_isTorrent( tor ) );
|
||||
assert( tr_isBool( isStreaming ) );
|
||||
|
||||
tor->isStreaming = isStreaming;
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
void
|
||||
tr_torrentSetPeerLimit( tr_torrent * tor,
|
||||
uint16_t maxConnectedPeers )
|
||||
|
||||
@@ -226,6 +226,7 @@ struct tr_torrent
|
||||
tr_torrent_ratio_limit_hit_func * ratio_limit_hit_func;
|
||||
void * ratio_limit_hit_func_user_data;
|
||||
|
||||
tr_bool isStreaming;
|
||||
tr_bool isRunning;
|
||||
tr_bool isDeleting;
|
||||
tr_bool needsSeedRatioCheck;
|
||||
|
||||
@@ -707,9 +707,6 @@ uint16_t tr_sessionGetPeerLimit( const tr_session * );
|
||||
void tr_sessionSetPeerLimitPerTorrent( tr_session *, uint16_t maxGlobalPeers );
|
||||
uint16_t tr_sessionGetPeerLimitPerTorrent( const tr_session * );
|
||||
|
||||
tr_priority_t tr_torrentGetPriority( const tr_torrent * );
|
||||
void tr_torrentSetPriority( tr_torrent *, tr_priority_t );
|
||||
|
||||
|
||||
/**
|
||||
* Load all the torrents in tr_getTorrentDir().
|
||||
@@ -1075,6 +1072,12 @@ void tr_torrentUseSessionLimits ( tr_torrent *, tr_bool );
|
||||
tr_bool tr_torrentUsesSessionLimits ( const tr_torrent * );
|
||||
|
||||
|
||||
tr_priority_t tr_torrentGetPriority( const tr_torrent * );
|
||||
void tr_torrentSetPriority( tr_torrent *, tr_priority_t );
|
||||
|
||||
tr_bool tr_torrentIsStreaming( const tr_torrent * );
|
||||
void tr_torrentSetStreaming( tr_torrent *, tr_bool );
|
||||
|
||||
/****
|
||||
***** Ratio Limits
|
||||
****/
|
||||
|
||||
Reference in New Issue
Block a user